/**@brief Function for dispatching a SoftDevice event to all modules with a S110 * SoftDevice event handler. * * @details This function is called from the S110 SoftDevice event interrupt handler after a * S110 SoftDevice event has been received. * * @param[in] p_ble_evt S110 SoftDevice event. */ static void ant_evt_dispatch(ant_evt_t * p_ant_evt) { antfs_message_process(p_ant_evt->msg.evt_buffer); // process regular ant event messages. while (antfs_event_extract(&m_antfs_event)) // check for antfs events. { antfs_event_process(&m_antfs_event); } }
/**@brief Function for application main entry, does not return. */ int main(void) { uint32_t err_code; #ifdef TRACE_UART // Configure and make UART ready for usage. const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_DISABLED, false, UART_BAUDRATE_BAUDRATE_Baud38400 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); #endif // Initialize timer module. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false); // Initialize GPIOTE module. APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); // Initialize and enable button handler module. static app_button_cfg_t buttons[] = { {BUTTON_0, false, BUTTON_PULL, button_event_handler}, {BUTTON_1, false, BUTTON_PULL, button_event_handler}, }; APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, false); softdevice_setup(); const antfs_params_t params = { ANTFS_CLIENT_SERIAL_NUMBER, ANTFS_CLIENT_DEV_TYPE, ANTFS_CLIENT_MANUF_ID, ANTFS_LINK_FREQ, ANTFS_DEFAULT_BEACON | DATA_AVAILABLE_FLAG_MASK, m_pass_key, m_friendly_name }; antfs_init(¶ms); antfs_channel_setup(); m_pairing_state = PAIRING_OFF; uint8_t event; uint8_t ant_channel; uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE]; bool allow_sleep; for (;;) { allow_sleep = true; // Process ANT-FS event queue. if (antfs_event_extract(&m_antfs_event)) { antfs_event_process(&m_antfs_event); allow_sleep = false; } // Process ANT event queue. if (sd_ant_event_get(&ant_channel, &event, event_message_buffer) == NRF_SUCCESS) { antfs_message_process(event_message_buffer); allow_sleep = false; } // Process user feedback for pairing authentication request. if (m_pairing_state != PAIRING_OFF) { pairing_user_feedback_handle(); // Reset to default state as been processed. m_pairing_state = PAIRING_OFF; allow_sleep = false; } // Sleep if allowed. if (allow_sleep) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } } }