OsIf_Timer.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : S32K14X
  5. * Dependencies : none
  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
  26. *
  27. * @addtogroup osif_drv
  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 "OsIf.h"
  40. #include "OsIf_Cfg.h"
  41. #include "OsIf_Cfg_TypesDef.h"
  42. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  43. /* Defines the Hw Timer functions to be implemented in OS-specific environments */
  44. #include "OsIf_Timer_System.h"
  45. #endif /* (OSIF_USE_SYSTEM_TIMER == STD_ON) */
  46. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  47. /* API functions to be implemented by user */
  48. #include "OsIf_Timer_Custom.h"
  49. #endif /* (OSIF_USE_CUSTOM_TIMER == STD_ON) */
  50. /*==================================================================================================
  51. * SOURCE FILE VERSION INFORMATION
  52. ==================================================================================================*/
  53. #define OSIF_TIMER_VENDOR_ID_C 43
  54. #define OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C 4
  55. #define OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C 4
  56. #define OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C 0
  57. #define OSIF_TIMER_SW_MAJOR_VERSION_C 1
  58. #define OSIF_TIMER_SW_MINOR_VERSION_C 0
  59. #define OSIF_TIMER_SW_PATCH_VERSION_C 0
  60. /*==================================================================================================
  61. * FILE VERSION CHECKS
  62. ==================================================================================================*/
  63. /* Checks against OsIf.h */
  64. #if (OSIF_TIMER_VENDOR_ID_C != OSIF_VENDOR_ID)
  65. #error "OsIf_Timer.c and OsIf.h have different vendor ids"
  66. #endif
  67. #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  68. (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION) || \
  69. (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_AR_RELEASE_REVISION_VERSION))
  70. #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf.h are different"
  71. #endif
  72. #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_SW_MAJOR_VERSION) || \
  73. (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_SW_MINOR_VERSION) || \
  74. (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_SW_PATCH_VERSION) \
  75. )
  76. #error "Software Version Numbers of OsIf_Timer.c and OsIf.h are different"
  77. #endif
  78. /* Checks against OsIf_Cfg.h */
  79. #if (OSIF_TIMER_VENDOR_ID_C != OSIF_CFG_VENDOR_ID)
  80. #error "OsIf_Timer.c and OsIf_Cfg.h have different vendor ids"
  81. #endif
  82. #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_CFG_AR_RELEASE_MAJOR_VERSION) || \
  83. (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_CFG_AR_RELEASE_MINOR_VERSION) || \
  84. (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_CFG_AR_RELEASE_REVISION_VERSION))
  85. #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf_Cfg.h are different"
  86. #endif
  87. #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_CFG_SW_MAJOR_VERSION) || \
  88. (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_CFG_SW_MINOR_VERSION) || \
  89. (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_CFG_SW_PATCH_VERSION) \
  90. )
  91. #error "Software Version Numbers of OsIf_Timer.c and OsIf_Cfg.h are different"
  92. #endif
  93. /* Checks against OsIf_Cfg_TypesDef.h */
  94. #if (OSIF_TIMER_VENDOR_ID_C != OSIF_CFG_TYPESDEF_VENDOR_ID)
  95. #error "OsIf_Timer.c and OsIf_Cfg_TypesDef.h have different vendor ids"
  96. #endif
  97. #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_MAJOR_VERSION) || \
  98. (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_MINOR_VERSION) || \
  99. (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_REVISION_VERSION))
  100. #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Cfg_TypesDef.h are different"
  101. #endif
  102. #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_CFG_TYPESDEF_SW_MAJOR_VERSION) || \
  103. (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_CFG_TYPESDEF_SW_MINOR_VERSION) || \
  104. (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_CFG_TYPESDEF_SW_PATCH_VERSION) \
  105. )
  106. #error "Software Version Numbers of OsIf_Timer.c and OsIf_Cfg_TypesDef.h are different"
  107. #endif
  108. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  109. /* Checks against OsIf_Timer_System.h */
  110. #if (OSIF_TIMER_VENDOR_ID_C != OSIF_TIMER_SYSTEM_VENDOR_ID)
  111. #error "OsIf_Timer.c and OsIf_Timer_System.h have different vendor ids"
  112. #endif
  113. #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION) || \
  114. (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION) || \
  115. (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION))
  116. #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf_Timer_System.h are different"
  117. #endif
  118. #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION) || \
  119. (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_SW_MINOR_VERSION) || \
  120. (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_TIMER_SYSTEM_SW_PATCH_VERSION) \
  121. )
  122. #error "Software Version Numbers of OsIf_Timer.c and OsIf_Timer_System.h are different"
  123. #endif
  124. #endif /* (OSIF_USE_SYSTEM_TIMER == STD_ON) */
  125. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  126. /* Checks against OsIf_Timer_Custom.h */
  127. #if (OSIF_TIMER_VENDOR_ID_C != OSIF_TIMER_CUSTOM_VENDOR_ID)
  128. #error "OsIf_Timer.c and OsIf_Timer_Custom.h have different vendor ids"
  129. #endif
  130. #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_CUSTOM_AR_RELEASE_MAJOR_VERSION) || \
  131. (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_CUSTOM_AR_RELEASE_MINOR_VERSION) || \
  132. (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_CUSTOM_AR_RELEASE_REVISION_VERSION))
  133. #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf_Timer_Custom.h are different"
  134. #endif
  135. #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_TIMER_CUSTOM_SW_MAJOR_VERSION) || \
  136. (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_TIMER_CUSTOM_SW_MINOR_VERSION) || \
  137. (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_TIMER_CUSTOM_SW_PATCH_VERSION) \
  138. )
  139. #error "Software Version Numbers of OsIf_Timer.c and OsIf_Timer_Custom.h are different"
  140. #endif
  141. #endif /* (OSIF_USE_CUSTOM_TIMER == STD_ON) */
  142. /*==================================================================================================
  143. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  144. ==================================================================================================*/
  145. /*==================================================================================================
  146. * LOCAL MACROS
  147. ==================================================================================================*/
  148. /*==================================================================================================
  149. * LOCAL CONSTANTS
  150. ==================================================================================================*/
  151. /*==================================================================================================
  152. * LOCAL VARIABLES
  153. ==================================================================================================*/
  154. /*==================================================================================================
  155. * GLOBAL CONSTANTS
  156. ==================================================================================================*/
  157. /*==================================================================================================
  158. * GLOBAL VARIABLES
  159. ==================================================================================================*/
  160. /*==================================================================================================
  161. * LOCAL FUNCTION PROTOTYPES
  162. ==================================================================================================*/
  163. #define BASE_START_SEC_CODE
  164. #include "Base_MemMap.h"
  165. static inline uint32 OsIf_Timer_Dummy_GetCounter(void);
  166. static inline uint32 OsIf_Timer_Dummy_GetElapsed(const uint32 * const CurrentRef);
  167. static inline void OsIf_Timer_Dummy_SetTimerFrequency(uint32 Freq);
  168. static inline uint32 OsIf_Timer_Dummy_MicrosToTicks(uint32 Micros);
  169. #define BASE_STOP_SEC_CODE
  170. #include "Base_MemMap.h"
  171. /*==================================================================================================
  172. * LOCAL FUNCTIONS
  173. ==================================================================================================*/
  174. #define BASE_START_SEC_CODE
  175. #include "Base_MemMap.h"
  176. static inline uint32 OsIf_Timer_Dummy_GetCounter(void)
  177. {
  178. return 0u;
  179. }
  180. static inline uint32 OsIf_Timer_Dummy_GetElapsed(const uint32 * const CurrentRef)
  181. {
  182. (void)CurrentRef;
  183. return 1u;
  184. }
  185. static inline void OsIf_Timer_Dummy_SetTimerFrequency(uint32 Freq)
  186. {
  187. (void)Freq;
  188. }
  189. static inline uint32 OsIf_Timer_Dummy_MicrosToTicks(uint32 Micros)
  190. {
  191. return Micros;
  192. }
  193. #define BASE_STOP_SEC_CODE
  194. #include "Base_MemMap.h"
  195. /*==================================================================================================
  196. * GLOBAL FUNCTIONS
  197. ==================================================================================================*/
  198. #define BASE_START_SEC_CODE
  199. #include "Base_MemMap.h"
  200. /* @implements OsIf_Init_Activity */
  201. void OsIf_Init(const void* Config)
  202. {
  203. #if (STD_ON == OSIF_DEV_ERROR_DETECT)
  204. if (Config != NULL_PTR)
  205. {
  206. #if defined(USING_OS_AUTOSAROS)
  207. (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_INIT, OSIF_E_INIT_FAILED);
  208. #else
  209. OSIF_DEV_ASSERT(FALSE);
  210. #endif
  211. }
  212. #else
  213. (void)Config;
  214. #endif
  215. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  216. OsIf_Timer_System_Init();
  217. #endif
  218. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  219. OsIf_Timer_Custom_Init();
  220. #endif
  221. }
  222. /* @implements OsIf_GetCounter_Activity */
  223. uint32 OsIf_GetCounter(OsIf_CounterType SelectedCounter)
  224. {
  225. uint32 Value = 0u;
  226. switch (SelectedCounter){
  227. case OSIF_COUNTER_DUMMY:
  228. Value = OsIf_Timer_Dummy_GetCounter();
  229. break;
  230. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  231. case OSIF_COUNTER_SYSTEM:
  232. Value = OsIf_Timer_System_GetCounter();
  233. break;
  234. #endif
  235. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  236. case OSIF_COUNTER_CUSTOM:
  237. Value = OsIf_Timer_Custom_GetCounter();
  238. break;
  239. #endif
  240. default: /* impossible */ break;
  241. }
  242. return Value;
  243. }
  244. /* @implements OsIf_GetElapsed_Activity */
  245. uint32 OsIf_GetElapsed(uint32 * const CurrentRef, OsIf_CounterType SelectedCounter)
  246. {
  247. uint32 Value = 0u;
  248. switch (SelectedCounter){
  249. case OSIF_COUNTER_DUMMY:
  250. Value = OsIf_Timer_Dummy_GetElapsed(CurrentRef);
  251. break;
  252. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  253. case OSIF_COUNTER_SYSTEM:
  254. Value = OsIf_Timer_System_GetElapsed(CurrentRef);
  255. break;
  256. #endif
  257. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  258. case OSIF_COUNTER_CUSTOM:
  259. Value = OsIf_Timer_Custom_GetElapsed(CurrentRef);
  260. break;
  261. #endif
  262. default: /* impossible */ break;
  263. }
  264. return Value;
  265. }
  266. /* @implements OsIf_SetTimerFrequency_Activity */
  267. void OsIf_SetTimerFrequency(uint32 Freq, OsIf_CounterType SelectedCounter)
  268. {
  269. switch (SelectedCounter){
  270. case OSIF_COUNTER_DUMMY:
  271. OsIf_Timer_Dummy_SetTimerFrequency(Freq);
  272. break;
  273. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  274. case OSIF_COUNTER_SYSTEM:
  275. OsIf_Timer_System_SetTimerFrequency(Freq);
  276. break;
  277. #endif
  278. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  279. case OSIF_COUNTER_CUSTOM:
  280. OsIf_Timer_Custom_SetTimerFrequency(Freq);
  281. break;
  282. #endif
  283. default: /* impossible */ break;
  284. }
  285. }
  286. /* @implements OsIf_MicrosToTicks_Activity */
  287. uint32 OsIf_MicrosToTicks(uint32 Micros, OsIf_CounterType SelectedCounter)
  288. {
  289. uint32 Value = 0u;
  290. switch (SelectedCounter){
  291. case OSIF_COUNTER_DUMMY:
  292. Value = OsIf_Timer_Dummy_MicrosToTicks(Micros);
  293. break;
  294. #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
  295. case OSIF_COUNTER_SYSTEM:
  296. Value = OsIf_Timer_System_MicrosToTicks(Micros);
  297. break;
  298. #endif
  299. #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
  300. case OSIF_COUNTER_CUSTOM:
  301. Value = OsIf_Timer_Custom_MicrosToTicks(Micros);
  302. break;
  303. #endif
  304. default: /* impossible */ break;
  305. }
  306. return Value;
  307. }
  308. #define BASE_STOP_SEC_CODE
  309. #include "Base_MemMap.h"
  310. #ifdef __cplusplus
  311. }
  312. #endif
  313. /** @} */