Index: App/Contollers/Buttons.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Contollers/Buttons.c (.../Buttons.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Contollers/Buttons.c (.../Buttons.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -177,21 +177,30 @@ /************************************************************************* * @brief userConfirmOffButton * The userConfirmOffButton function handles user confirmation of the off \n - * button. The off request will be initiated here. + * button. The off request will be initiated here if confirmed or cancelled \n + * if rejected by user. * @details - * Inputs : stopButtonState, prevStopButtonState + * Inputs : current operation mode * Outputs : stopButtonPressPending - * @param none + * @param response : 1 = confirmed, 0 = rejected * @return none *************************************************************************/ -void userConfirmOffButton( void ) +void userConfirmOffButton( U08 response ) { - if ( TRUE == isCurrentOpModeOkToTurnOff() ) + // did user confirm? + if ( 1 == response ) { - offButtonPressPending = TRUE; - offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; - offRequestPulseTimer = 0; + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + offButtonPressPending = TRUE; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offRequestPulseTimer = 0; + } } + else // user did not confirm + { + // for now, don't need to do anything to reject off button press + } } /************************************************************************* @@ -290,7 +299,7 @@ { // TODO - send off button to UI for user confirmation // TODO - remove later (just pretend user confirmed for now) - userConfirmOffButton(); + userConfirmOffButton(1); } } prevOffButtonState = offButtonState; Index: App/Contollers/Buttons.h =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Contollers/Buttons.h (.../Buttons.h) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Contollers/Buttons.h (.../Buttons.h) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -34,7 +34,7 @@ void execButtons( void ); BOOL isStopButtonPressed( void ); BOOL isButtonPressedRaw( BUTTON_T button ); -void userConfirmOffButton( void ); +void userConfirmOffButton( U08 response ); SELF_TEST_STATUS_T execStuckButtonTest( void ); #endif Index: App/Drivers/CPLD.c =================================================================== diff -u -r67c59954ab757ae9d57b3d80f2b3cb8087300be6 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Drivers/CPLD.c (.../CPLD.c) (revision 67c59954ab757ae9d57b3d80f2b3cb8087300be6) +++ App/Drivers/CPLD.c (.../CPLD.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -33,7 +33,7 @@ #define WD_PET_GIO_PORT_PIN 1U #define WD_EXP_GIO_PORT_PIN 2U -// LIN port pin assignments for pins connected to CPLD +// MIBSPI5 port pin assignments for pins connected to CPLD #define GREEN_SPI5_PORT_MASK 0x00000200 // (CLK - re-purposed as output GPIO) #define BLUE_SPI5_PORT_MASK 0x00000400 // (SIMO[0] - re-purposed as output GPIO) #define RED_SPI5_PORT_MASK 0x00000800 // (SOMI[0] - re-purposed as output GPIO) @@ -57,6 +57,33 @@ #define CLR_BLUE() mibspiREG5->PC3 &= ~BLUE_SPI5_PORT_MASK #define CLR_RED() mibspiREG5->PC3 &= ~RED_SPI5_PORT_MASK +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 1 +// for RM46 eval board, user button B uses the MIBSPI1_nCS[4] pin, so need to re-purpose that pin as GPIO to see the button +#define USER_BUTTON_MASK 0x00000010 // (nCS[4] +#define GET_USER_BUTTON() (PIN_SIGNAL_STATE_T)(((mibspiREG1->PC2 & USER_BUTTON_MASK) == 0 ? PIN_SIGNAL_LOW : PIN_SIGNAL_HIGH)) +PIN_SIGNAL_STATE_T getUserButtonState( void ) +{ + PIN_SIGNAL_STATE_T result = GET_USER_BUTTON(); + + return result; +} +// for RM46 eval board, user LED A uses the same GPIO pin that CPLD uses for watchdog pet. Had to disable watchdog pet to use as LED. +void setUserLED( BOOL on ) +{ + if ( on == TRUE ) + { + SET_WD_PET(); + } + else + { + CLR_WD_PET(); + } +} +#endif +// ************************** END TEST CODE ****************************** + /************************************************************************* * @brief initCPLD * The initCPLD function initializes the CPLD module. Index: App/Drivers/CPLD.h =================================================================== diff -u -r67c59954ab757ae9d57b3d80f2b3cb8087300be6 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Drivers/CPLD.h (.../CPLD.h) (revision 67c59954ab757ae9d57b3d80f2b3cb8087300be6) +++ App/Drivers/CPLD.h (.../CPLD.h) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -34,4 +34,12 @@ PIN_SIGNAL_STATE_T getCPLDOffButton( void ); PIN_SIGNAL_STATE_T getCPLDStopButton( void ); +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 1 +PIN_SIGNAL_STATE_T getUserButtonState( void ); +void setUserLED( BOOL on ); #endif +// ************************** END TEST CODE ****************************** + +#endif Index: App/Services/CommBuffers.c =================================================================== diff -u -r24f2fc89f0bfb62edcae316511e3fb4d7a336d01 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/CommBuffers.c (.../CommBuffers.c) (revision 24f2fc89f0bfb62edcae316511e3fb4d7a336d01) +++ App/Services/CommBuffers.c (.../CommBuffers.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -13,8 +13,7 @@ * @brief CommBuffers service module. Provides data buffering functionality. \n * Data coming in via CAN/UART Rx interrupts can be placed in a buffer to \n * be processed at a later time. Data is double buffered to prevent \n - * contention between Rx interrupt and the thread that is consuming the data \n - * at a later time. \n + * contention between Rx/Tx interrupts and the processing thread(s). \n * Data to be transmitted via CAN/UART can be placed in a buffer to be sent \n * when the transmitter becomes available. \n * If a buffer becomes too full to service more data, a s/w fault is triggered. @@ -26,6 +25,8 @@ // ********** private definitions ********** +#define COMM_BUFFER_LENGTH 128 // bytes + // ********** private data ********** static U32 commBufferByteCount[NUM_OF_COMM_BUFFERS][2]; // for each buffer, how many bytes does it contain? (also index to next available) @@ -70,9 +71,8 @@ * @brief addToCommBuffer * The addToCommBuffer function adds data of specified length to a specified \n * communication buffer. S/W fault if buffer too full to add data. \n - * Only one function in one thread should be calling this function. It is \n - * assumed that this thread will be higher priority than the thread calling \n - * the getFromCommBuffer() function so no thread protection is given. + * Only one function in one thread should be calling this function for a \n + * given buffer. This function will always add to the active double buffer. * @details * Inputs : commBufferByteCount[], activeDoubleBuffers[] * Outputs : commBuffers[], commBufferByteCount[] @@ -127,34 +127,40 @@ /************************************************************************* * @brief getFromCommBuffer - * The getFromCommBuffer function fills a given byte array with data from \n - * a given buffer and returns the number of bytes retrieved from the buffer. \n - * Only one function in one thread should be calling this function. + * The getFromCommBuffer function fills a given byte array with a given \n + * number of bytes from a given buffer and returns the number of bytes \n + * retrieved from the buffer. This function will always draw from the \n + * inactive double buffer. If some of the requested data is in the active \n + * double buffer, the double buffers will be switched when the inactive \n + * double buffer is emptied and the retrieve will continue to the requested \n + * number of bytes. + * Only one function in one thread should be calling this function for a given \n + * buffer. * @details * Inputs : commBuffers[], commBufferByteCount[] * Outputs : commBufferByteCount[], activeDoubleBuffers[] * @param buffer : which comm buffer to retrieve data from * @param data : pointer to byte array to stuff data into - * @param maxLen : maximum # of bytes to retrieve into given data array. + * @param len : # of bytes to retrieve into given data array. * @return the number of bytes retrieved. *************************************************************************/ -U32 getFromCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 maxLen ) +U32 getFromCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 len ) { U32 result = 0; // verify given buffer if ( buffer < NUM_OF_COMM_BUFFERS ) { - // check to see if anything in buffer - if ( FALSE == isCommBufferEmpty( buffer ) ) + // check to see if requested # of bytes is in given buffer + if ( getNumberOfBytesInCommBuffer( buffer ) >= len ) { // switch double buffer (now we'll read from what was active buffer and Rx interrupts will feed new active buffer) U32 activeBuffer = switchDoubleBuffer( buffer ); U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); U32 bytesRetrieved = commBufferByteCount[buffer][inactiveBuffer]; // ensure caller's data buffer can hold the data we have to retrieve - if ( bytesRetrieved <= maxLen ) + if ( bytesRetrieved <= 1000 ) // was maxLen { U08 *buffPtr; // buffer source for retrieved data U08 *dstPtr; // buffer destination for retrieved data @@ -179,7 +185,7 @@ // TODO - s/w fault? } } - else // buffer is empty + else // buffer contains insufficient data to satisfy the request { // result already set to zero } @@ -193,6 +199,34 @@ } /************************************************************************* + * @brief getNumberOfBytesInCommBuffer + * The getNumberOfBytesInCommBuffer function determines how many bytes \n + * are currently contained in a given comm buffer. Both double buffers \n + * are considered for this. + * @details + * Inputs : activeDoubleBuffers[], commBufferByteCount[] + * Outputs : none + * @param buffer : which comm buffer to get byte count for + * @return the number of bytes in the given comm buffer. + *************************************************************************/ +U32 getNumberOfBytesInCommBuffer( COMM_BUFFER_T buffer ) +{ + U32 result = 0; + + // verify given buffer + if ( buffer < NUM_OF_COMM_BUFFERS ) + { + result = commBufferByteCount[buffer][0] + commBufferByteCount[buffer][1]; + } + else // invalid buffer + { + // TODO - s/w fault. + } + + return result; +} + +/************************************************************************* * @brief switchDoubleBuffer * The switchDoubleBuffer function switches the active and inactive buffers \n * for the given buffer. Index: App/Services/CommBuffers.h =================================================================== diff -u -ree310a2e5262c05bf0dc0eb0d84da0ee50bac7fe -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/CommBuffers.h (.../CommBuffers.h) (revision ee310a2e5262c05bf0dc0eb0d84da0ee50bac7fe) +++ App/Services/CommBuffers.h (.../CommBuffers.h) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -21,31 +21,30 @@ // ********** public definitions ********** -#define COMM_BUFFER_LENGTH 128 // bytes - typedef enum Comm_Buffers { - COMM_BUFFER_CAN_HD_ALARM = 0, - COMM_BUFFER_CAN_DG_ALARM, - COMM_BUFFER_CAN_UI_ALARM, - COMM_BUFFER_CAN_HD_2_DG, - COMM_BUFFER_CAN_DG_2_HD, - COMM_BUFFER_CAN_HD_2_UI, - COMM_BUFFER_CAN_HD_BROADCAST, - COMM_BUFFER_CAN_DG_BROADCAST, - COMM_BUFFER_CAN_UI_2_HD, - COMM_BUFFER_CAN_UI_BROADCAST, - COMM_BUFFER_FPGA_IN, - COMM_BUFFER_FPGA_OUT, - COMM_BUFFER_DBG_IN, - COMM_BUFFER_DBG_OUT, + COMM_BUFFER_OUT_CAN_HD_ALARM = 0, + COMM_BUFFER_IN_CAN_DG_ALARM, + COMM_BUFFER_IN_CAN_UI_ALARM, + COMM_BUFFER_OUT_CAN_HD_2_DG, + COMM_BUFFER_IN_CAN_DG_2_HD, + COMM_BUFFER_OUT_CAN_HD_2_UI, + COMM_BUFFER_OUT_CAN_HD_BROADCAST, + COMM_BUFFER_IN_CAN_DG_BROADCAST, + COMM_BUFFER_IN_CAN_UI_2_HD, + COMM_BUFFER_IN_CAN_UI_BROADCAST, + COMM_BUFFER_IN_FPGA, + COMM_BUFFER_OUT_FPGA, + COMM_BUFFER_IN_DBG, + COMM_BUFFER_OUT_DBG, NUM_OF_COMM_BUFFERS } COMM_BUFFER_T; // ********** public function prototypes ********** void initCommBuffers( void ); BOOL addToCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 len ); -U32 getFromCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 maxLen ); +U32 getFromCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 len ); +U32 getNumberOfBytesInCommBuffer( COMM_BUFFER_T buffer ); #endif Index: App/Services/MsgQueues.c =================================================================== diff -u -r7d70e839bc71f6fc37da8cd12eecb374841882df -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/MsgQueues.c (.../MsgQueues.c) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) +++ App/Services/MsgQueues.c (.../MsgQueues.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -240,6 +240,31 @@ } /************************************************************************* + * @brief blankMessage + * The blankMessage function blanks a given message. + * @details + * Inputs : none + * Outputs : none + * @param message : Pointer to the message to blank. + * @return none + *************************************************************************/ +void blankMessage( MESSAGE_T *message ) +{ + U32 i; + U32 msgSize = sizeof(MESSAGE_T); + U08 *msgContent = (U08*)message; + + // zero out the message + for ( i = 0; i < msgSize; i++ ) + { + *msgContent++ = 0x0; + } + + // set msg ID out of bounds in case blank message goes somewhere + message->hdr.msgID = 0xFFFF; +} + +/************************************************************************* * @brief blankMessageInWrapper * The blankMessageInWrapper function blanks a given message in a wrapper. * @details @@ -251,9 +276,10 @@ void blankMessageInWrapper( MESSAGE_WRAPPER_T *message ) { U32 i; - U32 msgSize = sizeof(MESSAGE_WRAPPER_T); + U32 msgSize = sizeof(MESSAGE_T); U08 *msgContent = (U08*)message; + // zero out the message for ( i = 0; i < msgSize; i++ ) { *msgContent++ = 0x0; Index: App/Services/MsgQueues.h =================================================================== diff -u -r8695ea8b1a4709f240d5a5663db888625c72b823 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/MsgQueues.h (.../MsgQueues.h) (revision 8695ea8b1a4709f240d5a5663db888625c72b823) +++ App/Services/MsgQueues.h (.../MsgQueues.h) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -25,18 +25,13 @@ typedef enum Msg_Queues { - MSG_Q_CAN_HD_ALARM = 0, - MSG_Q_CAN_DG_ALARM, - MSG_Q_CAN_UI_ALARM, - MSG_Q_CAN_HD_2_DG, - MSG_Q_CAN_DG_2_HD, - MSG_Q_CAN_HD_2_UI, - MSG_Q_CAN_HD_BROADCAST, - MSG_Q_CAN_DG_BROADCAST, - MSG_Q_CAN_UI_2_HD, - MSG_Q_CAN_UI_BROADCAST, - MSG_Q_DBG_IN, - MSG_Q_DBG_OUT, + MSG_Q_IN_CAN_DG_ALARM = 0, + MSG_Q_IN_CAN_UI_ALARM, + MSG_Q_IN_CAN_DG_2_HD, + MSG_Q_IN_CAN_DG_BROADCAST, + MSG_Q_IN_CAN_UI_2_HD, + MSG_Q_IN_CAN_UI_BROADCAST, + MSG_Q_IN_DBG, NUM_OF_MSG_QUEUES } MSG_QUEUE_T; @@ -69,6 +64,7 @@ BOOL getFromMsgQueue( MSG_QUEUE_T queue, MESSAGE_WRAPPER_T *msg ); BOOL isMsgQueueEmpty( MSG_QUEUE_T queue ); BOOL isMsgQueueFull( MSG_QUEUE_T queue ); +void blankMessage( MESSAGE_T *message ); void blankMessageInWrapper( MESSAGE_WRAPPER_T *message ); #endif Index: App/Services/SystemComm.c =================================================================== diff -u -r8695ea8b1a4709f240d5a5663db888625c72b823 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/SystemComm.c (.../SystemComm.c) (revision 8695ea8b1a4709f240d5a5663db888625c72b823) +++ App/Services/SystemComm.c (.../SystemComm.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -24,8 +24,18 @@ #include "MsgQueues.h" #include "SystemComm.h" +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 1 +#include "CPLD.h" +#endif +// ************************** END TEST CODE ****************************** + // ********** private definitions ********** +#define MESSAGE_SYNC_BYTE 0xA5 +#define CAN_MESSAGE_CARGO_SIZE 8 + typedef enum Msg_IDs { MSG_ID_TEST = 0, @@ -38,6 +48,7 @@ // ********** private function prototypes ********** +static U32 serializeMessage( MESSAGE_T msg, U08 *data ); /************************************************************************* * @brief initSystemComm @@ -54,43 +65,21 @@ } /************************************************************************* - * @brief initSystemComm - * The initSystemComm function initializes the SystemComm module. + * @brief execSystemCommRx + * The execSystemCommRx function manages received data from other sub-systems. * @details * Inputs : none - * Outputs : SystemComm module initialized. + * Outputs : none * @param none * @return none *************************************************************************/ -void execSystemComm( void ) +void execSystemCommRx( 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 > 0 && dataSize <= 8 ) - { - canTransmit( canREG1, canMESSAGE_BOX1, data ); - } - // queue any received CAN messages if ( FALSE != canIsRxMessageArrived( canREG1, canMESSAGE_BOX2 ) ) { @@ -104,25 +93,107 @@ memcpy( &(rcvMsg.msg.cargo), dataPtr, rcvMsg.msg.hdr.cargoLen ); dataPtr += rcvMsg.msg.hdr.cargoLen; rcvMsg.crc = *dataPtr; - addToMsgQueue( MSG_Q_CAN_UI_2_HD, &rcvMsg ); + addToMsgQueue( MSG_Q_IN_CAN_UI_2_HD, &rcvMsg ); } // see if any messages received - isThereMsgRcvd = getFromMsgQueue( MSG_Q_CAN_UI_2_HD, &msg ); + isThereMsgRcvd = getFromMsgQueue( MSG_Q_IN_CAN_UI_2_HD, &msg ); if ( TRUE == isThereMsgRcvd ) { switch ( msg.msg.hdr.msgID ) { case MSG_ID_OFF_BUTTON_PRESS: - userConfirmOffButton(); + userConfirmOffButton( msg.msg.cargo[0] ); +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 1 + setUserLED( TRUE ); +#endif +// ************************** END TEST CODE ****************************** break; + default: break; } } } /************************************************************************* + * @brief execSystemCommTx + * The execSystemCommTx function manages data to be transmitted to other \n + * sub-systems. + * @details + * Inputs : none + * Outputs : none + * @param none + * @return none + *************************************************************************/ +void execSystemCommTx( void ) +{ + // TODO - this is ugly preliminary test code - nowhere near ready for code review + U08 data[sizeof(MESSAGE_WRAPPER_T)]; + U32 dataSize; + + // actually transmit any pending messages + dataSize = getFromCommBuffer( COMM_BUFFER_OUT_CAN_HD_2_UI, data, CAN_MESSAGE_CARGO_SIZE ); + if ( dataSize > 0 ) + { + canTransmit( canREG1, canMESSAGE_BOX1, data ); + } +} + +/************************************************************************* + * @brief serializeMessage + * The serializeMessage function serializes a given message into a given \n + * array of bytes. A sync byte is inserted at the beginning of the message \n + * and an 8-bit CRC is appended to the end of the message. The given array \n + * must be large enough to hold the message + 1 sync byte and 1 CRC byte and \n + * up to 7 CAN padding bytes. + * @details + * Inputs : none + * Outputs : given data array populated with serialized message data. + * @param msg : message to serialize + * @param data : byte array to populate with message data + * @return size (in bytes) of serialized message populated in given data array. + *************************************************************************/ +static U32 serializeMessage( MESSAGE_T msg, U08 *data ) +{ + U32 msgSize = 0; + U32 sizeMod, sizePad; + U32 i; + + // prefix data with message sync byte + //data[msgSize++] = MESSAGE_SYNC_BYTE; + + // serialize message header data + memcpy( &data[msgSize], &(msg.hdr), sizeof(MESSAGE_HEADER_T) ); + msgSize += sizeof(MESSAGE_HEADER_T); + + // serialize message cargo (only used bytes per cargoLen field) + memcpy( &data[msgSize], &(msg.cargo), msg.hdr.cargoLen ); + msgSize += msg.hdr.cargoLen; + + // TODO - calculate 8-bit CRC + data[msgSize++] = 0; // TODO - s/b 8-bit CRC when calc is available + + // pad with zero bytes to get length a multiple of CAN_MESSAGE_CARGO_SIZE (8) + sizeMod = msgSize % CAN_MESSAGE_CARGO_SIZE; + sizePad = ( sizeMod == 0 ? 0 : CAN_MESSAGE_CARGO_SIZE - sizeMod ); + for ( i = 0; i < sizePad; i++ ) + { + data[msgSize++] = 0; + } + + return msgSize; +} + + +/************************************************************************* +*************** SUITE OFF SEND MESSAGE FUNCTIONS BELOW ******************* +*************************************************************************/ + + +/************************************************************************* * @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. @@ -135,13 +206,22 @@ BOOL sendOffButtonMsgToUI( void ) { BOOL result; - MESSAGE_WRAPPER_T msg; + MESSAGE_T msg; + U32 msgSize; + U08 data[sizeof(MESSAGE_WRAPPER_T)+1+CAN_MESSAGE_CARGO_SIZE]; // must hold full (wrapped) message + sync + any CAN padding + U08 *dataPtr = data; - 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 ); + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_OFF_BUTTON_PRESS; + msg.hdr.cargoLen = 0; + // serialize the message (w/ sync, CRC, and appropriate CAN padding) + msgSize = serializeMessage( msg, data ); + + // add serialized message data to appropriate comm buffer + result = addToCommBuffer( COMM_BUFFER_OUT_CAN_HD_2_UI, dataPtr, msgSize ); + return result; } Index: App/Services/SystemComm.h =================================================================== diff -u -r7d70e839bc71f6fc37da8cd12eecb374841882df -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/SystemComm.h (.../SystemComm.h) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) +++ App/Services/SystemComm.h (.../SystemComm.h) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -24,7 +24,8 @@ // ********** public function prototypes ********** void initSystemComm( void ); -void execSystemComm( void ); +void execSystemCommRx( void ); +void execSystemCommTx( void ); BOOL sendOffButtonMsgToUI( void ); Index: App/Services/WatchdogMgmt.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -245,8 +245,13 @@ *************************************************************************/ static void petWatchdog( void ) { +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 0 // TODO - this is temporary test code - restore watchdog pet later // pulse the watchdog signal toggleCPLDWatchdog(); +#endif +// ************************** END TEST CODE ****************************** // remember when we last pet the watchdog lastWatchdogPetTime = getMSTimerCount(); Index: App/Tasks/TaskBG.c =================================================================== diff -u -ra6a0347eb72d17d8534fabc64fe410bbb1e8911e -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Tasks/TaskBG.c (.../TaskBG.c) (revision a6a0347eb72d17d8534fabc64fe410bbb1e8911e) +++ App/Tasks/TaskBG.c (.../TaskBG.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -16,6 +16,7 @@ #include "gio.h" +#include "Common.h" #include "WatchdogMgmt.h" #include "TaskTimer.h" Index: App/Tasks/TaskGeneral.c =================================================================== diff -u -r7d70e839bc71f6fc37da8cd12eecb374841882df -rc91e9da338d92432930d3589a4055ebbb404c6cb --- App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 7d70e839bc71f6fc37da8cd12eecb374841882df) +++ App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -24,7 +24,13 @@ #include "WatchdogMgmt.h" #include "TaskGeneral.h" -static U32 ctr = 0; // test code +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 1 +#include "CPLD.h" +static BOOL lastUserPress = FALSE; +#endif +// ************************** END TEST CODE ****************************** /************************************************************************* * @brief taskGeneral @@ -39,17 +45,37 @@ *************************************************************************/ void taskGeneral( void ) { - // test code - if ( ++ctr >= 40 ) { sendOffButtonMsgToUI(); ctr = 0; } - // manage system communication - execSystemComm(); +// ***************************** TEST CODE ****************************** +// TODO - remove later +#if 1 + if ( getUserButtonState() == PIN_SIGNAL_LOW ) + { + if ( lastUserPress == FALSE ) + { + lastUserPress = TRUE; + setUserLED( FALSE ); + sendOffButtonMsgToUI(); + } + } + else + { + lastUserPress = FALSE; + } +#endif +// ************************** END TEST CODE ****************************** + // manage data received from other sub-systems + execSystemCommRx(); + // run operation mode state machine execOperationModes(); // control alarm lamp execAlarmLamp(); + // manage data to be transmitted to other sub-systems + execSystemCommTx(); + // check in with watchdog manager checkInWithWatchdogMgmt( TASK_GENERAL ); Index: HD.dil =================================================================== diff -u -rd298a85322169dcc173c6197682864c2e9dbcd24 -rc91e9da338d92432930d3589a4055ebbb404c6cb --- HD.dil (.../HD.dil) (revision d298a85322169dcc173c6197682864c2e9dbcd24) +++ HD.dil (.../HD.dil) (revision c91e9da338d92432930d3589a4055ebbb404c6cb) @@ -1,4 +1,4 @@ -# RM46L852PGE 10/08/19 19:07:07 +# RM46L852PGE 10/09/19 13:45:05 # ARCH=RM46L852PGE # @@ -2347,7 +2347,7 @@ DRIVER.MIBSPI.VAR.MIBSPI5_TG7_BUF_CSHOLD.VALUE=0 DRIVER.MIBSPI.VAR.MIBSPI3_PORT_BIT5_PULL.VALUE=2 DRIVER.MIBSPI.VAR.MIBSPI3_TXINTLVL.VALUE=0 -DRIVER.MIBSPI.VAR.MIBSPI1_PORT_BIT4_DIR.VALUE=1 +DRIVER.MIBSPI.VAR.MIBSPI1_PORT_BIT4_DIR.VALUE=0 DRIVER.MIBSPI.VAR.MIBSPI1_TG3_TRGEVT.VALUE=TRG_ALWAYS DRIVER.MIBSPI.VAR.MIBSPI5_PORT_BIT1_PULDIS.VALUE=0 DRIVER.MIBSPI.VAR.MIBSPI5_TG5_USE_CS_ENCODE.VALUE=0