Index: firmware/source/sys_main.c =================================================================== diff -u -r850f8042a02fd17ee53b8db24bc2e3d17bbb9c7f -r24b4c7f4560296765373099ee83597baddc2cf94 --- firmware/source/sys_main.c (.../sys_main.c) (revision 850f8042a02fd17ee53b8db24bc2e3d17bbb9c7f) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 24b4c7f4560296765373099ee83597baddc2cf94) @@ -43,10 +43,6 @@ /* USER CODE BEGIN (0) */ - -static void initProcessor( void ); -static void initSoftware( void ); -static void initTasks( void ); /* USER CODE END */ /* Include Files */ @@ -62,7 +58,12 @@ #include "BLCommon.h" #include "CommBuffers.h" +#include "Download.h" +#include "FPGA.h" #include "Interrupts.h" +#include "NVDataMgmt.h" +#include "OperationModes.h" +#include "SystemComm.h" #include "TaskBG.h" #include "Timers.h" /* USER CODE END */ @@ -76,11 +77,24 @@ */ /* USER CODE BEGIN (2) */ +extern U32 apiLoadStart; +extern U32 apiRunStart; +extern U32 apiLoadSize; +/* + * For reference: + * https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/403240/change-load-address-when-debugging-with-tm4c129cnczad + * https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1218850/rm46l852-booting-main-application-from-can-bootloader-results-in-prefetchentry-system-interrupt + */ +static void copyFlashAPI2RAM( void ); +static void initProcessor( void ); +static void initSoftware( void ); +static void initTasks( void ); /* USER CODE END */ int main(void) { /* USER CODE BEGIN (3) */ + copyFlashAPI2RAM(); initProcessor(); initSoftware(); initTasks(); @@ -93,28 +107,69 @@ /* USER CODE BEGIN (4) */ + +/************************************************************************* + * @brief copyFlashAPI2RAM + * The copyFlashAPI2RAM function copies the flash API to RAM. + * @details Inputs: none + * @details Outputs:none + * @return none + *************************************************************************/ +static void copyFlashAPI2RAM( void ) +{ + // For memcpy: https://dev.ti.com/tirex/explore/node?isTheia=false&node=A__ACETON0B5e6CHwUmKRRZkQ__C2000WARE__1kRFgrO__5.03.00.00 + memcpy( &apiRunStart, &apiLoadStart, (U32)&apiLoadSize ); +} + +/************************************************************************* + * @brief initProcessor + * The initProcessor function initializes and configures the processor \n + * peripherals. + * @details Inputs: none + * @details Outputs: Processor peripherals initialized and configured. + * @return none + *************************************************************************/ static void initProcessor( void ) { canInit(); sciInit(); dmaEnable(); } +/************************************************************************* + * @brief initSoftware + * The initSoftware function calls all software unit initialization functions + * to initialize and configure the TD application. + * @details Inputs: none + * @details Outputs: All software units initialized. + * @return none + *************************************************************************/ static void initSoftware( void ) { initCommBuffers(); + initDownload(); + initFPGA(); initInterrupts(); + initNVDataMgmt(); + initOperationModes(); + initSystemComm(); initTimers(); } +/************************************************************************* + * @brief initTasks + * The initTasks function sets up and starts the scheduled tasks. + * @details Inputs: none + * @details Outputs: Scheduled tasks set up and started. + * @return none + *************************************************************************/ static void initTasks( void ) { // Initialize RTI to setup the 3 tasks rtiInit(); rtiEnableNotification( rtiNOTIFICATION_COMPARE0 | rtiNOTIFICATION_COMPARE1 | rtiNOTIFICATION_COMPARE3 ); rtiStartCounter( rtiCOUNTER_BLOCK0 ); - // The timer task requires FIQ enabled - _enable_FIQ(); + // NOTE: FIQ is not used in the bootloader. All the the tasks including the TaskTimer is on the IRQ. IRQ is disabled while flashing the firmwrae. // The general and priority tasks require IRQ enabled _enable_IRQ(); }