/**@brief Application main function. */ int main(void) { uint32_t err_code; connected = false; mlog_init(); timers_init(); gpiote_init(); buttons_init(); step_counter_init(); motor_init(); led1_init(); mlog_str("Starting MAIN...\r\n"); bond_manager_init(); ble_stack_init(); radio_notification_init(); // Initialize Bluetooth Stack parameters gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); // Actually start advertising //advertising_start(); app_button_enable(); // Enter main loop for (;;) { // Switch to a low power state until an event is available for the application err_code = sd_app_event_wait(); APP_ERROR_CHECK(err_code); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds = true; char buffer[256] = {'\0'}; // Initialize. timers_init(); buttons_leds_init(&erase_bonds); UART_init(); printf("S130 Template\n"); printf(TBC); Ble_Init(erase_bonds); printf("BLE is up\n"); printf(TBC); // Start execution. application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); printf("app start\n"); printf(TBC); // Enter main loop. for (;;) { if (UART_RxReady()) { UART_GetBuffer(buffer, sizeof(buffer) - 1); printf("<<< %s\n", buffer); BLE_Uart_Send(buffer, strlen(buffer)); } if (UART_TxReady()) { power_manage(); } } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); peer_manager_init(erase_bonds); if (erase_bonds == true) { NRF_LOG_INFO("Bonds erased!\r\n"); } gap_params_init(); advertising_init(); gatt_init(); services_init(); sensor_simulator_init(); conn_params_init(); // Start execution. NRF_LOG_INFO("Heart Rate Sensor Start!\r\n"); application_timers_start(); advertising_start(); // Enter main loop. for (;;) { if (NRF_LOG_PROCESS() == false) { power_manage(); } } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); peer_manager_init(erase_bonds); if (erase_bonds == true) { NRF_LOG_DEBUG("Bonds erased!\r\n"); } gap_params_init(); advertising_init(); services_init(); NRF_LOG_DEBUG("Services are initialized\r\n"); conn_params_init(); NRF_LOG_DEBUG("conn params are initialized\r\n"); // Start execution. application_timers_start(); NRF_LOG_DEBUG("app timers are started\r\n"); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); NRF_LOG_DEBUG("advertising is started\r\n"); // Enter main loop. for (;;) { if (NRF_LOG_PROCESS() == false) { 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); device_manager_init(erase_bonds); db_discovery_init(); scheduler_init(); gap_params_init(); service_init(); advertising_init(); conn_params_init(); LOG("ANT ANCS\n"); ant_profile_setup(); // 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) { struct io_listener *l; int fd; struct timers timers; struct timer timer, *expired; struct addrinfo *addrinfo; /* This is how many tests you plan to run */ plan_tests(7); fake_time = time_now(); timers_init(&timers, fake_time); timer_init(&timer); timer_add(&timers, &timer, timeabs_add(fake_time, time_from_sec(1000))); fd = make_listen_fd(PORT, &addrinfo); freeaddrinfo(addrinfo); ok1(fd >= 0); l = io_new_listener(NULL, fd, init_conn, NULL); ok1(l); fake_time.ts.tv_sec += 1000; ok1(io_time_override(get_fake_time) == time_now); ok1(io_loop(&timers, &expired) == NULL); ok1(expired == &timer); ok1(!timers_expire(&timers, fake_time)); ok1(io_time_override(time_now) == get_fake_time); io_close_listener(l); timers_cleanup(&timers); /* This exits depending on whether all tests passed */ return exit_status(); }
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(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; rotation_counter = NRF_TIMER1; debounce_timer = NRF_TIMER2; // Initialize. app_trace_init(); timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); sensor_simulator_init(); conn_params_init(); usr_init(30); set_pin(USR_EN_PIN); bat_adc_init(4); gpio_pin_out_init(BRD_LED_PIN); // Start execution. application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); usr_init(30); // Enter main loop. for (;; ) { power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); peer_manager_init(erase_bonds); if (erase_bonds == true) { NRF_LOG_INFO("Bonds erased!\r\n"); } gap_params_init(); advertising_init(); db_discovery_init(); alert_notification_init(); conn_params_init(); // Start execution. NRF_LOG_INFO("Alert Notification started\r\n"); advertising_start(); // Enter main loop. for (;;) { if (NRF_LOG_PROCESS() == false) { power_manage(); } } }
/**@brief Application main function. */ int main(void) { // Initialize leds_init(); timers_init(); buttons_init(); uart_init(); ble_stack_init(); device_manager_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); simple_uart_putstring(START_STRING); advertising_start(); // Enter main loop for (;;) { power_manage(); } }
int main(void) { uint32_t err_code; // Initialization led_init(LED_0); led_init(LED_1); led_init(LED_2); led_on(LED_0); // Setup clock SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION, false); // Setup and start timeri //APP_SCHED_INIT(APP_TIMER_SCHED_EVT_SIZE, 20); timers_init(); timers_start(); while (1) { //app_sched_execute(); power_manage(); //led_toggle(LED_1); } }
int main(void) { // Initialize app_trace_init(); app_trace_log("trace init\r\n"); timers_init(); ble_stack_init(); sec_params_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); motion_sensor_init(); // Start execution advertising_start(); app_trace_log("advertising start\r\n"); // Enter main loop for (;;) { power_manage(); } }
int platform_init() { // Set the clocking to run directly from the crystal. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // Setup PIO pios_init(); // Setup SSIs spis_init(); // Setup UARTs uarts_init(); // Setup timers timers_init(); // Set the send/recv functions std_set_send_func( uart_send ); std_set_get_func( uart_recv ); // All done return PLATFORM_OK; }
int main(void) { struct timers timers; struct timer t; /* This is how many tests you plan to run */ plan_tests(7); timers_init(&timers, grains_to_time(1364984760903400ULL)); ok1(timers.base == 1364984760903400ULL); timer_init(&t); timer_add(&timers, &t, grains_to_time(1364984761003398ULL)); ok1(t.time == 1364984761003398ULL); ok1(timers.first == 1364984761003398ULL); ok1(!timers_expire(&timers, grains_to_time(1364984760903444ULL))); ok1(timers_check(&timers, NULL)); ok1(!timers_expire(&timers, grains_to_time(1364984761002667ULL))); ok1(timers_check(&timers, NULL)); timers_cleanup(&timers); /* This exits depending on whether all tests passed */ return exit_status(); }
/**@brief Thread for handling the Application's BLE Stack events. * * @details This thread is responsible for handling BLE Stack events sent from on_ble_evt(). * * @param[in] arg Pointer used for passing some arbitrary information (context) from the * osThreadCreate() call to the thread. */ static void ble_stack_thread(void * arg) { uint32_t err_code; bool erase_bonds; UNUSED_PARAMETER(arg); // Initialize. timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); sensor_simulator_init(); conn_params_init(); application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); while (1) { /* Wait for event from SoftDevice */ while(pdFALSE == xSemaphoreTake(m_ble_event_ready, portMAX_DELAY)) { // Just wait again in the case when INCLUDE_vTaskSuspend is not enabled } // This function gets events from the SoftDevice and processes them by calling the function // registered by softdevice_ble_evt_handler_set during stack initialization. // In this code ble_evt_dispatch would be called for every event found. intern_softdevice_events_execute(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool is_notification_mode = false; bool is_non_connectable_mode = false; timers_init(); APP_GPIOTE_INIT(1); err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL); APP_ERROR_CHECK(err_code); #if BUTTONS_NUMBER > 2 // Check button states. // Notification Start button. err_code = bsp_button_is_pressed(NOTIF_BUTTON_ID, &(is_notification_mode)); APP_ERROR_CHECK(err_code); // Non-connectable advertisement start button. if (!is_notification_mode) { err_code = bsp_button_is_pressed(NON_CONN_ADV_BUTTON_ID, &(is_non_connectable_mode)); APP_ERROR_CHECK(err_code); } // Un-configured button. else { } #else is_notification_mode = true; #endif // Initialize SoftDevice. ble_stack_init(); if (!is_notification_mode && !is_non_connectable_mode) { // The startup was not because of button presses. This is the first start. // Go into System-Off mode. Button presses will wake the chip up. err_code = sd_power_system_off(); APP_ERROR_CHECK(err_code); } // If we reach this point, the application was woken up by pressing one of the two configured // buttons. gap_params_init(); if (is_notification_mode) { // Notification button is pressed. Start connectable advertisement. connectable_adv_init(); service_add(); } else { non_connectable_adv_init(); } advertising_data_init(); advertising_start(); // Enter main loop. for (;;) { power_manage(); } }
void main (void) { io_init(); servo_init(); timers_init(); i2c_init(); wdt_enable(WDTO_15MS); sei(); start_timers(); flags.new_buf_ready = 0; flags.i2c_first_byte = 0; flags.servo_pd_changed = 0; flags.servo_minmaxpd_cnahged = 0; #ifdef MEGADEBUG struct { uint8_t sw1 : 1; uint8_t sw2 : 1; } ss; UTILS_DDR_CLR(I2CSCL_PORT, I2CSCL_PIN); UTILS_DDR_CLR(I2CSDA_PORT, I2CSDA_PIN); UTILS_PORT_SET(I2CSCL_PORT, I2CSCL_PIN); UTILS_PORT_SET(I2CSDA_PORT, I2CSDA_PIN); #endif for (;;) { #ifdef MEGADEBUG if (!UTILS_PIN_VALUE(I2CSCL_PORT, I2CSCL_PIN)) { if (!ss.sw1) { servo[0].target += 16; } ss.sw1 = 1; } else { ss.sw1 = 0; } if (!UTILS_PIN_VALUE(I2CSDA_PORT, I2CSDA_PIN)) { if (!ss.sw2) { servo[0].target -= 16; } ss.sw2 = 1; } else { ss.sw2 = 0; } #endif #ifndef MEGADEBUG // i2c if (TWCR & _BV(TWINT)) { // i2c switch (TWSR) { case TW_SR_SLA_ACK: // i2c start flags.i2c_first_byte = 1; break; case TW_SR_DATA_ACK: // i2c byte received if (flags.i2c_first_byte) { i2cMemAddr = TWDR; flags.i2c_first_byte = 0; } else { i2c_read(); i2cMemAddr ++; } break; case TW_ST_DATA_ACK: i2c_write(); i2cMemAddr ++; break; } TWCR |= _BV(TWINT); } #endif // servo.position if (UTILS_AGGL(TIFR, ITIMER) & _BV(UTILS_AGGL2(OCF, ITIMER, A))) { // Timer ITIMER compare match A UTILS_AGGL(TIFR, ITIMER) |= _BV(UTILS_AGGL2(OCF, ITIMER, A)); for (uint8_t i = 0; i < SERVO_NUM; i ++) { if (servo[i].position != servo[i].target) { UTILS_PORT_SET(LED_PORT, LED_PIN); if (servo[i].speed == 0) { // Change position immediately servo[i].position = servo[i].target; servo_find_pd(i); flags.servo_pd_changed = 1; } else { if (servo[i].speed_counter == servo[i].speed) { // Change position if (servo[i].position < servo[i].target) servo[i].position ++; else servo[i].position --; servo_find_pd(i); flags.servo_pd_changed = 1; servo[i].speed_counter = 0; } else servo[i].speed_counter ++; } } else { UTILS_PORT_CLR(LED_PORT, LED_PIN); } } if (flags.servo_minmaxpd_cnahged) { for (uint8_t i = 0; i < SERVO_NUM; i ++) { servo_find_pd(i); } flags.servo_pd_changed = 1; flags.servo_minmaxpd_cnahged = 0; } if (flags.servo_pd_changed) { servo_sort(); outstate_gen(); flags.servo_pd_changed = 0; } } wdt_reset(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; sensor_init(); app_trace_init(); // Initialize. timers_init(); #if SOFTDEVICE_7_1_0 == 1 application_timers_start(); #endif //buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sentek_init(); // Start execution. #if SOFTDEVICE_7_1_0 != 1 application_timers_start(); #endif APPL_LOG("Start Advertising \r\n"); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); //************* Config Section ******************* cfgResetConfig(); cfgReadConfig((void *)&cfg_test, &test, sizeof(test)); test = 4444; cfgWriteConfig(&cfg_test, &test, sizeof(test)); // cfgReadConfig(&cfg_test, &test, sizeof(test)); test = 1000; cfgReadConfig(&cfg_test, &test, sizeof(test)); // cfgReadConfigDirect(&test, &cfg_test, sizeof(test)); cfgReadConfigDirect(&cfg_test, &test, sizeof(test)); // cfgReadConfig(&cfg_test, &test, sizeof(test)); //************* Config Section ******************* initDone = true; // Enter main loop. for (;;) { #if (SOFTDEVICE_7_1_0 == 1) && (SDK_IS_9_0_0_OR_ABOVE == 1) if(!log_seconds()) { power_manage(); } #else log_seconds(); agsensor_update(); power_manage(); #endif if ((sentek_measurement_time_counter >= 250) && (initDone == true)) { sentek_measurement_time_counter = 0; sentek_measurement_loop(); } } }
int main(void) { bool init_status; int retValue; int i = defaultPerso.fall_detection_window; // initialize LEDs nrf_gpio_cfg_output(LED_RESETTING); nrf_gpio_cfg_output(LED_NO_FALL); nrf_gpio_cfg_output(LED_FALL_DETECTED); nrf_gpio_cfg_output(LED_OTHER); welcomeLEDs(); // Initialize timers_init(); ble_stack_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); sec_params_init(); twi_master_init(); #ifdef TEST_ACTIVITY_LOG testActivityLog(); #endif initActivityLog(); initSnapshotBuffer(); initCoefficients(); // initialize values retValue = 0; init_status = mpu6050_init(MPU6050_DEVICE_ADDR); if ( false == init_status ) { init_status = mpu6050_init(MPU6050_DEVICE_ADDR+1); if ( false == init_status ) { retValue = -1; errorLEDs(); sd_nvic_SystemReset(); } } if ( 0 == retValue ) { init_status = false; i = 0; while ( false == init_status ) { if (i == 6) { errorLEDs(); sd_nvic_SystemReset(); } init_status = accel_setup(); i++; } } if (0 == retValue) { char outbuf[20]; // Start execution - write a log entry with zero steps to indicate startup // writeLogEntry(999); advertising_start(); setup_wdt(); timers_start(); // start sampliing while(1) { if (ReadSnapshots == 1) { FullSnapshotEntry* entry = (FullSnapshotEntry*)(SNAPSHOT_DATA_ADDRESS_START) ; SnapshotHeader *h; Sensor_Reading *r; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); for(int i=0;i < getActivityLogSize(); i++) { h = &entry->hdr; sprintf (outbuf, ": SNAPSHOT # %d \n ",(i)); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 16); sprintf (outbuf, "Version: 2 \n");// ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 12); sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); // ptr++; r = entry->r; for (int j = 0; j < NUMBER_OF_ENTRIES; j++) { #define FLASH_READ_DELAY 40 nrf_gpio_pin_set(LED_RESETTING); sprintf (outbuf, "i: %d T: %04x ",j,r[j].val.temp); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "A: x%04xy%04xz%04x",r[j].val.x_ac,r[j].val.y_ac,r[j].val.z_ac); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "G: x%04xy%04xz%04x",r[j].val.x_gy,r[j].val.y_gy,r[j].val.z_gy); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(FLASH_READ_DELAY); //ptr += sizeof(Sensor_Reading); } entry++; } ReadSnapshots = 0; } if (ReadSnapshotsPartial == 1) { PartialSnapTotal = ((PartialSnap1-('0'))*10)+(PartialSnap2-('0')); FullSnapshotEntry* entry = (FullSnapshotEntry*)(SNAPSHOT_DATA_ADDRESS_START+(((PartialSnapTotal*sizeof(FullSnapshotEntry)*10))/4)) ; SnapshotHeader *h; Sensor_Reading *r; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); for(int i=0;i < 10; i++) { h = &entry->hdr; sprintf (outbuf, ": SNAPSHOT # %d \n ",(i+(PartialSnapTotal*10))); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 16); sprintf (outbuf, "Version: 2 \n");// ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 12); sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); // ptr++; r = entry->r; for (int j = 0; j < NUMBER_OF_ENTRIES; j++) { #define FLASH_READ_DELAY 40 nrf_gpio_pin_set(LED_RESETTING); sprintf (outbuf, "i: %d T: %04x ",j,r[j].val.temp); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "A: x%04xy%04xz%04x",r[j].val.x_ac,r[j].val.y_ac,r[j].val.z_ac); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "G: x%04xy%04xz%04x",r[j].val.x_gy,r[j].val.y_gy,r[j].val.z_gy); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(FLASH_READ_DELAY); //ptr += sizeof(Sensor_Reading); } entry++; } ReadSnapshotsPartial = 0; } if (ReadDataBuffer == 1) { LogEntry *addr; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); addr = (LogEntry *)(STEP_DATA_ADDRESS_START); for(int i=0;i < getActivityLogSize(); i++) { nrf_gpio_pin_set(LED_RESETTING); nrf_delay_ms(20); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(20); // sprintf ( outbuf, ": h:%d s:%d a:%04f ",addr->item.hour, addr->item.sec, addr->item.activity_level); sprintf ( outbuf, "%d:%d - %03f ",addr->item.hour, (addr->item.sec)/60, addr->item.activity_level); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); //nrf_delay_ms(1); addr++; } ReadDataBuffer = 0; } if (ReadDataBufferPartial == 1) { LogEntry *addr; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); PartialCountTotal = ((PartialCount1-('0'))*10)+(PartialCount2-('0')); addr = (LogEntry *)(STEP_DATA_ADDRESS_START+(2*(PartialCountTotal*1000))); for(int i=0;i < 1000; i++) { nrf_gpio_pin_set(LED_RESETTING); nrf_delay_ms(20); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(20); // sprintf ( outbuf, ": h:%d s:%d a:%04f ",addr->item.hour, addr->item.sec, addr->item.activity_level); sprintf ( outbuf, "%d:%d - %03f ",addr->item.hour, (addr->item.sec)/60, addr->item.activity_level); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); //nrf_delay_ms(1); addr++; } ReadDataBufferPartial = 0; } if (Dumper == 1) { sprintf (outbuf, "Log: %d ",getActivityLogSize()); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); Dumper = 0; } if (ReadBigSnapshot == 1) { SnapshotHeader *h = getSnapshotHeader(); sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); for (i = 0; i < NUMBER_OF_ENTRIES; i++) //i <= h->data.latest_data_point_index; i++) { #define RAM_READ_DELAY 15 sprintf (outbuf, "i: %d T: %04x ",i,raw_data[i].val.temp); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(RAM_READ_DELAY); sprintf (outbuf, "A: x%04xy%04xz%04x",raw_data[i].val.x_ac,raw_data[i].val.y_ac,raw_data[i].val.z_ac); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(RAM_READ_DELAY); sprintf (outbuf, "G: x%04xy%04xz%04x",raw_data[i].val.x_gy,raw_data[i].val.y_gy,raw_data[i].val.z_gy); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(RAM_READ_DELAY); } ReadBigSnapshot = 0; } if (do_post_processing == true) { do_post_processing = false; if (emergencyCall == 1) { makeTheCall(); emergencyCall = 0; } post_comm_processing(); } // Power Method 1 // nrf_gpio_pin_write(LED_OTHER,1); // power_manage(); // nrf_gpio_pin_write(LED_OTHER,0); } } return retValue; }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; // Initialize app_trace_init(); leds_init(); timers_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); // Hardcode EUI_48. uint8_t mac[EUI_48_SIZE] = {0xD9, 0xDA, 0x27, 0x2F, 0x6D, 0x00}; memcpy(&ipv6_medium_eui48.identifier, mac, EUI_48_SIZE); //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(); coap_port_t local_port_list[COAP_PORT_COUNT] = { {.port_number = LOCAL_PORT_NUM} }; coap_transport_init_t port_list; port_list.p_port_table = &local_port_list[0]; err_code = coap_init(17, &port_list); APP_ERROR_CHECK(err_code); err_code = coap_error_handler_register(coap_error_handler); APP_ERROR_CHECK(err_code); coap_endpoints_init(); iot_timer_init(); APPL_LOG("\r\n"); APPL_LOG("[APPL]: Init complete.\r\n"); // Start execution connectable_mode_enter(); // Enter main loop for (;;) { power_manage(); } }
int main(int argc, char** argv) { uint32_t led_colors = 0; uint8_t at_parm_test[10]; unsigned once; uint32_t i = 0; uint8_t canPrescaler = 0; uint8_t* uart_tx_packet = 0; uint8_t* uart_rx_packet; uint32_t old_loadcell_data; uint16_t timeStep = 1; clock_init(); pin_init(); led_init(); timers_init(); state_init(); uart_init(); // Set up UART2 for 115200 baud. There's no round() on the dsPICs, so we implement our own. double brg = (double) 140000000 / 2.0 / 16.0 / 115200.0 - 1.0; if (brg - floor(brg) >= 0.5) { brg = ceil(brg); } else { brg = floor(brg); } // Uart2Init (brg); // Init UART 2 as 115200 baud/s loadcell_init(); loadcell_start(); led_rgb_off(); led_rgb_set(50, 0, 100); can_state.init_return = RET_UNKNOWN; if (can_init()) { while (1); } timer_state.prev_systime = 0; timer_state.systime = 0; #ifdef CONF71 // Start Reading the int pin on IMU mpuData.startData = 0; if (IMU_Init(400000, 70000000) == 0) { // imu_state.init_return = RET_OK; mpuData.startData = 1; } else { //imu_state.init_return = RET_ERROR; } #endif for (;;) { if (timer_state.systime != timer_state.prev_systime) { timer_state.prev_systime = timer_state.systime; //everything in here will be executed once every ms //make sure that everything in here takes less than 1ms //useful for checking state consistency, synchronization, watchdog... if(timer_state.systime % 1000 == 1) { LED_4 = 1; } led_update(); if (timer_state.systime % 10 == 1) { IMU_GetQuaternion(quaterion); QuaternionToYawPitchRoll(quaterion, ypr); } if (timer_state.systime % 5 == 1) { IMU_normalizeData(&mpuData, &magData, &imuData); // Run AHRS algorithm IMU_UpdateAHRS (&imuData); // Run IMU algorithm (does not use MAG data) // IMU_UpdateIMU(&imuData); //copy state to CAN dictionary IMU_CopyOutput(&imuData, &mpuData, &magData); } /** * CANFestival Loop */ if (can_state.init_return == RET_OK) { can_process(); /** * Sets CANFestival shared variables * specific to Sensor Board */ can_push_state(); } /** * Blinking LED Loop */ if (timer_state.systime % 25 == 0) { LED_1 = !LED_1; } } else { //untimed processes in main loop: //executed as fast as possible //these processes should NOT block the main loop // LED_4 = mpuData.accelX > 0; // LED_3 = mpuData.accelY > 0; // LED_1 = mpuData.accelZ > 0; // IMU_GetData(); IMU_CopyI2CData(&mpuData, &magData); if (!T1CONbits.TON) { RGB_RED = 0; RGB_GREEN = RGB_BLUE = 1; while (1); } if(can_flag){ TimeDispatch(); can_flag = 0; } uart_rx_packet = uart_rx_cur_packet(); if (uart_rx_packet != 0) { uart_rx_packet_consumed(); } /** * Handles CAN transmission buffers */ if ((txreq_bitarray & 0b00000001) && !C1TR01CONbits.TXREQ0) { C1TR01CONbits.TXREQ0 = 1; txreq_bitarray = txreq_bitarray & 0b11111110; } if ((txreq_bitarray & 0b00000010) && !C1TR01CONbits.TXREQ1) { C1TR01CONbits.TXREQ1 = 1; txreq_bitarray = txreq_bitarray & 0b11111101; } if ((txreq_bitarray & 0b00000100) && !C1TR23CONbits.TXREQ2) { C1TR23CONbits.TXREQ2 = 1; txreq_bitarray = txreq_bitarray & 0b11111011; } if ((txreq_bitarray & 0b00001000) && !C1TR23CONbits.TXREQ3) { C1TR23CONbits.TXREQ3 = 1; txreq_bitarray = txreq_bitarray & 0b11110111; } if ((txreq_bitarray & 0b00010000) && !C1TR45CONbits.TXREQ4) { C1TR45CONbits.TXREQ4 = 1; txreq_bitarray = txreq_bitarray & 0b11101111; } if ((txreq_bitarray & 0b00100000) && !C1TR45CONbits.TXREQ5) { C1TR45CONbits.TXREQ5 = 1; txreq_bitarray = txreq_bitarray & 0b11011111; } if ((txreq_bitarray & 0b01000000) && !C1TR67CONbits.TXREQ6) { C1TR67CONbits.TXREQ6 = 1; txreq_bitarray = txreq_bitarray & 0b10111111; } } } return (EXIT_SUCCESS); }
void arm_kernel_startup(void *pointer) { /* Initialize the core_data */ /* Used when bringing up other cores, must be at consistent global address * seen by all cores */ // Initialize system timers timers_init(config_timeslice); struct dcb *init_dcb; if (cpu_is_bsp()) { MSG("Doing BSP related bootup \n"); /* Initialize the location to allocate phys memory from */ printf("start_free_ram = 0x%lx\n", armv8_glbl_core_data->start_free_ram); bsp_init_alloc_addr = armv8_glbl_core_data->start_free_ram; /* allocate initial KCB */ kcb_current= (struct kcb *)local_phys_to_mem( bsp_alloc_phys(sizeof(*kcb_current))); assert(kcb_current); memset(kcb_current, 0, sizeof(*kcb_current)); init_dcb = spawn_bsp_init(BSP_INIT_MODULE_NAME); platform_gic_init(); // pit_start(0); } else { MSG("Doing non-BSP related bootup \n"); struct armv8_core_data *core_data = (struct armv8_core_data *)pointer; my_core_id = core_data->dst_core_id; /* Initialize the allocator */ app_alloc_phys_start = (core_data->memory.base); app_alloc_phys_end = (core_data->memory.length + app_alloc_phys_start); MSG("Memory: %lx, %lx, size=%zu kB\n", app_alloc_phys_start, app_alloc_phys_end, (app_alloc_phys_end - app_alloc_phys_start + 1) >> 10); kcb_current= (struct kcb *)local_phys_to_mem(core_data->kcb); init_dcb = spawn_app_init(core_data, APP_INIT_MODULE_NAME); // uint32_t irq = gic_get_active_irq(); // gic_ack_irq(irq); } // enable interrupt forwarding to cpu platform_gic_cpu_interface_enable(); MSG("Calling dispatch from arm_kernel_startup, entry point %#"PRIxLVADDR"\n", get_dispatcher_shared_aarch64(init_dcb->disp)->disabled_save_area.named.pc); // Should not return dispatch(init_dcb); panic("Error spawning init!"); }
/* * Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); if (app_reset) { NRF_POWER->GPREGRET = 0; } leds_init(); #if defined(DBGLOG_SUPPORT) uart_init(); #endif PUTS("\nBootloader *** " __DATE__ " " __TIME__ " ***"); // This check ensures that the defined fields in the bootloader // corresponds with actual setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); #if defined(BUTTON_SUPPORT) buttons_init(); #endif (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); dis_init(); } dfu_start = app_reset; #if defined(BUTTON_SUPPORT) dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false); #endif if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); PUTS("Start DFU"); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { PUTS("Start App"); // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }
/* Main function * * - Initialise device and any global variables * - Enable Interrupts * - Start endless loop */ void main(void) { unsigned long ulRetcode; // Initialise the device clock to 80MHz ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN ); // Enable SysTick for FatFS at 10ms intervals ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Enable the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Set the USB pins to be controlled by the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_DISCONNECTED; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); // // Determine whether or not an SDCard is installed. If not, print a // warning and have the user install one and restart. // ulRetcode = disk_initialize(0); // Enable Global interrupts ROM_IntMasterEnable(); // Enable floating point arithmetic unit, but disable stacking ROM_FPUEnable(); ROM_FPUStackingDisable(); // Initialise GPIO - All ports enabled ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Unlock NMI pins for GPIO usage (PD7 + PF0) HWREG(GPIO_PORTD_BASE + 0x520) = 0x4C4F434B; HWREG(GPIO_PORTF_BASE + 0x520) = 0x4C4F434B; HWREG(GPIO_PORTD_BASE + 0x524) = 0x000000FF; HWREG(GPIO_PORTF_BASE + 0x524) = 0x000000FF; HWREG(GPIO_PORTD_BASE + 0x520) = 0x00000000; HWREG(GPIO_PORTF_BASE + 0x520) = 0x00000000; // Initialise GPIO Expander (probably not happening) // Initialise Buttons btn_init(); // Initialise FX fx_init(); // Initialise ADC adc_init(); // Initialise DAC dac_init(); // Initialise SD Card and Mass storage sdcard_init(); // Initialise UART for debugging uart_init(); // Initialise Timers timers_init(); for(;;) { // Endless Loop ADCProcessorTrigger(ADC0_BASE, 0); SysCtlDelay(SysCtlClockGet() / 120); // 25ms } }
int platform_init() { // Set the clocking to run from PLL #if defined( FORLM3S9B92 ) || defined( FORLM3S9D92 ) MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #else MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); #endif // Setup PIO pios_init(); // Setup SSIs spis_init(); // Setup UARTs uarts_init(); // Setup timers timers_init(); // Setup PWMs pwms_init(); #ifdef BUILD_ADC // Setup ADCs adcs_init(); #endif #ifdef BUILD_CAN // Setup CANs cans_init(); #endif #ifdef BUILD_USB_CDC // Setup USB usb_init(); #endif // Setup system timer cmn_systimer_set_base_freq( MAP_SysCtlClockGet() ); cmn_systimer_set_interrupt_freq( SYSTICKHZ ); // Setup ethernet (TCP/IP) eth_init(); // Common platform initialization code cmn_platform_init(); // Virtual timers // If the ethernet controller is used the timer is already initialized, so skip this sequence #if VTMR_NUM_TIMERS > 0 && !defined( BUILD_UIP ) // Configure SysTick for a periodic interrupt. MAP_SysTickPeriodSet( MAP_SysCtlClockGet() / SYSTICKHZ ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); MAP_IntMasterEnable(); #endif MAP_FlashUsecSet( SysCtlClockGet() ); // All done return PLATFORM_OK; }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); if (app_reset) { NRF_POWER->GPREGRET = 0; } leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); } dfu_start = app_reset; dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE) ? true: false); // If button is held down for 3 seconds, don't start bootloader. // This means that we go straight to Espruino, where the button is still // pressed and can be used to stop execution of the sent code. if (dfu_start) { nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, BOOTLOADER_BUTTON_PRESS_LED_ONSTATE); int count = 3000; while (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE && count) { nrf_delay_us(999); count--; } if (!count) dfu_start = false; nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, !BOOTLOADER_BUTTON_PRESS_LED_ONSTATE); } if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }
int main(void) { struct task *next; /* Set the CPU speed */ uint32_t skuid = read32(DEVICEID_BASE + DEVICEID_SKUID_OFFSET); uint32_t cpuspeed_id = skuid & DEVICEID_SKUID_CPUSPEED_MASK; uint32_t clksel_val = (1<<19) | 12; if(cpuspeed_id == DEVICEID_SKUID_CPUSPEED_720) clksel_val |= (720 << 8); else if(cpuspeed_id == DEVICEID_SKUID_CPUSPEED_600) clksel_val |= (600 << 8); else panic("Unsupported CPU!"); write32(CM_MPU_BASE + PRM_CLKSEL1_PLL_MPU_OFFSET, clksel_val); /* Basic hardware initialization */ init_cpumodes(); // set up CPU modes for interrupt handling intc_init(); // initialize interrupt controller gpio_init(); // initialize gpio interrupt system /* Start up hardware */ timers_init(); // must come first, since it initializes the watchdog eth_init(); uart_init(); /* For some reason, turning on the caches causes the kernel to hang after finishing the third invocation. Maybe we have to clear the caches here, or enable the MMU. */ printk("mmu init\n"); prep_pagetable(); init_mmu(); printk("cache init\n"); init_cache(); /* Initialize other interrupts */ init_interrupts(); /* Initialize task queues */ init_tasks(); /* Initialize idle task */ syscall_spawn(NULL, 7, idle_task, NULL, 0, SPAWN_DAEMON); pmu_enable(); trace_init(); printk("userspace init\n"); /* Initialize first user program */ syscall_spawn(NULL, 6, init_task, NULL, 0, 0); while (nondaemon_count > 0) { next = schedule(); task_activate(next); check_stack(next); } pmu_disable(); intc_reset(); eth_deinit(); deinit_mmu(); return 0; }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); } dfu_start = app_reset; // dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON_PIN) == 0) ? true: false); if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(LED_0); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_clear(LED_0); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { leds_off(); // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } nrf_gpio_pin_clear(LED_0); nrf_gpio_pin_clear(LED_1); NVIC_SystemReset(); }
/**@brief Function for application main entry. */ int main(void) { // Initialize // nrf_gpio_cfg_output(23); // nrf_gpio_pin_write(23, 0); // nrf_gpio_pin_write(23, 1); // nrf_delay_ms(1000); // nrf_gpio_pin_write(23, 0); uart_init(); leds_init(); timers_init(); gpiote_init(); buttons_init(); app_button_enable(); wdt_init(); #ifdef DEBUG_LOG printf("uart_init\r\n"); printf("leds_init\r\n"); printf("timers_init\r\n"); printf("gpiote_init\r\n"); printf("buttons_init\r\n"); printf("wdt_init\r\n"); #endif bond_manager_init(); ble_stack_init(); gap_params_init(); #ifdef DEBUG_LOG printf("bond_manager_init\r\n"); printf("ble_stack_init\r\n"); printf("gap_params_init\r\n"); #endif advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE); services_init(); conn_params_init(); sec_params_init(); radio_notification_init(); #ifdef DEBUG_LOG printf("advertising_init\r\n"); printf("services_init\r\n"); printf("conn_params_init\r\n"); printf("radio_notification_init\r\n"); #endif advertising_start(); #ifdef DEBUG_LOG printf("advertising_start\r\n"); #endif HTU21D_Init(); #ifdef DEBUG_LOG printf("HTU21D_Init\r\n"); printf("OLED_Init\r\n"); #endif my_timer_init(); Auto_Time_Set(); #ifdef DEBUG_LOG printf("rtc my_timer_init\r\n"); printf("Auto_Time_Set\r\n"); #endif wdt_start(); #ifdef DEBUG_LOG printf("wdt_start\r\n"); printf("Enter main loop\r\n"); #endif OLED_POWER_CONTROL(1); nrf_delay_ms(2000); OLED_POWER_CONTROL(0); for (;;) { updata_by_min(); updata_by_hour(); power_manage(); } }