/** * OpenPilot Main function: * * Initialize PiOS<BR> * Create the "System" task (SystemModInitializein Modules/System/systemmod.c) <BR> * Start FreeRTOS Scheduler (vTaskStartScheduler) (Now handled by caller) * If something goes wrong, blink LED1 and LED2 every 100ms * */ int main() { /* NOTE: Do NOT modify the following start-up sequence */ /* Any new initialization functions should be added in OpenPilotInit() */ /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); /* Architecture dependant Hardware and * core subsystem initialisation * (see pios_board.c for your arch) * */ PIOS_Board_Init(); /* Initialize modules */ MODULE_INITIALISE_ALL(PIOS_WDG_Clear); /* swap the stack to use the IRQ stack */ Stack_Change(); /* Start the FreeRTOS scheduler which should never returns.*/ vTaskStartScheduler(); /* If all is well we will never reach here as the scheduler will now be running. */ /* Do some indication to user that something bad just happened */ while (1) { #if defined(PIOS_LED_HEARTBEAT) PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); #endif /* PIOS_LED_HEARTBEAT */ PIOS_DELAY_WaitmS(100); } return 0; }
/** * Tau Labs Main function: * * Initialize PiOS<BR> * Create the "System" task (SystemModInitializein Modules/System/systemmod.c) <BR> * Start FreeRTOS Scheduler (vTaskStartScheduler) (Now handled by caller) * If something goes wrong, blink LED1 and LED2 every 100ms * */ int main() { /* NOTE: Do NOT modify the following start-up sequence */ /* Any new initialization functions should be added in OpenPilotInit() */ /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); /* Architecture dependant Hardware and * core subsystem initialisation * (see pios_board.c for your arch) * */ PIOS_Board_Init(); PIOS_WDG_Clear(); #ifdef ERASE_FLASH PIOS_Flash_Jedec_EraseChip(); #if defined(PIOS_LED_HEARTBEAT) PIOS_LED_Off(PIOS_LED_HEARTBEAT); #endif /* PIOS_LED_HEARTBEAT */ while (1) ; #endif /* Initialize modules */ MODULE_INITIALISE_ALL(PIOS_WDG_Clear); /* swap the stack to use the IRQ stack */ Stack_Change(); /* Start the FreeRTOS scheduler, which should never return. * * NOTE: OpenPilot runs an operating system (FreeRTOS), which constantly calls * (schedules) function files (modules). These functions never return from their * while loops, which explains why each module has a while(1){} segment. Thus, * the OpenPilot software actually starts at the vTaskStartScheduler() function, * even though this is somewhat obscure. * * In addition, there are many main() functions in the OpenPilot firmware source tree * This is because each main() refers to a separate hardware platform. Of course, * C only allows one main(), so only the relevant main() function is compiled when * making a specific firmware. * */ vTaskStartScheduler(); /* If all is well we will never reach here as the scheduler will now be running. */ /* Do some indication to user that something bad just happened */ while (1) { #if defined(PIOS_LED_HEARTBEAT) PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); #endif /* PIOS_LED_HEARTBEAT */ PIOS_DELAY_WaitmS(100); } return 0; }
/** * Initialization task. * * Runs board and module initialization, then terminates. */ void initTask(void *parameters) { /* board driver init */ PIOS_Board_Init(); /* Initialize modules */ MODULE_INITIALISE_ALL(PIOS_WDG_Clear); /* terminate this task */ PIOS_Thread_Delete(NULL); }
/** * Initialize the hardware, libraries and modules (called by the System thread in systemmod.c) */ void OpenPilotInit() { /* Architecture dependant Hardware and * core subsystem initialisation * (see pios_board.c for your arch) * */ PIOS_Board_Init(); /* Initialize modules */ InitModules(); }
/** * @brief Bootloader Main function */ int main() { uint8_t GO_dfu = false; /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); /* Delay system */ PIOS_DELAY_Init(); for (uint32_t t = 0; t < 10000000; ++t) { if (NSS_HOLD_STATE == 1) GO_dfu = TRUE; else { GO_dfu = FALSE; break; } } //while(TRUE) // { // PIOS_LED_Toggle(LED1); // PIOS_DELAY_WaitmS(1000); // } //GO_dfu = TRUE; PIOS_IAP_Init(); GO_dfu = GO_dfu | PIOS_IAP_CheckRequest();// OR with app boot request if (GO_dfu == FALSE) { jump_to_app(); } if (PIOS_IAP_CheckRequest()) { PIOS_DELAY_WaitmS(1000); PIOS_IAP_ClearRequest(); } PIOS_Board_Init(); boot_status = idle; Fw_crc = PIOS_BL_HELPER_CRC_Memory_Calc(); PIOS_LED_On(LED1); while (1) { process_spi_request(); } return 0; }
/** * OpenPilot Main function: * * Initialize PiOS<BR> * Create the "System" task (SystemModInitializein Modules/System/systemmod.c) <BR> * Start FreeRTOS Scheduler (vTaskStartScheduler)<BR> * If something goes wrong, blink LED1 and LED2 every 100ms * */ int main() { /* NOTE: Do NOT modify the following start-up sequence */ /* Any new initialization functions should be added in OpenPilotInit() */ /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); /* Architecture dependant Hardware and * core subsystem initialisation * (see pios_board.c for your arch) * */ PIOS_Board_Init(); /* Initialize modules */ MODULE_INITIALISE_ALL #if INCLUDE_TEST_TASKS /* Create test tasks */ xTaskCreate(TaskTesting, (signed portCHAR *)"Testing", configMINIMAL_STACK_SIZE , NULL, 4, NULL); xTaskCreate(TaskHIDTest, (signed portCHAR *)"HIDTest", configMINIMAL_STACK_SIZE , NULL, 3, NULL); xTaskCreate(TaskServos, (signed portCHAR *)"Servos", configMINIMAL_STACK_SIZE , NULL, 3, NULL); xTaskCreate(TaskSDCard, (signed portCHAR *)"SDCard", configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 2), NULL); #endif /* swap the stack to use the IRQ stack (does nothing in sim mode) */ Stack_Change_Weak(); /* Start the FreeRTOS scheduler which should never returns.*/ vTaskStartScheduler(); /* If all is well we will never reach here as the scheduler will now be running. */ /* Do some indication to user that something bad just happened */ PIOS_LED_Off(LED1); \ for(;;) { \ PIOS_LED_Toggle(LED1); \ PIOS_DELAY_WaitmS(100); \ }; return 0; }
/** * Initialisation task. * * Runs board and module initialisation, then terminates. */ void initTask(void *parameters) { /* board driver init */ PIOS_Board_Init(); #ifdef ERASE_FLASH PIOS_Flash_Jedec_EraseChip(); #if defined(PIOS_LED_HEARTBEAT) PIOS_LED_Off(PIOS_LED_HEARTBEAT); #endif /* PIOS_LED_HEARTBEAT */ while (1) ; #endif /* Initialize modules */ MODULE_INITIALISE_ALL(PIOS_WDG_Clear); /* terminate this task */ PIOS_Thread_Delete(NULL); }
int main() { PIOS_SYS_Init(); if (BSL_HOLD_STATE == 0) USB_connected = TRUE; PIOS_IAP_Init(); if (PIOS_IAP_CheckRequest() == TRUE) { PIOS_Board_Init(); PIOS_DELAY_WaitmS(1000); User_DFU_request = TRUE; PIOS_IAP_ClearRequest(); } GO_dfu = (USB_connected == TRUE) || (User_DFU_request == TRUE); if (GO_dfu == TRUE) { PIOS_Board_Init(); if (User_DFU_request == TRUE) DeviceState = DFUidle; else DeviceState = BLidle; STOPWATCH_Init(100, LED_PWM_TIMER); } else JumpToApp = TRUE; STOPWATCH_Reset(LED_PWM_TIMER); while (TRUE) { if (JumpToApp == TRUE) jump_to_app(); switch (DeviceState) { case Last_operation_Success: case uploadingStarting: case DFUidle: period1 = 50; sweep_steps1 = 100; PIOS_LED_Off(BLUE); period2 = 0; break; case uploading: period1 = 50; sweep_steps1 = 100; period2 = 25; sweep_steps2 = 50; break; case downloading: period1 = 25; sweep_steps1 = 50; PIOS_LED_Off(BLUE); period2 = 0; break; case BLidle: period1 = 0; PIOS_LED_On(BLUE); period2 = 0; break; default://error period1 = 50; sweep_steps1 = 100; period2 = 50; sweep_steps2 = 100; } if (period1 != 0) { if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet(LED_PWM_TIMER))) PIOS_LED_On(BLUE); else PIOS_LED_Off(BLUE); } else PIOS_LED_On(BLUE); if (period2 != 0) { if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet(LED_PWM_TIMER))) PIOS_LED_On(BLUE); else PIOS_LED_Off(BLUE); } else PIOS_LED_Off(BLUE); if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100) STOPWATCH_Reset(LED_PWM_TIMER); if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle)) JumpToApp = TRUE; processRX(); DataDownload(start); } }
int main() { PIOS_SYS_Init(); PIOS_Board_Init(); PIOS_IAP_Init(); USB_connected = PIOS_USB_CheckAvailable(0); if (PIOS_IAP_CheckRequest() == true) { PIOS_DELAY_WaitmS(1000); User_DFU_request = true; PIOS_IAP_ClearRequest(); } GO_dfu = (USB_connected == true) || (User_DFU_request == true); if (GO_dfu == true) { PIOS_Board_Init(); if (User_DFU_request == true) DeviceState = DFUidle; else DeviceState = BLidle; } else JumpToApp = true; uint32_t stopwatch = 0; uint32_t prev_ticks = PIOS_DELAY_GetuS(); while (true) { /* Update the stopwatch */ uint32_t elapsed_ticks = PIOS_DELAY_GetuSSince(prev_ticks); prev_ticks += elapsed_ticks; stopwatch += elapsed_ticks; if (JumpToApp == true) jump_to_app(); switch (DeviceState) { case Last_operation_Success: case uploadingStarting: case DFUidle: period1 = 5000; sweep_steps1 = 100; PIOS_LED_Off(PIOS_LED_HEARTBEAT); period2 = 0; break; case uploading: period1 = 5000; sweep_steps1 = 100; period2 = 2500; sweep_steps2 = 50; break; case downloading: period1 = 2500; sweep_steps1 = 50; PIOS_LED_Off(PIOS_LED_HEARTBEAT); period2 = 0; break; case BLidle: period1 = 0; PIOS_LED_On(PIOS_LED_HEARTBEAT); period2 = 0; break; default://error period1 = 5000; sweep_steps1 = 100; period2 = 5000; sweep_steps2 = 100; } if (period1 != 0) { if (LedPWM(period1, sweep_steps1, stopwatch)) PIOS_LED_On(PIOS_LED_HEARTBEAT); else PIOS_LED_Off(PIOS_LED_HEARTBEAT); } else PIOS_LED_On(PIOS_LED_HEARTBEAT); if (period2 != 0) { if (LedPWM(period2, sweep_steps2, stopwatch)) PIOS_LED_On(PIOS_LED_HEARTBEAT); else PIOS_LED_Off(PIOS_LED_HEARTBEAT); } else PIOS_LED_Off(PIOS_LED_HEARTBEAT); if (stopwatch > 50 * 1000 * 1000) stopwatch = 0; if ((stopwatch > 6 * 1000 * 1000) && (DeviceState == BLidle)) JumpToApp = true; processRX(); DataDownload(start); } }
int main() { PIOS_SYS_Init(); PIOS_Board_Init(); PIOS_LED_On(PIOS_LED_HEARTBEAT); PIOS_DELAY_WaitmS(3000); PIOS_LED_Off(PIOS_LED_HEARTBEAT); /// Self overwrite check uint32_t base_address = SCB->VTOR; if ((0x08000000 + embedded_image_size) > base_address) error(PIOS_LED_HEARTBEAT, 1); /// /* * Make sure the bootloader we're carrying is for the same * board type and board revision as the one we're running on. * * Assume the bootloader in flash and the bootloader contained in * the updater both carry a board_info_blob at the end of the image. */ /* Calculate how far the board_info_blob is from the beginning of the bootloader */ uint32_t board_info_blob_offset = (uint32_t) &pios_board_info_blob - (uint32_t)0x08000000; /* Use the same offset into our embedded bootloader image */ struct pios_board_info * new_board_info_blob = (struct pios_board_info *) ((uint32_t)embedded_image_start + board_info_blob_offset); /* Compare the two board info blobs to make sure they're for the same HW revision */ if ((pios_board_info_blob.magic != new_board_info_blob->magic) || (pios_board_info_blob.board_type != new_board_info_blob->board_type) || (pios_board_info_blob.board_rev != new_board_info_blob->board_rev)) { error(PIOS_LED_HEARTBEAT, 2); } /* Embedded bootloader looks like it's the right one for this HW, proceed... */ FLASH_Unlock(); /// Bootloader memory space erase uint32_t pageAddress; pageAddress = 0x08000000; bool fail = false; while ((pageAddress < base_address) && (fail == false)) { for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { if (FLASH_ErasePage(pageAddress) == FLASH_COMPLETE) { fail = false; break; } else { fail = true; } } #ifdef STM32F10X_HD pageAddress += 2048; #elif defined (STM32F10X_MD) pageAddress += 1024; #endif } if (fail == true) error(PIOS_LED_HEARTBEAT, 3); /// /// Bootloader programing for (uint32_t offset = 0; offset < embedded_image_size / sizeof(uint32_t); ++offset) { bool result = false; PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); for (uint8_t retry = 0; retry < MAX_WRI_RETRYS; ++retry) { if (result == false) { result = (FLASH_ProgramWord(0x08000000 + (offset * 4), embedded_image_start[offset]) == FLASH_COMPLETE) ? true : false; } } if (result == false) error(PIOS_LED_HEARTBEAT, 4); } /// for (uint8_t x = 0; x < 3; ++x) { PIOS_LED_On(PIOS_LED_HEARTBEAT); PIOS_DELAY_WaitmS(1000); PIOS_LED_Off(PIOS_LED_HEARTBEAT); PIOS_DELAY_WaitmS(1000); } /// Invalidate the bootloader updater so we won't run /// the update again on the next power cycle. FLASH_ProgramWord(base_address, 0); FLASH_Lock(); for (;;) { PIOS_DELAY_WaitmS(1000); } }
int main() { /* NOTE: Do NOT modify the following start-up sequence */ /* Any new initialization functions should be added in OpenPilotInit() */ /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); if (BSL_HOLD_STATE == 0) USB_connected = TRUE; PIOS_IAP_Init(); if (PIOS_IAP_CheckRequest() == TRUE) { PIOS_Board_Init(); PIOS_DELAY_WaitmS(1000); User_DFU_request = TRUE; PIOS_IAP_ClearRequest(); } GO_dfu = (USB_connected == TRUE) || (User_DFU_request == TRUE); if (GO_dfu == TRUE) { if (USB_connected) ProgPort = Usb; else ProgPort = Serial; PIOS_Board_Init(); if(User_DFU_request == TRUE) DeviceState = DFUidle; else DeviceState = BLidle; STOPWATCH_Init(100,LED_PWM_TIMER); if (ProgPort == Serial) { fifoBuf_init(&ssp_buffer,rx_buffer,UART_BUFFER_SIZE); STOPWATCH_Init(100,SSP_TIMER);//nao devia ser 1000? STOPWATCH_Reset(SSP_TIMER); ssp_Init(&ssp_port, &SSP_PortConfig); } PIOS_OPAHRS_ForceSlaveSelected(true); } else JumpToApp = TRUE; STOPWATCH_Reset(LED_PWM_TIMER); while (TRUE) { if (ProgPort == Serial) { ssp_ReceiveProcess(&ssp_port); status=ssp_SendProcess(&ssp_port); while((status!=SSP_TX_IDLE) && (status!=SSP_TX_ACKED)){ ssp_ReceiveProcess(&ssp_port); status=ssp_SendProcess(&ssp_port); } } if (JumpToApp == TRUE) jump_to_app(); //pwm_period = 50; // *100 uS -> 5 mS //pwm_sweep_steps =100; // * 5 mS -> 500 mS switch (DeviceState) { case Last_operation_Success: case uploadingStarting: case DFUidle: period1 = 50; sweep_steps1 = 100; PIOS_LED_Off(RED); period2 = 0; break; case uploading: period1 = 50; sweep_steps1 = 100; period2 = 25; sweep_steps2 = 50; break; case downloading: period1 = 25; sweep_steps1 = 50; PIOS_LED_Off(RED); period2 = 0; break; case BLidle: period1 = 0; PIOS_LED_On(BLUE); period2 = 0; break; default://error period1 = 50; sweep_steps1 = 100; period2 = 50; sweep_steps2 = 100; } if (period1 != 0) { if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet(LED_PWM_TIMER))) PIOS_LED_On(BLUE); else PIOS_LED_Off(BLUE); } else PIOS_LED_On(BLUE); if (period2 != 0) { if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet(LED_PWM_TIMER))) PIOS_LED_On(RED); else PIOS_LED_Off(RED); } else PIOS_LED_Off(RED); if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100) STOPWATCH_Reset(LED_PWM_TIMER); if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle)) JumpToApp = TRUE; processRX(); DataDownload(start); } }
int main() { PIOS_SYS_Init(); PIOS_Board_Init(); PIOS_IAP_Init(); // Make sure the brown out reset value for this chip // is 2.7 volts check_bor(); #ifdef PIOS_INCLUDE_USB USB_connected = PIOS_USB_CheckAvailable(0); #endif if (PIOS_IAP_CheckRequest() == true) { PIOS_DELAY_WaitmS(1000); User_DFU_request = true; PIOS_IAP_ClearRequest(); } GO_dfu = (USB_connected == true) || (User_DFU_request == true); if (GO_dfu == true) { if (User_DFU_request == true) { DeviceState = DFUidle; } else { DeviceState = BLidle; } } else { JumpToApp = true; } uint32_t stopwatch = 0; uint32_t prev_ticks = PIOS_DELAY_GetuS(); while (true) { /* Update the stopwatch */ uint32_t elapsed_ticks = PIOS_DELAY_GetuSSince(prev_ticks); prev_ticks += elapsed_ticks; stopwatch += elapsed_ticks; if (JumpToApp == true) { jump_to_app(); } switch (DeviceState) { case Last_operation_Success: case uploadingStarting: case DFUidle: period1 = 5000; sweep_steps1 = 100; PIOS_LED_Off(PIOS_LED_HEARTBEAT); period2 = 0; break; case uploading: period1 = 5000; sweep_steps1 = 100; period2 = 2500; sweep_steps2 = 50; break; case downloading: period1 = 2500; sweep_steps1 = 50; PIOS_LED_Off(PIOS_LED_HEARTBEAT); period2 = 0; break; case BLidle: period1 = 0; PIOS_LED_On(PIOS_LED_HEARTBEAT); period2 = 0; break; default: // error period1 = 5000; sweep_steps1 = 100; period2 = 5000; sweep_steps2 = 100; } if (period1 != 0) { if (LedPWM(period1, sweep_steps1, stopwatch)) { PIOS_LED_On(PIOS_LED_HEARTBEAT); } else { PIOS_LED_Off(PIOS_LED_HEARTBEAT); } } else { PIOS_LED_On(PIOS_LED_HEARTBEAT); } if (period2 != 0) { if (LedPWM(period2, sweep_steps2, stopwatch)) { PIOS_LED_On(PIOS_LED_HEARTBEAT); } else { PIOS_LED_Off(PIOS_LED_HEARTBEAT); } } else { PIOS_LED_Off(PIOS_LED_HEARTBEAT); } if (stopwatch > 50 * 1000 * 1000) { stopwatch = 0; } if ((stopwatch > 6 * 1000 * 1000) && ((DeviceState == BLidle) || (DeviceState == DFUidle && !USB_connected))) { JumpToApp = true; } processRX(); DataDownload(start); } }
int main() { /* NOTE: Do NOT modify the following start-up sequence */ /* Any new initialization functions should be added in OpenPilotInit() */ /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); if (BSL_HOLD_STATE == 0) USB_connected = TRUE; PIOS_IAP_Init(); if (PIOS_IAP_CheckRequest() == TRUE) { PIOS_Board_Init(); PIOS_DELAY_WaitmS(1000); User_DFU_request = TRUE; PIOS_IAP_ClearRequest(); } GO_dfu = (USB_connected == TRUE) || (User_DFU_request == TRUE); if (GO_dfu == TRUE) { PIOS_Board_Init(); if(User_DFU_request == TRUE) DeviceState = DFUidle; else DeviceState = BLidle; STOPWATCH_Init(100,LED_PWM_TIMER); } else JumpToApp = TRUE; STOPWATCH_Reset(LED_PWM_TIMER); while (TRUE) { if (JumpToApp == TRUE) jump_to_app(); //pwm_period = 50; // *100 uS -> 5 mS //pwm_sweep_steps =100; // * 5 mS -> 500 mS switch (DeviceState) { case Last_operation_Success: case uploadingStarting: case DFUidle: period1 = 50; sweep_steps1 = 100; PIOS_LED_Off(BLUE); period2 = 0; break; case uploading: period1 = 50; sweep_steps1 = 100; period2 = 25; sweep_steps2 = 50; break; case downloading: period1 = 25; sweep_steps1 = 50; PIOS_LED_Off(BLUE); period2 = 0; break; case BLidle: period1 = 0; PIOS_LED_On(BLUE); period2 = 0; break; default://error period1 = 50; sweep_steps1 = 100; period2 = 50; sweep_steps2 = 100; } if (period1 != 0) { if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet(LED_PWM_TIMER))) PIOS_LED_On(BLUE); else PIOS_LED_Off(BLUE); } else PIOS_LED_On(BLUE); if (period2 != 0) { if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet(LED_PWM_TIMER))) PIOS_LED_On(BLUE); else PIOS_LED_Off(BLUE); } else PIOS_LED_Off(BLUE); if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100) STOPWATCH_Reset(LED_PWM_TIMER); if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle)) JumpToApp = TRUE; processRX(); DataDownload(start); } }