Index: source/sys_main.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -rcb47c5f896477ceae7597cb1a4191b3972e93f0d --- source/sys_main.c (.../sys_main.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ source/sys_main.c (.../sys_main.c) (revision cb47c5f896477ceae7597cb1a4191b3972e93f0d) @@ -51,16 +51,28 @@ /* USER CODE BEGIN (1) */ #include "system.h" +#include "sys_dma.h" +#include "can.h" #include "gio.h" -#include "lin.h" +#include "mibspi.h" +#include "sci.h" #include "rti.h" #include "Common.h" -#include "OperationModes.h" +#include "AlarmLamp.h" +#include "Buttons.h" +#include "CommBuffers.h" #include "CPLD.h" +#include "FPGA.h" +#include "MsgQueues.h" +#include "OperationModes.h" #include "SafetyShutdown.h" +#include "SystemComm.h" #include "TaskBG.h" +#include "Timers.h" +#include "WatchdogMgmt.h" +static void initProcessor( void ); static void initSoftware( void ); static void initHardware( void ); static void initTasks( void ); @@ -81,12 +93,15 @@ { /* USER CODE BEGIN (3) */ - initHardware(); - initSoftware(); - initTasks(); + initProcessor(); // configure processor + initSoftware(); // initialize software modules + initHardware(); // configure external hardware + initTasks(); // setup and start the scheduled tasks - // start task background (will no return) - taskBackground(); + // start task background (will not return) +#ifndef _VECTORCAST_ + taskBackground(); +#endif /* USER CODE END */ @@ -96,25 +111,131 @@ /* USER CODE BEGIN (4) */ +/************************************************************************* + * @brief initProcessor + * The initProcessor function initializes and configures the processor \n + * peripherals. + * @details + * Inputs : none + * Outputs : Processor peripherals initialized and configured. + * @return none + *************************************************************************/ +static void initProcessor( void ) +{ + gioInit(); // configure GPIO pins + mibspiInit(); // re-purposing MIBSPI5 I/O/C pins as GPIO + canInit(); // CAN1 = CAN, re-purposing CAN2 and CAN3 Rx and Tx pins as GPIO + sciInit(); // SCI1 used for PC serial interface, SCI2 used for FPGA serial interface + dmaEnable(); // enable DMA +} + +/************************************************************************* + * @brief initSoftware + * The initSoftware function calls all software module initialize functions. + * @details + * Inputs : none + * Outputs : All modules initialized. + * @return none + *************************************************************************/ static void initSoftware( void ) { - initSafetyShutdown(); - initCPLD(); - initOperationModes(); + initTimers(); + initSafetyShutdown(); + initCPLD(); + initOperationModes(); + initAlarmLamp(); + initButtons(); + initWatchdogMgmt(); + initFPGA(); + initCommBuffers(); + initMsgQueues(); + initSystemComm(); } +/************************************************************************* + * @brief initHardware + * The initHardware function initializes and configures external hardware. + * @details + * Inputs : none + * Outputs : External hardware initialized and configured. + * @return none + *************************************************************************/ static void initHardware( void ) { - gioInit(); - linInit(); // re-purposing LIN Rx & Tx pins as GPIO } +/************************************************************************* + * @brief initTasks + * The initTasks function sets up and starts the scheduled tasks. + * @details + * Inputs : none + * Outputs : Scheduled tasks set up and started. + * @return none + *************************************************************************/ static void initTasks( void ) { - _enable_IRQ(); - rtiInit(); - rtiEnableNotification( rtiNOTIFICATION_COMPARE0 | rtiNOTIFICATION_COMPARE1 | rtiNOTIFICATION_COMPARE3 ); - rtiStartCounter( rtiCOUNTER_BLOCK0 ); + // initialize RTI to setup the 3 tasks + rtiInit(); + rtiEnableNotification( rtiNOTIFICATION_COMPARE0 | rtiNOTIFICATION_COMPARE1 | rtiNOTIFICATION_COMPARE3 ); + rtiStartCounter( rtiCOUNTER_BLOCK0 ); + // the timer task (and other comm related interrupts) require FIQ enabled + _enable_FIQ(); + // the general and priority tasks require IRQ enabled + _enable_IRQ(); } +void sciNotification(sciBASE_t *sci, uint32 flags) +{ + static U32 fErrorCnt = 0; + static U32 oErrorCnt = 0; + + if ( ( flags & SCI_FE_INT ) != 0 ) + { + fErrorCnt++; + } + if ( ( flags & SCI_OE_INT ) != 0 ) + { + oErrorCnt++; + } +} + +void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel) +{ + if ( inttype == BTC ) + { + switch ( channel ) + { + case DMA_CH0: + // clear DMA receipt + scilinREG->CLEARINT = (uint32)((uint32)1U << 17U); /* Rx DMA */ + scilinREG->CLEARINT = (uint32)((uint32)1U << 18U); /* Rx DMA All */ + break; + + case DMA_CH1: + // clear DMA receipt + sciREG->CLEARINT = (uint32)((uint32)1U << 17U); /* Rx DMA */ + sciREG->CLEARINT = (uint32)((uint32)1U << 18U); /* Rx DMA All */ + // handle received packet from PC + handleUARTMsgRecvPacketInterrupt(); + break; + + case DMA_CH2: + // clear DMA xmit + scilinREG->CLEARINT = (uint32)((uint32)1U << 16U); /* Tx DMA */ + break; + + case DMA_CH3: + // clear DMA xmit + sciREG->CLEARINT = (uint32)((uint32)1U << 16U); /* Tx DMA */ + // send next pending packet to PC (if any) + handleUARTMsgXmitPacketInterrupt(); + break; + + default: + // TODO - ignore? + break; + } + } +} + /* USER CODE END */