Gpt.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : Ftm_Srtc_Lptmr_LPit
  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 Gpt.c
  26. * @implements Gpt.c_Artifact
  27. * @addtogroup gpt Gpt Driver
  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 "Gpt.h"
  41. #include "Gpt_Irq.h"
  42. #include "Gpt_Ipw.h"
  43. #include "Det.h"
  44. /*==================================================================================================
  45. * SOURCE FILE VERSION INFORMATION
  46. ==================================================================================================*/
  47. #define GPT_VENDOR_ID_C 43
  48. #define GPT_AR_RELEASE_MAJOR_VERSION_C 4
  49. #define GPT_AR_RELEASE_MINOR_VERSION_C 4
  50. #define GPT_AR_RELEASE_REVISION_VERSION_C 0
  51. #define GPT_SW_MAJOR_VERSION_C 1
  52. #define GPT_SW_MINOR_VERSION_C 0
  53. #define GPT_SW_PATCH_VERSION_C 0
  54. /*==================================================================================================
  55. * FILE VERSION CHECKS
  56. ==================================================================================================*/
  57. /* Check if source file and GPT header file are of the same vendor */
  58. #if (GPT_VENDOR_ID_C != GPT_VENDOR_ID)
  59. #error "Gpt.c and Gpt.h have different vendor ids"
  60. #endif
  61. /* Check if source file and GPT header file are of the same Autosar version */
  62. #if ((GPT_AR_RELEASE_MAJOR_VERSION_C != GPT_AR_RELEASE_MAJOR_VERSION) || \
  63. (GPT_AR_RELEASE_MINOR_VERSION_C != GPT_AR_RELEASE_MINOR_VERSION) || \
  64. (GPT_AR_RELEASE_REVISION_VERSION_C != GPT_AR_RELEASE_REVISION_VERSION) \
  65. )
  66. #error "AutoSar Version Numbers of Gpt.c and Gpt.h are different"
  67. #endif
  68. /* Check if source file and GPT header file are of the same Software version */
  69. #if ((GPT_SW_MAJOR_VERSION_C != GPT_SW_MAJOR_VERSION) || \
  70. (GPT_SW_MINOR_VERSION_C != GPT_SW_MINOR_VERSION) || \
  71. (GPT_SW_PATCH_VERSION_C != GPT_SW_PATCH_VERSION) \
  72. )
  73. #error "Software Version Numbers of Gpt.c and Gpt.h are different"
  74. #endif
  75. #if (GPT_VENDOR_ID_C != GPT_IPW_VENDOR_ID)
  76. #error "Gpt.c and Gpt_Ipw.h have different vendor ids"
  77. #endif
  78. /* Check if source file and GPT Ipw header file are of the same Autosar version */
  79. #if ((GPT_AR_RELEASE_MAJOR_VERSION_C != GPT_IPW_AR_RELEASE_MAJOR_VERSION) || \
  80. (GPT_AR_RELEASE_MINOR_VERSION_C != GPT_IPW_AR_RELEASE_MINOR_VERSION) || \
  81. (GPT_AR_RELEASE_REVISION_VERSION_C != GPT_IPW_AR_RELEASE_REVISION_VERSION) \
  82. )
  83. #error "AutoSar Version Numbers of Gpt.c and Gpt_Ipw.h are different"
  84. #endif
  85. /* Check if source file and GPT Ipw header file are of the same Software version */
  86. #if ((GPT_SW_MAJOR_VERSION_C != GPT_IPW_SW_MAJOR_VERSION) || \
  87. (GPT_SW_MINOR_VERSION_C != GPT_IPW_SW_MINOR_VERSION) || \
  88. (GPT_SW_PATCH_VERSION_C != GPT_IPW_SW_PATCH_VERSION) \
  89. )
  90. #error "Software Version Numbers of Gpt.c and Gpt_Ipw.h are different"
  91. #endif
  92. /* Check if source file and GPT header file are of the same vendor */
  93. #if (GPT_VENDOR_ID_C != GPT_IRQ_VENDOR_ID)
  94. #error "Gpt.c and Gpt_Irq.h have different vendor ids"
  95. #endif
  96. /* Check if source file and GPT header file are of the same Autosar version */
  97. #if ((GPT_AR_RELEASE_MAJOR_VERSION_C != GPT_IRQ_AR_RELEASE_MAJOR_VERSION) || \
  98. (GPT_AR_RELEASE_MINOR_VERSION_C != GPT_IRQ_AR_RELEASE_MINOR_VERSION) || \
  99. (GPT_AR_RELEASE_REVISION_VERSION_C != GPT_IRQ_AR_RELEASE_REVISION_VERSION)\
  100. )
  101. #error "AutoSar Version Numbers of Gpt.c and Gpt_Irq.h are different"
  102. #endif
  103. /* Check if source file and GPT header file are of the same Software version */
  104. #if ((GPT_SW_MAJOR_VERSION_C != GPT_IRQ_SW_MAJOR_VERSION) || \
  105. (GPT_SW_MINOR_VERSION_C != GPT_IRQ_SW_MINOR_VERSION) || \
  106. (GPT_SW_PATCH_VERSION_C != GPT_IRQ_SW_PATCH_VERSION) \
  107. )
  108. #error "Software Version Numbers of Gpt.c and Gpt_Irq.h are different"
  109. #endif
  110. /* Check if source file and DET header file are of the same version */
  111. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  112. #if ((GPT_AR_RELEASE_MAJOR_VERSION_C != DET_AR_RELEASE_MAJOR_VERSION) || \
  113. (GPT_AR_RELEASE_MINOR_VERSION_C != DET_AR_RELEASE_MINOR_VERSION) \
  114. )
  115. #error "AutoSar Version Numbers of Gpt.c and Det.h are different"
  116. #endif
  117. /* Check if this source file and OsIf.h file are of the same Autosar version */
  118. #if ((GPT_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  119. (GPT_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION))
  120. #error "AutoSar Version Numbers of Gpt.c and OsIf.h are different"
  121. #endif
  122. #endif
  123. /*==================================================================================================
  124. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  125. ==================================================================================================*/
  126. /**
  127. * @brief This enumeration type allows the selection of channel status type.
  128. * @details This enumeration specifies the return type of Gpt_ChannelStatusType
  129. *
  130. * @implements
  131. */
  132. typedef enum
  133. {
  134. GPT_STATUS_UNINITIALIZED = 0, /**< @brief GPT channel status - uninitialized */
  135. GPT_STATUS_INITIALIZED = 1, /**< @brief GPT channel status - initialized */
  136. GPT_STATUS_STOPPED = 2, /**< @brief GPT channel status - stopped */
  137. GPT_STATUS_EXPIRED = 3, /**< @brief GPT channel status - expired */
  138. GPT_STATUS_RUNNING = 4 /**< @brief GPT channel status - running */
  139. } Gpt_ChannelStatusType;
  140. /**
  141. * @brief Gpt runtime status type - this is the type of the data structure including the
  142. * runtime status informations of a channel.
  143. * @details It contains the information like GPT channel runtime status, Channel has notification enabled at runtime,
  144. * Channel has wakeup enabled at runtime,Channel executed wakeup.
  145. * @implements
  146. */
  147. typedef struct
  148. {
  149. Gpt_ChannelStatusType eChannelStatus; /**< @brief GPT channel runtime status */
  150. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON) /**< @brief GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON */
  151. boolean bNotificationEnabled; /**< @brief GPT channel has notification enabled at runtime */
  152. #endif
  153. /** @brief (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON) */
  154. #if((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  155. boolean bWakeupEnabled; /**< @brief GPT channel has wakeup enabled at runtime*/
  156. boolean bWakeupGenerated; /**< @brief GPT channel executed wakeup */
  157. #endif
  158. } Gpt_ChannelInfoType;
  159. /*==================================================================================================
  160. * LOCAL MACROS
  161. ==================================================================================================*/
  162. #if (GPT_MULTICORE_ENABLED == STD_ON)
  163. #define Gpt_GetCoreID() (uint32)OsIf_GetCoreID()
  164. #else
  165. #define Gpt_GetCoreID() ((uint32)0UL)
  166. #endif
  167. /*==================================================================================================
  168. * LOCAL CONSTANTS
  169. ==================================================================================================*/
  170. /*==================================================================================================
  171. * LOCAL VARIABLES
  172. ==================================================================================================*/
  173. #define GPT_START_SEC_VAR_INIT_UNSPECIFIED
  174. #include "Gpt_MemMap.h"
  175. /**
  176. * @brief Global variable used for indicating the current GPT driver mode.
  177. */
  178. static volatile Gpt_ModeType Gpt_eMode = GPT_MODE_NORMAL;
  179. #define GPT_STOP_SEC_VAR_INIT_UNSPECIFIED
  180. #include "Gpt_MemMap.h"
  181. #define GPT_START_SEC_VAR_CLEARED_UNSPECIFIED
  182. #include "Gpt_MemMap.h"
  183. /**
  184. * @brief Global variable (pointer) used for storing the GPT driver configuration data.
  185. */
  186. #if (GPT_MULTICORE_ENABLED == STD_ON)
  187. const Gpt_ConfigType *Gpt_pConfig[GPT_MAX_PARTITIONS];
  188. #else
  189. const Gpt_ConfigType *Gpt_pConfig[1U];
  190. #endif
  191. /**
  192. * @brief Global array variable used to store runtime internal context of each logic channel.
  193. */
  194. static Gpt_ChannelInfoType Gpt_aChannelInfo[GPT_HW_CHANNEL_NUM];
  195. /**
  196. * @brief Global array variable used to store for each channel the time value when it is
  197. * stopped
  198. */
  199. static volatile Gpt_ValueType Gpt_aStopTime[GPT_HW_CHANNEL_NUM];
  200. #define GPT_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  201. #include "Gpt_MemMap.h"
  202. /*==================================================================================================
  203. * GLOBAL CONSTANTS
  204. ==================================================================================================*/
  205. /*==================================================================================================
  206. * GLOBAL VARIABLES
  207. ==================================================================================================*/
  208. /*==================================================================================================
  209. * LOCAL FUNCTION PROTOTYPES
  210. ==================================================================================================*/
  211. #define GPT_START_SEC_CODE
  212. #include "Gpt_MemMap.h"
  213. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  214. static inline Std_ReturnType Gpt_ValidateChannelCall
  215. (
  216. uint8 u8ServiceId,
  217. Gpt_ChannelType channel,
  218. uint32 coreID
  219. );
  220. #endif
  221. #if(GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  222. static inline Std_ReturnType Gpt_ValidateGlobalCall
  223. (
  224. uint8 u8ServiceId,
  225. uint32 coreID
  226. );
  227. #endif
  228. #if ((GPT_VALIDATE_PARAM == STD_ON) && (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON))
  229. static inline Std_ReturnType Gpt_ValidateChannelNotification
  230. (
  231. uint8 u8ServiceId,
  232. Gpt_ChannelType channel,
  233. uint32 coreID
  234. );
  235. #endif
  236. #if ((GPT_VALIDATE_PARAM == STD_ON) && (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  237. static inline Std_ReturnType Gpt_ValidateChannelWakeup
  238. (
  239. uint8 u8ServiceId,
  240. Gpt_ChannelType channel,
  241. uint32 coreID
  242. );
  243. #endif
  244. #if (GPT_VALIDATE_STATE == STD_ON)
  245. static inline Std_ReturnType Gpt_ValidateChannelStatus
  246. (
  247. uint8 u8ServiceId,
  248. Gpt_ChannelType channel,
  249. uint32 coreID
  250. );
  251. #endif
  252. #if ((GPT_VALIDATE_PARAM == STD_ON) && (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  253. static inline Std_ReturnType Gpt_ValidateParamMode(Gpt_ModeType eMode);
  254. #endif
  255. #if (GPT_VALIDATE_PARAM == STD_ON)
  256. static inline Std_ReturnType Gpt_ValidateParamValue
  257. (
  258. uint8 u8ServiceId,
  259. Gpt_ChannelType channel,
  260. Gpt_ValueType value,
  261. uint32 coreID
  262. );
  263. #endif
  264. #if (GPT_VALIDATE_PARAM == STD_ON)
  265. static inline Std_ReturnType Gpt_ValidateParamPtrInit
  266. (
  267. const Gpt_ConfigType * configPtr
  268. );
  269. #endif
  270. #if (GPT_SET_CLOCK_MODE == STD_ON) && (GPT_VALIDATE_PARAM == STD_ON)
  271. static inline Std_ReturnType Gpt_ValidateParamSetClockMode
  272. (
  273. Gpt_ClockModeType eClkMode
  274. );
  275. #endif
  276. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  277. #if (GPT_VALIDATE_PARAM == STD_ON)
  278. static inline Std_ReturnType Gpt_ValidateParamTypePredefTimer
  279. (
  280. Gpt_PredefTimerType u32PredefTimer,
  281. uint32 coreID
  282. );
  283. static inline Std_ReturnType Gpt_ValidatePointerGetPredefTimer
  284. (
  285. const uint32 * ParamPtr
  286. );
  287. #endif
  288. #if (GPT_VALIDATE_STATE == STD_ON)
  289. static inline Std_ReturnType Gpt_ValidateMode
  290. (
  291. uint8 u8ServiceId
  292. );
  293. #endif
  294. #endif
  295. static inline Gpt_ChannelType Gpt_ConvertChannelIndexToChannel(Gpt_ChannelType ChannelIndex,
  296. uint32 coreID
  297. );
  298. /*==================================================================================================
  299. * LOCAL FUNCTIONS
  300. ==================================================================================================*/
  301. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  302. /**
  303. * @brief This function validates the call for a specific channel
  304. * @details This service is a non re entrant function on channel used for validating the calls
  305. * for functions that use one channel
  306. *
  307. * @param[in] Channel Numeric identifier of the GPT channel
  308. * @param[in] u8ServiceId The service id of the caller function
  309. * @return The validity of the function call
  310. * @returnValue E_OK The function call is valid
  311. * @returnValue E_NOT_OK The function call is invalid
  312. *
  313. * @pre Gpt_Init must be called before.
  314. * @implements Gpt_ValidateChannelCall_Activity
  315. *
  316. * */
  317. static inline Std_ReturnType Gpt_ValidateChannelCall
  318. (
  319. uint8 u8ServiceId,
  320. Gpt_ChannelType channel,
  321. uint32 coreID
  322. )
  323. {
  324. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  325. /* If driver is not initialized report error */
  326. if (NULL_PTR == Gpt_pConfig[coreID])
  327. {
  328. (void)Det_ReportError\
  329. (\
  330. (uint16)GPT_MODULE_ID,\
  331. (uint8)GPT_INSTANCE_ID,\
  332. (uint8)u8ServiceId,\
  333. (uint8)GPT_E_UNINIT\
  334. );
  335. }
  336. else
  337. {
  338. if (GPT_HW_CHANNEL_NUM <= channel)
  339. {
  340. /* Check if the configured channel is out of range */
  341. (void)Det_ReportError\
  342. (\
  343. (uint16)GPT_MODULE_ID,\
  344. (uint8)GPT_INSTANCE_ID,\
  345. (uint8)u8ServiceId,\
  346. (uint8)GPT_E_PARAM_CHANNEL\
  347. );
  348. }
  349. else
  350. {
  351. /* Check if the channel is used on the current core */
  352. if (255U != (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel])
  353. {
  354. returnValue = (Std_ReturnType)E_OK;
  355. }
  356. else
  357. {
  358. (void)Det_ReportError\
  359. (\
  360. (uint16)GPT_MODULE_ID,\
  361. (uint8)GPT_INSTANCE_ID,\
  362. (uint8)u8ServiceId,\
  363. (uint8)GPT_E_PARAM_CONFIG\
  364. );
  365. }
  366. }
  367. }
  368. return returnValue;
  369. }
  370. #endif
  371. #if(GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  372. /**
  373. * @brief This function validates the global call
  374. * @details This service is a non re-entrant function used for validating the calls for functions
  375. * that uses all the channels - Gpt_Init, Gpt_DeInit, Gpt_SetMode.
  376. *
  377. * @param[in] u8ServiceId The service id of the caller function
  378. *
  379. * @return The validity of the function call
  380. * @returnValue E_OK The function call is valid
  381. * @returnValue E_NOT_OK The function call is invalid
  382. *
  383. * @pre Gpt_Init must be called before.
  384. * @implements Gpt_ValidateGlobalCall_Activity
  385. * */
  386. static inline Std_ReturnType Gpt_ValidateGlobalCall
  387. (
  388. uint8 u8ServiceId,
  389. uint32 coreID
  390. )
  391. {
  392. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  393. /* If caller is the initialization function, error */
  394. if (NULL_PTR == Gpt_pConfig[coreID])
  395. {
  396. /* If caller is the initialization function, OK */
  397. if (GPT_INIT_ID == u8ServiceId)
  398. {
  399. returnValue = (Std_ReturnType)E_OK;
  400. }
  401. else
  402. {
  403. (void)Det_ReportError\
  404. (\
  405. (uint16)GPT_MODULE_ID,\
  406. (uint8)GPT_INSTANCE_ID,\
  407. (uint8)u8ServiceId,\
  408. (uint8)GPT_E_UNINIT\
  409. );
  410. }
  411. }
  412. else
  413. {
  414. if (GPT_INIT_ID == u8ServiceId)
  415. {
  416. (void)Det_ReportError\
  417. (\
  418. (uint16)GPT_MODULE_ID,\
  419. (uint8)GPT_INSTANCE_ID,\
  420. (uint8)u8ServiceId,\
  421. (uint8)GPT_E_ALREADY_INITIALIZED\
  422. );
  423. }
  424. else
  425. {
  426. returnValue = (Std_ReturnType)E_OK;
  427. }
  428. }
  429. return returnValue;
  430. }
  431. #endif
  432. #if ((GPT_VALIDATE_PARAM == STD_ON) && (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON))
  433. /**
  434. * @brief This function validate the channel notification capability for a
  435. * specific channel.
  436. * @details Validate the notification handler of a GPT channel.
  437. * In order to be valid, the notification handler should not be
  438. * NULL_PTR. In case it is NULL_PTR, the function will report an error to
  439. * DET or SERR, depending on the environment the driver is run in.
  440. * @param[in] u8ServiceId The service id of the caller function
  441. * @param[in] channel Numeric identifier of the GPT channel
  442. *
  443. * @return The validity of the function call
  444. * @returnValue E_OK The function call is valid
  445. * @returnValue E_NOT_OK The function call is invalid
  446. *
  447. * @pre The driver needs to be initialized and GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON.
  448. * @implements Gpt_ValidateChannelNotification_Activity
  449. *
  450. * */
  451. static inline Std_ReturnType Gpt_ValidateChannelNotification
  452. (
  453. uint8 u8ServiceId,
  454. Gpt_ChannelType channel,
  455. uint32 coreID
  456. )
  457. {
  458. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  459. uint8 ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  460. if (NULL_PTR == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_pfNotification)
  461. {
  462. (void)Det_ReportError\
  463. (\
  464. (uint16)GPT_MODULE_ID,\
  465. (uint8)GPT_INSTANCE_ID,\
  466. (uint8)u8ServiceId,\
  467. (uint8)GPT_E_PARAM_CHANNEL\
  468. );
  469. }
  470. else
  471. {
  472. returnValue = (Std_ReturnType)E_OK;
  473. }
  474. return returnValue;
  475. }
  476. #endif
  477. #if ((GPT_VALIDATE_PARAM == STD_ON) && (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  478. /**
  479. * @brief This function validate the channel wakeup capability for a specific channel.
  480. * @details Function validate the channel wakeup capability for a specific channel.
  481. * In case Gpt_bEnableWakeup is FALSE, the function will report an error to
  482. * DET or SERR, depending on the environment the driver is run in.
  483. * @param[in] u8ServiceId The service id of the caller function
  484. * @param[in] channel Numeric identifier of the GPT channel
  485. *
  486. * @return The validity of the function call
  487. * @returnValue E_OK The function call is valid
  488. * @returnValue E_NOT_OK The function call is invalid
  489. *
  490. * @pre The driver needs to be initialized.
  491. * @implements Gpt_ValidateChannelWakeup_Activity
  492. *
  493. * */
  494. static inline Std_ReturnType Gpt_ValidateChannelWakeup
  495. (
  496. uint8 u8ServiceId,
  497. Gpt_ChannelType channel,
  498. uint32 coreID
  499. )
  500. {
  501. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  502. uint8 ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  503. if (FALSE == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_bEnableWakeup)
  504. {
  505. (void)Det_ReportError\
  506. (\
  507. (uint16)GPT_MODULE_ID,\
  508. (uint8)GPT_INSTANCE_ID,\
  509. (uint8)u8ServiceId,\
  510. (uint8)GPT_E_PARAM_CHANNEL\
  511. );
  512. }
  513. else
  514. {
  515. returnValue = (Std_ReturnType)E_OK;
  516. }
  517. return returnValue;
  518. }
  519. #endif
  520. /**
  521. * @brief This function validate the channel status related to the caller function
  522. * and to a specific channel.
  523. * @details Function validate the channel status for a specific channel.
  524. * In case disabled wakeup channel in sleep mode ((bWakeupEnabled == False) && (GPT_MODE_SLEEP == Gpt_eMode)),
  525. * In case channel status (GPT_STATUS_RUNNING != eChannelStatus) && GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON
  526. * In case channel status (GPT_STATUS_RUNNING == eChannelStatus)
  527. * In case channel mode (GPT_CH_MODE_ONESHOT == eChannelMode) && GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON
  528. * the function will report an error to DET or SERR, depending on the environment the driver is run in.
  529. * @param[in] u8ServiceId The service id of the caller function
  530. * @param[in] channel Numeric identifier of the GPT channel
  531. *
  532. * @return The validity of the function call
  533. * @returnValue E_OK The function call is valid
  534. * @returnValue E_NOT_OK The function call is invalid
  535. *
  536. * @pre The driver needs to be initialized.
  537. * @implements
  538. * */
  539. static inline Std_ReturnType Gpt_ValidateChannelStatus
  540. (
  541. uint8 u8ServiceId,
  542. Gpt_ChannelType channel,
  543. uint32 coreID
  544. )
  545. {
  546. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  547. #if ((GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON) && (GPT_VALIDATE_STATE == STD_ON))
  548. uint8 ChannelIndex;
  549. #endif
  550. #if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_VALIDATE_STATE == STD_ON))
  551. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  552. /* Do not start a not enabled wakeup channel in sleep mode */
  553. if ((GPT_MODE_SLEEP == Gpt_eMode) && (FALSE == Gpt_aChannelInfo[channel].bWakeupEnabled) && (GPT_STARTTIMER_ID == u8ServiceId))
  554. {
  555. (void)Det_ReportError\
  556. (\
  557. (uint16)GPT_MODULE_ID,\
  558. (uint8)GPT_INSTANCE_ID,\
  559. (uint8)u8ServiceId,\
  560. (uint8)GPT_E_INVALID_CALL\
  561. );
  562. }
  563. else
  564. {
  565. #endif
  566. #endif /* (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_VALIDATE_STATE == STD_ON) */
  567. #if (GPT_VALIDATE_STATE == STD_OFF)
  568. (void) coreID;
  569. #endif
  570. #if (GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON)
  571. #if (GPT_VALIDATE_STATE == STD_ON)
  572. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  573. if ((GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID == u8ServiceId) && \
  574. (GPT_STATUS_RUNNING != Gpt_aChannelInfo[channel].eChannelStatus)
  575. )
  576. {
  577. (void)Det_ReportError\
  578. (\
  579. (uint16)GPT_MODULE_ID,\
  580. (uint8)GPT_INSTANCE_ID,\
  581. (uint8)u8ServiceId,\
  582. (uint8)GPT_E_INVALID_CALL\
  583. );
  584. }
  585. else if ((GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID == u8ServiceId) && \
  586. (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  587. )
  588. {
  589. (void)Det_ReportError\
  590. (\
  591. (uint16)GPT_MODULE_ID,\
  592. (uint8)GPT_INSTANCE_ID,\
  593. (uint8)u8ServiceId,\
  594. (uint8)GPT_E_PARAM_CHANNEL\
  595. );
  596. }
  597. else
  598. #endif /* (GPT_VALIDATE_STATE == STD_ON) */
  599. if ((GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID != u8ServiceId) && \
  600. (GPT_STATUS_RUNNING == Gpt_aChannelInfo[channel].eChannelStatus)
  601. )
  602. {
  603. (void)Det_ReportRuntimeError\
  604. (\
  605. (uint16)GPT_MODULE_ID,\
  606. (uint8)GPT_INSTANCE_ID,\
  607. (uint8)u8ServiceId,\
  608. (uint8)GPT_E_BUSY\
  609. );
  610. }
  611. else
  612. {
  613. #else
  614. if (GPT_STATUS_RUNNING == Gpt_aChannelInfo[channel].eChannelStatus)
  615. {
  616. (void)Det_ReportRuntimeError\
  617. (\
  618. (uint16)GPT_MODULE_ID,\
  619. (uint8)GPT_INSTANCE_ID,\
  620. (uint8)u8ServiceId,\
  621. (uint8)GPT_E_BUSY\
  622. );
  623. }
  624. else
  625. {
  626. #endif
  627. returnValue = (Std_ReturnType)E_OK;
  628. #if (GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_OFF)
  629. }
  630. #endif
  631. #if (GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON)
  632. }
  633. #endif
  634. #if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)&& (GPT_VALIDATE_STATE == STD_ON))
  635. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  636. }
  637. #endif
  638. #endif
  639. #if ((GPT_VALIDATE_STATE == STD_OFF)||(GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_OFF))
  640. /*variable coreID is not used in this case - this should be commented*/
  641. (void) coreID;
  642. #endif
  643. return returnValue;
  644. }
  645. #if ((GPT_VALIDATE_PARAM == STD_ON) && (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  646. /**
  647. * @brief This function validate the mode that will be set in the driver.
  648. * @details Validate the mode that will be set in the driver.
  649. * In case (GPT_MODE_SLEEP != eMode) && (GPT_MODE_NORMAL != eMode)
  650. * the function will report an error to DET or SERR, depending on the environment the driver is run in.
  651. * @param[in] eMode Specifies the operation mode
  652. *
  653. * @return The validity of the function call
  654. * @returnValue E_OK The function call is valid
  655. * @returnValue E_NOT_OK The function call is invalid
  656. *
  657. * @pre The driver needs to be initialized.
  658. * @implements Gpt_ValidateParamMode_Activity
  659. * */
  660. static inline Std_ReturnType Gpt_ValidateParamMode(Gpt_ModeType eMode)
  661. {
  662. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  663. if((GPT_MODE_SLEEP != eMode) && (GPT_MODE_NORMAL != eMode))
  664. {
  665. (void)Det_ReportError\
  666. (\
  667. (uint16)GPT_MODULE_ID,\
  668. (uint8)GPT_INSTANCE_ID,\
  669. (uint8)GPT_SETMODE_ID,\
  670. (uint8)GPT_E_PARAM_MODE\
  671. );
  672. }
  673. else
  674. {
  675. returnValue = (Std_ReturnType)E_OK;
  676. }
  677. return returnValue;
  678. }
  679. #endif
  680. #if (GPT_VALIDATE_PARAM == STD_ON)
  681. /**
  682. * @brief This function validate the time value parameter related to a specific GPT channel.
  683. * @details Function validate the time value parameter related to a specific GPT channel.
  684. * In case ((Gpt_ValueType)0 == value) || (value > Gpt_uChannelTickValueMax)
  685. * the function will report an error to DET or SERR, depending on the environment the driver is run in.
  686. * @param[in] u8ServiceId The service id of the caller function
  687. * @param[in] value The time value which is verified
  688. * @param[in] channel Numeric identifier of the GPT channel
  689. *
  690. * @return The validity of the function call
  691. * @returnValue E_OK The function call is valid
  692. * @returnValue E_NOT_OK The function call is invalid
  693. *
  694. * @pre The driver needs to be initialized.
  695. * @implements Gpt_ValidateParamValue_Activity
  696. *
  697. * */
  698. static inline Std_ReturnType Gpt_ValidateParamValue
  699. (
  700. uint8 u8ServiceId,
  701. Gpt_ChannelType channel,
  702. Gpt_ValueType value,
  703. uint32 coreID
  704. )
  705. {
  706. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  707. uint8 ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  708. if ((value > (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_uChannelTickValueMax) || \
  709. ((Gpt_ValueType)0 == value )
  710. )
  711. {
  712. (void)Det_ReportError\
  713. (\
  714. (uint16)GPT_MODULE_ID,\
  715. (uint8)GPT_INSTANCE_ID,\
  716. u8ServiceId,\
  717. (uint8)GPT_E_PARAM_VALUE\
  718. );
  719. }
  720. else
  721. {
  722. returnValue = (Std_ReturnType)E_OK;
  723. }
  724. return returnValue;
  725. }
  726. #endif
  727. #if (GPT_VALIDATE_PARAM == STD_ON)
  728. /**
  729. * @brief This function validate the initialization pointer.
  730. * @details Validate the initialization pointer.
  731. * In case NULL_PTR == configPtr and (GPT_PRECOMPILE_SUPPORT == STD_OFF)
  732. * In case NULL_PTR != configPtr and (GPT_PRECOMPILE_SUPPORT == STD_ON)
  733. * The function will report an error to DET or SERR, depending on the environment the driver is run in.
  734. * @param[in] configPtr Pointer to a selected configuration structure.
  735. *
  736. * @return The validity of the function call
  737. * @returnValue E_OK The function call is valid
  738. * @returnValue E_NOT_OK The function call is invalid
  739. *
  740. * @pre The data structure including the configuration set required for initializing the GPT driver.
  741. * @implements Gpt_ValidateParamPtrInit_Activity
  742. *
  743. * */
  744. static inline Std_ReturnType Gpt_ValidateParamPtrInit
  745. (
  746. const Gpt_ConfigType * configPtr
  747. )
  748. {
  749. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  750. #if (GPT_PRECOMPILE_SUPPORT == STD_OFF)
  751. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  752. if (NULL_PTR == configPtr)
  753. {
  754. (void)Det_ReportError\
  755. (\
  756. (uint16)GPT_MODULE_ID,\
  757. (uint8)GPT_INSTANCE_ID,\
  758. (uint8)GPT_INIT_ID,\
  759. (uint8)GPT_E_INIT_FAILED \
  760. );
  761. }
  762. else
  763. {
  764. returnValue = (Std_ReturnType)E_OK;
  765. }
  766. #endif
  767. #elif (GPT_PRECOMPILE_SUPPORT == STD_ON)
  768. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  769. if (NULL_PTR != configPtr)
  770. {
  771. (void)Det_ReportError\
  772. (\
  773. (uint16)GPT_MODULE_ID,\
  774. (uint8)GPT_INSTANCE_ID,\
  775. (uint8)GPT_INIT_ID,\
  776. (uint8)GPT_E_INIT_FAILED \
  777. );
  778. }
  779. else
  780. {
  781. returnValue=(Std_ReturnType)E_OK;
  782. }
  783. #endif
  784. #endif
  785. return returnValue;
  786. }
  787. #endif
  788. #if (GPT_SET_CLOCK_MODE == STD_ON) && (GPT_VALIDATE_PARAM == STD_ON)
  789. /**
  790. * @brief This function validates the eClkMode parameter.
  791. * @details Validate the function ValidateParamSetClockMode.
  792. * In case (GPT_CLOCKMODE_NORMAL != eClkMode) && (GPT_CLOCKMODE_ALTERNATE != eClkMode)
  793. * The function will report an error to DET or SERR, depending on the environment the driver is run in.
  794. * @param[in] eClkMode prescaler setting ( NORMAL or ALTERNATE )
  795. *
  796. * @return The validity of the function call
  797. * @returnValue E_OK The function call is valid
  798. * @returnValue E_NOT_OK The function call is invalid
  799. *
  800. * @pre The driver needs to be initialized.
  801. * @implements Gpt_ValidateParamSetClockMode_Activity
  802. *
  803. * */
  804. static inline Std_ReturnType Gpt_ValidateParamSetClockMode
  805. (
  806. Gpt_ClockModeType eClkMode
  807. )
  808. {
  809. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  810. if((GPT_CLOCKMODE_NORMAL != eClkMode) && (GPT_CLOCKMODE_ALTERNATE != eClkMode))
  811. {
  812. (void)Det_ReportError\
  813. (\
  814. (uint16)GPT_MODULE_ID,\
  815. (uint8)GPT_INSTANCE_ID,\
  816. (uint8)GPT_SET_CLOCK_MODE_ID,\
  817. (uint8)GPT_E_PARAM_CLOCK_MODE\
  818. );
  819. }
  820. else
  821. {
  822. returnValue=(Std_ReturnType)E_OK;
  823. }
  824. return returnValue;
  825. }
  826. #endif
  827. #if((GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON) && (GPT_VALIDATE_PARAM == STD_ON))
  828. /**
  829. * @brief This function validates parameter of PredefTimer
  830. * @details Validate the function Gpt_ValidateParamTypePredefTimer.
  831. * In case (Gpt_PredefTimerType != u32PredefTimer)
  832. * In case pointer to the GPT channel predeftimer configuration == NULL_PTR
  833. * The function will report an error to DET or SERR, depending on the environment the driver is run in.
  834. *
  835. * @param[in] u32PredefTimer Parameter of PredefTimer functionality
  836. * @return The validity of the function call
  837. * @returnValue E_OK The function call is valid
  838. * @returnValue E_NOT_OK The function call is invalid
  839. *
  840. * @pre The driver needs to be initialized.
  841. *
  842. * @implements Gpt_ValidateParamTypePredefTimer_Activity
  843. *
  844. **/
  845. static inline Std_ReturnType Gpt_ValidateParamTypePredefTimer
  846. (
  847. Gpt_PredefTimerType u32PredefTimer,
  848. uint32 coreID
  849. )
  850. {
  851. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  852. Gpt_ChannelType channel;
  853. if ((u32PredefTimer != GPT_PREDEF_TIMER_1US_16BIT) && \
  854. (u32PredefTimer != GPT_PREDEF_TIMER_1US_24BIT) && \
  855. (u32PredefTimer != GPT_PREDEF_TIMER_1US_32BIT) && \
  856. (u32PredefTimer != GPT_PREDEF_TIMER_100US_32BIT))
  857. {
  858. (void)Det_ReportError\
  859. (\
  860. (uint16)GPT_MODULE_ID,\
  861. (uint8)GPT_INSTANCE_ID,\
  862. (uint8)GPT_GET_PREDEF_TIMERVALUE_ID,\
  863. (uint8)GPT_E_PARAM_PREDEF_TIMER\
  864. );
  865. }
  866. else
  867. {
  868. channel = (Gpt_ChannelType)u32PredefTimer;
  869. if(NULL_PTR == ((Gpt_pConfig[coreID]->Gpt_pChannelPredefConfigType)[channel]))
  870. {
  871. (void)Det_ReportError\
  872. (\
  873. (uint16)GPT_MODULE_ID,\
  874. (uint8)GPT_INSTANCE_ID,\
  875. (uint8)GPT_GET_PREDEF_TIMERVALUE_ID,\
  876. (uint8)GPT_E_PARAM_PREDEF_TIMER\
  877. );
  878. }
  879. else
  880. {
  881. returnValue = (Std_ReturnType)E_OK;
  882. }
  883. }
  884. return returnValue;
  885. }
  886. /**
  887. * @brief This function validate the Pointer GetPredefTimer.
  888. * @details Validate the function Gpt_ValidatePointerGetPredefTimer.
  889. * In case (NULL_PTR == ParamPtr)
  890. * The function will report an error to DET or SERR, depending on the environment the driver is run in.
  891. * @param[in] ParamPtr Pointer to a selected configuration structure.
  892. * @return The validity of the function call
  893. * @returnValue E_OK The function call is valid
  894. * @returnValue E_NOT_OK The function call is invalid
  895. *
  896. * @pre The driver needs to be initialized.
  897. * @implements Gpt_ValidatePointerGetPredefTimer_Activity
  898. *
  899. **/
  900. static inline Std_ReturnType Gpt_ValidatePointerGetPredefTimer
  901. (
  902. const uint32 * ParamPtr
  903. )
  904. {
  905. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  906. if(NULL_PTR == ParamPtr)
  907. {
  908. (void)Det_ReportError\
  909. (\
  910. (uint16)GPT_MODULE_ID,\
  911. (uint8)GPT_INSTANCE_ID,\
  912. (uint8)GPT_GET_PREDEF_TIMERVALUE_ID,\
  913. (uint8)GPT_E_PARAM_POINTER\
  914. );
  915. }
  916. else
  917. {
  918. returnValue = (Std_ReturnType)E_OK;
  919. }
  920. return returnValue;
  921. }
  922. #endif
  923. #if (GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  924. /**
  925. * @brief This function validate the initialization mode.
  926. * @details Validate the function Gpt_ValidateMode.
  927. * In case (GPT_MODE_SLEEP == Gpt_eMode)
  928. * The function will report an error to DET or SERR, depending on the environment the driver is run in.
  929. * @param[in] u8ServiceId The service id of the caller function.
  930. *
  931. * @return The validity of the function call.
  932. * @returnValue E_OK The function call is valid.
  933. * @returnValue E_NOT_OK The function call is invalid.
  934. *
  935. * @pre The driver needs to be initialized.
  936. * @implements Gpt_ValidateMode_Activity
  937. *
  938. **/
  939. static inline Std_ReturnType Gpt_ValidateMode
  940. (
  941. uint8 u8ServiceId
  942. )
  943. {
  944. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  945. if (GPT_MODE_SLEEP == Gpt_eMode)
  946. {
  947. (void)Det_ReportRuntimeError\
  948. (\
  949. (uint16)GPT_MODULE_ID,\
  950. (uint8)GPT_INSTANCE_ID,\
  951. (uint8)u8ServiceId,\
  952. (uint8)GPT_E_MODE\
  953. );
  954. }
  955. else
  956. {
  957. returnValue = (Std_ReturnType)E_OK;
  958. }
  959. return returnValue;
  960. }
  961. #endif
  962. /**
  963. * @brief This function get the channel number corresponding to the index of channel
  964. *
  965. * @param[in] ChannelIndex Channel Index of the Gpt channel
  966. * @param[in] coreID The number of current core ID
  967. *
  968. * @return The channel number corresponds to the channel in the core
  969. * @pre Gpt_Init must be called before.
  970. *
  971. *
  972. * */
  973. static inline Gpt_ChannelType Gpt_ConvertChannelIndexToChannel(Gpt_ChannelType ChannelIndex,
  974. uint32 coreID
  975. )
  976. {
  977. Gpt_ChannelType Channel = GPT_HW_CHANNEL_NUM;
  978. for (Channel = 0U; Channel < GPT_HW_CHANNEL_NUM; Channel++)
  979. {
  980. if(ChannelIndex == (*Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap)[Channel])
  981. {
  982. break;
  983. }
  984. }
  985. return Channel;
  986. }
  987. /*==================================================================================================
  988. * GLOBAL FUNCTIONS
  989. ==================================================================================================*/
  990. /*================================================================================================*/
  991. #if (GPT_VERSION_INFO_API == STD_ON)
  992. /**
  993. * @brief This function returns the version information of this module.
  994. * @details This service returns the version information of this module. The version information
  995. * includes:
  996. * - Module Id
  997. * - Vendor Id
  998. * - Vendor specific version numbers
  999. * If source code for caller and callee of this function is available this function should
  1000. * be realized as a macro. The macro should be defined in the modules header file.
  1001. * @param[out] VersionInfoPtr - pointer to location to store version info
  1002. *
  1003. * @return void
  1004. * @api
  1005. *
  1006. * @pre Gpt_Init must be called before.
  1007. * @implements Gpt_GetVersionInfo_Activity
  1008. */
  1009. void Gpt_GetVersionInfo
  1010. (
  1011. Std_VersionInfoType * VersionInfoPtr
  1012. )
  1013. {
  1014. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  1015. if (NULL_PTR == VersionInfoPtr)
  1016. {
  1017. (void)Det_ReportError\
  1018. (\
  1019. (uint16)GPT_MODULE_ID,\
  1020. (uint8)GPT_INSTANCE_ID,\
  1021. (uint8)GPT_GETVERSIONINFO_ID,\
  1022. (uint8)GPT_E_PARAM_POINTER\
  1023. );
  1024. }
  1025. else
  1026. #endif
  1027. {
  1028. VersionInfoPtr->vendorID = (uint16)GPT_VENDOR_ID;
  1029. VersionInfoPtr->moduleID = (uint16)GPT_MODULE_ID;
  1030. VersionInfoPtr->sw_major_version = (uint8)GPT_SW_MAJOR_VERSION;
  1031. VersionInfoPtr->sw_minor_version = (uint8)GPT_SW_MINOR_VERSION;
  1032. VersionInfoPtr->sw_patch_version = (uint8)GPT_SW_PATCH_VERSION;
  1033. }
  1034. }
  1035. #endif
  1036. /*================================================================================================*/
  1037. /**
  1038. * @brief GPT driver initialization function.
  1039. * @details This service is a non reentrant function used for driver initialization.
  1040. * The Initialization function shall initialize all relevant registers of
  1041. * the configured hardware with the values of the structure referenced by the parameter ConfigPtr.
  1042. * All time units used within the API services of the GPT driver shall be of the unit ticks.
  1043. * This function shall only initialize the configured resources. Resources that are
  1044. * not configured in the configuration file shall not be touched.
  1045. * The following rules regarding initialization of controller registers shall apply
  1046. * to the GPT Driver implementation:
  1047. * [1] If the hardware allows for only one usage of the register, the driver
  1048. * module implementing that functionality is responsible for initializing the register
  1049. * [2] If the register can affect several hardware modules and if it is an IO register it
  1050. * shall be initialized by the PORT driver
  1051. * [3] If the register can affect several hardware modules and if it is not an IO register
  1052. * it shall be initialized by the MCU driver
  1053. * [4] One-time writable registers that require initialization directly after reset shall be
  1054. * initialized by the startup code
  1055. * [5] All other registers shall be initialized by the startup code
  1056. *
  1057. * @param[in] configPtr Pointer to a selected configuration structure
  1058. *
  1059. * @return void
  1060. * @api
  1061. *
  1062. * @pre The data structure including the configuration set required for initializing the GPT driver..
  1063. * @implements Gpt_Init_Activity
  1064. */
  1065. void Gpt_Init(const Gpt_ConfigType * configPtr)
  1066. {
  1067. uint32 coreID;
  1068. Gpt_ChannelType ChannelIndex;
  1069. Gpt_ChannelType channel;
  1070. coreID = (uint32)Gpt_GetCoreID();
  1071. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1072. /*Validate the calling context*/
  1073. if((Std_ReturnType)E_OK == Gpt_ValidateGlobalCall(GPT_INIT_ID, coreID))
  1074. {
  1075. #endif
  1076. #if (GPT_VALIDATE_PARAM == STD_ON)
  1077. /*Validate configuration pointer parameter.*/
  1078. if((Std_ReturnType)E_OK == Gpt_ValidateParamPtrInit(configPtr))
  1079. {
  1080. #endif
  1081. #if (GPT_PRECOMPILE_SUPPORT == STD_ON)
  1082. #if(GPT_MULTICORE_ENABLED == STD_ON)
  1083. Gpt_pConfig[coreID] = Gpt_Config[coreID];
  1084. #else
  1085. Gpt_pConfig[coreID] = &Gpt_Config;
  1086. #endif
  1087. (void)configPtr;
  1088. #else
  1089. Gpt_pConfig[coreID] = configPtr;
  1090. #endif
  1091. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  1092. /*Initialize and Start Predef Timers.*/
  1093. Gpt_Ipw_StartPredefTimer(Gpt_pConfig[coreID]);
  1094. #endif
  1095. Gpt_Ipw_InitInstances(Gpt_pConfig[coreID]);
  1096. /*Initialize for each channel the runtime status informations.*/
  1097. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  1098. {
  1099. channel = Gpt_ConvertChannelIndexToChannel(ChannelIndex, coreID);
  1100. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  1101. /*Disable notification*/
  1102. Gpt_aChannelInfo[channel].bNotificationEnabled = FALSE;
  1103. #endif
  1104. #if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  1105. /*Disable wakeup*/
  1106. Gpt_aChannelInfo[channel].bWakeupEnabled = FALSE;
  1107. /*Clear wakeup generation status*/
  1108. Gpt_aChannelInfo[channel].bWakeupGenerated = FALSE;
  1109. #endif
  1110. /* Initialize the running information of the channel*/
  1111. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_INITIALIZED;
  1112. Gpt_aStopTime[channel] = 0U;
  1113. /*Initialize hardware timer channel.*/
  1114. Gpt_Ipw_Init(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  1115. }
  1116. /*Set the driver to normal mode*/
  1117. Gpt_eMode = GPT_MODE_NORMAL;
  1118. #if (GPT_VALIDATE_PARAM == STD_ON)
  1119. }
  1120. #endif
  1121. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1122. }
  1123. #endif
  1124. return;
  1125. }
  1126. /*================================================================================================*/
  1127. #if (GPT_DEINIT_API == STD_ON)
  1128. /**
  1129. * @brief GPT driver de-initialization function.
  1130. * @details Service for de initializing all hardware timer channels to their power on reset state.
  1131. * The state of the peripheral after DeInit shall be the same as after power on
  1132. * reset.
  1133. * The service influences only the peripherals, which are allocated by static
  1134. * configuration and the runtime configuration set passed by the previous call of Gpt_Init()
  1135. * The driver needs to be initialized before calling Gpt_DeInit(). Otherwise, the
  1136. * function Gpt_DeInit shall raise the development error GPT_E_UNINIT and leave the desired
  1137. * de initialization functionality without any action.
  1138. *
  1139. * @api
  1140. * @return void
  1141. *
  1142. * @implements Gpt_DeInit_Activity
  1143. */
  1144. void Gpt_DeInit(void)
  1145. {
  1146. Gpt_ChannelType channel;
  1147. Gpt_ChannelType ChannelIndex;
  1148. Std_ReturnType allChannelStatus = (Std_ReturnType)E_OK;
  1149. uint32 coreID;
  1150. coreID = (uint32)Gpt_GetCoreID();
  1151. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1152. /*Validate if the calling context is valid*/
  1153. if((Std_ReturnType)E_OK == Gpt_ValidateGlobalCall(GPT_DEINIT_ID, coreID))
  1154. {
  1155. #endif
  1156. /* Initialize for each channel the runtime status informations.*/
  1157. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  1158. {
  1159. channel = Gpt_ConvertChannelIndexToChannel(ChannelIndex, coreID);
  1160. /*Check if the channel is not running.*/
  1161. if((Std_ReturnType)E_NOT_OK == Gpt_ValidateChannelStatus(GPT_DEINIT_ID, channel, coreID))
  1162. {
  1163. allChannelStatus = (Std_ReturnType)E_NOT_OK;
  1164. break;
  1165. }
  1166. }
  1167. if((Std_ReturnType)E_OK == allChannelStatus)
  1168. {
  1169. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  1170. {
  1171. channel = Gpt_ConvertChannelIndexToChannel(ChannelIndex, coreID);
  1172. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  1173. /*Disable notification*/
  1174. Gpt_aChannelInfo[channel].bNotificationEnabled = FALSE;
  1175. #endif
  1176. #if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))
  1177. /*Disable wakeup*/
  1178. Gpt_aChannelInfo[channel].bWakeupEnabled = FALSE;
  1179. /*Clear wakeup generation status*/
  1180. Gpt_aChannelInfo[channel].bWakeupGenerated = FALSE;
  1181. #endif
  1182. /* De initialize the running information of the channel*/
  1183. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_UNINITIALIZED;
  1184. Gpt_aStopTime[channel] = 0U;
  1185. /*Initialize hardware timer channel.*/
  1186. Gpt_Ipw_DeInit
  1187. (
  1188. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1189. );
  1190. }
  1191. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  1192. /* Deinitialize and stop Predef timers.*/
  1193. Gpt_Ipw_StopPredefTimer(Gpt_pConfig[coreID]);
  1194. #endif
  1195. /* Writing NULL to configuration pointer is mandatory because that variable
  1196. is used to test the initialization of the driver */
  1197. Gpt_pConfig[coreID] = NULL_PTR;
  1198. }
  1199. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1200. }
  1201. #endif
  1202. return;
  1203. }
  1204. #endif
  1205. /*================================================================================================*/
  1206. #if (GPT_TIME_ELAPSED_API == STD_ON)
  1207. /**
  1208. * @brief GPT driver function for fetching the elapsed timer value.
  1209. * @details Service for querying the time already elapsed.
  1210. * In one shot mode, this is the value relative to the point in time, the channel has been
  1211. * started with Gpt_StartTimer (calculated by the normal operation function by subtracting
  1212. * the current minus the initial timer value and returning the absolute value).
  1213. * In continuous mode, the function returns the timer value relative to the last timeout or
  1214. * the start of the channel.
  1215. * All time units used within the API services of the GPT driver shall be of the unit ticks.
  1216. * Usage of re-entrant capability is only allowed if the callers take care that
  1217. * there is no simultaneous usage of the same channel.
  1218. * To get times out of register values it is necessary to know the oscillator frequency, pre
  1219. * prescalers and so on. Since these settings are made in MCU and(or) in other modules it is
  1220. * not possible to calculate such times. Hence the conversions between time and ticks shall
  1221. * be part of an upper layer.
  1222. * The driver needs to be initialized before calling Gpt_GetTimeElapsed(). Otherwise, the
  1223. * function shall raise the development error GPT_E_UNINIT and return 0.
  1224. *
  1225. * @param[in] channel - channel id
  1226. *
  1227. * @return Gpt_ValueType - Elapsed Time in number of ticks
  1228. *
  1229. * @api
  1230. *
  1231. * @pre The driver needs to be initialized.
  1232. * @implements Gpt_GetTimeElapsed_Activity
  1233. */
  1234. Gpt_ValueType Gpt_GetTimeElapsed(Gpt_ChannelType channel)
  1235. {
  1236. static Gpt_HwChannelInfoType returnHwChannelInfo;
  1237. uint32 coreID;
  1238. uint8 ChannelIndex;
  1239. Gpt_ValueType returnValue = (Gpt_ValueType)0;
  1240. returnHwChannelInfo.bChannelRollover =FALSE;
  1241. returnHwChannelInfo.uTargetTime =(Gpt_ValueType)0;
  1242. coreID = (uint32)Gpt_GetCoreID();
  1243. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1244. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_TIMEELAPSED_ID, channel, coreID))
  1245. {
  1246. #endif
  1247. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1248. /*Gpt_Ipw_GetTimeElapsed() shall be called first, because the occurred ISRs can change
  1249. the logical channel state between the checking of logical channel state and timestamp
  1250. retrieval*/
  1251. returnValue = Gpt_Ipw_GetTimeElapsed((((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)), &returnHwChannelInfo);
  1252. /*Check the channel status*/
  1253. switch(Gpt_aChannelInfo[channel].eChannelStatus)
  1254. {
  1255. case GPT_STATUS_RUNNING:
  1256. {
  1257. /*Check if channel counter has already rollover*/
  1258. if ((TRUE == returnHwChannelInfo.bChannelRollover) && \
  1259. (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1260. )
  1261. {
  1262. /*The timer has already expired.The hardware timer status is not yet
  1263. synchronized with the logical timer status*/
  1264. returnValue = returnHwChannelInfo.uTargetTime;
  1265. }
  1266. }
  1267. break;
  1268. case GPT_STATUS_INITIALIZED:
  1269. {
  1270. returnValue = (Gpt_ValueType)0;
  1271. }
  1272. break;
  1273. case GPT_STATUS_STOPPED:
  1274. {
  1275. /*Return elapsed time at the when the channel was stopped*/
  1276. returnValue = Gpt_aStopTime[channel];
  1277. }
  1278. break;
  1279. case GPT_STATUS_EXPIRED:
  1280. {
  1281. returnValue = returnHwChannelInfo.uTargetTime;
  1282. }
  1283. break;
  1284. default:
  1285. /*Only the above four channel states are allowed when this function is called*/
  1286. break;
  1287. }
  1288. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1289. }
  1290. #endif
  1291. return (returnValue);
  1292. }
  1293. #endif
  1294. /*================================================================================================*/
  1295. #if (GPT_TIME_REMAINING_API == STD_ON)
  1296. /**
  1297. * @brief GPT driver function for fetching the remaining timer value.
  1298. * @details This function returns the timer value remaining until the next timeout period will
  1299. * expire (calculated by the normal operation function by subtracting the timeout minus
  1300. * the current timer value and returning the absolute value)
  1301. * All time units used within the API services of the GPT driver shall be of the unit ticks.
  1302. * Usage of re-entrant capability is only allowed if the callers take care that there is no
  1303. * simultaneous usage of the same channel.
  1304. * To get times out of register values it is necessary to know the oscillator frequency,
  1305. * pre-scalers and so on. Since these settings are made in MCU and(or) in other modules it is
  1306. * not possible to calculate such times. Hence the conversions between time and ticks shall
  1307. * be part of an upper layer.
  1308. * The driver needs to be initialized before calling Gpt_GetTimeRemaining(). Otherwise, the
  1309. * function shall raise the development error GPT_E_UNINIT and return 0.
  1310. *
  1311. *
  1312. * @param[in] channel - channel id
  1313. *
  1314. * @return Gpt_ValueType - Returns the time remaining until the target time is reached in number of ticks.
  1315. *
  1316. * @api
  1317. *
  1318. * @pre The driver needs to be initialized.
  1319. * @implements Gpt_GetTimeRemaining_Activity
  1320. */
  1321. Gpt_ValueType Gpt_GetTimeRemaining(Gpt_ChannelType channel)
  1322. {
  1323. uint32 coreID;
  1324. uint8 ChannelIndex;
  1325. static Gpt_HwChannelInfoType returnHwChannelInfo;
  1326. Gpt_ValueType returnValue = (Gpt_ValueType)0;
  1327. returnHwChannelInfo.bChannelRollover =FALSE;
  1328. returnHwChannelInfo.uTargetTime =(Gpt_ValueType)0;
  1329. coreID = (uint32)Gpt_GetCoreID();
  1330. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1331. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_TIMEREMAINING_ID, channel, coreID))
  1332. {
  1333. #endif
  1334. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1335. /* Calculate the remaining time from the elapsed time*/
  1336. /* Gpt_Ipw_GetTimeElapsed() shall be called first, because the occurred ISRs can
  1337. change the logical channel state between the checking of logical channel state
  1338. and timestamps retrieval*/
  1339. returnValue = Gpt_Ipw_GetTimeElapsed((((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)), &returnHwChannelInfo);
  1340. /*Check the channel status*/
  1341. switch(Gpt_aChannelInfo[channel].eChannelStatus)
  1342. {
  1343. case GPT_STATUS_RUNNING:
  1344. {
  1345. /*Check if channel counter has already roll-over*/
  1346. if((TRUE == returnHwChannelInfo.bChannelRollover) && \
  1347. (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1348. )
  1349. {
  1350. /*The timer has already expired.The hardware timer status is not yet
  1351. synchronized with the logical timer status*/
  1352. returnValue = (Gpt_ValueType)0;
  1353. }
  1354. else
  1355. {
  1356. /*Calculate remaining time from elapsed time*/
  1357. returnValue = returnHwChannelInfo.uTargetTime - returnValue;
  1358. }
  1359. }
  1360. break;
  1361. case GPT_STATUS_INITIALIZED:
  1362. {
  1363. returnValue = (Gpt_ValueType)0;
  1364. }
  1365. break;
  1366. case GPT_STATUS_STOPPED:
  1367. {
  1368. returnValue = returnHwChannelInfo.uTargetTime-Gpt_aStopTime[channel];
  1369. }
  1370. break;
  1371. case GPT_STATUS_EXPIRED:
  1372. {
  1373. returnValue = (Gpt_ValueType)0;
  1374. }
  1375. break;
  1376. default:
  1377. /*Only the above four channel states are allowed when this function is called*/
  1378. break;
  1379. }
  1380. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1381. }
  1382. #endif
  1383. return(returnValue);
  1384. }
  1385. #endif
  1386. /*================================================================================================*/
  1387. /**
  1388. * @brief GPT driver function for starting a timer channel.
  1389. * @details The function Gpt_StartTimer shall start the selected timer channel with a defined
  1390. * time-out period.
  1391. * The function Gpt_StartTimer shall invoke the configured notification for that channel
  1392. * (see also GPT292) after the time-out period referenced via the parameter value (if
  1393. * enabled).
  1394. * All time units used within the API services of the GPT driver shall be of the unit ticks.
  1395. * In production mode no error is generated. The rational is that it adds no
  1396. * additional functionality to the driver. In this case the timer will be restarted with the
  1397. * time-out value, given as a parameter to the service.
  1398. * Usage of re-entrant capability is only allowed if the callers take care that
  1399. * there is no simultaneous usage of the same channel.
  1400. * To get times out of register values it is necessary to know the oscillator
  1401. * frequency, pre-scalers and so on. Since these settings are made in MCU and(or) in other
  1402. * modules it is not possible to calculate such times. Hence the conversions between time
  1403. * and ticks shall be part of an upper layer.
  1404. * The driver needs to be initialized before calling Gpt_StartTimer(). Otherwise, the
  1405. * function Gpt_StartTimer shall raise the development error GPT_E_UNINIT.
  1406. *
  1407. * @param[in] channel channel id
  1408. * @param[in] value time-out period (in number of ticks) after a notification or a
  1409. * wakeup event shall occur
  1410. *
  1411. * @api
  1412. * @return void
  1413. *
  1414. * @pre The driver needs to be initialized.
  1415. * @implements Gpt_StartTimer_Activity
  1416. */
  1417. void Gpt_StartTimer
  1418. (
  1419. Gpt_ChannelType channel,
  1420. Gpt_ValueType value
  1421. )
  1422. {
  1423. uint32 coreID;
  1424. uint8 ChannelIndex;
  1425. Std_ReturnType returnValue;
  1426. coreID = (uint32)Gpt_GetCoreID();
  1427. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1428. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_STARTTIMER_ID, channel, coreID))
  1429. {
  1430. #endif
  1431. if ((Std_ReturnType)E_OK == Gpt_ValidateChannelStatus(GPT_STARTTIMER_ID, channel, coreID))
  1432. {
  1433. #if (GPT_VALIDATE_PARAM == STD_ON)
  1434. if ((Std_ReturnType)E_OK == Gpt_ValidateParamValue(GPT_STARTTIMER_ID, channel, value, coreID))
  1435. {
  1436. #endif
  1437. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1438. /*Enable hardware interrupts for the one-shot mode to set the status of channel*/
  1439. if (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1440. {
  1441. Gpt_Ipw_EnableInterrupt
  1442. (
  1443. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1444. );
  1445. }
  1446. /* Change GPT channel status.Channel status change shall be made before to start
  1447. the hardware in order to not change the channel status from EXPIRED to RUNNING*/
  1448. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_RUNNING;
  1449. /* Call low level API */
  1450. returnValue = Gpt_Ipw_StartTimer(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig),value);
  1451. if((Std_ReturnType)E_OK != returnValue)
  1452. {
  1453. (void)Det_ReportRuntimeError\
  1454. (\
  1455. (uint16)GPT_MODULE_ID,\
  1456. (uint8)GPT_INSTANCE_ID,\
  1457. (uint8)GPT_STARTTIMER_ID,\
  1458. (uint8)GPT_E_TIMEOUT\
  1459. );
  1460. }
  1461. #if (GPT_VALIDATE_PARAM == STD_ON)
  1462. }
  1463. #endif
  1464. }
  1465. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1466. }
  1467. #endif
  1468. return;
  1469. }
  1470. /*================================================================================================*/
  1471. /**
  1472. * @brief GPT driver function for stopping a timer channel.
  1473. * @details Service for stopping the selected timer channel
  1474. * Stopping a timer channel, not been started before will not return a development error
  1475. * Timer channels configured in one shot mode are stopped automatically, when the
  1476. * time-out period has expired.
  1477. * Usage of re-entrant capability is only allowed if the callers take care that
  1478. * there is no simultaneous usage of the same channel.
  1479. * The driver needs to be initialized before calling Gpt_StopTimer(). Otherwise,
  1480. * the function shall raise the development error GPT_E_UNINIT.
  1481. *
  1482. * @param[in] channel channel id
  1483. * @return void
  1484. *
  1485. * @api
  1486. *
  1487. * @pre The driver needs to be initialized. Gpt_StartTimer must be called before.
  1488. * @implements Gpt_StopTimer_Activity
  1489. */
  1490. void Gpt_StopTimer(Gpt_ChannelType channel)
  1491. {
  1492. uint32 coreID;
  1493. uint8 ChannelIndex;
  1494. static Gpt_HwChannelInfoType returnHwChannelInfo;
  1495. Gpt_ValueType uElapsedTime;
  1496. returnHwChannelInfo.bChannelRollover =FALSE;
  1497. returnHwChannelInfo.uTargetTime =(Gpt_ValueType)0;
  1498. coreID = (uint32)Gpt_GetCoreID();
  1499. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1500. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_STOPTIMER_ID, channel, coreID))
  1501. {
  1502. #endif
  1503. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1504. /*Gpt_Ipw_GetTimeElapsed() shall be called first, because the occurred ISRs can change
  1505. the logical channel state between the checking of logical channel state and timestamps
  1506. retrieval*/
  1507. /* Get the elapsed time for later use by other API calls*/
  1508. uElapsedTime = Gpt_Ipw_GetTimeElapsed((((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)), &returnHwChannelInfo);
  1509. /*Check the logical channel status*/
  1510. if (GPT_STATUS_RUNNING == Gpt_aChannelInfo[channel].eChannelStatus)
  1511. {
  1512. /* Call low level stop timer */
  1513. Gpt_Ipw_StopTimer(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  1514. if ((TRUE == returnHwChannelInfo.bChannelRollover) && \
  1515. (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1516. )
  1517. {
  1518. /*This action could be executed only when the function is called during a critical
  1519. section implemented by disabling all interrupts*/
  1520. /*Set channel status to EXPIRED*/
  1521. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_EXPIRED;
  1522. }
  1523. else
  1524. {
  1525. /* Store the stopping time for later use by other API calls*/
  1526. Gpt_aStopTime[channel] = uElapsedTime;
  1527. /* Set GPT channel status to stopped*/
  1528. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_STOPPED;
  1529. }
  1530. }
  1531. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1532. }
  1533. #endif
  1534. return;
  1535. }
  1536. /*================================================================================================*/
  1537. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  1538. /**
  1539. * @brief GPT driver function for enabling the notification for a timer channel.
  1540. * @details Service for enabling the notification for a channel during runtime.
  1541. * This function can be called, while the timer is already running.
  1542. * Usage of re-entrant capability is only allowed if the callers take care that
  1543. * there is no simultaneous usage of the same channel.
  1544. * The driver needs to be initialized before calling Gpt_EnableNotification(). Otherwise,
  1545. * the function Gpt_EnableNotification shall raise the development error GPT_E_UNINIT.
  1546. *
  1547. * @param[in] channel channel id
  1548. * @return void
  1549. * @api
  1550. *
  1551. * @pre The driver needs to be initialized.
  1552. * @implements Gpt_EnableNotification_Activity
  1553. */
  1554. void Gpt_EnableNotification(Gpt_ChannelType channel)
  1555. {
  1556. uint32 coreID;
  1557. uint8 ChannelIndex;
  1558. coreID = (uint32)Gpt_GetCoreID();
  1559. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1560. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_ENABLENOTIFICATION_ID, channel, coreID))
  1561. {
  1562. #endif
  1563. #if (GPT_VALIDATE_PARAM == STD_ON)
  1564. if ((Std_ReturnType)E_OK == Gpt_ValidateChannelNotification(GPT_ENABLENOTIFICATION_ID, channel, coreID))
  1565. {
  1566. #endif
  1567. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1568. /* Set the enable notification attribute */
  1569. Gpt_aChannelInfo[channel].bNotificationEnabled = TRUE;
  1570. if (GPT_MODE_NORMAL == Gpt_eMode)
  1571. {
  1572. /*Enable hardware interrupts*/
  1573. Gpt_Ipw_EnableInterrupt
  1574. (
  1575. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1576. );
  1577. }
  1578. #if (GPT_VALIDATE_PARAM == STD_ON)
  1579. }
  1580. #endif
  1581. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1582. }
  1583. #endif
  1584. return;
  1585. }
  1586. #endif
  1587. /*================================================================================================*/
  1588. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  1589. /**
  1590. * @brief GPT driver function for disabling the notification for a timer channel.
  1591. * @details Service for disabling the notification for a channel during runtime.
  1592. * This function can be called, while the timer is already running
  1593. * When disabled, no notification will be sent. When re-enabled again, the user
  1594. * will not be notified of events, occurred while notifications have been disabled.
  1595. * Usage of re-entrant capability is only allowed if the callers take care that
  1596. * there is no simultaneous usage of the same channel.
  1597. * The driver needs to be initialized before calling Gpt_DisableNotification().
  1598. * Otherwise, the function shall raise the development error GPT_E_UNINIT.
  1599. *
  1600. * @param[in] channel channel id
  1601. * @return void
  1602. * @api
  1603. *
  1604. * @pre The driver needs to be initialized.
  1605. * @implements Gpt_DisableNotification_Activity
  1606. */
  1607. void Gpt_DisableNotification(Gpt_ChannelType channel)
  1608. {
  1609. uint32 coreID;
  1610. uint8 ChannelIndex;
  1611. coreID = (uint32)Gpt_GetCoreID();
  1612. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1613. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_DISABLENOTIFICATION_ID, channel, coreID))
  1614. {
  1615. #endif
  1616. #if (GPT_VALIDATE_PARAM == STD_ON)
  1617. if ((Std_ReturnType)E_OK == Gpt_ValidateChannelNotification(GPT_DISABLENOTIFICATION_ID, channel, coreID))
  1618. {
  1619. #endif
  1620. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1621. /* Set the enable notification attribute */
  1622. Gpt_aChannelInfo[channel].bNotificationEnabled = FALSE;
  1623. /* Disable hardware interrupts if the channel is not running in the ONE-SHUT mode.
  1624. This is needed because the channel state is updated by ISR for ONE-SHOT mode */
  1625. if ((GPT_MODE_NORMAL == Gpt_eMode) && \
  1626. ((GPT_CH_MODE_CONTINUOUS == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode) \
  1627. || (GPT_STATUS_RUNNING != Gpt_aChannelInfo[channel].eChannelStatus)
  1628. )
  1629. )
  1630. {
  1631. /*Disable hardware interrupts*/
  1632. Gpt_Ipw_DisableInterrupt
  1633. (
  1634. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1635. );
  1636. }
  1637. #if (GPT_VALIDATE_PARAM == STD_ON)
  1638. }
  1639. #endif
  1640. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1641. }
  1642. #endif
  1643. return;
  1644. }
  1645. #endif
  1646. /*================================================================================================*/
  1647. #if (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)
  1648. /**
  1649. * @brief GPT driver function for setting the operation mode.
  1650. * @details Service for GPT mode selection. This service shall set the operation mode to the given
  1651. * mode parameter .
  1652. * When sleep mode is requested, the ECU State Manager calls Gpt_SetMode with mode
  1653. * parameter "GPT_MODE_SLEEP" and prepares the GPT for sleep mode. The MCU Driver is then
  1654. * putting the controller into SLEEP mode
  1655. * The driver needs to be initialized before calling Gpt_SetMode(). Otherwise, the
  1656. * function Gpt_SetMode shall raise the development error GPT_E_UNINIT.
  1657. *
  1658. * @param[in] eMode operation mode
  1659. * - GPT_MODE_NORMAL: Normal operation mode of the GPT driver.
  1660. * - GPT_MODE_SLEEP: Sleep mode of the GPT driver (wakeup capable)
  1661. * @return void
  1662. * @api
  1663. *
  1664. * @pre The driver needs to be initialized.
  1665. * @implements Gpt_SetMode_Activity
  1666. */
  1667. void Gpt_SetMode(Gpt_ModeType eMode)
  1668. {
  1669. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1670. uint32 coreID = (uint32)Gpt_GetCoreID();
  1671. #endif
  1672. #if (GPT_REPORT_WAKEUP_SOURCE == STD_OFF)
  1673. (void)eMode;
  1674. #endif
  1675. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1676. static Gpt_HwChannelInfoType returnHwChannelInfo;
  1677. Gpt_ValueType uElapsedTime = 0U;
  1678. Gpt_ChannelType ChannelIndex;
  1679. Gpt_ChannelType channel;
  1680. returnHwChannelInfo.bChannelRollover =FALSE;
  1681. returnHwChannelInfo.uTargetTime =(Gpt_ValueType)0;
  1682. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1683. /*Validate the driver calling context*/
  1684. if((Std_ReturnType)E_OK == Gpt_ValidateGlobalCall(GPT_SETMODE_ID, coreID))
  1685. {
  1686. #endif
  1687. #if (GPT_VALIDATE_PARAM == STD_ON)
  1688. if((Std_ReturnType)E_OK == Gpt_ValidateParamMode(eMode))
  1689. {
  1690. #endif
  1691. /*Implements the behaviour for the sleep mode*/
  1692. if(GPT_MODE_SLEEP == eMode)
  1693. {
  1694. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  1695. {
  1696. channel = Gpt_ConvertChannelIndexToChannel(ChannelIndex, coreID);
  1697. /* Check for wakeup enabled channel*/
  1698. if (TRUE == Gpt_aChannelInfo[channel].bWakeupEnabled)
  1699. {
  1700. /*Enable hardware interrupts*/
  1701. Gpt_Ipw_EnableInterrupt(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  1702. }
  1703. /* Disable interrupts and stop the channel*/
  1704. else
  1705. {
  1706. /*Disable hardware interrupts*/
  1707. Gpt_Ipw_DisableInterrupt(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  1708. /*Gpt_Ipw_GetTimeElapsed() shall be called first, because the occurred ISRs
  1709. can change the logical channel state between the checking of logical channel
  1710. state and timestamp retrieval*/
  1711. /* Get the elapsed time for later use by other API calls*/
  1712. uElapsedTime = Gpt_Ipw_GetTimeElapsed((((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)), &returnHwChannelInfo);
  1713. /*Stop the running timer*/
  1714. if (GPT_STATUS_RUNNING == Gpt_aChannelInfo[channel].eChannelStatus)
  1715. {
  1716. if ((TRUE == returnHwChannelInfo.bChannelRollover) && \
  1717. (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1718. )
  1719. {
  1720. /*This action could be executed only when the function is called
  1721. during a critical section implemented by disabling all interrupts*/
  1722. /*Set the channel status to EXPIRED*/
  1723. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_EXPIRED;
  1724. }
  1725. else
  1726. {
  1727. /* Store the stopping time for later use by other API calls*/
  1728. Gpt_aStopTime[channel] = uElapsedTime;
  1729. /* Set the channel status to STOPPED*/
  1730. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_STOPPED;
  1731. }
  1732. /* Call low level stop timer */
  1733. Gpt_Ipw_StopTimer
  1734. (
  1735. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1736. );
  1737. }
  1738. }
  1739. }
  1740. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  1741. /* Deinitialize and Stop Predef Timers. */
  1742. Gpt_Ipw_StopPredefTimer(Gpt_pConfig[coreID]);
  1743. #endif
  1744. /*Set the driver mode to sleep */
  1745. Gpt_eMode = GPT_MODE_SLEEP;
  1746. }
  1747. else if (GPT_MODE_NORMAL == eMode)
  1748. {
  1749. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  1750. if ((Gpt_ModeType)GPT_MODE_SLEEP == Gpt_eMode)
  1751. {
  1752. /* Start for each predef timer status informations. */
  1753. Gpt_Ipw_StartPredefTimer(Gpt_pConfig[coreID]);
  1754. }
  1755. #endif
  1756. /*Implements the behavior for normal mode*/
  1757. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  1758. {
  1759. channel = Gpt_ConvertChannelIndexToChannel(ChannelIndex, coreID);
  1760. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  1761. if (TRUE == Gpt_aChannelInfo[channel].bNotificationEnabled)
  1762. {
  1763. /*Enable hardware interrupts*/
  1764. Gpt_Ipw_EnableInterrupt
  1765. (
  1766. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1767. );
  1768. }
  1769. else
  1770. {
  1771. #endif
  1772. /* Disable hardware interrupts if the channel is not running in the ONE-SHUT mode.
  1773. This is needed because the channel state is updated by ISR for ONE-SHOT mode */
  1774. if((GPT_STATUS_RUNNING != Gpt_aChannelInfo[channel].eChannelStatus) || \
  1775. (GPT_CH_MODE_CONTINUOUS == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1776. )
  1777. {
  1778. /*Disable hardware interrupts*/
  1779. Gpt_Ipw_DisableInterrupt
  1780. (
  1781. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1782. );
  1783. }
  1784. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  1785. }
  1786. #endif
  1787. }
  1788. /*Set the driver mode to normal mode*/
  1789. Gpt_eMode = GPT_MODE_NORMAL;
  1790. }
  1791. else
  1792. {
  1793. /* This else clause is required due to MISRA rules */
  1794. }
  1795. #if (GPT_VALIDATE_PARAM == STD_ON)
  1796. }
  1797. #endif
  1798. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1799. }
  1800. #endif
  1801. #endif /*GPT_REPORT_WAKEUP_SOURCE*/
  1802. return;
  1803. }
  1804. #endif
  1805. /*================================================================================================*/
  1806. #if (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)
  1807. /**
  1808. * @brief GPT driver function for disabling the wakeup interrupt invocation for a timer channel.
  1809. * @details This service shall disable the wakeup interrupt invocation of a single GPT
  1810. * channel.
  1811. * Usage of re-entrant capability is only allowed if the callers take care that
  1812. * there is no simultaneous usage of the same channel.
  1813. * The driver needs to be initialized before calling Gpt_DisableWakeup(). Otherwise, the
  1814. * function Gpt_DisableWakeup shall raise the development error GPT_E_UNINIT.
  1815. *
  1816. * @param[in] channel channel id
  1817. * @return void
  1818. * @api
  1819. *
  1820. * @pre The driver needs to be initialized.
  1821. * @implements Gpt_DisableWakeup_Activity
  1822. */
  1823. void Gpt_DisableWakeup(Gpt_ChannelType channel)
  1824. {
  1825. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1826. uint32 coreID = (uint32)Gpt_GetCoreID();
  1827. uint8 ChannelIndex;
  1828. #endif
  1829. #if (GPT_REPORT_WAKEUP_SOURCE == STD_OFF)
  1830. (void)channel;
  1831. #endif
  1832. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1833. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1834. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_DISABLEWAKEUP_ID, channel, coreID))
  1835. {
  1836. #endif
  1837. #if (GPT_VALIDATE_PARAM == STD_ON)
  1838. if((Std_ReturnType)E_OK == Gpt_ValidateChannelWakeup(GPT_DISABLEWAKEUP_ID, channel, coreID))
  1839. {
  1840. #endif
  1841. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1842. /* Set the enable wakeup attribute */
  1843. Gpt_aChannelInfo[channel].bWakeupEnabled = FALSE;
  1844. /* Disable hardware interrupts if the channel is not running in the ONE-SHUT mode.
  1845. This is needed because the channel state is updated by ISR for ONE-SHOT mode */
  1846. if ((GPT_MODE_SLEEP == Gpt_eMode) && \
  1847. ((GPT_CH_MODE_CONTINUOUS == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  1848. || (GPT_STATUS_RUNNING != Gpt_aChannelInfo[channel].eChannelStatus)
  1849. )
  1850. )
  1851. {
  1852. /*Disable hardware interrupts*/
  1853. Gpt_Ipw_DisableInterrupt
  1854. (
  1855. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1856. );
  1857. }
  1858. #if (GPT_VALIDATE_PARAM == STD_ON)
  1859. }
  1860. #endif
  1861. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1862. }
  1863. #endif
  1864. #endif /*GPT_REPORT_WAKEUP_SOURCE*/
  1865. return;
  1866. }
  1867. #endif
  1868. /*================================================================================================*/
  1869. #if (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)
  1870. /**
  1871. * @brief GPT driver function for enabling the wakeup interrupt invocation for a timer channel.
  1872. * @details This service shall re-enable the wakeup interrupt invocation of a single GPT
  1873. * channel.
  1874. * If supported by hardware and enabled, an internal hardware timer can serve as a
  1875. * wakeup source
  1876. * Usage of re-entrant capability is only allowed if the callers take care that
  1877. * there is no simultaneous usage of the same channel.
  1878. *
  1879. * @param[in] channel channel id
  1880. * @return void
  1881. * @api
  1882. *
  1883. * @pre The driver needs to be initialized. The channel must be configured as wakeup capable.
  1884. * @implements Gpt_EnableWakeup_Activity
  1885. */
  1886. void Gpt_EnableWakeup(Gpt_ChannelType channel)
  1887. {
  1888. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1889. uint32 coreID = (uint32)Gpt_GetCoreID();
  1890. uint8 ChannelIndex;
  1891. #endif
  1892. #if (GPT_REPORT_WAKEUP_SOURCE == STD_OFF)
  1893. (void)channel;
  1894. #endif
  1895. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1896. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1897. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_ENABLEWAKEUP_ID, channel, coreID))
  1898. {
  1899. #endif
  1900. #if (GPT_VALIDATE_PARAM == STD_ON)
  1901. if((Std_ReturnType)E_OK == Gpt_ValidateChannelWakeup(GPT_ENABLEWAKEUP_ID, channel, coreID))
  1902. {
  1903. #endif
  1904. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  1905. /* Functionality implementation */
  1906. /* Set the enable wakeup attribute */
  1907. Gpt_aChannelInfo[channel].bWakeupEnabled = TRUE;
  1908. if (GPT_MODE_SLEEP == Gpt_eMode)
  1909. {
  1910. /*Enable hardware interrupts*/
  1911. Gpt_Ipw_EnableInterrupt
  1912. (
  1913. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig)
  1914. );
  1915. }
  1916. #if (GPT_VALIDATE_PARAM == STD_ON)
  1917. }
  1918. #endif
  1919. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  1920. }
  1921. #endif
  1922. #endif /*GPT_REPORT_WAKEUP_SOURCE*/
  1923. return;
  1924. }
  1925. #endif
  1926. /*================================================================================================*/
  1927. #if (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)
  1928. /**
  1929. * @brief GPT driver function for checking if a wakeup capable GPT channel is the source for a
  1930. * wakeup event.
  1931. * @details Checks if a wakeup capable GPT channel is the source for a wakeup event and calls the ECU
  1932. * state manager service EcuM_SetWakeupEvent in case of a valid GPT channel wakeup event.
  1933. * The driver needs to be initialized before calling Gpt_CheckWakeup(). Otherwise, the
  1934. * function Gpt_CheckWakeup shall raise the development error GPT_E_UNINIT.
  1935. *
  1936. * @param[in] wakeupSource wakeup source
  1937. * @return void
  1938. * @api
  1939. *
  1940. * @pre The driver needs to be initialized. The channel must be configured as wakeup capable.
  1941. * @implements Gpt_CheckWakeup_Activity
  1942. */
  1943. void Gpt_CheckWakeup(EcuM_WakeupSourceType wakeupSource)
  1944. {
  1945. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1946. uint32 coreID = (uint32)Gpt_GetCoreID();
  1947. #endif
  1948. #if (GPT_REPORT_WAKEUP_SOURCE == STD_OFF)
  1949. (void) wakeupSource;
  1950. #endif
  1951. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  1952. Gpt_ChannelType channel;
  1953. uint32 ChannelIndex;
  1954. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1955. /*Validate the driver calling context*/
  1956. if((Std_ReturnType)E_OK == Gpt_ValidateGlobalCall(GPT_CHECKWAKEUP_ID, coreID))
  1957. {
  1958. #endif
  1959. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  1960. {
  1961. channel = Gpt_ConvertChannelIndexToChannel(ChannelIndex, coreID);
  1962. if ((((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_uWakeupSource) == wakeupSource) && \
  1963. (TRUE == Gpt_aChannelInfo[channel].bWakeupGenerated)
  1964. )
  1965. {
  1966. /*Reset the wakeup flag */
  1967. Gpt_aChannelInfo[channel].bWakeupGenerated = FALSE;
  1968. /* Calling EcuM_SetWakeupEvent and exit*/
  1969. EcuM_SetWakeupEvent(wakeupSource);
  1970. break;
  1971. }
  1972. } /*for*/
  1973. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  1974. }
  1975. #endif
  1976. #endif /* GPT_REPORT_WAKEUP_SOURCE */
  1977. return;
  1978. }
  1979. #endif /* GPT_WAKEUP_FUNCTIONALITY_API */
  1980. /*================================================================================================*/
  1981. /**
  1982. * @brief Gpt common handler to implements generic part of the ISR.
  1983. * @details Generic function used by all interrupt service routines to call notification
  1984. * functions and wakeup the EcuM
  1985. *
  1986. * @param[in] channel logic channel number
  1987. * @return void
  1988. * @pre The driver needs to be initialized.
  1989. * @implements Gpt_ProcessCommonInterrupt_Activity
  1990. */
  1991. void Gpt_ProcessCommonInterrupt(uint8 channel)
  1992. {
  1993. uint32 coreID;
  1994. uint8 ChannelIndex;
  1995. coreID = (uint32)Gpt_GetCoreID();
  1996. if (Gpt_pConfig[coreID] != NULL_PTR)
  1997. {
  1998. /* Extract the logical channel from the hardware to logic map table */
  1999. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  2000. /*Stop the timer for one-shot mode*/
  2001. if (GPT_CH_MODE_ONESHOT == (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_eChannelMode)
  2002. {
  2003. /*Stop channel*/
  2004. Gpt_Ipw_StopTimer(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  2005. /* Change the channel status to expired */
  2006. Gpt_aChannelInfo[channel].eChannelStatus = GPT_STATUS_EXPIRED;
  2007. }
  2008. #if (GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON)
  2009. if ((GPT_MODE_NORMAL == Gpt_eMode) && (TRUE == Gpt_aChannelInfo[channel].bNotificationEnabled))
  2010. {
  2011. (*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_pfNotification();
  2012. }
  2013. #endif
  2014. #if (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)
  2015. #if (GPT_REPORT_WAKEUP_SOURCE == STD_ON)
  2016. if ((GPT_MODE_SLEEP == Gpt_eMode) && (TRUE == Gpt_aChannelInfo[channel].bWakeupEnabled))
  2017. {
  2018. Gpt_aChannelInfo[channel].bWakeupGenerated =TRUE;
  2019. EcuM_CheckWakeup((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_uWakeupSource);
  2020. }
  2021. #endif
  2022. #endif
  2023. }
  2024. return;
  2025. }
  2026. /*================================================================================================*/
  2027. #if (GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON)
  2028. /**
  2029. * @brief The function changes the time out period value of the requested running channel.
  2030. * @details The function changes the time out period (in number of ticks) of the channel is
  2031. * running which will be used after the first compare matching.
  2032. * This is a non-autosar function.
  2033. * @param[in] channel channel id
  2034. * @param[in] value time out period (in number of ticks) after a notification shall occur
  2035. * @return void
  2036. * @pre Gpt_Init and Gpt_StartTimer must be called before.
  2037. * @implements
  2038. */
  2039. void Gpt_ChangeNextTimeoutValue(Gpt_ChannelType channel, Gpt_ValueType value)
  2040. {
  2041. uint32 coreID;
  2042. uint8 ChannelIndex;
  2043. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  2044. Std_ReturnType returnValue;
  2045. #endif
  2046. coreID = (uint32)Gpt_GetCoreID();
  2047. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  2048. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID, channel, coreID))
  2049. {
  2050. #endif
  2051. if ((Std_ReturnType)E_OK == Gpt_ValidateChannelStatus(GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID, channel, coreID))
  2052. {
  2053. #if (GPT_VALIDATE_PARAM == STD_ON)
  2054. if ((Std_ReturnType)E_OK == Gpt_ValidateParamValue(GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID, channel, value, coreID))
  2055. {
  2056. #endif
  2057. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  2058. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  2059. /* Call low level API */
  2060. returnValue = Gpt_Ipw_ChangeNextTimeoutValue(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig), value);
  2061. if((Std_ReturnType)E_OK != returnValue)
  2062. {
  2063. (void)Det_ReportError\
  2064. (\
  2065. (uint16)GPT_MODULE_ID,\
  2066. (uint8)GPT_INSTANCE_ID,\
  2067. (uint8)GPT_CHANGE_NEXT_TIMEOUT_VALUE_ID,\
  2068. (uint8)GPT_E_PARAM_CHANNEL\
  2069. );
  2070. }
  2071. #else
  2072. /* Call low level API */
  2073. (void)Gpt_Ipw_ChangeNextTimeoutValue(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig), value);
  2074. #endif
  2075. #if (GPT_VALIDATE_PARAM == STD_ON)
  2076. }
  2077. #endif
  2078. }
  2079. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  2080. }
  2081. #endif
  2082. return;
  2083. }
  2084. #endif /* GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON */
  2085. /*================================================================================================*/
  2086. #if (GPT_CHAIN_MODE == STD_ON)
  2087. /**
  2088. * @brief The function enables the chain functionality for timer.
  2089. * @details The function enables the chain functionality for timer. Timer will be chained with timer n-1.
  2090. Channel 0 cannot be chained.
  2091. * This is a non-autosar function.
  2092. * @param[in] channel channel id
  2093. * @return void
  2094. * @pre Gpt_Init must be called before.
  2095. *
  2096. * @implements Gpt_Channel_EnableChainMode_Activity
  2097. */
  2098. void Gpt_Channel_EnableChainMode(Gpt_ChannelType channel)
  2099. {
  2100. uint32 coreID;
  2101. uint8 ChannelIndex;
  2102. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  2103. Std_ReturnType returnValue;
  2104. #endif
  2105. coreID = (uint32)Gpt_GetCoreID();
  2106. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  2107. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_ENABLE_CHAIN_MODE_ID, channel, coreID))
  2108. {
  2109. #endif
  2110. if ((Std_ReturnType)E_OK == Gpt_ValidateChannelStatus(GPT_ENABLE_CHAIN_MODE_ID, channel, coreID))
  2111. {
  2112. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  2113. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  2114. /* Call low level API */
  2115. returnValue = Gpt_Ipw_EnableChainMode(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  2116. if((Std_ReturnType)E_OK != returnValue)
  2117. {
  2118. (void)Det_ReportError\
  2119. (\
  2120. (uint16)GPT_MODULE_ID,\
  2121. (uint8)GPT_INSTANCE_ID,\
  2122. (uint8)GPT_ENABLE_CHAIN_MODE_ID,\
  2123. (uint8)GPT_E_PARAM_CHANNEL\
  2124. );
  2125. }
  2126. #else
  2127. /*Call low level API.*/
  2128. (void)Gpt_Ipw_EnableChainMode(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  2129. #endif
  2130. }
  2131. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  2132. }
  2133. #endif
  2134. }
  2135. #endif /*GPT_CHAIN_MODE == STD_ON*/
  2136. /*================================================================================================*/
  2137. #if (GPT_CHAIN_MODE == STD_ON)
  2138. /**
  2139. * @brief The function disables the chain functionality for timer.
  2140. * @details The function disables the chain functionality for timer. Timer will not be chained with timer n-1.
  2141. Channel 0 cannot be chained or unchained.
  2142. * This is a non-autosar function.
  2143. * @param[in] channel channel id
  2144. * @return void
  2145. * @pre Gpt_Init must be called before.
  2146. *
  2147. * @implements Gpt_Channel_DisableChainMode_Activity
  2148. */
  2149. void Gpt_Channel_DisableChainMode(Gpt_ChannelType channel)
  2150. {
  2151. uint32 coreID;
  2152. uint8 ChannelIndex;
  2153. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  2154. Std_ReturnType returnValue;
  2155. #endif
  2156. coreID = (uint32)Gpt_GetCoreID();
  2157. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  2158. if((Std_ReturnType)E_OK == Gpt_ValidateChannelCall(GPT_DISABLE_CHAIN_MODE_ID, channel, coreID))
  2159. {
  2160. #endif
  2161. if ((Std_ReturnType)E_OK == Gpt_ValidateChannelStatus(GPT_DISABLE_CHAIN_MODE_ID, channel, coreID))
  2162. {
  2163. ChannelIndex = (*(Gpt_pConfig[coreID]->u8GptChannelIdToIndexMap))[channel];
  2164. #if (GPT_DEV_ERROR_DETECT == STD_ON)
  2165. /* Call low level API */
  2166. returnValue = Gpt_Ipw_DisableChainMode(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  2167. if((Std_ReturnType)E_OK != returnValue)
  2168. {
  2169. (void)Det_ReportError\
  2170. (\
  2171. (uint16)GPT_MODULE_ID,\
  2172. (uint8)GPT_INSTANCE_ID,\
  2173. (uint8)GPT_DISABLE_CHAIN_MODE_ID,\
  2174. (uint8)GPT_E_PARAM_CHANNEL\
  2175. );
  2176. }
  2177. #else
  2178. /*Call low level API.*/
  2179. (void)Gpt_Ipw_DisableChainMode(((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig));
  2180. #endif
  2181. }
  2182. #if (GPT_VALIDATE_CHANNEL_CALL == STD_ON)
  2183. }
  2184. #endif
  2185. }
  2186. #endif /*GPT_CHAIN_MODE == STD_ON*/
  2187. /*================================================================================================*/
  2188. #if (GPT_SET_CLOCK_MODE == STD_ON)
  2189. /**
  2190. * @brief This function changes the channel pre scaler.
  2191. * @details This function sets all channels pre scalers based on the input mode.
  2192. *
  2193. * @param[in] eClkMode prescaler setting ( NORMAL or ALTERNATE )
  2194. * @return void
  2195. * @pre Gpt_Init must be called before.
  2196. *
  2197. * @implements Gpt_SetClockMode_Activity
  2198. */
  2199. void Gpt_SetClockMode(Gpt_ClockModeType eClkMode)
  2200. {
  2201. uint32 coreID = (uint32)Gpt_GetCoreID();
  2202. Gpt_ChannelType ChannelIndex;
  2203. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  2204. Std_ReturnType returnValue;
  2205. returnValue = Gpt_ValidateGlobalCall(GPT_SET_CLOCK_MODE_ID, coreID);
  2206. if((Std_ReturnType)E_OK == returnValue)
  2207. {
  2208. #endif
  2209. #if (GPT_VALIDATE_PARAM == STD_ON)
  2210. if ((Std_ReturnType)E_OK == Gpt_ValidateParamSetClockMode(eClkMode))
  2211. {
  2212. #endif
  2213. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->instanceCount; ChannelIndex++)
  2214. {
  2215. Gpt_Ipw_SetClockModeInStance
  2216. (
  2217. (&((*(Gpt_pConfig[coreID]->Gpt_Ipw_HwInstanceConfig))[ChannelIndex])), eClkMode
  2218. );
  2219. }
  2220. #if (GPT_HW_CHANNEL_USED == STD_ON)
  2221. for (ChannelIndex = 0U; ChannelIndex < Gpt_pConfig[coreID]->channelCount; ChannelIndex++)
  2222. {
  2223. Gpt_Ipw_SetClockModeChannel
  2224. (
  2225. ((*(Gpt_pConfig[coreID]->Gpt_pChannelConfig))[ChannelIndex].Gpt_Ipw_HwChannelConfig),eClkMode
  2226. );
  2227. }
  2228. #endif
  2229. #if (GPT_VALIDATE_PARAM == STD_ON)
  2230. }
  2231. #endif
  2232. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  2233. }
  2234. #endif
  2235. }
  2236. #endif /* GPT_SET_CLOCK_MODE */
  2237. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  2238. /*================================================================================================*/
  2239. /**
  2240. * @brief Provides the current value of the given predefined free-running timer
  2241. * @details This function provides the current value of the given predefined free-running timer.
  2242. *
  2243. * @param[in] PredefTimer: Gpt_PredefTimerType ( GPT_PREDEF_TIMER_1US_16BIT,
  2244. * GPT_PREDEF_TIMER_1US_24BIT,
  2245. * GPT_PREDEF_TIMER_1US_32BIT
  2246. * GPT_PREDEF_TIMER_100US_32BIT)
  2247. * @param[out] TimeValuePtr: Pointer to time value destination data in RAM
  2248. * @pre Gpt_Init must be called before.
  2249. * @return returnValue - E_OK: no error has been detected.
  2250. * - E_NOT_OK: aborted due to errors.
  2251. *
  2252. * @implements Gpt_GetPredefTimerValue_Activity
  2253. */
  2254. Std_ReturnType Gpt_GetPredefTimerValue
  2255. (
  2256. Gpt_PredefTimerType PredefTimer,
  2257. uint32 * TimeValuePtr
  2258. )
  2259. {
  2260. uint32 coreID;
  2261. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  2262. Gpt_ChannelType channel;
  2263. coreID = (uint32)Gpt_GetCoreID();
  2264. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  2265. returnValue = Gpt_ValidateGlobalCall(GPT_GET_PREDEF_TIMERVALUE_ID, coreID);
  2266. if((Std_ReturnType)E_OK == returnValue)
  2267. {
  2268. #endif
  2269. #if (GPT_VALIDATE_PARAM == STD_ON)
  2270. returnValue = Gpt_ValidatePointerGetPredefTimer(TimeValuePtr);
  2271. if((Std_ReturnType)E_OK == returnValue)
  2272. {
  2273. returnValue = Gpt_ValidateParamTypePredefTimer(PredefTimer, coreID);
  2274. if((Std_ReturnType)E_OK == returnValue)
  2275. {
  2276. #endif
  2277. returnValue = Gpt_ValidateMode(GPT_GET_PREDEF_TIMERVALUE_ID);
  2278. if((Std_ReturnType)E_OK ==returnValue)
  2279. {
  2280. channel = (Gpt_ChannelType)PredefTimer;
  2281. Gpt_Ipw_GetPredefTimerValue((Gpt_pConfig[coreID]->Gpt_pChannelPredefConfigType)[channel], PredefTimer, TimeValuePtr);
  2282. }
  2283. else
  2284. {
  2285. *TimeValuePtr = 0U;
  2286. }
  2287. #if (GPT_VALIDATE_PARAM == STD_ON)
  2288. }
  2289. else
  2290. {
  2291. *TimeValuePtr = 0U;
  2292. }
  2293. }
  2294. else
  2295. {
  2296. /* This else clause is required due to MISRA rules */
  2297. }
  2298. #endif
  2299. #if (GPT_VALIDATE_GLOBAL_CALL == STD_ON)
  2300. }
  2301. #endif
  2302. return returnValue;
  2303. }
  2304. #endif
  2305. #define GPT_STOP_SEC_CODE
  2306. #include "Gpt_MemMap.h"
  2307. #ifdef __cplusplus
  2308. }
  2309. #endif /* GPT_C */
  2310. /** @} */