Dem_stub.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral :
  5. * Dependencies :
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file Dem_stub.c
  26. *
  27. * @addtogroup DEM_MODULE
  28. * @{
  29. */
  30. #ifdef __cplusplus
  31. extern "C"{
  32. #endif
  33. /*==================================================================================================
  34. * INCLUDE FILES
  35. * 1) system and project includes
  36. * 2) needed interfaces from external units
  37. * 3) internal and external interfaces from this unit
  38. ==================================================================================================*/
  39. #include "Mcal.h"
  40. #include "OsIf.h"
  41. #include "Dem_stub.h"
  42. /*==================================================================================================
  43. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  44. ==================================================================================================*/
  45. /*==================================================================================================
  46. * LOCAL MACROS
  47. ==================================================================================================*/
  48. /*==================================================================================================
  49. * LOCAL CONSTANTS
  50. ==================================================================================================*/
  51. /*==================================================================================================
  52. * LOCAL VARIABLES
  53. ==================================================================================================*/
  54. /*==================================================================================================
  55. * GLOBAL CONSTANTS
  56. ==================================================================================================*/
  57. /*==================================================================================================
  58. * GLOBAL VARIABLES
  59. ==================================================================================================*/
  60. /*==================================================================================================
  61. * LOCAL FUNCTION PROTOTYPES
  62. ==================================================================================================*/
  63. /*==================================================================================================
  64. * LOCAL FUNCTIONS
  65. ==================================================================================================*/
  66. /*==================================================================================================
  67. * GLOBAL FUNCTIONS
  68. ==================================================================================================*/
  69. #define DEM_START_SEC_CODE
  70. #include "Dem_MemMap.h"
  71. /*================================================================================================*/
  72. /**
  73. * @brief Tests if an expected event has been reported to DEM
  74. * @details This function will search the buffer of events, from the last event logged to the first one
  75. * (from the newest to the oldest event), for the event ID&Status passed as parameter.
  76. * This function will also delete the event found ( (NumberOfEvents--) && (all events
  77. * will be shifted with one position in the buffer))
  78. *
  79. * @param[in] EventId - ID of the event reported
  80. * @param[in] EventStatus - event status
  81. * @return boolean - True - if the event is found (the first one found) with the requested status
  82. * @return boolean - False - if that event is not found in the entire buffer with the requested status
  83. *
  84. */
  85. boolean Dem_TestLastReportErrorStatus(Dem_EventIdType EventId, Dem_EventStatusType EventStatus)
  86. {
  87. boolean result = 0U;
  88. sint32 counterDown;
  89. uint32 counterUp;
  90. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  91. /* Search all events, from the last event logged to the first one */
  92. for(counterDown = (Dem_numEventErrors[u32CoreId] - 1); (sint32)0 <= counterDown; counterDown--)
  93. {
  94. /* If the specific event is found */
  95. if((EventId == Dem_EventId[u32CoreId][counterDown]) && (EventStatus == Dem_EventStatus[u32CoreId][counterDown]))
  96. {
  97. /* Mark the result as found */
  98. result = 1;
  99. /* shift all the newest events with one position(discard the one that it is found) */
  100. for(counterUp = (uint32)counterDown; counterUp < (Dem_numEventErrors[u32CoreId] - 1);counterUp++)
  101. {
  102. Dem_EventId[u32CoreId][counterUp] = Dem_EventId[u32CoreId][(counterUp+1)];
  103. Dem_EventStatus[u32CoreId][counterUp] = Dem_EventStatus[u32CoreId][(counterUp+1)];
  104. }
  105. /* update the Dem_numEventErrors (the event found is discarded) */
  106. Dem_numEventErrors[u32CoreId]--;
  107. /* terminate the search */
  108. break;
  109. }
  110. }
  111. return result;
  112. }
  113. /*================================================================================================*/
  114. /**
  115. * @brief Tests if a FAILED or PREFAILED event has been reported to DEM
  116. * @details Tests if a FAILED or PREFAILED event has been reported to DEM
  117. * This function will also reset all the events, after the above check (NumberOfEvents=0)
  118. *
  119. * @return boolean - true in case of NO event has been reported
  120. *
  121. */
  122. boolean Dem_TestNoError(void) {
  123. boolean result = 1U;
  124. uint32 counter;
  125. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  126. for(counter = 0;counter < Dem_numEventErrors[u32CoreId]; counter++)
  127. {
  128. if((DEM_EVENT_STATUS_FAILED == Dem_EventStatus[u32CoreId][counter]) || (DEM_EVENT_STATUS_PREFAILED == Dem_EventStatus[u32CoreId][counter]))
  129. {
  130. result = 0U;
  131. /* terminate the search */
  132. break;
  133. }
  134. }
  135. Dem_numEventErrors[u32CoreId] = 0;
  136. return result;
  137. }
  138. /*================================================================================================*/
  139. /**
  140. * @brief Tests if a DEM extended data has been reported to DEM
  141. * @details Tests if a DEM extended data has been reported to DEM
  142. *
  143. * @return boolean - true in case of expected extended data was found
  144. *
  145. */
  146. boolean Dem_TestLastReportErrorStatusPreExtData
  147. (
  148. Dem_EventIdType Dem_EventIdRaw,
  149. Dem_EventStatusType Dem_EventStatusRaw,
  150. uint8* Dem_pui8_PreExtData,
  151. uint8 Dem_PreExtDataSize
  152. )
  153. {
  154. boolean bRetValue = 1U;
  155. sint32 counterDown;
  156. uint32 counterUp;
  157. uint8 u8Counter;
  158. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  159. /* Search all events, from the last event logged to the first one */
  160. for(counterDown = (Dem_numEventErrors[u32CoreId] - 1); (sint32)0 <= counterDown; counterDown--)
  161. {
  162. /* If the specific event is found */
  163. if((Dem_EventIdRaw == Dem_EventId[u32CoreId][counterDown]) && (Dem_EventStatusRaw == Dem_EventStatus[u32CoreId][counterDown]))
  164. {
  165. /* If EventId and EventStatus match, check if data provided through pointer and length matches */
  166. for(u8Counter=0; u8Counter < Dem_PreExtDataSize; u8Counter++)
  167. {
  168. /* Skip over Dem extended data marked as not used */
  169. if (DEM_EXT_DATA_NOT_USED_U8 == Dem_pui8_PreExtData[u8Counter])
  170. continue;
  171. /* Check for match between expected and existing DEM extended data */
  172. if (Dem_pui8_PreExtData[u8Counter] != Dem_au8ExtendedData[u32CoreId][u8Counter])
  173. {
  174. bRetValue = (boolean)FALSE;
  175. }
  176. }
  177. /* shift all the newest events with one position(discard the one that it is found) */
  178. for(counterUp = (uint32)counterDown; counterUp < (Dem_numEventErrors[u32CoreId] - 1);counterUp++)
  179. {
  180. Dem_EventId[u32CoreId][counterUp] = Dem_EventId[u32CoreId][(counterUp+1)];
  181. Dem_EventStatus[u32CoreId][counterUp] = Dem_EventStatus[u32CoreId][(counterUp+1)];
  182. }
  183. /* update the Dem_numEventErrors (the event found is discarded) */
  184. Dem_numEventErrors[u32CoreId]--;
  185. /* terminate the search */
  186. break;
  187. }
  188. }
  189. /* Clear the stored information */
  190. for(u8Counter=0; u8Counter < DEM_MAX_EXTENDED_DATA_LENGTH_U8; u8Counter++)
  191. {
  192. Dem_au8ExtendedData[u32CoreId][u8Counter] = 0x0U;
  193. }
  194. /* Return */
  195. return bRetValue;
  196. }
  197. /*================================================================================================*/
  198. /**
  199. * @brief Function that will reset the events.
  200. * @details This function will reset the counter that holds the number of DEM events.
  201. *
  202. * @return
  203. *
  204. */
  205. void Dem_ClearEvents(void)
  206. {
  207. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  208. Dem_numEventErrors[u32CoreId] = 0U;
  209. }
  210. /*================================================================================================*/
  211. /**
  212. * @brief It will return the event found on the index passed as parameter(IndexNumber)
  213. * @details This function will return the event found on the index passed as parameter(IndexNumber)
  214. * This function will use the parameters 2 and 3(&EventId, &EventStatus) to return that entry.
  215. *
  216. * @return boolean - true in case IndexNumber is OutOfRange
  217. *
  218. */
  219. boolean Dem_GetEvent(uint32 IndexNumber, Dem_EventIdType* EventId, Dem_EventStatusType* EventStatus)
  220. {
  221. boolean result = 0;
  222. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  223. if(IndexNumber < Dem_numEventErrors[u32CoreId])
  224. {
  225. *EventId = Dem_EventId[u32CoreId][IndexNumber];
  226. *EventStatus = Dem_EventStatus[u32CoreId][IndexNumber];
  227. }
  228. else
  229. {
  230. result = 1;
  231. }
  232. return result;
  233. }
  234. /*================================================================================================*/
  235. /**
  236. * @brief Returns the NumberOfEvents that are logged so far.
  237. * @details This function returns the NumberOfEvents that are logged so far.
  238. *
  239. * @return uint8 - NumberOfEvents
  240. *
  241. */
  242. uint32 Dem_GetEventCount(void)
  243. {
  244. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  245. return Dem_numEventErrors[u32CoreId];
  246. }
  247. /*================================================================================================*/
  248. /**
  249. * @brief Return if the maximum number of events was exceeded(256)
  250. * @details This function returns true if the maximum number of events was exceeded(256).
  251. * In case of Overflow: the last position (Dem_EventId[255] )will be overwritten if
  252. * the new event is a PREFAILED or FAILED. This way, you will always have the last
  253. * error reported. And together with the function Dem_BufferOverflow, you will know
  254. * if you have the entire/correct sequence of events reported to DEM.
  255. *
  256. * @return boolean
  257. * True - if the number of events logged so far exceeds the DEM event buffer size elements
  258. * False - if there is still room in the buffer
  259. *
  260. */
  261. boolean Dem_BufferOverflow(void)
  262. {
  263. uint32 u32CoreId = (uint32)OsIf_GetCoreID();
  264. return Dem_OverflowEvent[u32CoreId];
  265. }
  266. #define DEM_STOP_SEC_CODE
  267. #include "Dem_MemMap.h"
  268. #ifdef __cplusplus
  269. }
  270. #endif
  271. /** @} */