S2-LP: astyle run done

pull/8585/head
Jarkko Paso 2018-10-30 15:52:51 +02:00
parent ef1e121937
commit 3916c0ba5e
3 changed files with 147 additions and 148 deletions

View File

@ -140,7 +140,7 @@ RFPins::RFPins(PinName spi_sdi, PinName spi_sdo,
#endif //TEST_GPIOS_ENABLED #endif //TEST_GPIOS_ENABLED
PinName spi_gpio0, PinName spi_gpio1, PinName spi_gpio2, PinName spi_gpio0, PinName spi_gpio1, PinName spi_gpio2,
PinName spi_gpio3) PinName spi_gpio3)
: spi(spi_sdi, spi_sdo, spi_sclk), : spi(spi_sdi, spi_sdo, spi_sclk),
CS(spi_cs), CS(spi_cs),
SDN(spi_sdn), SDN(spi_sdn),
#ifdef TEST_GPIOS_ENABLED #ifdef TEST_GPIOS_ENABLED
@ -155,7 +155,7 @@ RFPins::RFPins(PinName spi_sdi, PinName spi_sdo,
GPIO2(spi_gpio2), GPIO2(spi_gpio2),
GPIO3(spi_gpio3) GPIO3(spi_gpio3)
#ifdef MBED_CONF_RTOS_PRESENT #ifdef MBED_CONF_RTOS_PRESENT
,irq_thread(osPriorityRealtime, 1024) , irq_thread(osPriorityRealtime, 1024)
#endif //MBED_CONF_RTOS_PRESENT #endif //MBED_CONF_RTOS_PRESENT
{ {
#ifdef MBED_CONF_RTOS_PRESENT #ifdef MBED_CONF_RTOS_PRESENT
@ -322,7 +322,7 @@ static void rf_write_register_field(uint8_t addr, uint8_t field, uint8_t value)
static s2lp_states_e rf_read_state(void) static s2lp_states_e rf_read_state(void)
{ {
return (s2lp_states_e) (rf_read_register_with_status(MC_STATE0, NULL) >> 1); return (s2lp_states_e)(rf_read_register_with_status(MC_STATE0, NULL) >> 1);
} }
static void rf_poll_state_change(s2lp_states_e state) static void rf_poll_state_change(s2lp_states_e state)
@ -338,7 +338,7 @@ static void rf_poll_state_change(s2lp_states_e state)
static void rf_enable_gpio_signal(uint8_t gpio_pin, uint8_t interrupt_signal, uint8_t gpio_mode) static void rf_enable_gpio_signal(uint8_t gpio_pin, uint8_t interrupt_signal, uint8_t gpio_mode)
{ {
rf_write_register(GPIO0_CONF+gpio_pin, (interrupt_signal<<3) | gpio_mode); rf_write_register(GPIO0_CONF + gpio_pin, (interrupt_signal << 3) | gpio_mode);
} }
static void rf_enable_interrupt(uint8_t event) static void rf_enable_interrupt(uint8_t event)
@ -434,8 +434,8 @@ static uint8_t rf_read_rx_fifo(uint8_t *ptr, uint16_t length)
static void rf_write_packet_length(uint16_t packet_length) static void rf_write_packet_length(uint16_t packet_length)
{ {
rf_write_register(PCKTLEN1, packet_length/256); rf_write_register(PCKTLEN1, packet_length / 256);
rf_write_register(PCKTLEN0, packet_length%256); rf_write_register(PCKTLEN0, packet_length % 256);
} }
static uint32_t read_irq_status(void) static uint32_t read_irq_status(void)
@ -463,7 +463,7 @@ static void rf_init_registers(void)
rf_conf_calculate_datarate_registers(phy_subghz.datarate, &datarate_m, &datarate_e); rf_conf_calculate_datarate_registers(phy_subghz.datarate, &datarate_m, &datarate_e);
rf_write_register_field(MOD2, DATARATE_E_FIELD, datarate_e); rf_write_register_field(MOD2, DATARATE_E_FIELD, datarate_e);
rf_write_register(MOD3, (uint8_t)datarate_m); rf_write_register(MOD3, (uint8_t)datarate_m);
rf_write_register(MOD4, datarate_m>>8); rf_write_register(MOD4, datarate_m >> 8);
// Set RX filter bandwidth // Set RX filter bandwidth
uint8_t chflt_m, chflt_e; uint8_t chflt_m, chflt_e;
rf_conf_calculate_rx_filter_bandwidth_registers(RX_FILTER_BANDWIDTH, &chflt_m, &chflt_e); rf_conf_calculate_rx_filter_bandwidth_registers(RX_FILTER_BANDWIDTH, &chflt_m, &chflt_e);
@ -480,7 +480,7 @@ static void rf_init_registers(void)
// Set channel spacing // Set channel spacing
uint8_t ch_space; uint8_t ch_space;
uint8_t ch_space_divider = 1; uint8_t ch_space_divider = 1;
while (rf_conf_calculate_channel_spacing_registers(phy_subghz.channel_spacing/ch_space_divider, &ch_space)) { while (rf_conf_calculate_channel_spacing_registers(phy_subghz.channel_spacing / ch_space_divider, &ch_space)) {
ch_space_divider++; ch_space_divider++;
rf_channel_multiplier++; rf_channel_multiplier++;
} }
@ -557,11 +557,11 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
*data_ptr = true; *data_ptr = true;
break; break;
case PHY_EXTENSION_GET_TIMESTAMP: case PHY_EXTENSION_GET_TIMESTAMP:
timer_value = (uint32_t*)data_ptr; timer_value = (uint32_t *)data_ptr;
*timer_value = rf_get_timestamp(); *timer_value = rf_get_timestamp();
break; break;
case PHY_EXTENSION_SET_CSMA_PARAMETERS: case PHY_EXTENSION_SET_CSMA_PARAMETERS:
csma_params = (phy_csma_params_t*)data_ptr; csma_params = (phy_csma_params_t *)data_ptr;
if (csma_params->backoff_time == 0) { if (csma_params->backoff_time == 0) {
rf_cca_timer_stop(); rf_cca_timer_stop();
if (rf_read_register_with_status(TX_FIFO_STATUS, NULL)) { if (rf_read_register_with_status(TX_FIFO_STATUS, NULL)) {
@ -581,12 +581,12 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
} }
break; break;
case PHY_EXTENSION_READ_TX_FINNISH_TIME: case PHY_EXTENSION_READ_TX_FINNISH_TIME:
timer_value = (uint32_t*)data_ptr; timer_value = (uint32_t *)data_ptr;
*timer_value = tx_finnish_time; *timer_value = tx_finnish_time;
break; break;
case PHY_EXTENSION_GET_SYMBOLS_PER_SECOND: case PHY_EXTENSION_GET_SYMBOLS_PER_SECOND:
timer_value = (uint32_t*)data_ptr; timer_value = (uint32_t *)data_ptr;
*timer_value = symbols_in_seconds; *timer_value = symbols_in_seconds;
break; break;
@ -601,8 +601,7 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_t rf_channel) static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_t rf_channel)
{ {
int8_t ret_val = 0; int8_t ret_val = 0;
switch (new_state) switch (new_state) {
{
/*Reset PHY driver and set to idle*/ /*Reset PHY driver and set to idle*/
case PHY_INTERFACE_RESET: case PHY_INTERFACE_RESET:
break; break;
@ -632,7 +631,7 @@ static void rf_tx_sent_handler(void)
TEST_TX_DONE TEST_TX_DONE
rf_state = RF_IDLE; rf_state = RF_IDLE;
rf_receive(rf_rx_channel); rf_receive(rf_rx_channel);
if(device_driver.phy_tx_done_cb){ if (device_driver.phy_tx_done_cb) {
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_TX_SUCCESS, 0, 0); device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_TX_SUCCESS, 0, 0);
} }
} else { } else {
@ -645,7 +644,7 @@ static void rf_tx_threshold_handler(void)
{ {
rf_disable_interrupt(TX_FIFO_ALMOST_EMPTY); rf_disable_interrupt(TX_FIFO_ALMOST_EMPTY);
// TODO check the FIFO threshold. By default, threshold is half of the FIFO size // TODO check the FIFO threshold. By default, threshold is half of the FIFO size
uint8_t written_length = rf_write_tx_fifo(tx_data_ptr, tx_data_length, FIFO_SIZE/2); uint8_t written_length = rf_write_tx_fifo(tx_data_ptr, tx_data_length, FIFO_SIZE / 2);
if (written_length < tx_data_length) { if (written_length < tx_data_length) {
tx_data_ptr += written_length; tx_data_ptr += written_length;
tx_data_length -= written_length; tx_data_length -= written_length;
@ -761,7 +760,7 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h
tx_sequence = *(data_ptr + 2); tx_sequence = *(data_ptr + 2);
} }
// TODO: Define this better // TODO: Define this better
rf_write_packet_length(data_length+4); rf_write_packet_length(data_length + 4);
mac_tx_handle = tx_handle; mac_tx_handle = tx_handle;
if (tx_time) { if (tx_time) {
uint32_t backoff_time = tx_time - rf_get_timestamp(); uint32_t backoff_time = tx_time - rf_get_timestamp();
@ -789,7 +788,7 @@ static void rf_send_ack(uint8_t seq)
rf_state = RF_TX_ACK; rf_state = RF_TX_ACK;
uint8_t ack_frame[3] = {MAC_TYPE_ACK, 0, seq}; uint8_t ack_frame[3] = {MAC_TYPE_ACK, 0, seq};
rf_write_tx_fifo(ack_frame, sizeof(ack_frame), FIFO_SIZE); rf_write_tx_fifo(ack_frame, sizeof(ack_frame), FIFO_SIZE);
rf_write_packet_length(sizeof(ack_frame)+4); rf_write_packet_length(sizeof(ack_frame) + 4);
tx_data_ptr = NULL; tx_data_ptr = NULL;
rf_start_tx(); rf_start_tx();
TEST_ACK_TX_STARTED TEST_ACK_TX_STARTED
@ -824,7 +823,7 @@ static void rf_rx_ready_handler(void)
} else if (rf_rx_filter(rx_buffer, s2lp_MAC, s2lp_short_address, s2lp_PAN_ID)) { } else if (rf_rx_filter(rx_buffer, s2lp_MAC, s2lp_short_address, s2lp_PAN_ID)) {
rf_state = RF_IDLE; rf_state = RF_IDLE;
int8_t rssi = (rf_read_register_with_status(RSSI_LEVEL, NULL) - RSSI_OFFSET); int8_t rssi = (rf_read_register_with_status(RSSI_LEVEL, NULL) - RSSI_OFFSET);
if( device_driver.phy_rx_cb ){ if (device_driver.phy_rx_cb) {
device_driver.phy_rx_cb(rx_buffer, rx_data_length, 0xf0, rssi, rf_radio_driver_id); device_driver.phy_rx_cb(rx_buffer, rx_data_length, 0xf0, rssi, rf_radio_driver_id);
} }
// Check Ack request // Check Ack request
@ -862,7 +861,7 @@ static void rf_receive(uint8_t rx_channel)
rf_send_command(S2LP_CMD_FLUSHRXFIFO); rf_send_command(S2LP_CMD_FLUSHRXFIFO);
rf_poll_state_change(S2LP_STATE_READY); rf_poll_state_change(S2LP_STATE_READY);
if (rx_channel != rf_rx_channel) { if (rx_channel != rf_rx_channel) {
rf_write_register(CHNUM, rx_channel*rf_channel_multiplier); rf_write_register(CHNUM, rx_channel * rf_channel_multiplier);
rf_rx_channel = rf_new_channel = rx_channel; rf_rx_channel = rf_new_channel = rx_channel;
} }
rf_state_change(S2LP_STATE_LOCK, false); rf_state_change(S2LP_STATE_LOCK, false);
@ -1005,7 +1004,7 @@ static int8_t rf_device_register(const uint8_t *mac_addr)
rf_init(); rf_init();
/*Set pointer to MAC address*/ /*Set pointer to MAC address*/
device_driver.PHY_MAC = (uint8_t *)mac_addr; device_driver.PHY_MAC = (uint8_t *)mac_addr;
device_driver.driver_description = (char*)"S2LP_MAC"; device_driver.driver_description = (char *)"S2LP_MAC";
device_driver.link_type = PHY_LINK_15_4_SUBGHZ_TYPE; device_driver.link_type = PHY_LINK_15_4_SUBGHZ_TYPE;
device_driver.phy_channel_pages = phy_channel_pages; device_driver.phy_channel_pages = phy_channel_pages;
device_driver.phy_MTU = RF_MTU; device_driver.phy_MTU = RF_MTU;
@ -1084,7 +1083,7 @@ NanostackRfPhys2lp::NanostackRfPhys2lp(PinName spi_sdi, PinName spi_sdo, PinName
PinName spi_test1, PinName spi_test2, PinName spi_test3, PinName spi_test4, PinName spi_test5, PinName spi_test1, PinName spi_test2, PinName spi_test3, PinName spi_test4, PinName spi_test5,
#endif //TEST_GPIOS_ENABLED #endif //TEST_GPIOS_ENABLED
PinName spi_gpio0, PinName spi_gpio1, PinName spi_gpio2, PinName spi_gpio3) PinName spi_gpio0, PinName spi_gpio1, PinName spi_gpio2, PinName spi_gpio3)
: _mac_addr(), _rf(NULL), _mac_set(false), : _mac_addr(), _rf(NULL), _mac_set(false),
_spi_sdi(spi_sdi), _spi_sdo(spi_sdo), _spi_sclk(spi_sclk), _spi_cs(spi_cs), _spi_sdn(spi_sdn), _spi_sdi(spi_sdi), _spi_sdo(spi_sdo), _spi_sclk(spi_sclk), _spi_cs(spi_cs), _spi_sdn(spi_sdn),
#ifdef TEST_GPIOS_ENABLED #ifdef TEST_GPIOS_ENABLED
_spi_test1(spi_test1), _spi_test2(spi_test2), _spi_test3(spi_test3), _spi_test4(spi_test4), _spi_test5(spi_test5), _spi_test1(spi_test1), _spi_test2(spi_test2), _spi_test3(spi_test3), _spi_test4(spi_test4), _spi_test5(spi_test5),

View File

@ -40,9 +40,9 @@ void rf_conf_calculate_datarate_registers(uint32_t datarate, uint16_t *datarate_
uint8_t datarate_e = 1; uint8_t datarate_e = 1;
while (datarate_m >= DEF_2EXP16) { while (datarate_m >= DEF_2EXP16) {
datarate_e++; datarate_e++;
uint16_t var_2exp_datarate_e = (uint32_t)2 << (datarate_e-1); uint16_t var_2exp_datarate_e = (uint32_t)2 << (datarate_e - 1);
datarate_m = (uint64_t)datarate * DEF_2EXP33; datarate_m = (uint64_t)datarate * DEF_2EXP33;
datarate_m = datarate_m/((uint64_t)var_2exp_datarate_e*F_DIG); datarate_m = datarate_m / ((uint64_t)var_2exp_datarate_e * F_DIG);
datarate_m -= DEF_2EXP16; datarate_m -= DEF_2EXP16;
} }
*datarate_mantissa = datarate_m; *datarate_mantissa = datarate_m;
@ -52,7 +52,7 @@ void rf_conf_calculate_datarate_registers(uint32_t datarate, uint16_t *datarate_
void rf_conf_calculate_base_frequency_registers(uint32_t frequency, uint8_t *synt3, uint8_t *synt2, uint8_t *synt1, uint8_t *synt0) void rf_conf_calculate_base_frequency_registers(uint32_t frequency, uint8_t *synt3, uint8_t *synt2, uint8_t *synt1, uint8_t *synt0)
{ {
uint64_t freq_tmp = (uint64_t)frequency * RESOLUTION_MULTIPLIER; uint64_t freq_tmp = (uint64_t)frequency * RESOLUTION_MULTIPLIER;
freq_tmp = (freq_tmp / (F_XO/((BAND_SELECTOR/2)*REF_DIVIDER))); freq_tmp = (freq_tmp / (F_XO / ((BAND_SELECTOR / 2) * REF_DIVIDER)));
freq_tmp *= DEF_2EXP20; freq_tmp *= DEF_2EXP20;
freq_tmp /= RESOLUTION_MULTIPLIER; freq_tmp /= RESOLUTION_MULTIPLIER;
*synt3 = (uint8_t)(freq_tmp >> 24); *synt3 = (uint8_t)(freq_tmp >> 24);
@ -68,10 +68,10 @@ void rf_conf_calculate_deviation_registers(uint32_t deviation, uint8_t *fdev_m,
while (fdev_m_tmp > 255) { while (fdev_m_tmp > 255) {
fdev_e_tmp++; fdev_e_tmp++;
uint16_t var_2exp_datarate_e_minus_1 = (uint16_t)2 << ((fdev_e_tmp-1)-1); uint16_t var_2exp_datarate_e_minus_1 = (uint16_t)2 << ((fdev_e_tmp - 1) - 1);
fdev_m_tmp = (uint64_t)deviation * RESOLUTION_MULTIPLIER; fdev_m_tmp = (uint64_t)deviation * RESOLUTION_MULTIPLIER;
fdev_m_tmp = (((fdev_m_tmp/F_XO) * DEF_2EXP19 * BAND_SELECTOR * REF_DIVIDER * (8/BAND_SELECTOR))/var_2exp_datarate_e_minus_1); fdev_m_tmp = (((fdev_m_tmp / F_XO) * DEF_2EXP19 * BAND_SELECTOR * REF_DIVIDER * (8 / BAND_SELECTOR)) / var_2exp_datarate_e_minus_1);
fdev_m_tmp += RESOLUTION_MULTIPLIER/2; fdev_m_tmp += RESOLUTION_MULTIPLIER / 2;
fdev_m_tmp /= RESOLUTION_MULTIPLIER; fdev_m_tmp /= RESOLUTION_MULTIPLIER;
fdev_m_tmp -= 256; fdev_m_tmp -= 256;
} }
@ -84,7 +84,7 @@ int rf_conf_calculate_channel_spacing_registers(uint32_t channel_spacing, uint8_
uint64_t ch_space_tmp = (uint64_t)channel_spacing * RESOLUTION_MULTIPLIER; uint64_t ch_space_tmp = (uint64_t)channel_spacing * RESOLUTION_MULTIPLIER;
ch_space_tmp /= F_XO; ch_space_tmp /= F_XO;
ch_space_tmp *= DEF_2EXP15; ch_space_tmp *= DEF_2EXP15;
ch_space_tmp += RESOLUTION_MULTIPLIER/2; ch_space_tmp += RESOLUTION_MULTIPLIER / 2;
ch_space_tmp /= RESOLUTION_MULTIPLIER; ch_space_tmp /= RESOLUTION_MULTIPLIER;
// Check if channel spacing is too high // Check if channel spacing is too high
if (ch_space_tmp > 255) { if (ch_space_tmp > 255) {
@ -104,35 +104,35 @@ void rf_conf_calculate_rx_filter_bandwidth_registers(uint32_t rx_bandwidth, uint
uint8_t chflt_e_tmp = 0; uint8_t chflt_e_tmp = 0;
uint8_t chflt_m_tmp = 0; uint8_t chflt_m_tmp = 0;
while (rx_bandwidth < 900000/(2 << chflt_e_tmp)) { while (rx_bandwidth < 900000 / (2 << chflt_e_tmp)) {
chflt_e_tmp++; chflt_e_tmp++;
} }
uint32_t rx_bandwidth_tmp = rx_bandwidth; uint32_t rx_bandwidth_tmp = rx_bandwidth;
if (chflt_e_tmp > 0) { if (chflt_e_tmp > 0) {
rx_bandwidth_tmp = rx_bandwidth * (2 << (chflt_e_tmp - 1)); rx_bandwidth_tmp = rx_bandwidth * (2 << (chflt_e_tmp - 1));
} }
if ( 852000 > rx_bandwidth_tmp ) { if (852000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 806000 > rx_bandwidth_tmp ) { if (806000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 760000 > rx_bandwidth_tmp ) { if (760000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 724000 > rx_bandwidth_tmp ) { if (724000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 682000 > rx_bandwidth_tmp ) { if (682000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 650000 > rx_bandwidth_tmp ) { if (650000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 588000 > rx_bandwidth_tmp ) { if (588000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
if ( 542000 > rx_bandwidth_tmp ) { if (542000 > rx_bandwidth_tmp) {
chflt_m_tmp++; chflt_m_tmp++;
} }
*chflt_m = chflt_m_tmp; *chflt_m = chflt_m_tmp;