Index: App/Services/MsgQueues.c =================================================================== diff -u -r24f2fc89f0bfb62edcae316511e3fb4d7a336d01 -r7d70e839bc71f6fc37da8cd12eecb374841882df --- App/Services/MsgQueues.c (.../MsgQueues.c) (revision 24f2fc89f0bfb62edcae316511e3fb4d7a336d01) +++ App/Services/MsgQueues.c (.../MsgQueues.c) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) @@ -30,8 +30,6 @@ // ********** private function prototypes ********** -static void blankMessageInWrapper( MESSAGE_WRAPPER_T *message ); - /************************************************************************* * @brief initMsgQueues * The initMsgQueues function initializes the MsgQueues module. @@ -69,11 +67,7 @@ * @param msg : a pointer to a message structure to add to the queue * @return TRUE if message added to queue, FALSE if could not *************************************************************************/ -//static U32 msgQueueCounts[NUM_OF_MSG_QUEUES]; -//static U32 msgQueueStarts[NUM_OF_MSG_QUEUES]; -//static U32 msgQueueNexts[NUM_OF_MSG_QUEUES]; -//static MESSAGE_WRAPPER_T msgQueues[NUM_OF_MSG_QUEUES][MAX_MSG_QUEUE_SIZE]; -BOOL addToMsgQueue( MSG_QUEUE_T queue, MESSAGE_T *msg ) +BOOL addToMsgQueue( MSG_QUEUE_T queue, MESSAGE_WRAPPER_T *msg ) { BOOL result = FALSE; @@ -107,7 +101,7 @@ if ( FALSE == full ) { // add message to queue - msgQueues[queue][next].msg = *msg; + msgQueues[queue][next] = *msg; // TODO - calculate CRC for given message (just zero for now) msgQueues[queue][next].crc = 0x0; @@ -171,6 +165,8 @@ { // get message from queue *msg = msgQueues[queue][first]; + + result = TRUE; } else // message queue is full { @@ -249,10 +245,10 @@ * @details * Inputs : none * Outputs : none - * @param message : the message in a wrapper to blank. + * @param message : Pointer to the message in a wrapper to blank. * @return none *************************************************************************/ -static void blankMessageInWrapper( MESSAGE_WRAPPER_T *message ) +void blankMessageInWrapper( MESSAGE_WRAPPER_T *message ) { U32 i; U32 msgSize = sizeof(MESSAGE_WRAPPER_T); @@ -267,3 +263,5 @@ message->msg.hdr.msgID = 0xFFFF; } + + Index: App/Services/MsgQueues.h =================================================================== diff -u -r24f2fc89f0bfb62edcae316511e3fb4d7a336d01 -r7d70e839bc71f6fc37da8cd12eecb374841882df --- App/Services/MsgQueues.h (.../MsgQueues.h) (revision 24f2fc89f0bfb62edcae316511e3fb4d7a336d01) +++ App/Services/MsgQueues.h (.../MsgQueues.h) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) @@ -58,12 +58,15 @@ U08 crc; // message CRC } MESSAGE_WRAPPER_T; +#define MESSAGE_OVERHEAD_SIZE (sizeof(MESSAGE_HEADER_T) + sizeof(U08)) + // ********** public function prototypes ********** void initMsgQueues( void ); -BOOL addToMsgQueue( MSG_QUEUE_T queue, MESSAGE_T *msg ); +BOOL addToMsgQueue( MSG_QUEUE_T queue, MESSAGE_WRAPPER_T *msg ); BOOL getFromMsgQueue( MSG_QUEUE_T queue, MESSAGE_WRAPPER_T *msg ); BOOL isMsgQueueEmpty( MSG_QUEUE_T queue ); BOOL isMsgQueueFull( MSG_QUEUE_T queue ); +void blankMessageInWrapper( MESSAGE_WRAPPER_T *message ); #endif Index: App/Services/SystemComm.c =================================================================== diff -u -ree310a2e5262c05bf0dc0eb0d84da0ee50bac7fe -r7d70e839bc71f6fc37da8cd12eecb374841882df --- App/Services/SystemComm.c (.../SystemComm.c) (revision ee310a2e5262c05bf0dc0eb0d84da0ee50bac7fe) +++ App/Services/SystemComm.c (.../SystemComm.c) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) @@ -16,14 +16,29 @@ * **************************************************************************/ +#include "can.h" + #include "Common.h" +#include "Buttons.h" +#include "CommBuffers.h" +#include "MsgQueues.h" #include "SystemComm.h" // ********** private definitions ********** +typedef enum Msg_IDs +{ + MSG_ID_TEST = 0, + MSG_ID_OFF_BUTTON_PRESS, + NUM_OF_MSG_IDS +} MSG_ID_T; + // ********** private data ********** +// ********** private function prototypes ********** + + /************************************************************************* * @brief initSystemComm * The initSystemComm function initializes the SystemComm module. @@ -35,6 +50,96 @@ *************************************************************************/ void initSystemComm( void ) { + } +/************************************************************************* + * @brief initSystemComm + * The initSystemComm function initializes the SystemComm module. + * @details + * Inputs : none + * Outputs : SystemComm module initialized. + * @param none + * @return none + *************************************************************************/ +void execSystemComm( void ) +{ + // TODO - this is ugly preliminary test code - nowhere near ready for code review + BOOL isThereMsgToXmit; + BOOL isThereMsgRcvd; + U08 data[sizeof(MESSAGE_WRAPPER_T)]; + U32 dataSize; + MESSAGE_WRAPPER_T msg; + // get next msg to transmit to UI + isThereMsgToXmit = getFromMsgQueue( MSG_Q_CAN_HD_2_UI, &msg ); + if ( TRUE == isThereMsgToXmit ) + { + U08 *dataPtr = data; + + memcpy( dataPtr, &(msg.msg.hdr), sizeof(MESSAGE_HEADER_T) ); + memcpy( dataPtr+sizeof(MESSAGE_HEADER_T), &(msg.msg.cargo), msg.msg.hdr.cargoLen ); + memcpy( dataPtr+(sizeof(MESSAGE_HEADER_T) + msg.msg.hdr.cargoLen), &(msg.crc), sizeof(U08) ); + + addToCommBuffer( COMM_BUFFER_CAN_HD_2_UI, dataPtr, MESSAGE_OVERHEAD_SIZE + msg.msg.hdr.cargoLen ); + } + + // actually transmit any pending messages + dataSize = getFromCommBuffer( COMM_BUFFER_CAN_HD_2_UI, data, sizeof(MESSAGE_WRAPPER_T) ); + if ( dataSize <= 8 ) + { + canTransmit( canREG1, canMESSAGE_BOX1, data ); + } + + // queue any received CAN messages + if ( FALSE != canIsRxMessageArrived( canREG1, canMESSAGE_BOX2 ) ) + { + MESSAGE_WRAPPER_T rcvMsg; + U08 *dataPtr = data; + + canGetData( canREG1, canMESSAGE_BOX2, data ); + blankMessageInWrapper( &rcvMsg ); + memcpy( &(rcvMsg.msg.hdr), dataPtr, sizeof(MESSAGE_HEADER_T) ); + memcpy( &(rcvMsg.msg.cargo), dataPtr+sizeof(MESSAGE_HEADER_T), rcvMsg.msg.hdr.cargoLen ); + memcpy( &(rcvMsg.crc), dataPtr+(sizeof(MESSAGE_HEADER_T)+rcvMsg.msg.hdr.cargoLen), sizeof(U08) ); + addToMsgQueue( MSG_Q_CAN_UI_2_HD, &rcvMsg ); + } + + // see if any messages received + isThereMsgRcvd = getFromMsgQueue( MSG_Q_CAN_UI_2_HD, &msg ); + if ( TRUE == isThereMsgRcvd ) + { + switch ( msg.msg.hdr.msgID ) + { + case MSG_ID_OFF_BUTTON_PRESS: + userConfirmOffButton(); + break; + default: + break; + } + } +} + +/************************************************************************* + * @brief sendOffButtonMsgToUI + * The sendOffButtonMsgToUI function constructs an off button msg to the UI \n + * and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : Off button msg constructed and queued. + * @param none + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendOffButtonMsgToUI( void ) +{ + BOOL result; + MESSAGE_WRAPPER_T msg; + + blankMessageInWrapper( &msg ); + msg.msg.hdr.msgID = MSG_ID_OFF_BUTTON_PRESS; + msg.msg.hdr.cargoLen = 0; + result = addToMsgQueue( MSG_Q_CAN_HD_2_UI, &msg ); + + return result; +} + Index: App/Services/SystemComm.h =================================================================== diff -u -ree310a2e5262c05bf0dc0eb0d84da0ee50bac7fe -r7d70e839bc71f6fc37da8cd12eecb374841882df --- App/Services/SystemComm.h (.../SystemComm.h) (revision ee310a2e5262c05bf0dc0eb0d84da0ee50bac7fe) +++ App/Services/SystemComm.h (.../SystemComm.h) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) @@ -19,8 +19,13 @@ #include "Common.h" +// ********** public definitions ********** + // ********** public function prototypes ********** void initSystemComm( void ); +void execSystemComm( void ); +BOOL sendOffButtonMsgToUI( void ); + #endif Index: App/Tasks/TaskGeneral.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r7d70e839bc71f6fc37da8cd12eecb374841882df --- App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) @@ -17,11 +17,15 @@ #include "gio.h" #include "lin.h" +#include "Common.h" #include "AlarmLamp.h" #include "OperationModes.h" +#include "SystemComm.h" #include "WatchdogMgmt.h" #include "TaskGeneral.h" +static U32 ctr = 0; // test code + /************************************************************************* * @brief taskGeneral * The taskGeneral function handles the scheduled General Task interrupt.\n @@ -35,6 +39,11 @@ *************************************************************************/ void taskGeneral( void ) { + // test code + if ( ++ctr >= 40 ) { sendOffButtonMsgToUI(); ctr = 0; } + // manage system communication + execSystemComm(); + // run operation mode state machine execOperationModes(); Index: HD.dil =================================================================== diff -u -rbbd766eed69a6ae143a42731965848da85fd4500 -r7d70e839bc71f6fc37da8cd12eecb374841882df --- HD.dil (.../HD.dil) (revision bbd766eed69a6ae143a42731965848da85fd4500) +++ HD.dil (.../HD.dil) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) @@ -1,4 +1,4 @@ -# RM46L852PGE 10/08/19 14:27:47 +# RM46L852PGE 10/08/19 17:59:56 # ARCH=RM46L852PGE # @@ -105,7 +105,7 @@ DRIVER.SYSTEM.VAR.VIM_CHANNEL_18_MAPPING.VALUE=18 DRIVER.SYSTEM.VAR.PMM_LOGIC_PD2_STATEVALUE.VALUE=0x5 DRIVER.SYSTEM.VAR.CLKT_VCLK3_DOMAIN_DISABLE.VALUE=0 -DRIVER.SYSTEM.VAR.FLASH_ECC_ENABLE.VALUE=0 +DRIVER.SYSTEM.VAR.FLASH_ECC_ENABLE.VALUE=1 DRIVER.SYSTEM.VAR.FLASH_BANKS.VALUE=4 DRIVER.SYSTEM.VAR.CORE_MPU_REGION_9_SUB_4_DISABLE.VALUE=0 DRIVER.SYSTEM.VAR.CORE_MPU_REGION_2_SUB_2_DISABLE.VALUE=0 @@ -628,7 +628,7 @@ DRIVER.SYSTEM.VAR.VIM_CHANNEL_103_NAME.VALUE=etpwm7TripZoneInterrupt DRIVER.SYSTEM.VAR.PBIST_ALGO_16.VALUE=0 DRIVER.SYSTEM.VAR.CLKT_VCLK2_DIVIDER.VALUE=1 -DRIVER.SYSTEM.VAR.RAM_LINK_LENGTH.VALUE=0x0002EB00 +DRIVER.SYSTEM.VAR.RAM_LINK_LENGTH.VALUE=0x0002eb00 DRIVER.SYSTEM.VAR.CORE_MPU_REGION_11_END_ADDRESS.VALUE=0x080017ff DRIVER.SYSTEM.VAR.VIM_CHANNEL_30_INT_ENABLE.VALUE=0 DRIVER.SYSTEM.VAR.VIM_CHANNEL_22_INT_ENABLE.VALUE=0