Index: Utilities.c =================================================================== diff -u -r839935998cfe2a1a7594e6b6810301ad3c2aa872 -r82fa83e4d882fdcd96b4b5bdf706044d45a82c70 --- Utilities.c (.../Utilities.c) (revision 839935998cfe2a1a7594e6b6810301ad3c2aa872) +++ Utilities.c (.../Utilities.c) (revision 82fa83e4d882fdcd96b4b5bdf706044d45a82c70) @@ -26,19 +26,22 @@ // ********** private definitions ********** -#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function -#define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function +#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function +#define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function -#define ASCII_CODE_LETTER_A 0x41 ///< ASCII code in hex for letter A. -#define ASCII_CODE_NUMBER_ZERO 0x30 ///< ASCII code in hex for number zero. -#define ASCII_CODE_NUMBER_SEVEN 0x37 ///< ASCII code in hex for number seven. +#define ASCII_CODE_LETTER_A 0x41 ///< ASCII code in hex for letter A. +#define ASCII_CODE_NUMBER_ZERO 0x30 ///< ASCII code in hex for number zero. +#define ASCII_CODE_NUMBER_SEVEN 0x37 ///< ASCII code in hex for number seven. + +#define SEMAPHORE_IN_USE_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Taken semaphore timeout in milliseconds. // ********** private data ********** /// Semaphore data structure typedef struct { - volatile BOOL isSemaphoreTaken; ///< Flag to indicate whether the semaphore is taken or not. + U32 semaphoreStartTimeMS; ///< Semaphore start time in milliseconds. + volatile BOOL isSemaphoreTaken; ///< Flag to indicate whether the semaphore is taken or not. } SEMAPHORE_STATUS_T; /// CRC-32 look-up table. @@ -671,9 +674,14 @@ _disable_IRQ(); if ( FALSE == sempahoreStatus[ s ].isSemaphoreTaken ) { - sempahoreStatus[ s ].isSemaphoreTaken = TRUE; - result = TRUE; + sempahoreStatus[ s ].semaphoreStartTimeMS = getMSTimerCount(); + sempahoreStatus[ s ].isSemaphoreTaken = TRUE; + result = TRUE; } + else if ( TRUE == didTimeout( sempahoreStatus[ s ].semaphoreStartTimeMS, SEMAPHORE_IN_USE_TIMEOUT_MS ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, (U32)s ) + } _enable_IRQ(); return result; @@ -696,9 +704,17 @@ } } +/*********************************************************************//** + * @brief + * The isSemaphoreReleased function returns the status of a taken semaphore + * @details Inputs: none + * @details Outputs: sempahoreStatus + * @param s which is the semaphore to check + * @return status of the semaphore + *************************************************************************/ BOOL isSemaphoreReleased( SEMAPHORE_T s ) { - return sempahoreStatus[ s ].isSemaphoreTaken; + return ( TRUE == sempahoreStatus[ s ].isSemaphoreTaken ? FALSE : TRUE ); } /**@}*/