void nrf_pwr_mgmt_run(void) { #if NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED /* * Clear FPU exceptions. * Without this step, the FPU interrupt is marked as pending, * preventing system from sleeping. */ uint32_t fpscr = __get_FPSCR(); __set_FPSCR(fpscr & ~0x9Fu); __DMB(); NVIC_ClearPendingIRQ(FPU_IRQn); // Assert if a critical FPU exception is signaled. ASSERT((fpscr & 0x03) == 0); #endif // NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED SLEEP_LOCK(); #if NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED uint32_t sleep_start; uint32_t sleep_end; uint32_t sleep_duration; sleep_start = app_timer_cnt_get(); #endif // NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED DEBUG_PIN_SET(); // Wait for an event. #ifdef SOFTDEVICE_PRESENT ret_code_t ret_code = sd_app_evt_wait(); if (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) { __WFE(); __SEV(); __WFE(); } else { APP_ERROR_CHECK(ret_code); } #else __WFE(); __SEV(); __WFE(); #endif // SOFTDEVICE_PRESENT DEBUG_PIN_CLEAR(); #if NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED sleep_end = app_timer_cnt_get(); UNUSED_VARIABLE(app_timer_cnt_diff_compute(sleep_end, sleep_start, &sleep_duration)); m_ticks_sleeping += sleep_duration; #endif // NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED SLEEP_RELEASE(); }
void crypto_storeKeys(void) { uint32_t err_code; if (crypto_storing) { pstorage_handle_t handle; err_code = pstorage_block_identifier_get(&crypto_store_handle, 0, &handle); APP_ERROR_CHECK(err_code); crypto_persistent_keys_t keys = {}; memcpy(keys.srp_b, srp.b, 32); memcpy(keys.srp_salt, srp.salt, 16); memcpy(keys.srp_v, srp.v, 384); memcpy(keys.srp_B, srp.B, 384); memcpy(keys.sign_secret, crypto_keys.sign.secret, 64); memcpy(keys.clientname, crypto_keys.client.name, 36); memcpy(keys.ltpk, crypto_keys.client.ltpk, 32); keys.instance = CRYPTO_INSTANCE; keys.valid0 = 0x55; keys.valid1 = 0xAA; err_code = pstorage_update(&handle, (uint8_t*)&keys, sizeof(keys), 0); APP_ERROR_CHECK(err_code); // Pump events until the store is done while (crypto_storing) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); app_sched_execute(); } } }
/**@brief Function for application main entry. Does not return. */ int main(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; utils_setup(); // Setup SoftDevice and events handler err_code = softdevice_ant_evt_handler_set(ant_io_tx_event_handler); APP_ERROR_CHECK(err_code); err_code = softdevice_handler_init(&clock_lf_cfg, NULL, 0, NULL); APP_ERROR_CHECK(err_code); err_code = ant_stack_static_config(); APP_ERROR_CHECK(err_code); // Setup and start ANT channel ant_io_tx_setup(); // Enter main loop. for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
int main(void) { /* Silence the compiler */ (void) g_sd_assert_pc; (void) g_evt; uart_init(); char start_msg[128]; sprintf(&start_msg[0], "\n| %s |---------------------------------------------------\r\n\n", __TIME__); uart_putstring((uint8_t*) &start_msg[0]); nrf_gpio_range_cfg_output(0, 30); for(int i = LED_START; i <= LED_STOP; ++i) nrf_gpio_pin_set(i); uint32_t error_code = sd_softdevice_enable((uint32_t)NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_cb); APP_ERROR_CHECK(error_code); error_code = sd_nvic_EnableIRQ(SD_EVT_IRQn); APP_ERROR_CHECK(error_code); ble_setup(); /* Enable a generic SD advertiser to display concurrent operation */ nrf_adv_conn_init(); while (true) { sd_app_evt_wait(); } }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; //Initialize. app_trace_init(); leds_init(); scheduler_init(); timers_init(); iot_timer_init(); button_init(); ble_stack_init(); advertising_init(); ip_stack_init (); //Start execution. advertising_start(); //Enter main loop. for (;;) { //Execute event schedule. app_sched_execute(); //Sleep waiting for an application event. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; // Initialize. app_trace_init(); leds_init(); timers_init(); gpiote_init(); err_code = ipv6_transport_init(); APP_ERROR_CHECK(err_code); // Initialize IP Stack. ip_stack_init(); APPL_LOG("\r\n"); APPL_LOG("[APPL]: Init complete.\r\n"); // Start execution. advertising_start(); // Enter main loop. for (;;) { /* Sleep waiting for an application event. */ err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
static uint32_t socket_recv(socket_handle_t * p_socket_handle, void * p_buf, uint32_t buf_size, uint32_t * buf_len, int flags) { if ((p_socket_handle->flags & O_NONBLOCK) != 0 && (flags & MSG_WAITALL) == 0) { flags |= MSG_DONTWAIT; } uint32_t err_code = NRF_SUCCESS; if (mbuf_empty(&p_socket_handle->mbuf_head) == true) { if ((flags & MSG_DONTWAIT) != 0) { err_code = SOCKET_WOULD_BLOCK; } else { while ((mbuf_empty(&p_socket_handle->mbuf_head) == true) && (err_code == NRF_SUCCESS)) { err_code = sd_app_evt_wait(); } } } if (err_code == NRF_SUCCESS) { *buf_len = mbuf_read(&p_socket_handle->mbuf_head, p_buf, buf_size); p_socket_handle->read_events = 0; } return err_code; }
/**@brief Function for application main entry. Does not return. */ int main(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; utils_setup(); // Enable SoftDevice. err_code = softdevice_ant_evt_handler_set(ant_evt_dispatch); APP_ERROR_CHECK(err_code); err_code = softdevice_handler_init(&clock_lf_cfg, NULL, 0, NULL); APP_ERROR_CHECK(err_code); err_code = ant_stack_static_config(); APP_ERROR_CHECK(err_code); // Setup and open Channel_0 as a Bidirectional Master. app_channel_setup(); #ifdef INCLUDE_DEBUG_CHANNEL // Setup and open Debug Channel ad_init(); ad_register_custom_command_callback(app_custom_debug_command_handler); #endif // Enter main loop for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/* Main function */ int main(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; utils_setup(); // Setup SoftDevice and events handler err_code = softdevice_ant_evt_handler_set(continuous_scan_event_handler); APP_ERROR_CHECK(err_code); err_code = softdevice_handler_init(&clock_lf_cfg, NULL, 0, NULL); APP_ERROR_CHECK(err_code); err_code = ant_stack_static_config(); APP_ERROR_CHECK(err_code); continuous_scan_init(); err_code = app_timer_create(&m_scan_timer_id, APP_TIMER_MODE_SINGLE_SHOT, scan_timeout_event); APP_ERROR_CHECK(err_code); // Enter main loop for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for application main entry. Does not return. */ int main(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Setup buttons and timer utils_setup(); LEDS_CONFIGURE(LEDS_MASK); // Setup SoftDevice and events handler err_code = softdevice_ant_evt_handler_set(ant_async_tx_event_handler); APP_ERROR_CHECK(err_code); err_code = softdevice_handler_init(&clock_lf_cfg, NULL, 0, NULL); APP_ERROR_CHECK(err_code); err_code = ant_stack_static_config(); APP_ERROR_CHECK(err_code); // Setup async tx channel ant_async_tx_setup(APP_TIMER_PRESCALER); // Enter main loop for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for the application main entry. */ int main(void) { uint32_t err_code; timers_init(); gpiote_init(); buttons_init(); ble_stack_init(); device_manager_init(); // Initialize Bluetooth Stack parameters. gap_params_init(); advertising_init(); services_init(); conn_params_init(); // Start advertising. advertising_start(); // Enter main loop. for (;;) { // Switch to a low power state until an event is available for the application err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code = NRF_SUCCESS; // Initialize. ble_stack_init(); APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL); err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(APP_BUTTON_DETECTION_DELAY, APP_TIMER_PRESCALER), bsp_event_handler); APP_ERROR_CHECK(err_code); // Initialize advertising. advertising_init(); // Start execution. advertising_start(); // Enter main loop. for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for initializing the DTM mode. */ static void dtm_init(void) { uint32_t err_code; app_uart_stream_comm_params_t uart_params; uart_params.baud_rate = UART_BAUD_RATE_19200; uart_params.rx_pin_no = DTM_RX_PIN_NO; uart_params.tx_pin_no = DTM_TX_PIN_NO; err_code = ble_dtm_init(&uart_params); if (err_code == NRF_SUCCESS) { err_code = bsp_indication_set(BSP_INDICATE_USER_STATE_OFF); APP_ERROR_CHECK(err_code); // Close serialization transport layer. err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); // Enter to infinite loop. for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } } APP_ERROR_CHECK(err_code); }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; //Initialize. app_trace_init(); leds_init(); timers_init(); ble_stack_init(); advertising_init(); ip_stack_init (); udp_port_setup(); //Start execution. advertising_start(); //Enter main loop. for (;;) { //Sleep waiting for an application event. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for the application main entry. */ int main(void) { uint32_t err_code; timers_init(); gpiote_init(); buttons_init(); nrf_gpio_cfg_output(CONNECTED_LED_PIN_NO); //DM: Green LED controlled directly. Red through GPIOTE task (Timer1_Compare[0]) ble_stack_init(); bond_manager_init(); // Initialize Bluetooth Stack parameters gap_params_init(); advertising_init(); services_init(); conn_params_init(); //just for relayr, iBeacon does´t allow connect sec_params_init(); //iBeacon: no security // Start advertising advertising_start(); // Enter main loop for (;;) { // Switch to a low power state until an event is available for the application err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for application main entry. Does not return. */ int main(void) { utils_setup(); softdevice_setup(); ant_channel_tx_broadcast_setup(); // Main loop. for (;;) { #ifdef CPU_LOAD_TRACE // Disabling interrupts in this way is highly not recommended. It has an impact on the work // of the softdecive and it is used only in order to show CPU load. __disable_irq(); LEDS_OFF(BSP_LED_0_MASK); __WFI(); LEDS_ON(BSP_LED_0_MASK); __enable_irq(); #else // Put CPU in sleep if possible. uint32_t err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); #endif // CPU_LOAD_TRACE } }
/** @brief main function */ int main(void) { /* Enable Softdevice (including sd_ble before framework */ uint32_t error_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_handler); APP_ERROR_CHECK(error_code); ble_enable_params_t ble_enable_params; ble_enable_params.gatts_enable_params.service_changed = 0; error_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(error_code); /* init leds and pins */ gpio_init(); #ifdef RBC_MESH_SERIAL /* only want to enable serial interface, and let external host setup the framework */ mesh_aci_init(); #else /* Enable mesh framework on channel 37, min adv interval at 100ms, 2 characteristics */ rbc_mesh_init_params_t init_params; init_params.access_addr = 0xA541A68F; init_params.adv_int_ms = 100; init_params.channel = 38; init_params.handle_count = 2; init_params.packet_format = RBC_MESH_PACKET_FORMAT_ORIGINAL; init_params.radio_mode = RBC_MESH_RADIO_MODE_BLE_1MBIT; error_code = rbc_mesh_init(init_params); APP_ERROR_CHECK(error_code); /* request values for both LEDs on the mesh */ error_code = rbc_mesh_value_enable(1); APP_ERROR_CHECK(error_code); error_code = rbc_mesh_value_enable(2); APP_ERROR_CHECK(error_code); /* init BLE gateway softdevice application: */ nrf_adv_conn_init(); #endif /* enable softdevice IRQ */ sd_nvic_EnableIRQ(SD_EVT_IRQn); /* sleep */ while (true) { sd_app_evt_wait(); } }
void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) { TickType_t wakeupTime; /* Make sure the SysTick reload value does not overflow the counter. */ if( xExpectedIdleTime > portNRF_RTC_MAXTICKS - configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) { xExpectedIdleTime = portNRF_RTC_MAXTICKS - configEXPECTED_IDLE_TIME_BEFORE_SLEEP; } /* Block the scheduler now */ portDISABLE_INTERRUPTS(); /* Stop tick events */ nrf_rtc_int_disable(portNRF_RTC_REG, NRF_RTC_INT_TICK_MASK); /* Configure CTC interrupt */ wakeupTime = nrf_rtc_counter_get(portNRF_RTC_REG) + xExpectedIdleTime; wakeupTime &= portNRF_RTC_MAXTICKS; nrf_rtc_cc_set(portNRF_RTC_REG, 0, wakeupTime); nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0); nrf_rtc_int_enable(portNRF_RTC_REG, NRF_RTC_INT_COMPARE0_MASK); if( eTaskConfirmSleepModeStatus() == eAbortSleep ) { portENABLE_INTERRUPTS(); } else { TickType_t xModifiableIdleTime = xExpectedIdleTime; configPRE_SLEEP_PROCESSING( xModifiableIdleTime ); if( xModifiableIdleTime > 0 ) { __DSB(); #ifdef SOFTDEVICE_PRESENT /* With SD there is no problem with possibility of interrupt lost. * every interrupt is counted and the counter is processed inside * sd_app_evt_wait function. */ portENABLE_INTERRUPTS(); sd_app_evt_wait(); #else /* No SD - we would just block interrupts globally. * BASEPRI cannot be used for that because it would prevent WFE from wake up. */ __disable_irq(); portENABLE_INTERRUPTS(); do{ __WFE(); } while(0 == (NVIC->ISPR[0] | NVIC->ISPR[1])); __enable_irq(); #endif } configPOST_SLEEP_PROCESSING( xExpectedIdleTime ); portENABLE_INTERRUPTS(); } // We can do operations below safely, because when we are inside vPortSuppressTicksAndSleep // scheduler is already suspended. nrf_rtc_int_disable(portNRF_RTC_REG, NRF_RTC_INT_COMPARE0_MASK); nrf_rtc_int_enable (portNRF_RTC_REG, NRF_RTC_INT_TICK_MASK); }
/**@brief Power manager. */ static void power_manage(void) { uint32_t err_code; // Wait for events err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); }
void dev_event_exec(void) { uint32_t err_code; //スケジュール済みイベントの実行(mainloop内で呼び出す) app_sched_execute(); err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; //Initialize. app_trace_init(); leds_init(); timers_init(); iot_timer_init(); #ifdef COMMISSIONING_ENABLED err_code = pstorage_init(); APP_ERROR_CHECK(err_code); buttons_init(); #endif // COMMISSIONING_ENABLED static ipv6_medium_init_params_t ipv6_medium_init_params; memset(&ipv6_medium_init_params, 0x00, sizeof(ipv6_medium_init_params)); ipv6_medium_init_params.ipv6_medium_evt_handler = on_ipv6_medium_evt; ipv6_medium_init_params.ipv6_medium_error_handler = on_ipv6_medium_error; ipv6_medium_init_params.use_scheduler = false; #ifdef COMMISSIONING_ENABLED ipv6_medium_init_params.commissioning_id_mode_cb = commissioning_id_mode_cb; ipv6_medium_init_params.commissioning_power_off_cb = commissioning_power_off_cb; #endif // COMMISSIONING_ENABLED err_code = ipv6_medium_init(&ipv6_medium_init_params, \ IPV6_MEDIUM_ID_BLE, \ &m_ipv6_medium); APP_ERROR_CHECK(err_code); eui48_t ipv6_medium_eui48; err_code = ipv6_medium_eui48_get(m_ipv6_medium.ipv6_medium_instance_id, \ &ipv6_medium_eui48); ipv6_medium_eui48.identifier[EUI_48_SIZE - 1] = 0x00; err_code = ipv6_medium_eui48_set(m_ipv6_medium.ipv6_medium_instance_id, \ &ipv6_medium_eui48); APP_ERROR_CHECK(err_code); ip_stack_init(); udp_port_setup(); //Start execution. connectable_mode_enter(); //Enter main loop. for (;;) { //Sleep waiting for an application event. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for application main entry. Does not return. */ int main(void) { // ANT event message buffer. static ANT_MESSAGE ant_message_buffer; // Enable SoftDevice. uint32_t err_code; #if defined(S212) || defined(S332) err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback, ANT_LICENSE_KEY); #else err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback); #endif APP_ERROR_CHECK(err_code); // Set application IRQ to lowest priority. err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); APP_ERROR_CHECK(err_code); // Enable application IRQ (triggered from protocol). err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn); APP_ERROR_CHECK(err_code); // Configure ant stack regards used channels. err_code = ant_stack_static_config(); APP_ERROR_CHECK(err_code); // Setup channel ant_channel_tx_broadcast_setup(); uint8_t event; uint8_t ant_channel; // Main loop. for (;;) { // Put CPU in sleep if possible. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); // Extract and process all pending ANT events as long as there are any left. do { // Fetch the event. err_code = sd_ant_event_get(&ant_channel, &event, ant_message_buffer.aucMessage); if (err_code == NRF_SUCCESS) { // Handle event channel_event_handle(event, &ant_message_buffer); } } while (err_code == NRF_SUCCESS); } }
void vApplicationIdleHook( void ) { uint32_t err_code = sd_app_evt_wait(); /* This signals the softdevice handler that we want the CPU to sleep until an event/interrupt occurs. During this time the softdevice will do what it needs to do; in our case: send adverts */ APP_ERROR_CHECK(err_code); }
/** * @brief Function called while waiting for connectivity chip response. It handles incoming events. */ static void ser_sd_rsp_wait(void) { do { (void)sd_app_evt_wait(); //intern_softdevice_events_execute(); } while (ser_sd_transport_is_busy()); }
/**@brief Function for doing power management. */ static void power_manage(void) { // Clear both leds before sleep if not indicating button press if (nrf_gpio_pin_read(BUTTON_1)) { GREEN_LED_OFF; RED_LED_OFF; } uint32_t err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); }
int select(int nfds, fd_set * p_readset, fd_set * p_writeset, fd_set * p_exceptset, const struct timeval * timeout) { VERIFY_SOCKET_ID(nfds - 1); // TODO: Support writeset and exceptset (void) p_writeset; (void) p_exceptset; if (timeout != NULL) { set_errno(EINVAL); return -1; } fd_set readset; FD_ZERO(&readset); int num_ready = 0; uint32_t err_code = NRF_SUCCESS; while (err_code == NRF_SUCCESS) { SOCKET_MUTEX_LOCK(); for (int sock = 0; sock < nfds; sock++) { socket_entry_t * p_socket_entry = &m_socket_table[sock]; if (FD_ISSET(sock, p_readset) && p_socket_entry->handle.read_events > 0) { FD_SET(sock, &readset); num_ready++; } else { FD_CLR(sock, &readset); } } SOCKET_MUTEX_UNLOCK(); // TODO: Check out how app events queue up while we checked the socket if (fd_set_cmp(p_readset, &readset) == 0) { break; } else { err_code = sd_app_evt_wait(); } } return num_ready; }
/**@brief Function for the application main entry. */ int main(void) { uint32_t err_code; load_app(); gpio_init(); ble_stack_init(); device_manager_init(); juma_init(); // initialize Bluetooth Stack parameters. gap_params_init(); advertising_init(); services_init(); dispatch_init(); flash_init(); if (app) { device_current_statue_set(DEVICE_STATUE_APP); data_storage_init(); on_ready(); } else { device_current_statue_set(DEVICE_STATUE_OTA); ble_device_set_name("OTA Mode"); ota_init(); ble_device_set_advertising_interval(200); ble_device_start_advertising(); } // Enter main loop. for (;;) { watchDog_sys_SDK_dog1_RR(); if(0 != enter_ota_mode_statue) { enter_ota_process(NULL); } else { dispatch(); } serial_get(); // Switch to a low power state until an event is available for the application err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for application main entry. Does not return. */ int main(void) { #if 0 led_init(); led_on(BSP_LED_0); led_on(BSP_LED_1); for (;;) { } #endif // 0 uint32_t err_code; // Configure pins LED_A - LED_D as outputs. led_init(); // Enable SoftDevice. err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback); APP_ERROR_CHECK(err_code); // Set application IRQ to lowest priority. err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); APP_ERROR_CHECK(err_code); // Enable application IRQ (triggered from protocol). err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn); APP_ERROR_CHECK(err_code); //Initialise and start the one second timer; init_timer(); //Initialise and start the auto shared channel module ascs_init(&m_asc_parameters); ascs_turn_on(); check_and_handle_asc_flags(); // Main loop. for (;;) { // Put CPU in sleep if possible. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); poll_for_ant_events(); check_and_handle_asc_flags(); } }
/**@brief Function for Stride and Distance Monitor RX example main loop. * * @details The main loop will try to sleep as much as possible. Every time a protocol event * occours, the application will be woken up, polling the ANT stack event queue. When finished * processing all events, the application will go back to sleep. */ void sdm_main_loop(void) { uint8_t event_id; uint8_t ant_channel; uint32_t err_code; // ANT event message buffer. static uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE]; // Main loop. for (;;) { // Put CPU in sleep if possible. err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); // Extract and process all pending ANT events as long as there are any left. do { // Fetch the event. err_code = sd_ant_event_get(&ant_channel, &event_id, event_message_buffer); if (err_code == NRF_SUCCESS) { // Handle event. switch (event_id) { case EVENT_RX: err_code = sdm_rx_data_process( &event_message_buffer[ANT_EVENT_BUFFER_INDEX_PAGE_NUM]); APP_ERROR_CHECK(err_code); err_code = sdm_rx_log( event_message_buffer[ANT_EVENT_BUFFER_INDEX_PAGE_NUM]); APP_ERROR_CHECK(err_code); break; case EVENT_RX_FAIL: err_code = sdm_rx_log(SDM_PAGE_EVENT_RX_FAIL); APP_ERROR_CHECK(err_code); break; default: break; } } } while (err_code == NRF_SUCCESS); } }
/**@brief Function for application main entry, does not return. */ int main(void) { uint32_t err_code; utils_setup(); softdevice_setup(); ant_state_indicator_init( m_ant_hrm.channel_number, HRM_TX_CHANNEL_TYPE); profile_setup(); for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }