/** * @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 timers_init(); ble_stack_init(); bsp_module_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); adc_init(); // Start execution timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop for (;;) { if(start_adc_sampling == true) { nrf_drv_saadc_sample_convert(0, &adc_value); ble_android_characteristic_update(&m_android, &adc_value); start_adc_sampling = false; } app_sched_execute(); // power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { // Initialize leds_init(); timers_init(); gpiote_init(); buttons_init(); simple_uart_config(UART_RTS, UART_TX, UART_CTS, UART_RX, 0); ble_stack_init(); scheduler_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); sec_params_init(); // Start execution //app_button_enable(); advertising_start(); uart_tx_str("nRF51822 run"); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
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 Application main function. */ int main(void) { // Initialize leds_init(); timers_init(); gpiote_init(); buttons_init(); bond_manager_init(); ble_stack_init(); scheduler_init(); gap_params_init(); advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE); services_init(); sensor_sim_init(); conn_params_init(); sec_params_init(); radio_notification_init(); // Start execution timers_start(); advertising_start(); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { // Initialize timers_init(); gpiote_init(); ble_stack_init(); bsp_module_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); // Start execution timers_start(); advertising_start(); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; // Initialize timers_init(); ble_stack_init(); bsp_module_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); // Start execution timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize timers_init(); nrf_log_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); db_discovery_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); // Start execution err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); NRF_LOG("\r\nCTS Start!\r\n"); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { bool erase_bonds; uint32_t err_code; // Initialize. app_trace_init(); timers_init(); uart_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); printf("BLE ANCS\n"); device_manager_init(erase_bonds); db_discovery_init(); scheduler_init(); gap_params_init(); service_init(); advertising_init(); conn_params_init(); // Start execution. err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop. for (;;) { app_sched_execute(); power_manage(); } }
int main(void) { nrf_gpio_cfg_output(PIN_LED_0); nrf_gpio_cfg_output(PIN_LED_1); nrf_gpio_cfg_input(PIN_BUTTON_0, GPIO_PIN_CNF_PULL_Pullup); nrf_gpio_pin_clear(PIN_LED_0); nrf_gpio_pin_clear(PIN_LED_1); lfclk_request(); APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, app_timer_evt_schedule); APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); create_timers(); timer_start(0); timer_start(1); while (1) { app_sched_execute(); __WFI(); } }
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) { #ifdef OSSW_DEBUG init_uart(); #endif spi_init(); ext_ram_init(); init_lcd_with_splash_screen(); accel_init(); // Initialize. timers_init(); rtc_timer_init(); buttons_init(); battery_init(); // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL); // splash screen nrf_delay_ms(500); fs_init(); config_init(); scr_mngr_init(); vibration_init(); notifications_init(); stopwatch_init(); timer_feature_init(); mlcd_timers_init(); // Enter main loop. for (;;) { if (rtc_should_store_current_time()) { rtc_store_current_time(); } app_sched_execute(); stopwatch_process(); command_process(); watchset_process_async_operation(); scr_mngr_draw_screen(); power_manage(); } }
/**@brief Application main function. */ int main(void) { // Initialize. uart_init(); scheduler_init(); timer_init(); led_init(); printf("Hi please enter the string to be converted to morse code.\nOnly alphabets supported\n"); // Enter main loop. for (;;) { app_sched_execute(); } }
/**@brief Function for application main entry. */ int main(void) { // Initialize app_trace_init(); simple_uart_putstring((const uint8_t*) "trace init\r\n"); leds_init(); simple_uart_putstring((const uint8_t*) "leds init\r\n"); timers_init(); simple_uart_putstring((const uint8_t*) "timers init\r\n"); gpiote_init(); simple_uart_putstring((const uint8_t*) "gpiote init\r\n"); buttons_init(); simple_uart_putstring((const uint8_t*) "buttons init\r\n"); ble_stack_init(); simple_uart_putstring((const uint8_t*) "stack init\r\n"); scheduler_init(); simple_uart_putstring((const uint8_t*) "schedler init\r\n"); gap_params_init(); simple_uart_putstring((const uint8_t*) "gap init\r\n"); advertising_init(); simple_uart_putstring((const uint8_t*) "adv init\r\n"); services_init(); simple_uart_putstring((const uint8_t*) "services init\r\n"); conn_params_init(); simple_uart_putstring((const uint8_t*) "conn init\r\n"); sec_params_init(); simple_uart_putstring((const uint8_t*) "sec init\r\n"); ext_sensors_init(); simple_uart_putstring((const uint8_t*) "ext init\r\n"); // lfclk_config(); // simple_uart_putstring((const uint8_t*) "lfk init\r\n"); // Start execution timers_start(); advertising_start(); simple_uart_putstring((const uint8_t*) "main\r\n"); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Main function of the connectivity application. */ int main(void) { uint32_t err_code = NRF_SUCCESS; #if ( defined(SER_PHY_HCI_DEBUG_ENABLE) || defined(SER_PHY_DEBUG_APP_ENABLE)) debug_init(NULL); #endif /* Initialize scheduler queue. */ APP_SCHED_INIT(SER_CONN_SCHED_MAX_EVENT_DATA_SIZE, SER_CONN_SCHED_QUEUE_SIZE); /* Initialize SoftDevice. * SoftDevice Event IRQ is not scheduled but immediately copies BLE events to the application * scheduler queue */ SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false); /* Subscribe for BLE events. */ err_code = softdevice_ble_evt_handler_set(ser_conn_ble_event_handle); APP_ERROR_CHECK(err_code); /* Open serialization HAL Transport layer and subscribe for HAL Transport events. */ err_code = ser_hal_transport_open(ser_conn_hal_transport_event_handle); APP_ERROR_CHECK(err_code); /* Enter main loop. */ for (;;) { /* Process SoftDevice events. */ app_sched_execute(); /* Process received packets. * We can NOT add received packets as events to the application scheduler queue because * received packets have to be processed before SoftDevice events but the scheduler queue * does not have priorities. */ err_code = ser_conn_rx_process(); APP_ERROR_CHECK(err_code); /* Sleep waiting for an application event. */ err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
bool delay_ms(uint32_t ms) { uint32_t startTicks; uint32_t nowTicks; uint32_t elapsedTicks; uint32_t scheduleTicks; if (app_timer_cnt_get(&startTicks) != NRF_SUCCESS) { return false; } if (app_timer_cnt_get(&scheduleTicks) != NRF_SUCCESS) { return false; } do { if (app_timer_cnt_get(&nowTicks) != NRF_SUCCESS) { return false; } /* The RTC is only a 24-bit counter, so when subtracting the two * tick counts to find the elapsed number of ticks, we must mask out the * 8 most significant bits. */ elapsedTicks = 0x00FFFFFF & (nowTicks - startTicks); #if (0) uint32_t intermediaryTicks; intermediaryTicks = elapsedTicks - scheduleTicks; if (intermediaryTicks > APP_TIMER_TICKS(15, APP_TIMER_PRESCALER)) { app_sched_execute(); if (app_timer_cnt_get(&scheduleTicks) != NRF_SUCCESS) { return false; } } #endif if (elapsedTicks * USEC_PER_APP_TIMER_TICK >= 1000 * ms) { return true; } } while (1); return false; }
int main() { HardwareInit(); APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); timers_init(); BLEStart(); // timers_start(); // blink(); while (1) { app_sched_execute(); uint32_t err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); //BlueIOADCStart(); } }
/**@brief Function for waiting for events. * * @details This function will place the chip in low power mode while waiting for events from * the S110 SoftDevice or other peripherals. When interrupted by an event, it will call the * @ref app_sched_execute function to process the received event. This function will return * when the final state of the firmware update is reached OR when a tear down is in * progress. */ static void wait_for_events(void) { for (;;) { // Wait in low power state for any events. uint32_t err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); // Event received. Process it from the scheduler. app_sched_execute(); if ((m_update_status == BOOTLOADER_COMPLETE) || (m_update_status == BOOTLOADER_TIMEOUT) || (m_update_status == BOOTLOADER_RESET)) { // When update has completed or a timeout/reset occured we will return. return; } } }
/**@brief Function for waiting for events. * * @details This function will place the chip in low power mode while waiting for events from * the SoftDevice or other peripherals. When interrupted by an event, it will call the * @ref app_sched_execute function to process the received event. This function will return * when the final state of the firmware update is reached OR when a tear down is in * progress. */ static void wait_for_events(void) { for (;;) { __SEV(); __WFI(); __WFE(); // Event received. Process it from the scheduler. app_sched_execute(); if ((m_update_status == BOOTLOADER_COMPLETE) || (m_update_status == BOOTLOADER_TIMEOUT) || (m_update_status == BOOTLOADER_RESET)) { // When update has completed or a timeout/reset occured we will return. return; } } }
/**@brief Function for waiting for events. * * @details This function will place the chip in low power mode while waiting for events from * the BLE stack or other peripherals. When interrupted by an event, it will call the @ref * app_sched_execute function to process the received event. This function will return * when the final state of the firmware update is reached OR when a tear down is in * progress. */ static void wait_for_events(void) { for (;;) { // Wait in low power state for any events. uint32_t err_code = sd_app_event_wait(); APP_ERROR_CHECK(err_code); // Event received. Process it from the scheduler. app_sched_execute(); if (m_tear_down_in_progress) { // Wait until disconnected event is received. Once the disconnected event is received // from the stack, the macro IS_CONNECTED will return false. if (!IS_CONNECTED()) { err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); if (m_activate_img_after_tear_down) { // Start the currently valid application. (void)dfu_image_activate(); // Ignoring the error code returned by dfu_image_activate because if the // function fails, there is nothing that can be done to recover, other than // returning and letting the system go under reset. Also since the // tear down of the BLE Transport is already complete and the connection // with the DFU Controller is down. Hence the DFU Controller cannot be informed // about this failure. It is assumed that the DFU Controller is already // aware of a failed update procedure from errors returned by earlier // operations (eg. Validate operation would have returned a failure if there // was a failed image transfer). } return; } } } }
int main(void) { // Initialization of various modules. timers_init(); leds_init(); gpiote_init(); buttons_init(); ble_stack_init(); scheduler_init(); device_manager_init(); mb_init(); // Start scanning for peripherals bt_scan_start(); for (;; ) { app_sched_execute(); power_manage(); } }
int main() { //APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); nrf_gpio_cfg_output(LED_CONNECTED); APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); timers_init(); uart_init(); // blink(); nrf_gpio_pin_clear(LED_CONNECTED); BLEStart(); // timers_start(); // blink(); while (1) { app_sched_execute(); uint32_t err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); //BlueIOADCStart(); } }
/** This is where it all starts ++++++++++++++++++++++++++++++++++++++++++ main is entered as a result of one of SEVERAL events: - Normal startup from press of reset button. - Battery inserted. - After DFU (Device Firmware Upgrade) at manufacturing Quality Assurance or user DFU. - WatchDogTimer expiration and its interrupt handler didn't feed new value. - Some error occured and - Spontenous unknown reset. All subsystems are initalized and any failures are noted and available later in init_status Since some events occur after tag is deployed and no one can see the LEDs the system continues operating. After initalizition (including setting up interrupts) we loop here calling app_sched_execute and sd_app_evt_wait */ int main(void) { // LEDs first (they're easy and cannot fail) drivers/init/init.c init_leds(); RED_LED_ON; if( init_log() ) { init_status |=LOG_FAILED_INIT; } else { NRF_LOG_INFO("LOG initalized \r\n"); } // subsequent initalizations assume log is working // start watchdog now in case program hangs up. // watchdog_default_handler logs error and resets the tag. init_watchdog(NULL); // Battery voltage initialization cannot fail under any reasonable circumstance. battery_voltage_init(); vbat = getBattery(); if( vbat < BATTERY_MIN_V ) { init_status |=BATTERY_FAILED_INIT; } else NRF_LOG_INFO("BATTERY initalized \r\n"); if(init_sensors() == NRF_SUCCESS ) { model_plus = true; NRF_LOG_INFO("Sensors initialized \r\n"); } // Init NFC ASAP in case we're waking from deep sleep via NFC (todo) // outputs ID:DEVICEID ,MAC:DEVICEADDR, SW:REVision set_nfc_callback(app_nfc_callback); if( init_nfc() ) { init_status |= NFC_FAILED_INIT; } else { NRF_LOG_INFO("NFC init \r\n"); } pin_interrupt_init(); if( pin_interrupt_enable(BSP_BUTTON_0, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIO_PIN_PULLUP, button_press_handler) ) { init_status |= BUTTON_FAILED_INIT; } // Initialize BLE Stack. Starts LFCLK required for timer operation. if( init_ble() ) { init_status |= BLE_FAILED_INIT; } bluetooth_configure_advertisement_type(STARTUP_ADVERTISEMENT_TYPE); bluetooth_tx_power_set(BLE_TX_POWER); bluetooth_configure_advertising_interval(ADVERTISING_INTERVAL_STARTUP); advertisement_delay = NRF_FICR->DEVICEID[0]&0x0F; // Priorities 2 and 3 are after SD timing critical events. // 6, 7 after SD non-critical events. // Triggers ADC, so use 3. ble_radio_notification_init(3, NRF_RADIO_NOTIFICATION_DISTANCE_800US, on_radio_evt); // If GATT is enabled BLE init inits peer manager which uses flash. // BLE init should handle insufficient space gracefully (i.e. erase flash and proceed). // Flash must be initialized after softdevice. if(flash_init()) { NRF_LOG_ERROR("Failed to init flash \r\n"); } size_t flash_space_remaining = 0; flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Largest continuous space remaining %d bytes\r\n", flash_space_remaining); if(4000 > flash_space_remaining) { NRF_LOG_INFO("Flash space is almost used, running gc\r\n") flash_gc_run(); flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Continuous space remaining after gc %d bytes\r\n", flash_space_remaining); } else if (flash_record_get(FDS_FILE_ID, FDS_RECORD_ID, sizeof(tag_mode), &tag_mode)) { NRF_LOG_INFO("Did not find mode in flash, is this first boot? \r\n"); } else { NRF_LOG_INFO("Loaded mode %d from flash\r\n", tag_mode); } if( init_rtc() ) { init_status |= RTC_FAILED_INIT; } else { NRF_LOG_INFO("RTC initialized \r\n"); } // Initialize lis2dh12 and BME280 - TODO: Differentiate LIS2DH12 and BME280 if (model_plus) { lis2dh12_reset(); // Clear memory. // Enable Low-To-Hi rising edge trigger interrupt on nRF52 to detect acceleration events. if (pin_interrupt_enable(INT_ACC2_PIN, NRF_GPIOTE_POLARITY_LOTOHI, NRF_GPIO_PIN_NOPULL, lis2dh12_int2_handler) ) { init_status |= ACC_INT_FAILED_INIT; } nrf_delay_ms(10); // Wait for LIS reboot. // Enable XYZ axes. lis2dh12_enable(); lis2dh12_set_scale(LIS2DH12_SCALE); lis2dh12_set_sample_rate(LIS2DH12_SAMPLERATE_RAWv1); lis2dh12_set_resolution(LIS2DH12_RESOLUTION); lis2dh12_set_activity_interrupt_pin_2(LIS2DH12_ACTIVITY_THRESHOLD); NRF_LOG_INFO("Accelerometer configuration done \r\n"); // oversampling must be set for each used sensor. bme280_set_oversampling_hum (BME280_HUMIDITY_OVERSAMPLING); bme280_set_oversampling_temp (BME280_TEMPERATURE_OVERSAMPLING); bme280_set_oversampling_press(BME280_PRESSURE_OVERSAMPLING); bme280_set_iir(BME280_IIR); bme280_set_interval(BME280_DELAY); bme280_set_mode(BME280_MODE_NORMAL); NRF_LOG_INFO("BME280 configuration done \r\n"); } // Enter stored mode after boot - or default mode if store mode was not found app_sched_event_put (&tag_mode, sizeof(&tag_mode), change_mode); // Initialize repeated timer for sensor read and single-shot timer for button reset if( init_timer(main_timer_id, APP_TIMER_MODE_REPEATED, MAIN_LOOP_INTERVAL_RAW, main_timer_handler) ) { init_status |= TIMER_FAILED_INIT; } if( init_timer(reset_timer_id, APP_TIMER_MODE_SINGLE_SHOT, BUTTON_RESET_TIME, reboot) ) { init_status |= TIMER_FAILED_INIT; } // Init starts timers, stop the reset app_timer_stop(reset_timer_id); // Log errors, add a note to NFC, blink RED to visually indicate the problem if (init_status) { snprintf((char* )NFC_message, NFC_message_length, "Error: %X", init_status); NRF_LOG_WARNING (" -- Initalization error : %X \r\n", init_status); for ( int16_t i=0; i<13; i++) { RED_LED_ON; nrf_delay_ms(500u); RED_LED_OFF; nrf_delay_ms(500u); } } // Turn green led on if model+ with no errors. // Power manage turns led off if (model_plus & !init_status) { GREEN_LED_ON; } // Turn off red led, leave green on to signal model+ without errors RED_LED_OFF; // Wait for sensors to take first sample nrf_delay_ms(1000); // Get first sample from sensors app_sched_event_put (NULL, 0, main_sensor_task); app_sched_execute(); // Start advertising bluetooth_advertising_start(); NRF_LOG_INFO("Advertising started\r\n"); // Enter main loop. Executes tasks scheduled by timers and interrupts. for (;;) { app_sched_execute(); // Sleep until next event. power_manage(); } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { CLK_Config(); FlashInit(); sim(); // disable interrupts GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOG, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); delay1s(5); #ifdef DEBUG AppTrace_Init(); printf("\r\nSTM8L152 Start ...\r\n"); #endif LED_Init(); LED1_ON(); scheduler_init(); // Build count init event count_event.eCount_event = COUNT_INIT; app_sched_event_put(&count_event,sizeof(count_event),count_event_handler); // Build key init event key_event.eKey_event = KEY_INIT; app_sched_event_put(&key_event,sizeof(key_event),key_event_handler); // Build the valve standby event valve_event.eValve_event = VALVE_STANDBY_EVENT; app_sched_event_put(&valve_event,sizeof(valve_event),valve_event_handler); // Build the LCD init event lcd_event.eLcd_event = LCD_INIT; app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler); // Build the beeper init event beeper_event.eBeeper_event = BEEPER_INIT; app_sched_event_put(&beeper_event,sizeof(beeper_event),beeper_event_handler); // Build the cc1120 Init event cc112x_event.eCC112x_event = CC112X_INIT_EVENT; app_sched_event_put(&cc112x_event,sizeof(cc112x_event),cc112x_event_handler); // Build the IC card Init event ic_card_event.eIC_event = IC_CARD_INIT; app_sched_event_put(&ic_card_event,sizeof(ic_card_event),ic_event_handler); // Build the IC card Init event battery_event.eBattery_event = INT_BATTERY_EVENT; app_sched_event_put(&battery_event,sizeof(battery_event),battery_event_handler); // enable interrupts rim(); LED1_OFF(); // Infinite loop while (1) { app_sched_execute(); app_evt_wait(); } }
int EventManager::processAllEvents() { /** process all events */ app_sched_execute(); return 1; }
int main(){ initialize_all(); char buf[30]; uint8_t uart_data; // Print Device ID uint64_t this_device_id = (((uint64_t) NRF_FICR->DEVICEID[1] << 32) | ((uint64_t) NRF_FICR->DEVICEID[0])); sprintf((char*)buf, "ID: %llx\n", this_device_id); simple_uart_putstring(buf); uint8_t availability; bool radio_executed = false; // main application loop while (1) { //All the mugs that will be invited have been set if (is_connected()) { // Deal with radios sd_softdevice_disable(); radio_configure(); // simple_uart_putstring("Configured radio\n"); // simple_uart_putstring("Disabled soft device\n"); // END - Deal with radios bool disovery_complete = false; bool all_final_state = true; int8_t current_mug = 0; while (!disovery_complete){ uint64_t device_id = 0; // vibration_update(); if (receive_packet(20)){ device_id = packet[1]; if (this_device_id == device_id){ if (packet[0] == 0xcfcf){ // Master init sequence simple_uart_putstring("Got init!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... simple_uart_putstring("[a]ccept or [r]eject:\n"); uart_data = simple_uart_get(); switch (uart_data) { case 'a': availability = 0xaa; simple_uart_putstring("Accepted\n"); break; case 'r': availability = 0xff; simple_uart_putstring("Rejected\n"); break; } uart_data = simple_uart_get(); } else if (packet[0] == 0xabab) { // Master poll availability simple_uart_putstring("Sent availability status!\n"); packet[0] = availability; // Send ACK to Master send_packet(1); } else if (packet[0] == 0xdede) { // Master kettle boiling simple_uart_putstring("Got invitation!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... for (uint8_t i=0; i<100; i++){ nrf_gpio_pin_toggle(0); nrf_delay_ms(200); } } else { sprintf((char*)buf, "Brocken command: %llx\n", packet[0]); simple_uart_putstring(buf); } } else { simple_uart_putstring("Not applicable packet\n"); sprintf((char*)buf, "Target: %llx\n", packet[1]); simple_uart_putstring(buf); sprintf((char*)buf, "Command: %llx\n", packet[0]); simple_uart_putstring(buf); } } if (bump_action()) { disovery_complete = true; // uint8_t bump_evt = 1; // ble_update_bump(&bump_evt) } } // Deal with radios sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION,app_error_handler); // simple_uart_putstring("Enabled soft device\n"); // END - Deal with radios // uint8_t bump_val = 1; // ble_update_bump(&bump_val); // simple_uart_putstring("They see me bumpin', I see 'em hatin'!\n"); disovery_complete = false; // RSVP_App(); //sends MUG information back to app via ble, defined in slip_ble.c } //debug_ble_ids(); // vibration_update(); app_sched_execute(); nrf_delay_ms(500); } }