Index: SystemComm.c =================================================================== diff -u -r6520e649188757399c2dfd58a30af80d96256295 -r5fb988facecb08dceb2bba1c462d3097b53617f0 --- SystemComm.c (.../SystemComm.c) (revision 6520e649188757399c2dfd58a30af80d96256295) +++ SystemComm.c (.../SystemComm.c) (revision 5fb988facecb08dceb2bba1c462d3097b53617f0) @@ -45,18 +45,18 @@ // ********** private definitions ********** -#define CAN_XMIT_PACKET_TIMEOUT_MS 200 ///< If transmitted CAN frame does not cause a transmit complete interrupt within this time, re-send or move on -#define MAX_XMIT_RETRIES 5 ///< Maximum number of retries on no transmit complete interrupt timeout +#define CAN_XMIT_PACKET_TIMEOUT_MS 200 ///< If transmitted CAN frame does not cause a transmit complete interrupt within this time, re-send or move on +#define MAX_XMIT_RETRIES 5 ///< Maximum number of retries on no transmit complete interrupt timeout -#define MSG_NOT_ACKED_TIMEOUT_MS 250 ///< Maximum time for a Denali message that requires ACK to be ACK'd +#define MSG_NOT_ACKED_TIMEOUT_MS 250 ///< Maximum time for a Denali message that requires ACK to be ACK'd -#define MSG_NOT_ACKED_MAX_RETRIES 10 ///< Maximum number of times a message that requires ACK that was not ACK'd can be re-sent before alarm -#define PENDING_ACK_LIST_SIZE 25 ///< Maximum number of Denali messages that can be pending ACK at any given time +#define MSG_NOT_ACKED_MAX_RETRIES 10 ///< Maximum number of times a message that requires ACK that was not ACK'd can be re-sent before alarm +#define PENDING_ACK_LIST_SIZE 25 ///< Maximum number of Denali messages that can be pending ACK at any given time -#define PENDING_ACK_LIST_OVERRIDE_UI_CHANNEL 1 ///< Value for determining UI channel when Pending ACKs are overriden. -#define PENDING_ACK_LIST_OVERRIDE_DG_CHANNEL 2 ///< Value for determining DG channel when Pending ACKs are overriden. -#define PENDING_ACK_LIST_OVERRIDE_TD_CHANNEL 3 ///< Value for determining TD channel when Pending ACKs are overriden. -#define PENDING_ACK_LIST_OVERRIDE_RO_CHANNEL 4 ///< Value for determining RO channel when Pending ACKs are overriden. +#define PENDING_ACK_LIST_OVERRIDE_UI_CHANNEL 1 ///< Value for determining UI channel when Pending ACKs are overriden. +#define PENDING_ACK_LIST_OVERRIDE_DG_CHANNEL 2 ///< Value for determining DG channel when Pending ACKs are overriden. +#define PENDING_ACK_LIST_OVERRIDE_TD_CHANNEL 3 ///< Value for determining TD channel when Pending ACKs are overriden. +#define PENDING_ACK_LIST_OVERRIDE_RO_CHANNEL 4 ///< Value for determining RO channel when Pending ACKs are overriden. #pragma pack(push, 1) @@ -76,13 +76,13 @@ // ********** private data ********** -static U08 lastCANPacketSent[ CAN_FRAME_PAYLOAD_SIZE ]; ///< Keep last packet sent on CAN bus in case we need to re-send. -static CAN_MESSAGE_BOX_T lastCANPacketSentChannel = (CAN_MESSAGE_BOX_T)0; ///< Keep channel last packet was sent on CAN bus in case we need to re-send. -static U32 lastCANPacketSentTimeStamp = 0; ///< Keep time last packet sent on CAN bus so we can timeout on transmission attempt. -static U32 canXmitRetryCtr = 0; ///< Counter for CAN transmit retries. +static U08 lastCANPacketSent[ CAN_FRAME_PAYLOAD_SIZE ]; ///< Keep last packet sent on CAN bus in case we need to re-send. +static CAN_MESSAGE_BOX_T lastCANPacketSentChannel; ///< Keep channel last packet was sent on CAN bus in case we need to re-send. +static U32 lastCANPacketSentTimeStamp; ///< Keep time last packet sent on CAN bus so we can timeout on transmission attempt. +static U32 canXmitRetryCtr; ///< Counter for CAN transmit retries. -static volatile PENDING_ACK_RECORD_T pendingAckList[ PENDING_ACK_LIST_SIZE ]; ///< List of outgoing messages that are awaiting an ACK -static OVERRIDE_U32_T pendingACKOverride = { 0, 0, 0, 0 }; ///< Pending ACK override data structure. +static volatile PENDING_ACK_RECORD_T pendingAckList[ PENDING_ACK_LIST_SIZE ]; ///< List of outgoing messages that are awaiting an ACK +static OVERRIDE_U32_T pendingACKOverride = { 0, 0, 0, 0 }; ///< Pending ACK override data structure. // ********** private function prototypes ********** @@ -99,14 +99,18 @@ /*********************************************************************//** * @brief - * The initSystemComm function initializes the SystemComm module. - * @details Inputs: none - * @details Outputs: SystemComm module initialized. + * The initSystemComm function initializes the SystemComm unit. + * @details \b Inputs: none + * @details \b Outputs: SystemComm unit variables initialized. * @return none *************************************************************************/ void initSystemComm( void ) { - U32 i; + U32 i; + + lastCANPacketSentTimeStamp = 0; + canXmitRetryCtr = 0; + lastCANPacketSentChannel = (CAN_MESSAGE_BOX_T)0; // Initialize pending ACK list for ( i = 0; i < PENDING_ACK_LIST_SIZE; i++ ) @@ -117,9 +121,11 @@ /*********************************************************************//** * @brief - * The execSystemCommRx function manages received data from other sub-systems. - * @details Inputs: none - * @details Outputs: Incoming messages parsed and processed. + * The execSystemCommRx function manages received data from other sub-systems. + * @note This function should be called periodically to keep up with incoming + * data on CAN bus. + * @details \b Inputs: none + * @details \b Outputs: Incoming messages parsed and processed. * @return none *************************************************************************/ void execSystemCommRx( void ) @@ -147,8 +153,11 @@ * @brief * The execSystemCommTx function manages data to be transmitted to other * sub-systems. - * @details Inputs: none - * @details Outputs: Outgoing messages transmitted. + * @note This function should be called periodically to keep up with outgoing + * data being queued for transmit on CAN bus. + * @details \b Inputs: lastCANPacketSentTimeStamp, canXmitRetryCtr, lastCANPacketSentChannel + * @details \b Outputs: Outgoing message transmission from outgoing CAN buffers + * is initiated * @return none *************************************************************************/ void execSystemCommTx( void ) @@ -190,13 +199,15 @@ /*********************************************************************//** * @brief - * The handleCANMsgInterrupt function handles a CAN message interrupt. - * This may have occurred because a CAN packet transmission has completed - * or because a CAN packet has been received. The appropriate handler is - * called. - * @details Inputs: none - * @details Outputs: message interrupt handled - * @param srcCANBox which CAN message box triggered this interrupt + * The handleCANMsgInterrupt function handles a CAN frame interrupt from + * a given CAN mail box. + * This may have occurred because a CAN frame transmission has completed + * or because a CAN frame has been received. The appropriate handler is + * called. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid CAN mail box given. + * @details \b Inputs: none + * @details \b Outputs: message interrupt handled + * @param srcCANBox which CAN mail box triggered this interrupt * @return none *************************************************************************/ void handleCANMsgInterrupt( CAN_MESSAGE_BOX_T srcCANBox ) @@ -240,12 +251,12 @@ /*********************************************************************//** * @brief - * The isCANBoxForXmit function determines whether a given CAN message box + * The isCANBoxForXmit function determines whether a given CAN mail box * is configured for transmit. - * @details Inputs: CAN_OUT_BUFFERS[] - * @details Outputs: none - * @param srcCANBox which CAN message box to check - * @return TRUE if the given CAN message box is configured for transmit, FALSE if not. + * @details \b Inputs: CAN_OUT_BUFFERS[] + * @details \b Outputs: none + * @param srcCANBox which CAN mail box to determine configuration for + * @return TRUE if the given CAN mail box is configured for transmit, FALSE if not. *************************************************************************/ BOOL isCANBoxForXmit( CAN_MESSAGE_BOX_T srcCANBox ) { @@ -266,12 +277,12 @@ /*********************************************************************//** * @brief - * The isCANBoxForRecv function determines whether a given CAN message box + * The isCANBoxForRecv function determines whether a given CAN mail box * is configured for receiving. - * @details Inputs: CAN_IN_BUFFERS[] - * @details Outputs: none - * @param srcCANBox which CAN message box to check - * @return TRUE if the given CAN message box is configured for receiving, FALSE if not. + * @details \b Inputs: CAN_IN_BUFFERS[] + * @details \b Outputs: none + * @param srcCANBox which CAN mail box to determine configuration for + * @return TRUE if the given CAN mail box is configured for receiving, FALSE if not. *************************************************************************/ BOOL isCANBoxForRecv( CAN_MESSAGE_BOX_T srcCANBox ) { @@ -298,12 +309,12 @@ /*********************************************************************//** * @brief - * The findNextHighestPriorityCANPacketToTransmit function gets the next - * 8 byte packet and initiates a CAN transmit on the appropriate CAN channel. - * @details Inputs: Output CAN Comm Buffer(s) - * @details Outputs: none - * @return buffer with highest priority CAN packet to transmit, - * COMM_BUFFER_NOT_USED if not CAN packets pending transmit found + * The findNextHighestPriorityCANPacketToTransmit function determines which + * outgoing buffer with data in it has the highest priority. + * @details \b Inputs: Outgoing CAN buffer + * @details \b Outputs: none + * @return Highest priority CAN buffer with data to transmit, + * COMM_BUFFER_NOT_USED if there is no data to be transmitted. *************************************************************************/ static COMM_BUFFER_T findNextHighestPriorityCANPacketToTransmit( void ) { @@ -325,11 +336,14 @@ /*********************************************************************//** * @brief - * The transmitNextCANPacket function gets the next 8 byte packet and initiates - * a CAN transmit on the appropriate CAN channel. - * @details Inputs: Output CAN Comm Buffers - * @details Outputs: CAN packet transmit initiated. - * @return number of bytes transmitted + * The transmitNextCANPacket function creates a frame from the next 8 bytes + * to transmit (if there is data to transmit) and initiates a CAN transmit + * on the appropriate CAN channel. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid byte count or + * if frame transmit fails. + * @details \b Inputs: Output CAN buffers + * @details \b Outputs: none + * @return number of bytes transmitted (8 or 0) *************************************************************************/ static U32 transmitNextCANPacket( void ) { @@ -379,11 +393,10 @@ /*********************************************************************//** * @brief - * The processIncomingData function parses out messages from the Input - * Comm Buffers and adds them to the Received Message Queue. - * @details Inputs: none - * @details Outputs: rcvMsg, dgIsCommunicating, - * timeOfLastDGCheckIn, timeOfLastUICheckIn, uiDidCommunicate + * The processIncomingData function parses out messages from the incoming + * CAN buffers and adds them to the Received Message Queue. + * @details \b Inputs: none + * @details \b Outputs: canXmitRetryCtr * @return none *************************************************************************/ static void processIncomingData( void ) @@ -472,10 +485,11 @@ /*********************************************************************//** * @brief * The consumeBufferPaddingBeforeSync function removes any bytes in a given - * buffer that lie before a sync byte. - * @details Inputs: none - * @details Outputs: Any padding at front of buffer is consumed. - * @param buffer the comm buffer to process + * buffer that lie before a sync byte to re-sync with the data. + * @details \b Inputs: none + * @details \b Outputs: Any bytes in buffers preceding a sync byte at front + * of buffer is consumed. + * @param buffer the CAN buffer to re-sync * @return none *************************************************************************/ static void consumeBufferPaddingBeforeSync( COMM_BUFFER_T buffer ) @@ -502,13 +516,17 @@ /*********************************************************************//** * @brief * The parseMessageFromBuffer function looks for a complete message in a - * given buffer. If a message is found, its size is returned. - * @details Inputs: none - * @details Outputs: none - * @param data pointer to byte array to search for a message + * buffer (pointed to by given data pointer). If a message is found, its + * size is returned. + * @note The message is not consumed (removed) from the buffer. Calling + * function is expected to retrieve the message by consuming the returned + * message size from the given buffer. + * @details \b Inputs: none + * @details \b Outputs: none + * @param data pointer to start of a CAN buffer to search for a message in * @param len number of bytes in the data to search - * @return size of message if found, zero if no complete message found, - * -1 if message found but CRC fails. + * @return The size of the message, if found, zero if no complete message + * is found, -1 if message found but CRC fails. *************************************************************************/ static S32 parseMessageFromBuffer( U08 *data, U32 len ) { Index: SystemComm.h =================================================================== diff -u -rf4b440f1a4e29598b7726826d87a8cfb7885e214 -r5fb988facecb08dceb2bba1c462d3097b53617f0 --- SystemComm.h (.../SystemComm.h) (revision f4b440f1a4e29598b7726826d87a8cfb7885e214) +++ SystemComm.h (.../SystemComm.h) (revision 5fb988facecb08dceb2bba1c462d3097b53617f0) @@ -28,7 +28,7 @@ #include "ROCommon.h" #endif -#include "CommBuffers.h" +#include "CommBuffers.h" #include "MsgQueues.h" /** @@ -58,6 +58,7 @@ BOOL isCANBoxForXmit( CAN_MESSAGE_BOX_T srcCANBox ); BOOL isCANBoxForRecv( CAN_MESSAGE_BOX_T srcCANBox ); BOOL addMsgToPendingACKList( MESSAGE_T *msg, COMM_BUFFER_T channel, U08 *msgData, U32 len ); + BOOL testSetPendingACKOverride( U32 value ); BOOL testResetPendingACKOverride( void ); Index: Timers.c =================================================================== diff -u -r6d80d69a210f45c733e5307859351f2cd820a8e7 -r5fb988facecb08dceb2bba1c462d3097b53617f0 --- Timers.c (.../Timers.c) (revision 6d80d69a210f45c733e5307859351f2cd820a8e7) +++ Timers.c (.../Timers.c) (revision 5fb988facecb08dceb2bba1c462d3097b53617f0) @@ -30,9 +30,9 @@ /*********************************************************************//** * @brief - * The initTimers function initializes the Timers module. - * @details Inputs: msTimerCount - * @details Outputs: msTimerCount + * The initTimers function initializes the Timers unit. + * @details \b Inputs: none + * @details \b Outputs: msTimerCount * @return none *************************************************************************/ void initTimers( void ) @@ -43,8 +43,8 @@ /*********************************************************************//** * @brief * The incMSTimerCount function increments the ms timer count. - * @details Inputs: msTimerCount - * @details Outputs: msTimerCount + * @details \b Inputs: msTimerCount + * @details \b Outputs: msTimerCount * @return none *************************************************************************/ void incMSTimerCount( void ) @@ -55,9 +55,9 @@ /*********************************************************************//** * @brief * The getMSTimerCount function returns the current ms timer count. - * @details Inputs: msTimerCount - * @details Outputs: none - * @return msTimerCount as a U32 + * @details \b Inputs: msTimerCount + * @details \b Outputs: none + * @return The current 32-bit millisecond timer count. *************************************************************************/ U32 getMSTimerCount( void ) { @@ -68,8 +68,8 @@ * @brief * The didTimeout function determines whether a timeout has occurred between * a given start count and a given timeout period (in ms). - * @details Inputs: msTimerCount - * @details Outputs: none + * @details \b Inputs: msTimerCount + * @details \b Outputs: none * @param startMSCount the ms count at the start of the timeout period * @param timeoutPeriod the period for the timeout (in ms) * @return TRUE if a timeout has occurred, FALSE if not @@ -104,11 +104,11 @@ /*********************************************************************//** * @brief * The calcTimeSince function calculates the time (in ms) from a given start - * time until now. - * @details Inputs: msTimerCount - * @details Outputs: none + * time until right now. + * @details \b Inputs: msTimerCount + * @details \b Outputs: none * @param startMSCount the ms count at the start of the period - * @return ms since given start time + * @return The number of milliseconds since the given start time. *************************************************************************/ U32 calcTimeSince( U32 startMSCount ) { @@ -132,11 +132,11 @@ * @brief * The calcTimeBetween function calculates the time (in ms) from a given start * time until a given end time. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param startMSCount the ms count at the start of the period * @param endMSCount the ms count at the end of the period - * @return ms between two given times + * @return The number of milliseconds between the given start and end times *************************************************************************/ U32 calcTimeBetween( U32 startMSCount, U32 endMSCount ) { Index: Utilities.c =================================================================== diff -u -r8b18c3e875bd5d265399b603b8ea0a4c3ce8fcbe -r5fb988facecb08dceb2bba1c462d3097b53617f0 --- Utilities.c (.../Utilities.c) (revision 8b18c3e875bd5d265399b603b8ea0a4c3ce8fcbe) +++ Utilities.c (.../Utilities.c) (revision 5fb988facecb08dceb2bba1c462d3097b53617f0) @@ -17,7 +17,6 @@ #include // For memcpy -#include "Common.h" #include "FPGA.h" #include "Timers.h" #include "Utilities.h" @@ -140,24 +139,26 @@ }; // variables for time windowed counts (counts # of instances in a specific window of time) -static BOOL timeWindowedCountsInitialized[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Initialized flags for time windowed counts -static U32 timeWindowedCountsMaxCount[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Max. counts for time windowed counts -static U32 timeWindowedCountsWindowMs[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Time windows (in ms) for time windowed counts -static U32 timeWindowedCounts[ NUM_OF_TIME_WINDOWED_COUNTS ][ MAX_TIME_WINDOWED_COUNT ]; ///< Time stamps for instances for time windowed counts -static U32 timeWindowedCountIndexes[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< List indexes for time windowed counts -static U32 timeWindowedCountCounts[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Current counts for time windowed counts -static SEMAPHORE_STATUS_T sempahoreStatus[ NUM_OF_SEMAPHORES ]; +static BOOL timeWindowedCountsInitialized[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Initialized flags for time windowed counts. +static U32 timeWindowedCountsMaxCount[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Max. counts for time windowed counts. +static U32 timeWindowedCountsWindowMs[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Time windows (in ms) for time windowed counts. +static U32 timeWindowedCounts[ NUM_OF_TIME_WINDOWED_COUNTS ][ MAX_TIME_WINDOWED_COUNT ]; ///< Time stamps for instances for time windowed counts. +static U32 timeWindowedCountIndexes[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< List indexes for time windowed counts. +static U32 timeWindowedCountCounts[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Current counts for time windowed counts. +// variables for semaphores +static SEMAPHORE_STATUS_T sempahoreStatus[ NUM_OF_SEMAPHORES ]; ///< Status of each defined semaphore. + /*********************************************************************//** * @brief * The crc32 function calculates a 32-bit CRC for a given range of bytes * in memory. Poly = 0x1EDC6F41. Not reflected. Initial value = 0x00000000. - * @details Inputs: CRC32_TABLE[] - * @details Outputs: none + * @details \b Inputs: CRC32_TABLE[] + * @details \b Outputs: none * @param initialValue initial CRC seed value * @param address pointer to start address of memory range to calculate CRC for * @param len number of bytes in the memory range to calculate CRC for - * @return CRC as a U32 + * @return 32-bit CRC *************************************************************************/ U32 crc32( U32 const initialValue, const U08 *address, U32 len ) { @@ -176,11 +177,11 @@ * @brief * The crc16 function calculates a 16-bit CRC for a given range of bytes * in memory. Poly = 0x1021. Not reflected. Initial value = 0xFFFF. - * @details Inputs: CRC16_TABLE[] - * @details Outputs: none + * @details \b Inputs: CRC16_TABLE[] + * @details \b Outputs: none * @param address pointer to start address of memory range to calculate CRC for * @param len number of bytes in the memory range to calculate CRC for - * @return CRC as a U16 + * @return 16-bit CRC *************************************************************************/ U16 crc16( const U08 *address, U32 len ) { @@ -199,11 +200,11 @@ * @brief * The crc8 function calculates a 8-bit CRC for a given range of bytes * in memory. - * @details Inputs: CRC8_TABLE[] - * @details Outputs: none + * @details \b Inputs: CRC8_TABLE[] + * @details \b Outputs: none * @param address pointer to start address of memory range to calculate CRC for * @param len number of bytes in the memory range to calculate CRC for - * @return CRC as a U08 + * @return 8-bit CRC *************************************************************************/ U08 crc8( const U08 *address, U32 len ) { @@ -222,11 +223,11 @@ * @brief * The crc4 function calculates a 4-bit CRC for a given range of bytes * in memory. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param buffer pointer to start address of memory range to calculate CRC for * @param byteCount number of bytes in the memory range to calculate CRC for - * @return CRC as a U08 + * @return 4-bit CRC (4 lsb of byte) *************************************************************************/ U08 crc4( U16* buffer, U32 byteCount ) { @@ -269,11 +270,11 @@ * unsigned 32-bit numbers. If the second (ending) number is less than the * first (starting) number, then the difference is calculated with a wrap past * 32-bit full scale to zero. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param start first number to compute difference for * @param end second number to compute difference for - * @return the difference between the two given numbers + * @return the unsigned difference between the two given 32-bit values *************************************************************************/ U32 u32DiffWithWrap( U32 start, U32 end ) { @@ -287,11 +288,11 @@ * The u16BiDiffWithWrap function calculates the difference between two given * unsigned 16-bit numbers. This version of function returns a signed value * to allow for a negative difference. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param start first number to compute difference for * @param end second number to compute difference for - * @return the difference between the two given numbers + * @return the signed difference between the two given values *************************************************************************/ S32 u32BiDiffWithWrap( U32 start, U32 end ) { @@ -318,11 +319,11 @@ * unsigned 16-bit numbers. If the second (ending) number is less than the * first (starting) number, then the difference is calculated with a wrap past * 16-bit full scale to zero. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param start first number to compute difference for * @param end second number to compute difference for - * @return the difference between the two given numbers + * @return the unsigned difference between the two given values *************************************************************************/ U16 u16DiffWithWrap( U16 start, U16 end ) { @@ -336,11 +337,11 @@ * The u16BiDiffWithWrap function calculates the difference between two given * unsigned 16-bit numbers. This version of function returns a signed value * to allow for a negative difference. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param start first number to compute difference for * @param end second number to compute difference for - * @return the difference between the two given numbers + * @return the signed difference between the two given values *************************************************************************/ S16 u16BiDiffWithWrap( U16 start, U16 end ) { @@ -364,9 +365,10 @@ /*********************************************************************//** * @brief * The initTimeWindowedCount function initializes a given time windowed count. - * @details Inputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized - * @details Outputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized, alarm if - * software fault occurred + * @details \b Alarm: ALARM_ID_XX_SOFTWARE_FAULT triggered if given count or + * maximum count is invalid. + * @details \b Inputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized + * @details \b Outputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized * @param cnt ID of the time windowed count to initialize * @param maxCnt maximum number of instances in the time window for this count * @param winMs number of ms in the time window for this count @@ -418,11 +420,11 @@ * The incTimeWindowedCount function adds a new instance to a given time * windowed count. Must call initTimeWindowedCount() prior to calling this * function for a given time windowed count. - * *Note - thread protection not provided - assumed function will be called - * by one task for a given time windowed count. - * @details Inputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts - * @details Outputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts, - * alarm if a software fault occurred + * @warning Thread protection not provided - assumed function will be called + * by one task only for a given time windowed count. + * @details \b Alarm: ALARM_ID_XX_SOFTWARE_FAULT if invalid count given + * @details \b Inputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts + * @details \b Outputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts, * @param cnt ID of the time windowed count to add an instance to * @return TRUE if this instances brings the count to the maximum within * this counts time window, otherwise FALSE @@ -465,8 +467,10 @@ * The getCriticalData function gets the value for a given critical data * record. The integrity of the critical data is checked first. If the * critical data record fails the integrity check, a fault is triggered. - * @details Inputs: none - * @details Outputs: alarm if HD critical error occurred + * @details \b Alarm: ALARM_ID_XX_CRITICAL_DATA_ERROR if integrity check + * fails for the given critical data. + * @details \b Inputs: none + * @details \b Outputs: none * @param data Ptr to a critical data record * @return The data from a critical data record *************************************************************************/ @@ -501,8 +505,8 @@ * @brief * The isCriticalDataInRange function determines whether a critical data * value is within the range set for that critical data. - * @details Inputs: none - * @details Outputs: none + * @details \b Inputs: none + * @details \b Outputs: none * @param data Ptr to a critical data record * @return TRUE if given data is in range, FALSE if not *************************************************************************/ @@ -539,8 +543,10 @@ * @brief * The setCriticalData function sets the value for a given critical data * record. - * @details Inputs: none - * @details Outputs: alarm if HD critical error occurred + * @details \b Alarm: ALARM_ID_XX_CRITICAL_DATA_ERROR if given critical + * data's type is invalid. + * @details \b Inputs: none + * @details \b Outputs: none * @param data Ptr to a critical data record * @param value a value to set * @return TRUE if set was successful, FALSE if not (out of range) @@ -579,9 +585,10 @@ /*********************************************************************//** * @brief - * The resetCriticalData function resets a critical data record. - * @details Inputs: none - * @details Outputs: Given critical data record is reset to unset w/ default value. + * The resetCriticalData function resets a given critical data record to + * unset with its default value. + * @details \b Inputs: none + * @details \b Outputs: none * @param data Ptr to a critical data record * @return none *************************************************************************/ @@ -595,9 +602,9 @@ /*********************************************************************//** * @brief - * The hexStrToDec function convert hex string to decimal value. - * @details Inputs: none - * @details Outputs: none + * The hexStrToDec function converts a given hex string to a decimal value. + * @details \b Inputs: none + * @details \b Outputs: convValuePtr (ref param) is set to converted decimal value. * @param valuePtr pointer to hex string to convert * @param convValuePtr pointer to the provided buffer to write the converted * values back @@ -670,9 +677,9 @@ /*********************************************************************//** * @brief - * The initSemaphores function initializes the semaphores - * @details Inputs: none - * @details Outputs: sempahoreStatus + * The initSemaphores function initializes the defined semaphores. + * @details \b Inputs: none + * @details \b Outputs: sempahoreStatus[] * @return none *************************************************************************/ void initSemaphores( void ) @@ -687,30 +694,31 @@ /*********************************************************************//** * @brief - * The getSemaphore function gets a semaphore for the requested semaphore. - * @details Inputs: none - * @details Outputs: sempahoreStatus - * @param s which is the semaphore to be taken - * @return TRUE if semaphore is available and now it is taken otherwise, FALSE + * The acquireSemaphore function attempts to acquire the given semaphore. + * @details \b Alarm: ALARM_ID_XX_SOFTWARE_FAULT if given semaphore is invalid. + * @details \b Inputs: none + * @details \b Outputs: sempahoreStatus + * @param sem ID of semaphore to be acquired + * @return TRUE if semaphore is available and now acquired, otherwise FALSE *************************************************************************/ -BOOL getSemaphore( SEMAPHORE_T s ) +BOOL acquireSemaphore( SEMAPHORE_T sem ) { BOOL result = FALSE; _disable_IRQ(); - if ( FALSE == sempahoreStatus[ s ].isSemaphoreTaken ) + if ( FALSE == sempahoreStatus[ sem ].isSemaphoreTaken ) { - sempahoreStatus[ s ].semaphoreStartTimeMS = getMSTimerCount(); - sempahoreStatus[ s ].isSemaphoreTaken = TRUE; - result = TRUE; + sempahoreStatus[ sem ].semaphoreStartTimeMS = getMSTimerCount(); + sempahoreStatus[ sem ].isSemaphoreTaken = TRUE; + result = TRUE; } - else if ( TRUE == didTimeout( sempahoreStatus[ s ].semaphoreStartTimeMS, SEMAPHORE_IN_USE_TIMEOUT_MS ) ) + else if ( TRUE == didTimeout( sempahoreStatus[ sem ].semaphoreStartTimeMS, SEMAPHORE_IN_USE_TIMEOUT_MS ) ) { #ifdef _TD_ - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, (U32)s ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, (U32)sem ) #endif #ifdef _DD_ - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, (U32)s ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, (U32)sem ) #endif } _enable_IRQ(); @@ -720,30 +728,31 @@ /*********************************************************************//** * @brief - * The releaseSemaphore function releases a semaphore that was previously taken - * for a job. - * @details Inputs: none - * @details Outputs: sempahoreStatus - * @param s which is the semaphore to be released + * The releaseSemaphore function releases a semaphore that was previously + * acquired. + * @details \b Inputs: none + * @details \b Outputs: sempahoreStatus[] + * @param sem which is the semaphore to be released * @return none *************************************************************************/ -void releaseSemaphore( SEMAPHORE_T s ) +void releaseSemaphore( SEMAPHORE_T sem ) { - if ( TRUE == sempahoreStatus[ s ].isSemaphoreTaken ) + if ( TRUE == sempahoreStatus[ sem ].isSemaphoreTaken ) { - sempahoreStatus[ s ].isSemaphoreTaken = FALSE; + sempahoreStatus[ sem ].isSemaphoreTaken = FALSE; } } /*********************************************************************//** * @brief - * The isSemaphoreReleased function returns the status of a taken semaphore - * @details Inputs: none - * @details Outputs: sempahoreStatus + * The isSemaphoreAvailable function returns whether a given semaphore + * is available. + * @details \b Inputs: sempahoreStatus[] + * @details \b Outputs: none * @param s which is the semaphore to check - * @return status of the semaphore + * @return TRUE if semaphore is available, FALSE if already acquired *************************************************************************/ -BOOL isSemaphoreReleased( SEMAPHORE_T s ) +BOOL isSemaphoreAvailable( SEMAPHORE_T s ) { return ( TRUE == sempahoreStatus[ s ].isSemaphoreTaken ? FALSE : TRUE ); } Index: Utilities.h =================================================================== diff -u -r6d80d69a210f45c733e5307859351f2cd820a8e7 -r5fb988facecb08dceb2bba1c462d3097b53617f0 --- Utilities.h (.../Utilities.h) (revision 6d80d69a210f45c733e5307859351f2cd820a8e7) +++ Utilities.h (.../Utilities.h) (revision 5fb988facecb08dceb2bba1c462d3097b53617f0) @@ -18,6 +18,16 @@ #ifndef __UTILITIES_H__ #define __UTILITIES_H__ +#ifdef _TD_ +#include "TDCommon.h" +#endif +#ifdef _DD_ +#include "DDCommon.h" +#endif +#ifdef _RO_ +#include "ROCommon.h" +#endif + /** * @defgroup Utilities Utilities * @brief Utilities module contains various utility functions. @@ -98,22 +108,25 @@ U16 crc16( const U08 *address, U32 len ); U08 crc8( const U08 *address, U32 len ); U08 crc4( U16* buffer, U32 byteCount ); + U32 u32DiffWithWrap( U32 start, U32 end ); S32 u32BiDiffWithWrap( U32 start, U32 end ); U16 u16DiffWithWrap( U16 start, U16 end ); S16 u16BiDiffWithWrap( U16 start, U16 end ); + void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ); BOOL incTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt ); + CRITICAL_DATAS_T getCriticalData( CRITICAL_DATA_T *data ); BOOL setCriticalData( CRITICAL_DATA_T *data, CRITICAL_DATAS_T value ); BOOL isCriticalDataInRange( CRITICAL_DATA_T *data ); void resetCriticalData( CRITICAL_DATA_T *data ); BOOL hexStrToDec( U08 const * const valuePtr, U32* convValueAddress, U08 size ); void initSemaphores( void ); -BOOL getSemaphore( SEMAPHORE_T s ); +BOOL acquireSemaphore( SEMAPHORE_T s ); void releaseSemaphore( SEMAPHORE_T s ); -BOOL isSemaphoreReleased( SEMAPHORE_T s ); +BOOL isSemaphoreAvailable( SEMAPHORE_T s ); /**@}*/