void radio_sb_init( hal_nrf_operation_mode_t operational_mode ) { if( !bus_initialized ) radio_bus_init(); switch( operational_mode ) { case HAL_NRF_PRX: radio_mode = DEVICE_PRX_SB; break; case HAL_NRF_PTX: radio_mode = DEVICE_PTX_SB; break; } hal_nrf_close_pipe(HAL_NRF_ALL); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe(HAL_NRF_PIPE0, false); // Open pipe0, without/autoack hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT); // Operates in 16bits CRC mode hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY); // Disables auto retransmit hal_nrf_set_address_width(HAL_NRF_AW_5BYTES); // 5 bytes address width hal_nrf_set_address(HAL_NRF_TX, address); // Set device's addresses hal_nrf_set_address(HAL_NRF_PIPE0, address); // Sets recieving address on // pipe0 if(operational_mode == HAL_NRF_PTX) // Mode depentant settings { hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter TX mode } else { hal_nrf_set_operation_mode(HAL_NRF_PRX); // Enter RX mode hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel(RF_CHANNEL); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up device //hal_nrf_set_datarate(HAL_NRF_1MBPS); // Uncomment this line for // compatibility with nRF2401 // and nRF24E1 radio_wait(); radio_set_status (RF_IDLE); // Radio now ready }
void radio_esb_init( hal_nrf_operation_mode_t operational_mode ) { if( !bus_initialized ) radio_bus_init(); switch( operational_mode ) { case HAL_NRF_PRX: radio_mode = DEVICE_PRX_ESB; break; case HAL_NRF_PTX: radio_mode = DEVICE_PTX_ESB; break; } hal_nrf_close_pipe( HAL_NRF_ALL ); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe( HAL_NRF_PIPE0, true ); // Then open pipe0, w/autoack // Changed from sb/radio_sb.c hal_nrf_set_crc_mode( HAL_NRF_CRC_16BIT ); // Operates in 16bits CRC mode hal_nrf_set_auto_retr( RF_RETRANSMITS, RF_RETRANS_DELAY ); // Enables auto retransmit. // 3 retrans with 250ms delay // Changed from sb/radio_sb.c hal_nrf_set_address_width( HAL_NRF_AW_5BYTES ); // 5 bytes address width hal_nrf_set_address( HAL_NRF_TX, address ); // Set device's addresses hal_nrf_set_address( HAL_NRF_PIPE0, address ); // Sets recieving address on // pipe0 if( operational_mode == HAL_NRF_PTX ) // Mode depentant settings { hal_nrf_set_operation_mode( HAL_NRF_PTX ); // Enter TX mode } else { hal_nrf_set_operation_mode( HAL_NRF_PRX ); // Enter RX mode hal_nrf_set_rx_pload_width( (uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH ); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel( RF_CHANNEL ); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode( HAL_NRF_PWR_UP ); // Power up device radio_wait(); radio_set_status( RF_IDLE ); // Radio now ready }
void radio_sb_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode) { hal_nrf_close_pipe(HAL_NRF_ALL); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe(HAL_NRF_PIPE0, FALSE); // Open pipe0, without/autoack hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT); // Operates in 16bits CRC mode hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY); // Disables auto retransmit hal_nrf_set_address_width(HAL_NRF_AW_5BYTES); // 5 bytes address width hal_nrf_set_address(HAL_NRF_TX, address); // Set device's addresses hal_nrf_set_address(HAL_NRF_PIPE0, address); // Sets recieving address on // pipe0 if(operational_mode == HAL_NRF_PTX) // Mode depentant settings { hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter TX mode } else { hal_nrf_set_operation_mode(HAL_NRF_PRX); // Enter RX mode hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel(RF_CHANNEL); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up device hal_nrf_set_datarate(HAL_NRF_250KBPS); // Uncomment this line for // compatibility with nRF2401 // and nRF24E1 //hal_nrf_set_output_power(hal_nrf_output_power_t power); //default reset value is 0dbm // Wait for the radio to power up, max. 4.5ms depending on crystal Ls Timeout_SetTimeout2(5); while(!Timeout_IsTimeout2()); radio_set_status (RF_IDLE); // Radio now ready }
void gzll_rx_start() { uint8_t i; uint32_t flag; gzll_goto_idle(); if(gzll_rx_setup_modified) { flag = gzll_interupts_save(); gzll_rx_setup_modified = false; gzll_tx_setup_modified = true; /* Restore pipe 0 address (this may have been altered during transmission) */ hal_nrf_set_address(HAL_NRF_PIPE0, gzll_p0_adr); /* Enable the receive pipes selected by gzll_set_param() */ hal_nrf_close_pipe(HAL_NRF_ALL); for(i = 0; i < 6; i++) { if(gzll_dyn_params[GZLL_PARAM_RX_PIPES] & (1 << i)) { hal_nrf_open_pipe((hal_nrf_address_t)i, EN_AA); } } hal_nrf_set_operation_mode(HAL_NRF_PRX); } gzll_set_radio_power_on(true); gzll_timeout_counter = 0; gzll_state_var = GZLL_HOST_ACTIVE; GZLL_RFCE_HIGH(); gzll_interupts_restore(flag); }
bool gzll_tx_data(const uint8_t *src, uint8_t length, uint8_t pipe) { uint8_t temp_address[GZLL_ADDRESS_WIDTH]; uint16_t temp; uint32_t flag; ASSERT(length <= GZLL_MAX_FW_PAYLOAD_LENGTH && length > 0); ASSERT(pipe <= 5); /* Length check to prevent memory corruption. (Note, assertion will capture this as well). */ if(length == 0 || length > GZLL_MAX_FW_PAYLOAD_LENGTH) { return false; } gzll_current_tx_payload_length = length; if(gzll_state_var == GZLL_HOST_ACTIVE) { gzll_goto_idle(); } flag = gzll_interupts_save(); /* If the specified pipe is different from the previous TX pipe, the TX setup must be updated */ if(pipe != gzll_current_tx_pipe) { gzll_current_tx_pipe = pipe; gzll_tx_setup_modified = true; } /* Here, state can be GZLL_IDLE or GZLL_DEVICE_ACTIVE */ if(gzll_state_var == GZLL_IDLE) { if(gzll_tx_setup_modified) // TX setup has to be restored? { gzll_tx_setup_modified = false; gzll_rx_setup_modified = true; hal_nrf_set_operation_mode(HAL_NRF_PTX); hal_nrf_open_pipe(HAL_NRF_PIPE0, EN_AA); //Read out the full RX address for pipe number "pipe" if(pipe == HAL_NRF_PIPE0) { hal_nrf_set_address(HAL_NRF_TX, gzll_p0_adr); hal_nrf_set_address(HAL_NRF_PIPE0, gzll_p0_adr); } else { //lint -esym(550,bytes_in_buffer) "variable not accessed" //lint -esym(438,bytes_in_buffer) "last assigned value not used" uint8_t bytes_in_buffer; bytes_in_buffer = hal_nrf_get_address(HAL_NRF_PIPE1, temp_address); if(pipe != HAL_NRF_PIPE1) { switch(pipe) { default: case HAL_NRF_PIPE2: bytes_in_buffer = hal_nrf_get_address(HAL_NRF_PIPE2, temp_address); break; case HAL_NRF_PIPE3: bytes_in_buffer = hal_nrf_get_address(HAL_NRF_PIPE3, temp_address); break; case HAL_NRF_PIPE4: bytes_in_buffer = hal_nrf_get_address(HAL_NRF_PIPE4, temp_address); break; case HAL_NRF_PIPE5: bytes_in_buffer = hal_nrf_get_address(HAL_NRF_PIPE5, temp_address); break; } bytes_in_buffer = bytes_in_buffer; } //Here, temp_address will contain the full TX address hal_nrf_set_address(HAL_NRF_PIPE0, temp_address); hal_nrf_set_address(HAL_NRF_TX, temp_address); /* Change seed for random generator. Will prevent different devices transmitting to the same host from using the same channel hopping sequence. */ //lint -esym(534, gzll_lfsr_get) "return value ignored" gzll_lfsr_get(pipe, 1); } } // Prepare for new transmission gzll_timeout_counter = 0; gzll_channel_switch_counter = 0; gzll_try_counter = 0; hal_nrf_flush_tx(); GZLL_UPLOAD_PAYLOAD_TO_RADIO(); gzll_tx_success_f = false; // Transmission by default "failure" temp = gzll_dyn_params[GZLL_PARAM_DEVICE_MODE]; gzll_set_radio_power_on(true); if(gzll_sync_on) { switch(temp) { case GZLL_DEVICE_MODE_2: default: gzll_start_new_tx(GZLL_CHANNEL_PREVIOUS_SUCCESS); break; case GZLL_DEVICE_MODE_3: gzll_start_new_tx(GZLL_CHANNEL_RANDOM); break; case GZLL_DEVICE_MODE_4: gzll_start_new_tx(GZLL_CHANNEL_ESTIMATED); break; } } else { switch(temp) { case GZLL_DEVICE_MODE_0: case GZLL_DEVICE_MODE_2: gzll_start_new_tx(GZLL_CHANNEL_PREVIOUS_SUCCESS); break; default: gzll_start_new_tx(GZLL_CHANNEL_RANDOM); break; } } gzll_state_var = GZLL_DEVICE_ACTIVE; gzll_interupts_restore(flag); return true; // Payload successfully written to TX FIFO } else // Else TRANSMIT state { /* Check if criteria for starting new transmission when already transmitting is fulfilled */ if(!gzll_tx_setup_modified && !hal_nrf_tx_fifo_full() ) { GZLL_UPLOAD_PAYLOAD_TO_RADIO(); gzll_interupts_restore(flag); return true; // Payload successfully written to TX FIFO } else { gzll_interupts_restore(flag); return false; // Payload not written to TX FIFO } } }
void radio_pl_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode) { hal_nrf_close_pipe(HAL_NRF_ALL); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe(HAL_NRF_PIPE0, true); // Then open pipe0, w/autoack hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT); // Operates in 16bits CRC mode hal_nrf_set_auto_retr(RF_RETRANSMITS, RF_RETRANS_DELAY); // Enables auto retransmit. // 3 retrans with 250ms delay hal_nrf_set_address_width(HAL_NRF_AW_5BYTES); // 5 bytes address width hal_nrf_set_address(HAL_NRF_TX, address); // Set device's addresses hal_nrf_set_address(HAL_NRF_PIPE0, address); // Sets recieving address on // pipe0 /***************************************************************************** * Changed from esb/radio_esb.c * * Enables: * * - ACK payload * * - Dynamic payload width * * - Dynamic ACK * *****************************************************************************/ hal_nrf_enable_ack_pl(); // Try to enable ack payload // When the features are locked, the FEATURE and DYNPD are read out 0x00 // even after we have tried to enable ack payload. This mean that we need to // activate the features. if(hal_nrf_read_reg(FEATURE) == 0x00 && (hal_nrf_read_reg(DYNPD) == 0x00)) { hal_nrf_lock_unlock (); // Activate features hal_nrf_enable_ack_pl(); // Enables payload in ack } hal_nrf_enable_dynamic_pl(); // Enables dynamic payload hal_nrf_setup_dyn_pl(ALL_PIPES); // Sets up dynamic payload on // all data pipes. /***************************************************************************** * End changes from esb/radio_esb.c * *****************************************************************************/ if(operational_mode == HAL_NRF_PTX) // Mode depentant settings { hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter TX mode } else { hal_nrf_set_operation_mode(HAL_NRF_PRX); // Enter RX mode hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel(RF_CHANNEL); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up device start_timer(RF_POWER_UP_DELAY); // Wait for the radio to wait_for_timer(); // power up radio_set_status (RF_IDLE); // Radio now ready }
/* To be compatible with nRF24L01, please disable the auto ack function. */ void epl_rf_en_rcv_pipe_config(hal_nrf_address_t in_pipe_num, char *in_pipe_rcv_addr, unsigned char in_pipe_pload_length, epl_rf_en_auto_ack_t in_auto_ack) { hal_nrf_open_pipe(in_pipe_num, in_auto_ack); // Open pipe and configure the auto ack function. hal_nrf_set_address(in_pipe_num, in_pipe_rcv_addr); // Address for PRX pipe hal_nrf_set_rx_payload_width(in_pipe_num, in_pipe_pload_length); }