/** Tx data */ static void sm_enter_tx_send(void) { bb_advGenericStart(); periph_radio_packet_ptr_set(&ble_adv_data[0]); radio_setMode(RADIO_MODE_ADV_TX); }
/***************************************** * Functions for start/end of WAIT_FOR_IDLE ******************************************/ static void sm_enter_wait_for_idle(bool req_rx_accepted) { sm_state = STATE_WAIT_FOR_IDLE; /* enable disabled interrupt to avoid race conditions */ periph_radio_intenset(RADIO_INTENSET_DISABLED_Msk); /* different behaviour depending on whether we actually received a scan request or not */ if (req_rx_accepted) { /* need to answer request, set scan_rsp packet and let radio continue to send */ periph_radio_packet_ptr_set(&ble_scan_rsp_data[0]); periph_radio_shorts_set(RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk); /* wait exactly 150us to send response. NOTE: the Reference manual is wrong */ periph_radio_tifs_set(150); /* send scan req to user space */ scan_req_evt_dispatch(); } else { /* remove shorts and disable radio */ periph_radio_shorts_set(0); PERIPHERAL_TASK_TRIGGER(NRF_RADIO->TASKS_DISABLE); } }
/****************************************** * Functions for start/end of adv_send state ******************************************/ static void sm_enter_adv_send(void) { sm_state = STATE_ADV_SEND; periph_radio_ch_set(channel); /* trigger task early, the rest of the setup can be done in RXRU */ PERIPHERAL_TASK_TRIGGER(NRF_RADIO->TASKS_TXEN); periph_radio_packet_ptr_set(&ble_adv_data[0]); periph_radio_shorts_set( RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_DISABLED_RXEN_Msk); periph_radio_intenset(RADIO_INTENSET_DISABLED_Msk); }
/****************************************** * Functions for start/end of SCAN_REQ_RSP ******************************************/ static void sm_enter_scan_req_rsp(void) { sm_state = STATE_SCAN_REQ_RSP; periph_radio_packet_ptr_set(&ble_rx_buf[0]); periph_radio_shorts_set( RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_DISABLED_TXEN_Msk | RADIO_SHORTS_ADDRESS_RSSISTART_Msk); periph_radio_intenset( RADIO_INTENSET_DISABLED_Msk); /* change the tifs in order to be able to capture all packets */ periph_radio_tifs_set(148); /* start the timer that aborts the RX if no address is received. */ periph_timer_start(0, 200, true); /* set PPI pipe to stop the timer as soon as an address is received */ periph_ppi_set(0, &(NRF_TIMER0->TASKS_STOP), &(NRF_RADIO->EVENTS_ADDRESS)); }