Adc_Ipw_Irq.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : ADC
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file
  26. *
  27. * @internal
  28. * @addtogroup adc_ipw Adc Ipw
  29. * @{
  30. */
  31. #ifdef __cplusplus
  32. extern "C"{
  33. #endif
  34. /*==================================================================================================
  35. * INCLUDE FILES
  36. * 1) system and project includes
  37. * 2) needed interfaces from external Units
  38. * 3) internal and external interfaces from this Unit
  39. ==================================================================================================*/
  40. /* TODO: only added for: extern const Adc_ConfigType * Adc_pCfgPtr[ADC_MAX_PARTITIONS]*/
  41. #include "Adc.h"
  42. #include "Adc_Ipw.h"
  43. #include "Adc_Ipw_Irq.h"
  44. #include "Adc_Ipw_Types.h"
  45. #include "Mcal.h"
  46. #include "Det.h"
  47. /*==================================================================================================
  48. * SOURCE FILE VERSION INFORMATION
  49. ==================================================================================================*/
  50. #define ADC_VENDOR_ID_IPW_IRQ_C 43
  51. #define ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C 4
  52. #define ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C 4
  53. #define ADC_AR_RELEASE_REVISION_VERSION_IPW_IRQ_C 0
  54. #define ADC_SW_MAJOR_VERSION_IPW_IRQ_C 1
  55. #define ADC_SW_MINOR_VERSION_IPW_IRQ_C 0
  56. #define ADC_SW_PATCH_VERSION_IPW_IRQ_C 0
  57. /*==================================================================================================
  58. * FILE VERSION CHECKS
  59. ==================================================================================================*/
  60. /* Check if Adc_Ipw_Irq.c file and Adc.h file are of the same vendor */
  61. #if (ADC_VENDOR_ID_IPW_IRQ_C != ADC_VENDOR_ID)
  62. #error "Adc_Ipw_Irq.c and Adc.h have different vendor ids"
  63. #endif
  64. /* Check if Adc_Ipw_Irq.c file and Adc.h file are of the same Autosar version */
  65. #if ((ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MAJOR_VERSION) || \
  66. (ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MINOR_VERSION) || \
  67. (ADC_AR_RELEASE_REVISION_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_REVISION_VERSION) \
  68. )
  69. #error "AutoSar Version Numbers of Adc_Ipw_Irq.c and Adc.h are different"
  70. #endif
  71. /* Check if Adc_Ipw_Irq.c file and Adc.h file are of the same Software version */
  72. #if ((ADC_SW_MAJOR_VERSION_IPW_IRQ_C != ADC_SW_MAJOR_VERSION) || \
  73. (ADC_SW_MINOR_VERSION_IPW_IRQ_C != ADC_SW_MINOR_VERSION) || \
  74. (ADC_SW_PATCH_VERSION_IPW_IRQ_C != ADC_SW_PATCH_VERSION) \
  75. )
  76. #error "Software Version Numbers of Adc_Ipw_Irq.c and Adc.h are different"
  77. #endif
  78. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw.h file are of the same vendor */
  79. #if (ADC_VENDOR_ID_IPW_IRQ_C != ADC_VENDOR_ID_IPW_H)
  80. #error "Adc_Ipw_Irq.c and Adc_Ipw.h have different vendor ids"
  81. #endif
  82. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw.h file are of the same Autosar version */
  83. #if ((ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MAJOR_VERSION_IPW_H) || \
  84. (ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MINOR_VERSION_IPW_H) || \
  85. (ADC_AR_RELEASE_REVISION_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_REVISION_VERSION_IPW_H) \
  86. )
  87. #error "AutoSar Version Numbers of Adc_Ipw_Irq.c and Adc_Ipw.h are different"
  88. #endif
  89. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw.h file are of the same Software version */
  90. #if ((ADC_SW_MAJOR_VERSION_IPW_IRQ_C != ADC_SW_MAJOR_VERSION_IPW_H) || \
  91. (ADC_SW_MINOR_VERSION_IPW_IRQ_C != ADC_SW_MINOR_VERSION_IPW_H) || \
  92. (ADC_SW_PATCH_VERSION_IPW_IRQ_C != ADC_SW_PATCH_VERSION_IPW_H) \
  93. )
  94. #error "Software Version Numbers of Adc_Ipw_Irq.c and Adc_Ipw.h are different"
  95. #endif
  96. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw_Irq.h file are of the same vendor */
  97. #if (ADC_VENDOR_ID_IPW_IRQ_C != ADC_VENDOR_ID_IPW_IRQ_H)
  98. #error "Adc_Ipw_Irq.c and Adc_Ipw_Irq.h have different vendor ids"
  99. #endif
  100. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw_Irq.h file are of the same Autosar version */
  101. #if ((ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_H) || \
  102. (ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_H) || \
  103. (ADC_AR_RELEASE_REVISION_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_REVISION_VERSION_IPW_IRQ_H) \
  104. )
  105. #error "AutoSar Version Numbers of Adc_Ipw_Irq.c and Adc_Ipw_Irq.h are different"
  106. #endif
  107. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw_Irq.h file are of the same Software version */
  108. #if ((ADC_SW_MAJOR_VERSION_IPW_IRQ_C != ADC_SW_MAJOR_VERSION_IPW_IRQ_H) || \
  109. (ADC_SW_MINOR_VERSION_IPW_IRQ_C != ADC_SW_MINOR_VERSION_IPW_IRQ_H) || \
  110. (ADC_SW_PATCH_VERSION_IPW_IRQ_C != ADC_SW_PATCH_VERSION_IPW_IRQ_H) \
  111. )
  112. #error "Software Version Numbers of Adc_Ipw_Irq.c and Adc_Ipw_Irq.h are different"
  113. #endif
  114. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw_Types.h file are of the same vendor */
  115. #if (ADC_VENDOR_ID_IPW_IRQ_C != ADC_VENDOR_ID_IPW_TYPES_H)
  116. #error "Adc_Ipw_Irq.c and Adc_Ipw_Types.h have different vendor ids"
  117. #endif
  118. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw_Types.h file are of the same Autosar version */
  119. #if ((ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MAJOR_VERSION_IPW_TYPES_H) || \
  120. (ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_MINOR_VERSION_IPW_TYPES_H) || \
  121. (ADC_AR_RELEASE_REVISION_VERSION_IPW_IRQ_C != ADC_AR_RELEASE_REVISION_VERSION_IPW_TYPES_H) \
  122. )
  123. #error "AutoSar Version Numbers of Adc_Ipw_Irq.c and Adc_Ipw_Types.h are different"
  124. #endif
  125. /* Check if Adc_Ipw_Irq.c file and Adc_Ipw_Types.h file are of the same Software version */
  126. #if ((ADC_SW_MAJOR_VERSION_IPW_IRQ_C != ADC_SW_MAJOR_VERSION_IPW_TYPES_H) || \
  127. (ADC_SW_MINOR_VERSION_IPW_IRQ_C != ADC_SW_MINOR_VERSION_IPW_TYPES_H) || \
  128. (ADC_SW_PATCH_VERSION_IPW_IRQ_C != ADC_SW_PATCH_VERSION_IPW_TYPES_H) \
  129. )
  130. #error "Software Version Numbers of Adc_Ipw_Irq.c and Adc_Ipw_Types.h are different"
  131. #endif
  132. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  133. /* Check if source file and Mcal header file are of the same AutoSar version */
  134. #if ((ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C != MCAL_AR_RELEASE_MAJOR_VERSION) || \
  135. (ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C != MCAL_AR_RELEASE_MINOR_VERSION) \
  136. )
  137. #error "AutoSar Version Numbers of Adc_Ipw_Irq.c and Mcal.h are different"
  138. #endif
  139. /* Check if Adc_Ipw_Irq.c file and Det.h file are of the same Autosar version */
  140. #if ((ADC_AR_RELEASE_MAJOR_VERSION_IPW_IRQ_C != DET_AR_RELEASE_MAJOR_VERSION) || \
  141. (ADC_AR_RELEASE_MINOR_VERSION_IPW_IRQ_C != DET_AR_RELEASE_MINOR_VERSION) \
  142. )
  143. #error "AutoSar Version Numbers of Adc_Ipw_Irq.c and Det.h are different"
  144. #endif
  145. #endif /* DISABLE_MCAL_INTERMODULE_ASR_CHECK */
  146. /*==================================================================================================
  147. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  148. ==================================================================================================*/
  149. /*==================================================================================================
  150. * LOCAL MACROS
  151. ==================================================================================================*/
  152. /* The macro to calculate the index of the first channel in the previous configuration */
  153. #define ADC_IPW_PREV_CHANNEL_INDEX(x) ((((x) % ADC_MAX_CHAN_COUNT) == 0U) ? ((x) - ADC_MAX_CHAN_COUNT) : ((Adc_ChannelIndexType)((x)-((x) % ADC_MAX_CHAN_COUNT))))
  154. /*==================================================================================================
  155. * LOCAL CONSTANTS
  156. ==================================================================================================*/
  157. /*==================================================================================================
  158. * LOCAL VARIABLES
  159. ==================================================================================================*/
  160. /*==================================================================================================
  161. * GLOBAL CONSTANTS
  162. ==================================================================================================*/
  163. /*==================================================================================================
  164. * GLOBAL VARIABLES
  165. ==================================================================================================*/
  166. #define ADC_START_SEC_VAR_CLEARED_UNSPECIFIED
  167. #include "Adc_MemMap.h"
  168. #if (ADC_SETCHANNEL_API == STD_ON)
  169. extern Adc_RuntimeGroupChannelType Adc_aRuntimeGroupChannel[ADC_MAX_GROUPS];
  170. #endif
  171. #define ADC_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  172. #include "Adc_MemMap.h"
  173. /*==================================================================================================
  174. * LOCAL FUNCTION PROTOTYPES
  175. ==================================================================================================*/
  176. #define ADC_START_SEC_CODE
  177. #include "Adc_MemMap.h"
  178. #if ((defined(ADC_UNIT_0_ISR_USED)) || (defined(ADC_UNIT_1_ISR_USED)) || \
  179. (defined(ADC_DMA_SUPPORTED)) \
  180. )
  181. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  182. static inline void Adc_Ipw_CallNotification
  183. (
  184. Adc_GroupType Group,
  185. uint32 u32CoreId
  186. );
  187. #endif /* ADC_GRP_NOTIF_CAPABILITY == STD_ON */
  188. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  189. static inline void Adc_Ipw_UpdateQueue
  190. (
  191. Adc_HwUnitType Unit,
  192. uint32 u32CoreId
  193. );
  194. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  195. #if (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON)
  196. static inline void Adc_Ipw_CallExtraNotification
  197. (
  198. Adc_GroupType Group,
  199. uint32 u32CoreId
  200. );
  201. #endif /* (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON) */
  202. static inline Std_ReturnType Adc_Ipw_CheckConversionChannels
  203. (
  204. Adc_HwUnitType Unit,
  205. Adc_GroupType Group,
  206. Adc_StreamNumSampleType GroupSamples,
  207. uint32 u32CoreId
  208. );
  209. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  210. static inline void Adc_Ipw_HandleConversionCheckFail
  211. (
  212. Adc_HwUnitType Unit,
  213. Adc_GroupType Group,
  214. const Adc_GroupConfigurationType * GroupPtr,
  215. uint32 u32CoreId
  216. );
  217. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  218. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  219. static inline void Adc_Ipw_RestartConversion
  220. (
  221. Adc_HwUnitType Unit,
  222. Adc_GroupType Group,
  223. uint32 u32CoreId
  224. );
  225. static inline void Adc_Ipw_UpdateSoftwareGroupState
  226. (
  227. Adc_HwUnitType Unit,
  228. Adc_GroupType Group,
  229. Adc_StreamNumSampleType GroupSamples,
  230. uint32 u32CoreId
  231. );
  232. #if (ADC_HW_TRIGGER_API == STD_ON)
  233. #ifdef ADC_DMA_SUPPORTED
  234. static inline void Adc_Ipw_CheckAndUpdateDmaHwGroupState
  235. (
  236. Adc_HwUnitType Unit,
  237. Adc_GroupType Group,
  238. const uint32 u32AdcDmaLogicChId,
  239. uint32 u32CoreId
  240. );
  241. #endif /* ADC_DMA_SUPPORTED */
  242. static inline uint32 Adc_Ipw_GetCurrentSampleCount
  243. (
  244. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  245. Adc_GroupType Group,
  246. Adc_HwUnitType Unit,
  247. Adc_StreamNumSampleType GroupSamples,
  248. uint32 u32CoreId
  249. #else
  250. Adc_GroupType Group
  251. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  252. );
  253. static inline void Adc_Ipw_UpdateHardwareGroupState
  254. (
  255. Adc_HwUnitType Unit,
  256. Adc_GroupType Group,
  257. Adc_StreamNumSampleType GroupSamples,
  258. uint32 u32CoreId
  259. );
  260. #endif /* (ADC_HW_TRIGGER_API == STD_ON) */
  261. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  262. static inline void Adc_Ipw_EndConversion
  263. (
  264. Adc_HwUnitType Unit,
  265. Adc_GroupType Group,
  266. boolean IsSoftwareConversion,
  267. uint32 u32CoreId
  268. );
  269. #ifdef ADC_DMA_SUPPORTED
  270. static inline void Adc_Ipw_EndDmaConversion
  271. (
  272. Adc_HwUnitType Unit,
  273. Adc_GroupType Group,
  274. boolean IsSoftwareConversion,
  275. uint32 u32CoreId
  276. );
  277. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  278. static inline void Adc_Ipw_UpdateDmaConfig
  279. (
  280. const Adc_ValueGroupType * DataPtr,
  281. const uint32 DmaLogicChId,
  282. uint8 NumChannel
  283. );
  284. static inline void Adc_Ipw_ContinueDmaConversion
  285. (
  286. Adc_HwUnitType Unit,
  287. Adc_GroupType Group,
  288. const Adc_ChannelIndexType ChannelCount,
  289. const uint32 AdcDmaLogicChId,
  290. uint32 u32CoreId
  291. );
  292. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  293. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  294. static inline Std_ReturnType Adc_Ipw_CheckGroupConvResultDma
  295. (
  296. const Adc_GroupConfigurationType * pGroupPtr,
  297. uint32 u32CoreId
  298. );
  299. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  300. #endif /* ADC_DMA_SUPPORTED */
  301. static inline void Adc_Ipw_ReadData
  302. (
  303. const Adc_GroupConfigurationType * GroupPtr,
  304. Adc_ValueGroupType * pResult,
  305. const Adc_StreamNumSampleType GroupSamples,
  306. const Adc_ChannelIndexType Index,
  307. const uint16 ConvResult
  308. );
  309. static inline void Adc_Ipw_EndConversionNotification
  310. (
  311. const Adc_HwUnitType PhysicalAdcUnit
  312. );
  313. #endif /* (defined(ADC_UNIT_0_ISR_USED) || ... */
  314. /*==================================================================================================
  315. * LOCAL FUNCTIONS
  316. ==================================================================================================*/
  317. #if ((defined(ADC_UNIT_0_ISR_USED)) || (defined(ADC_UNIT_1_ISR_USED)) || \
  318. (defined(ADC_DMA_SUPPORTED)))
  319. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  320. /**
  321. * @brief This function checks and calls group notification
  322. * @details This function checks and calls group notification
  323. *
  324. * @param[in] Group The group to be converted
  325. * @param[in] u32CoreId Current CoreID
  326. *
  327. * @return void
  328. *
  329. */
  330. static inline void Adc_Ipw_CallNotification
  331. (
  332. Adc_GroupType Group,
  333. uint32 u32CoreId
  334. )
  335. {
  336. Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  337. /* SWS_Adc_00080, SWS_Adc_00083 */
  338. if ((ADC_NOTIFICATION_ENABLED == Adc_aGroupStatus[Group].eNotification) && \
  339. (NULL_PTR != Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].Notification)
  340. )
  341. {
  342. /* Execute notification function */
  343. Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].Notification();
  344. }
  345. }
  346. #endif /* ADC_GRP_NOTIF_CAPABILITY == STD_ON */
  347. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  348. /**
  349. * @brief This function updates queue
  350. * @details This function updates queue elements after a conversion
  351. * and start conversion if requests are still available in queue
  352. *
  353. * @param[in] Unit The ADC hardware unit
  354. * @param[in] u32CoreId Current CoreID
  355. *
  356. * @return void
  357. *
  358. */
  359. static inline void Adc_Ipw_UpdateQueue
  360. (
  361. Adc_HwUnitType Unit,
  362. uint32 u32CoreId
  363. )
  364. {
  365. #if (ADC_ENABLE_QUEUING == STD_ON)
  366. /* Remove current request element in queue */
  367. Adc_RemoveFromQueue(Unit, 0U);
  368. #if (ADC_ENABLE_START_STOP_GROUP_API == STD_ON)
  369. if (Adc_aUnitStatus[Unit].SwNormalQueueIndex > (Adc_QueueIndexType)0U)
  370. {
  371. /* Start conversion if request elements are still available in queue */
  372. Adc_Ipw_StartNormalConversion(Unit, u32CoreId);
  373. }
  374. #endif /* (ADC_ENABLE_START_STOP_GROUP_API == STD_ON) */
  375. #else
  376. /* No element will be present in the queue */
  377. Adc_aUnitStatus[Unit].SwNormalQueueIndex = (Adc_QueueIndexType)0;
  378. #endif /* ADC_ENABLE_QUEUING == STD_ON */
  379. (void)u32CoreId;
  380. }
  381. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  382. #if (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON)
  383. /**
  384. * @brief This function calls extra notification
  385. * @details This function calls extra notification
  386. *
  387. * @param[in] Group The channel group to be converted
  388. * @param[in] u32CoreId Current CoreID
  389. *
  390. * @return void
  391. * CPR-MCAL-797.adc, SWS_Adc_00140
  392. */
  393. static inline void Adc_Ipw_CallExtraNotification
  394. (
  395. Adc_GroupType Group,
  396. uint32 u32CoreId
  397. )
  398. {
  399. Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  400. /* Call notification if available */
  401. if (Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].ExtraNotification != NULL_PTR)
  402. {
  403. Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].ExtraNotification();
  404. }
  405. }
  406. #endif /* (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON) */
  407. /**
  408. * @brief This function checks conversion results
  409. * @details This function checks conversion results
  410. *
  411. * @param[in] Unit Adc Logical Unit Id
  412. * @param[in] Group Selected group Id
  413. * @param[in] GroupSamples Number of samples
  414. * @param[in] u32CoreId Current CoreID
  415. *
  416. * @return void
  417. */
  418. static inline Std_ReturnType Adc_Ipw_CheckConversionChannels
  419. (
  420. Adc_HwUnitType Unit,
  421. Adc_GroupType Group,
  422. Adc_StreamNumSampleType GroupSamples,
  423. uint32 u32CoreId
  424. )
  425. {
  426. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  427. const Adc_GroupConfigurationType * GroupPtr; /* Pointer to AdcGroup */
  428. Adc_ChannelIndexType CurrentChannel = Adc_aGroupStatus[Group].CurrentChannel;
  429. Adc_ChannelIndexType Temp;
  430. Adc_ChannelIndexType Index;
  431. uint16 ConvResult;
  432. Adc_ValueGroupType * ResultIndex = NULL_PTR;
  433. Adc_HwUnitType PhysicalHwUnitId = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->aAdcPhysicalId[Unit];
  434. Std_ReturnType Status = (Std_ReturnType)E_OK;
  435. const uint8 NumsBitShift = Adc_Ipw_CalculateNumsBitShift(Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->apAdcConfig[Unit]->Resolution);
  436. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  437. Adc_ChannelType HwChannel;
  438. boolean bFlag = FALSE;
  439. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  440. boolean ValidConversion = TRUE;
  441. /* record the result of the Channel conversion and update group status */
  442. #if (ADC_SETCHANNEL_API == STD_ON)
  443. Index = Adc_aRuntimeGroupChannel[Group].ChannelCount;
  444. #else
  445. Index = Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].AssignedChannelCount;
  446. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  447. GroupPtr = &(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex]);
  448. if (CurrentChannel <= Index)
  449. {
  450. /* Calculate the index of the first channel in the previous configuration */
  451. Temp = (Adc_ChannelIndexType)ADC_IPW_PREV_CHANNEL_INDEX(CurrentChannel);
  452. #if (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON)
  453. /* Get the result buffer pointer */
  454. if (FALSE == GroupPtr->bStreamResultGroupMultiSets)
  455. {
  456. #endif /* (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON) */
  457. ResultIndex = GroupPtr->pResultsBufferPtr[Group] + Adc_aGroupStatus[Group].ResultIndex;
  458. #if (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON)
  459. }
  460. else
  461. {
  462. ResultIndex = GroupPtr->pResultsBufferPtr[Group] + (Adc_aGroupStatus[Group].ResultIndex * Index);
  463. }
  464. #endif /* (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON) */
  465. ValidConversion = Adc_Ipw_CheckValidConversion(PhysicalHwUnitId, Temp, CurrentChannel);
  466. if (ValidConversion)
  467. {
  468. /* For each of channels in the list of previous configuration, read data and take result into user buffer */
  469. for (Index = Temp; Index < CurrentChannel; Index++)
  470. {
  471. ConvResult = Adc_Ip_GetConvData(PhysicalHwUnitId, Index - Temp);
  472. /* Assumption: the width of the register is less than 16 */
  473. ConvResult = ConvResult << (NumsBitShift);
  474. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  475. if (
  476. (TRUE == GroupPtr->bAdcGroupLimitcheck)
  477. #if (ADC_SETCHANNEL_API == STD_ON)
  478. || (TRUE == Adc_aRuntimeGroupChannel[Group].bAdcRuntimeGroupLimitcheck)
  479. #endif /* ADC_SETCHANNEL_API == STD_ON */
  480. )
  481. {
  482. #if (ADC_SETCHANNEL_API == STD_ON)
  483. HwChannel = Adc_aRuntimeGroupChannel[Group].pChannel[Index];
  484. #else
  485. HwChannel = Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].pAssignment[Index];
  486. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  487. /* ADC446, ADC447 */
  488. bFlag = Adc_Ipw_CheckConversionValuesInRange(ConvResult, Unit, HwChannel, u32CoreId);
  489. if (TRUE == bFlag)
  490. {
  491. Adc_Ipw_ReadData(GroupPtr, ResultIndex, GroupSamples, Index, ConvResult);
  492. Adc_aGroupStatus[Group].bLimitCheckFailed = FALSE;
  493. }
  494. else
  495. {
  496. Adc_aGroupStatus[Group].eAlreadyConverted = ADC_ALREADY_CONVERTED;
  497. Adc_aGroupStatus[Group].bLimitCheckFailed = TRUE;
  498. Status = E_NOT_OK;
  499. break;
  500. }
  501. }
  502. else
  503. {
  504. Adc_Ipw_ReadData(GroupPtr, ResultIndex, GroupSamples, Index, ConvResult);
  505. }
  506. #else
  507. Adc_Ipw_ReadData(GroupPtr, ResultIndex, GroupSamples, Index, ConvResult);
  508. #endif /* ADC_ENABLE_LIMIT_CHECK == STD_ON */
  509. }
  510. }
  511. else
  512. {
  513. Status = (Std_ReturnType)E_NOT_OK;
  514. }
  515. }
  516. return Status;
  517. }
  518. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  519. /**
  520. * @brief This function handles the case where conversion check fails
  521. * @details This function stop all ongoing conversions, clears channel
  522. * configurations and conversion complete flag if the one shot
  523. * mode is selected, but reconfigures hardware if continuous mode
  524. * is selected for the group.
  525. *
  526. *
  527. * @param[in] Unit Adc Logical Unit Id
  528. * @param[in] Group Selected group Id
  529. * @param[in] GroupPtr Pointer to group config
  530. *
  531. * @return void
  532. */
  533. static inline void Adc_Ipw_HandleConversionCheckFail
  534. (
  535. Adc_HwUnitType Unit,
  536. Adc_GroupType Group,
  537. const Adc_GroupConfigurationType * GroupPtr,
  538. uint32 u32CoreId
  539. )
  540. {
  541. uint8 Channel;
  542. Adc_Ip_ChanConfigType ChannelConfig;
  543. Adc_HwUnitType PhysicalHwUnitId = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->aAdcPhysicalId[Unit];
  544. if (ADC_CONV_MODE_ONESHOT == GroupPtr->eMode)
  545. {
  546. /* Stop and clear all internal channels */
  547. for (Channel = 0U; Channel < Adc_aUnitStatus[Unit].u8Sc1Used; Channel++)
  548. {
  549. ChannelConfig.ChnIdx = Channel;
  550. ChannelConfig.Channel = ADC_IP_INPUTCHAN_DISABLED;
  551. ChannelConfig.InterruptEnable = FALSE;
  552. Adc_Ip_ConfigChannel(PhysicalHwUnitId, &ChannelConfig);
  553. }
  554. }
  555. /* Group configured as continuous will be re-configured*/
  556. else
  557. {
  558. Adc_aGroupStatus[Group].CurrentChannel = 0U;
  559. Adc_Ipw_ConfigureConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, 1U, u32CoreId);
  560. }
  561. }
  562. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  563. #if (ADC_SETCHANNEL_API == STD_ON)
  564. /**
  565. * @brief This function reconfigures runtime updated channels
  566. * @details This function reconfigures runtime updated channels
  567. *
  568. * @param[in] Unit Adc Logical Unit Id
  569. * @param[in] GroupPtr Selected group pointer
  570. * @param[in] NumChannel Calculated number of channels within range of SC1 registers
  571. * @param[in] u32CoreId Current CoreID
  572. *
  573. * @return void
  574. */
  575. static inline void Adc_Ipw_ConfigureRuntimeChannels
  576. (
  577. Adc_HwUnitType Unit,
  578. const Adc_GroupConfigurationType * GroupPtr,
  579. uint8 NumChannel,
  580. uint32 CoreId
  581. )
  582. {
  583. Adc_GroupType Group = GroupPtr->GroupId;
  584. Adc_aGroupStatus[Group].CurrentChannel = 0U;
  585. Adc_aGroupStatus[Group].ResultIndex = 0U;
  586. #ifdef ADC_DMA_SUPPORTED
  587. /* Not required to check u8AdcWithoutDma == FALSE in DMA notification handler */
  588. if ((ADC_DMA == Adc_pCfgPtr[CoreId]->pAdcIpwConfig->Mapping.u8Adc_DmaInterruptSoftware[Unit]))
  589. {
  590. if((uint8)STD_OFF == GroupPtr->u8AdcExtDMAChanEnable)
  591. {
  592. /* Configure for DMA transfer, starting from first sample, consider both Optimize DMA stream and normal DMA scenarios */
  593. Adc_Ipw_StartDmaOperation(Unit, Group, NumChannel, CoreId);
  594. }
  595. /* Reconfigure DMA transfer */
  596. #if (ADC_HW_TRIGGER_API == STD_ON)
  597. Adc_Ipw_ConfigureDmaConversion(Unit, Group, GroupPtr->HwTriggerSource, NumChannel);
  598. #else
  599. Adc_Ipw_ConfigureDmaConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, NumChannel);
  600. #endif
  601. }
  602. else
  603. #endif /* ADC_DMA_SUPPORTED */
  604. {
  605. /* Re-configure group channels and trigger PDB by software */
  606. #if (ADC_HW_TRIGGER_API == STD_ON)
  607. Adc_Ipw_ConfigureConversion(Unit, Group, GroupPtr->HwTriggerSource, NumChannel, CoreId);
  608. #else
  609. Adc_Ipw_ConfigureConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, NumChannel, CoreId);
  610. #endif
  611. }
  612. /* Reset runtime update status */
  613. Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated = FALSE;
  614. }
  615. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  616. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  617. /**
  618. * @brief This function restarts a conversion
  619. * @details This function restarts a conversion and reconfigure the
  620. * hardware if necessary
  621. *
  622. * @param[in] Unit Adc Logical Unit Id
  623. * @param[in] Group Selected group Id
  624. * @param[in] u32CoreId Current CoreID
  625. *
  626. * @return void
  627. */
  628. static inline void Adc_Ipw_RestartConversion
  629. (
  630. Adc_HwUnitType Unit,
  631. Adc_GroupType Group,
  632. uint32 u32CoreId
  633. )
  634. {
  635. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  636. #if ((ADC_SETCHANNEL_API == STD_ON) || defined(ADC_DMA_SUPPORTED))
  637. /* Pointer to AdcGroup */
  638. const Adc_GroupConfigurationType * GroupPtr = &(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex]);
  639. #endif /* ((ADC_SETCHANNEL_API == STD_ON) || (defined(ADC_DMA_SUPPORTED)) */
  640. #ifdef ADC_DMA_SUPPORTED
  641. const uint32 AdcDmaLogicChId = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.au8Adc_DmaChannel[Unit];
  642. uint16 ResultIndex;
  643. #endif /*ADC_DMA_SUPPORTED*/
  644. uint8 NumChannel;
  645. Adc_ChannelIndexType ChannelCount;
  646. Adc_HwUnitType PhysicalHwUnitId = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->aAdcPhysicalId[Unit];
  647. #if (ADC_SETCHANNEL_API == STD_ON)
  648. /* Get channel count in case of changing at runtime */
  649. ChannelCount = Adc_aRuntimeGroupChannel[Group].ChannelCount;
  650. #else
  651. /* Get channel count from configuration */
  652. ChannelCount = Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].AssignedChannelCount;
  653. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  654. /* Get left channel from channel count */
  655. NumChannel = (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(ChannelCount);
  656. #if (ADC_SETCHANNEL_API == STD_ON)
  657. /* Configure again Adc hardware unit in case of channels of group configured */
  658. if (TRUE == Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated)
  659. {
  660. Adc_Ipw_ConfigureRuntimeChannels(Unit, GroupPtr, NumChannel, u32CoreId);
  661. }
  662. else
  663. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  664. {
  665. #ifdef ADC_DMA_SUPPORTED
  666. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  667. if (FALSE == GroupPtr->bAdcOptimizeDmaStream)
  668. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  669. #endif /*ADC_DMA_SUPPORTED*/
  670. {
  671. /* Incase of the number of channels in group less than the SC1 register used then update group status and start Pdb */
  672. if (ChannelCount <= ADC_MAX_CHAN_COUNT)
  673. {
  674. /* No need to re-configure channels if they are not changed */
  675. /* End of chain interrupt (if used) is still in last channel (= ChannelCount) */
  676. Adc_aGroupStatus[Group].CurrentChannel = ChannelCount;
  677. /* Trigger PDB by software */
  678. Pdb_Adc_Ip_SwTrigger(PhysicalHwUnitId);
  679. }
  680. /* Incase of the number of channels greater than max SC1 register, re-configure Adc hardware unit for the next conversion */
  681. else
  682. {
  683. Adc_aGroupStatus[Group].CurrentChannel = 0U;
  684. #ifdef ADC_DMA_SUPPORTED
  685. if (ADC_DMA == Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.u8Adc_DmaInterruptSoftware[Unit])
  686. {
  687. /* Dma need to be re-init for next result index */
  688. if ((uint8)STD_OFF == GroupPtr->u8AdcExtDMAChanEnable)
  689. {
  690. #if (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON)
  691. if (TRUE == GroupPtr->bStreamResultGroupMultiSets)
  692. {
  693. ResultIndex = Adc_aGroupStatus[Group].ResultIndex * ChannelCount;
  694. }
  695. else
  696. #endif /* (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON) */
  697. {
  698. ResultIndex = Adc_aGroupStatus[Group].ResultIndex;
  699. }
  700. /* Update DMA configuration for new samples */
  701. Adc_Ipw_UpdateDmaConfig((&(GroupPtr->pResultsBufferPtr[Group][ResultIndex])), AdcDmaLogicChId, NumChannel);
  702. }
  703. Adc_Ipw_ConfigureDmaConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, NumChannel);
  704. }
  705. else
  706. #endif /*ADC_DMA_SUPPORTED*/
  707. {
  708. /* Re-configure other segment channels of groups And start next conversion*/
  709. Adc_Ipw_ConfigureConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, NumChannel, u32CoreId);
  710. }
  711. }
  712. }
  713. }
  714. }
  715. static inline uint32 Adc_Ipw_GetCurrentSampleCount
  716. (
  717. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  718. Adc_GroupType Group,
  719. Adc_HwUnitType Unit,
  720. Adc_StreamNumSampleType GroupSamples,
  721. uint32 u32CoreId
  722. #else
  723. Adc_GroupType Group
  724. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  725. )
  726. {
  727. Adc_StreamNumSampleType CurrentSampleCount;
  728. #ifdef ADC_DMA_SUPPORTED
  729. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  730. uint32 CurrentIter = 0U;
  731. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  732. const Adc_Ipw_Config * const pAdcIpwConfigPtr = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig;
  733. const uint32 u32AdcDmaLogicChId = (uint32) pAdcIpwConfigPtr->Mapping.au8Adc_DmaChannel[Unit];
  734. const uint32 u32AdcCountingDmaLogicChId = (uint32) pAdcIpwConfigPtr->Mapping.au8Adc_CountingDmaChannel[Unit];
  735. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  736. #endif /* ADC_DMA_SUPPORTED */
  737. #ifdef ADC_DMA_SUPPORTED
  738. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  739. if (TRUE == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].bAdcOptimizeDmaStream)
  740. {
  741. if (1U < Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].AssignedChannelCount)
  742. {
  743. (void)Dma_Ip_GetLogicChannelParam(u32AdcCountingDmaLogicChId, DMA_IP_CH_GET_CURRENT_ITER_COUNT, &CurrentIter);
  744. }
  745. else
  746. {
  747. (void)Dma_Ip_GetLogicChannelParam(u32AdcDmaLogicChId, DMA_IP_CH_GET_CURRENT_ITER_COUNT, &CurrentIter);
  748. }
  749. /* This condition only occurs at half interrupt */
  750. if ((Adc_StreamNumSampleType)CurrentIter != GroupSamples)
  751. {
  752. /* Re-calculate CurrentSampleCount because CITER decrements its value from GroupSamples to 1 */
  753. CurrentSampleCount = GroupSamples - (Adc_StreamNumSampleType)CurrentIter;
  754. }
  755. else
  756. {
  757. /* When major loop completed, CITER roll back to be equal to GroupSamples so no need to re-calculate */
  758. CurrentSampleCount = (Adc_StreamNumSampleType)CurrentIter;
  759. }
  760. Adc_aGroupStatus[Group].ResultIndex = CurrentSampleCount;
  761. }
  762. else
  763. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  764. #endif /* ADC_DMA_SUPPORTED */
  765. {
  766. CurrentSampleCount = Adc_aGroupStatus[Group].ResultIndex;
  767. }
  768. return CurrentSampleCount;
  769. }
  770. /**
  771. * @brief This function update state of software conversion according to AutoSar diagrams
  772. * @details This function update state of software conversion according to AutoSar diagrams
  773. *
  774. * @param[in] Unit Adc Logical Unit Id
  775. * @param[in] Group Selected group Id
  776. * @param[in] GroupSamples Number of samples
  777. * @param[in] u32CoreId Current CoreID
  778. *
  779. * @return void
  780. */
  781. static inline void Adc_Ipw_UpdateSoftwareGroupState
  782. (
  783. Adc_HwUnitType Unit,
  784. Adc_GroupType Group,
  785. Adc_StreamNumSampleType GroupSamples,
  786. uint32 u32CoreId
  787. )
  788. {
  789. uint32 CurrentSampleCount;
  790. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  791. #ifdef ADC_DMA_SUPPORTED
  792. const Adc_Ipw_Config * const pAdcIpwConfigPtr = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig;
  793. const uint32 u32AdcDmaLogicChId = (uint32) pAdcIpwConfigPtr->Mapping.au8Adc_DmaChannel[Unit];
  794. Adc_HwUnitType PhysicalHwUnitId = pAdcIpwConfigPtr->aAdcPhysicalId[Unit];
  795. Dma_Ip_LogicChannelScatterGatherListType LocTransferList[1U];
  796. #endif /* ADC_DMA_SUPPORTED */
  797. /* At least once the group was converted */
  798. /* It's already check for validation */
  799. Adc_aGroupStatus[Group].eAlreadyConverted = ADC_ALREADY_CONVERTED;
  800. /* Although updating eConversion is a RMW operation, it does not need an
  801. * exclusive area because two simultaneous interrupts will not access the
  802. * same areas e.g. the interrupt for ADC1 will not have the same group as
  803. * an interrupt on ADC0 */
  804. /* Change when configuration is ADC streaming access mode */
  805. if (ADC_BUSY == Adc_aGroupStatus[Group].eConversion)
  806. {
  807. Adc_aGroupStatus[Group].eConversion = ADC_COMPLETED;
  808. }
  809. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  810. CurrentSampleCount = Adc_Ipw_GetCurrentSampleCount(Group, Unit, GroupSamples, u32CoreId);
  811. #else
  812. CurrentSampleCount = Adc_Ipw_GetCurrentSampleCount(Group);
  813. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  814. /* If buffer is full of samples */
  815. if (CurrentSampleCount >= GroupSamples)
  816. {
  817. /* Change to stream complete according to AutoSar diagram */
  818. Adc_aGroupStatus[Group].eConversion = ADC_STREAM_COMPLETED;
  819. if ((ADC_STREAM_BUFFER_LINEAR == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eBufferMode) && \
  820. (ADC_ACCESS_MODE_STREAMING == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eAccessMode) \
  821. )
  822. {
  823. #ifdef ADC_DMA_SUPPORTED
  824. /* Not required to check u8AdcWithoutDma == FALSE, because u8AdcWithoutDma is only supported for SW normal triggered which cannot be ADC_ACCESS_MODE_STREAMING when DMA transfer selected for HW unit */
  825. if (ADC_DMA == pAdcIpwConfigPtr->Mapping.u8Adc_DmaInterruptSoftware[Unit])
  826. {
  827. /* Disable ADC DMA Request */
  828. Adc_Ip_DisableDma(PhysicalHwUnitId);
  829. }
  830. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  831. /* Because of PDB was configured as CONT MODE then need to disable */
  832. if (TRUE == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].bAdcOptimizeDmaStream)
  833. {
  834. Pdb_Adc_Ip_DisableAndClearPdb(PhysicalHwUnitId);
  835. }
  836. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  837. #endif /* ADC_DMA_SUPPORTED */
  838. /* Update queue and execute new start conversion request from queue if available */
  839. Adc_Ipw_UpdateQueue(Unit, u32CoreId);
  840. }
  841. else
  842. {
  843. /* ADC_ACCESS_MODE_STREAMING && ADC_STREAM_BUFFER_CIRCULAR */
  844. if (ADC_CONV_MODE_CONTINUOUS == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eMode)
  845. {
  846. /* Restart new continuous conversion */
  847. Adc_aGroupStatus[Group].ResultIndex = 0U;
  848. #ifdef ADC_DMA_SUPPORTED
  849. /* TODO: Optimization: It's not necessary to reload the destination address in case of groups have 1 sample (continuous single access or continuous circular with 1 sample) since it's automatically reloaded by DLAST field*/
  850. if (ADC_DMA == pAdcIpwConfigPtr->Mapping.u8Adc_DmaInterruptSoftware[Unit])
  851. {
  852. if((uint8)STD_OFF == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].u8AdcExtDMAChanEnable)
  853. {
  854. LocTransferList[0].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
  855. LocTransferList[0].Value = (uint32)(&(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].pResultsBufferPtr[Group][0U]));
  856. (void)Dma_Ip_SetLogicChannelTransferList(u32AdcDmaLogicChId, LocTransferList, 1U);
  857. }
  858. }
  859. #endif /*ADC_DMA_SUPPORTED*/
  860. Adc_Ipw_RestartConversion(Unit, Group, u32CoreId);
  861. }
  862. else
  863. {
  864. /* Update queue and execute new request from queue if available */
  865. Adc_Ipw_UpdateQueue(Unit, u32CoreId);
  866. }
  867. }
  868. }
  869. else
  870. {
  871. /* Need to restart conversion until buffer is full */
  872. Adc_Ipw_RestartConversion(Unit, Group, u32CoreId);
  873. }
  874. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  875. /* Implement user notification function if available */
  876. Adc_Ipw_CallNotification(Group, u32CoreId);
  877. #endif /* (ADC_GRP_NOTIF_CAPABILITY == STD_ON) */
  878. }
  879. #if (ADC_HW_TRIGGER_API == STD_ON)
  880. #ifdef ADC_DMA_SUPPORTED
  881. static inline void Adc_Ipw_CheckAndUpdateDmaHwGroupState
  882. (
  883. Adc_HwUnitType Unit,
  884. Adc_GroupType Group,
  885. const uint32 u32AdcDmaLogicChId,
  886. uint32 u32CoreId
  887. )
  888. {
  889. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  890. Dma_Ip_LogicChannelScatterGatherListType LocTransferList[1U];
  891. /* ADC_ACCESS_MODE_STREAMING && ADC_STREAM_BUFFER_CIRCULAR */
  892. if ((ADC_STREAM_BUFFER_CIRCULAR == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eBufferMode) && \
  893. (ADC_ACCESS_MODE_STREAMING == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eAccessMode)
  894. )
  895. {
  896. if (ADC_DMA == Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.u8Adc_DmaInterruptSoftware[Unit])
  897. {
  898. if((uint8)STD_OFF == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].u8AdcExtDMAChanEnable)
  899. {
  900. LocTransferList[0].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
  901. LocTransferList[0].Value = (uint32)(&(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].pResultsBufferPtr[Group][0U]));
  902. (void)Dma_Ip_SetLogicChannelTransferList(u32AdcDmaLogicChId, LocTransferList, 1U);
  903. }
  904. }
  905. }
  906. }
  907. #endif /* ADC_DMA_SUPPORTED */
  908. /**
  909. * @brief This function update state of hardware conversion according to AutoSar diagrams
  910. * @details This function update state of hardware conversion according to AutoSar diagrams
  911. *
  912. * @param[in] Unit Adc Logical Unit Id
  913. * @param[in] Group Selected group Id
  914. * @param[in] GroupSamples Number of samples
  915. * @param[in] u32CoreId Current CoreID
  916. *
  917. * @return void
  918. */
  919. static inline void Adc_Ipw_UpdateHardwareGroupState
  920. (
  921. Adc_HwUnitType Unit,
  922. Adc_GroupType Group,
  923. Adc_StreamNumSampleType GroupSamples,
  924. uint32 u32CoreId
  925. )
  926. {
  927. boolean NotificationCalled = FALSE;
  928. uint32 CurrentSampleCount;
  929. Adc_ChannelIndexType ChannelCount;
  930. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  931. const Adc_Ipw_Config * const pAdcIpwConfigPtr = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig;
  932. Adc_HwUnitType PhysicalHwUnitId = pAdcIpwConfigPtr->aAdcPhysicalId[Unit];
  933. #ifdef ADC_DMA_SUPPORTED
  934. const uint32 u32AdcDmaLogicChId = (uint32) pAdcIpwConfigPtr->Mapping.au8Adc_DmaChannel[Unit];
  935. #endif /* ADC_DMA_SUPPORTED */
  936. #if (ADC_SETCHANNEL_API == STD_ON)
  937. ChannelCount = Adc_aRuntimeGroupChannel[Group].ChannelCount;
  938. #else
  939. ChannelCount = Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].AssignedChannelCount;
  940. #endif
  941. /* At least once the group was converted */
  942. Adc_aGroupStatus[Group].eAlreadyConverted = ADC_ALREADY_CONVERTED;
  943. /* Although updating eConversion is a RMW operation, it does not need an
  944. * exclusive area because two simultaneous interrupts will not access the
  945. * same areas e.g. the interrupt for ADC1 will not have the same group as
  946. * an interrupt on ADC0 */
  947. if (ADC_BUSY == Adc_aGroupStatus[Group].eConversion)
  948. {
  949. Adc_aGroupStatus[Group].eConversion = ADC_COMPLETED;
  950. }
  951. #if (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS)
  952. CurrentSampleCount = Adc_Ipw_GetCurrentSampleCount(Group, Unit, GroupSamples, u32CoreId);
  953. #else
  954. CurrentSampleCount = Adc_Ipw_GetCurrentSampleCount(Group);
  955. #endif /* (STD_ON == ADC_OPTIMIZE_DMA_STREAMING_GROUPS) */
  956. if (CurrentSampleCount >= GroupSamples)
  957. {
  958. Adc_aGroupStatus[Group].eConversion = ADC_STREAM_COMPLETED;
  959. if ((ADC_STREAM_BUFFER_LINEAR == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eBufferMode) && \
  960. (ADC_ACCESS_MODE_STREAMING == Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex].eAccessMode)
  961. )
  962. {
  963. Adc_Ip_DisableChannelNotification(PhysicalHwUnitId, (Adc_aUnitStatus[Unit].u8Sc1Used - 1U));
  964. #ifdef ADC_DMA_SUPPORTED
  965. /* Not required to check u8AdcWithoutDma == FALSE, because u8AdcWithoutDma is only supported for SW normal triggered which cannot be ADC_ACCESS_MODE_STREAMING when DMA transfer selected for HW unit */
  966. if (ADC_DMA == pAdcIpwConfigPtr->Mapping.u8Adc_DmaInterruptSoftware[Unit])
  967. {
  968. /* Disable ADC DMA Request */
  969. Adc_Ip_DisableDma(PhysicalHwUnitId);
  970. }
  971. #endif /* ADC_DMA_SUPPORTED */
  972. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  973. Adc_Ipw_CallNotification(Group, u32CoreId);
  974. #endif /* (ADC_GRP_NOTIF_CAPABILITY == STD_ON) */
  975. NotificationCalled = TRUE;
  976. }
  977. else
  978. {
  979. Adc_aGroupStatus[Group].ResultIndex = 0U;
  980. #ifdef ADC_DMA_SUPPORTED
  981. Adc_Ipw_CheckAndUpdateDmaHwGroupState(Unit, Group, u32AdcDmaLogicChId, u32CoreId);
  982. #endif /* ADC_DMA_SUPPORTED */
  983. }
  984. }
  985. if (NotificationCalled == FALSE)
  986. {
  987. /* Setting up to PDB HW trigger mode for each completed sample in case of configured channels > SC */
  988. if ((ChannelCount > ADC_MAX_CHAN_COUNT)
  989. #if (ADC_SETCHANNEL_API == STD_ON)
  990. || (TRUE == Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated)
  991. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  992. )
  993. {
  994. Adc_Ipw_StartHwTrigConversion(Unit, Group, u32CoreId);
  995. }
  996. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  997. Adc_Ipw_CallNotification(Group, u32CoreId);
  998. #endif /* (ADC_GRP_NOTIF_CAPABILITY == STD_ON) */
  999. }
  1000. }
  1001. #endif /* (ADC_HW_TRIGGER_API == STD_ON) */
  1002. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  1003. /**
  1004. * @brief This function handles conversion ending routines
  1005. * @details This function handles conversion ending routines
  1006. *
  1007. * @param[in] Unit Adc Logical Unit Id
  1008. * @param[in] Group Selected group Id
  1009. * @param[in] IsSoftwareConversion Software or Hardware triggered conversion
  1010. * @param[in] u32CoreId Current CoreID
  1011. *
  1012. * @return void
  1013. */
  1014. static inline void Adc_Ipw_EndConversion
  1015. (
  1016. Adc_HwUnitType Unit,
  1017. Adc_GroupType Group,
  1018. boolean IsSoftwareConversion,
  1019. uint32 u32CoreId
  1020. )
  1021. {
  1022. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  1023. const Adc_GroupConfigurationType * GroupPtr; /* Pointer to AdcGroup */
  1024. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  1025. Adc_ChannelIndexType NumChannel;
  1026. uint8 LeftChannel;
  1027. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  1028. #if ((ADC_SETCHANNEL_API == STD_ON) || ((ADC_SETCHANNEL_API == STD_OFF) && (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)))
  1029. Adc_ChannelIndexType ChannelCount;
  1030. #endif /* ((ADC_SETCHANNEL_API == STD_ON) || ((ADC_SETCHANNEL_API == STD_OFF) && (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF))) */
  1031. /* Get the group configuration */
  1032. GroupPtr = &(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex]);
  1033. #if (ADC_SETCHANNEL_API == STD_ON)
  1034. /* Channels configured at runtime */
  1035. ChannelCount = Adc_aRuntimeGroupChannel[Group].ChannelCount;
  1036. /* Check if channel was updated before interrupt of previous conversions */
  1037. if (TRUE == Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated)
  1038. {
  1039. Adc_Ipw_ConfigureRuntimeChannels(Unit, GroupPtr, (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(ChannelCount), u32CoreId);
  1040. }
  1041. else
  1042. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1043. {
  1044. /* Limit checking */
  1045. if (Adc_Ipw_CheckConversionChannels(Unit, Group, GroupPtr->NumSamples, u32CoreId) == (Std_ReturnType)E_OK)
  1046. {
  1047. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  1048. /* Following code will not be reduced when oneshot hardware trigger optimization is not enabled */
  1049. #if (ADC_SETCHANNEL_API == STD_OFF)
  1050. /* Channels configured when initializing */
  1051. ChannelCount = GroupPtr->AssignedChannelCount;
  1052. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1053. /* More channels in group */
  1054. /* Both HW and SW groups are using PDB SW trigger mode to restart conversion when ChannelCount > Max SC registers */
  1055. if (Adc_aGroupStatus[Group].CurrentChannel < ChannelCount)
  1056. {
  1057. /* Get left channel */
  1058. NumChannel = ChannelCount - Adc_aGroupStatus[Group].CurrentChannel;
  1059. /* In case of left channels excess maximum allowed channels */
  1060. LeftChannel = (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(NumChannel);
  1061. /* Configure left channels and start more conversions */
  1062. Adc_Ipw_ConfigureConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, LeftChannel, u32CoreId);
  1063. }
  1064. /* All of channels converted */
  1065. else
  1066. #endif
  1067. {
  1068. #if (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON)
  1069. Adc_Ipw_CallExtraNotification(Group, u32CoreId);
  1070. #endif /* (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON) */
  1071. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_ON)
  1072. /* At least once the group was converted */
  1073. Adc_aGroupStatus[Group].eAlreadyConverted = ADC_ALREADY_CONVERTED;
  1074. Adc_aGroupStatus[Group].eConversion = ADC_STREAM_COMPLETED;
  1075. #if (ADC_SETCHANNEL_API == STD_ON)
  1076. /* Check if channel was updated in Adc_Ipw_CallExtraNotification */
  1077. if (TRUE == Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated)
  1078. {
  1079. Adc_Ipw_ConfigureRuntimeChannels(Unit, GroupPtr, (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(ChannelCount), u32CoreId);
  1080. }
  1081. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1082. #if (ADC_ENABLE_LIMIT_CHECK == STD_OFF)
  1083. (void)IsSoftwareConversion;
  1084. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_OFF) */
  1085. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  1086. /* Check notification of a group and call the notification function if needed */
  1087. Adc_Ipw_CallNotification(Group, u32CoreId);
  1088. #endif /* (ADC_GRP_NOTIF_CAPABILITY == STD_ON) */
  1089. #else /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  1090. /* Although this is a RMW operation, it does not need an exclusive area because two
  1091. * simultaneous interrupts will not access the same areas e.g. the interrupt for
  1092. * ADC1 will not have the same group as an interrupt on ADC0 */
  1093. /* Increment ResultIndex with modulo 'NumSamples' to remember that another sample is completed */
  1094. Adc_aGroupStatus[Group].ResultIndex++;
  1095. /* Update state following AutoSar diagrams */
  1096. if (TRUE == IsSoftwareConversion)
  1097. {
  1098. Adc_Ipw_UpdateSoftwareGroupState(Unit, Group, GroupPtr->NumSamples, u32CoreId);
  1099. }
  1100. #if (ADC_HW_TRIGGER_API == STD_ON)
  1101. else
  1102. {
  1103. Adc_Ipw_UpdateHardwareGroupState(Unit, Group, GroupPtr->NumSamples, u32CoreId);
  1104. }
  1105. #endif /* (ADC_HW_TRIGGER_API == STD_ON) */
  1106. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_ON) */
  1107. }
  1108. }
  1109. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  1110. else
  1111. {
  1112. if (TRUE == IsSoftwareConversion)
  1113. {
  1114. Adc_Ipw_HandleConversionCheckFail(Unit, Group, GroupPtr, u32CoreId);
  1115. }
  1116. }
  1117. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  1118. }
  1119. }
  1120. #ifdef ADC_DMA_SUPPORTED
  1121. /**
  1122. * @brief This function handles conversion ending routines incase of DMA Transfering
  1123. * @details This function handles conversion ending routines incase of DMA Transfering
  1124. *
  1125. * @param[in] Unit Adc Logical Unit Id
  1126. * @param[in] Group Selected group Id
  1127. * @param[in] IsSoftwareConversion Software or Hardware triggered conversion
  1128. * @param[in] u32CoreId Current CoreID
  1129. *
  1130. * @return void
  1131. */
  1132. static inline void Adc_Ipw_EndDmaConversion
  1133. (
  1134. Adc_HwUnitType Unit,
  1135. Adc_GroupType Group,
  1136. boolean IsSoftwareConversion,
  1137. uint32 u32CoreId
  1138. )
  1139. {
  1140. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  1141. const Adc_GroupConfigurationType * GroupPtr = &(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex]); /* Pointer to AdcGroup */
  1142. const uint32 AdcDmaLogicChId = (uint32) Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.au8Adc_DmaChannel[Unit];
  1143. #if ((ADC_SETCHANNEL_API == STD_ON) || ((ADC_SETCHANNEL_API == STD_OFF) && (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)))
  1144. Adc_ChannelIndexType ChannelCount;
  1145. #endif /* ((ADC_SETCHANNEL_API == STD_ON) || ((ADC_SETCHANNEL_API == STD_OFF) && (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF))) */
  1146. #if (ADC_SETCHANNEL_API == STD_ON)
  1147. /* Channels configured at runtime */
  1148. ChannelCount = Adc_aRuntimeGroupChannel[Group].ChannelCount;
  1149. /* Check if channel was updated before interrupt of previous conversions */
  1150. if (TRUE == Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated)
  1151. {
  1152. Adc_Ipw_ConfigureRuntimeChannels(Unit, GroupPtr, (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(ChannelCount), u32CoreId);
  1153. }
  1154. else
  1155. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1156. {
  1157. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  1158. if (Adc_Ipw_CheckGroupConvResultDma(GroupPtr, u32CoreId) == (Std_ReturnType)E_OK)
  1159. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  1160. {
  1161. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  1162. /* Following code will not be reduced when oneshot hardware trigger optimization is not enabled */
  1163. #if (ADC_SETCHANNEL_API == STD_OFF)
  1164. /* Channels configured when initializing */
  1165. ChannelCount = GroupPtr->AssignedChannelCount;
  1166. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1167. /* More channels in group */
  1168. if (Adc_aGroupStatus[Group].CurrentChannel < ChannelCount)
  1169. {
  1170. Adc_Ipw_ContinueDmaConversion(Unit, Group, ChannelCount, AdcDmaLogicChId, u32CoreId);
  1171. }
  1172. /* All of channels converted */
  1173. else
  1174. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  1175. {
  1176. #if (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON)
  1177. Adc_Ipw_CallExtraNotification(Group, u32CoreId);
  1178. #endif /* (ADC_ENABLE_INITIAL_NOTIFICATION == STD_ON) */
  1179. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_ON)
  1180. /* At least once the group was converted */
  1181. Adc_aGroupStatus[Group].eAlreadyConverted = ADC_ALREADY_CONVERTED;
  1182. Adc_aGroupStatus[Group].eConversion = ADC_STREAM_COMPLETED;
  1183. #if (ADC_SETCHANNEL_API == STD_ON)
  1184. /* Check if channel was updated in Adc_Ipw_CallExtraNotification */
  1185. if (TRUE == Adc_aRuntimeGroupChannel[Group].bRuntimeUpdated)
  1186. {
  1187. Adc_Ipw_ConfigureRuntimeChannels(Unit, GroupPtr, (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(ChannelCount), u32CoreId);
  1188. }
  1189. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1190. #if (ADC_ENABLE_LIMIT_CHECK == STD_OFF)
  1191. (void)IsSoftwareConversion;
  1192. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_OFF) */
  1193. #if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
  1194. /* Check notification of a group and call the notification function if needed */
  1195. Adc_Ipw_CallNotification(Group, u32CoreId);
  1196. #endif /* (ADC_GRP_NOTIF_CAPABILITY == STD_ON) */
  1197. #else /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  1198. /* Although this is a RMW operation, it does not need an exclusive area because two
  1199. * simultaneous interrupts will not access the same areas e.g. the interrupt for
  1200. * ADC1 will not have the same group as an interrupt on ADC0 */
  1201. /* Increment ResultIndex with modulo 'NumSamples' to remember that another sample is completed */
  1202. Adc_aGroupStatus[Group].ResultIndex++;
  1203. /* Update state following AutoSar diagrams */
  1204. if (TRUE == IsSoftwareConversion)
  1205. {
  1206. Adc_Ipw_UpdateSoftwareGroupState(Unit, Group, GroupPtr->NumSamples, u32CoreId);
  1207. }
  1208. #if (ADC_HW_TRIGGER_API == STD_ON)
  1209. else
  1210. {
  1211. Adc_Ipw_UpdateHardwareGroupState(Unit, Group, GroupPtr->NumSamples, u32CoreId);
  1212. }
  1213. #endif /* (ADC_HW_TRIGGER_API == STD_ON) */
  1214. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_ON) */
  1215. if (ADC_DMA == Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.u8Adc_DmaInterruptSoftware[Unit])
  1216. {
  1217. if((uint8)STD_OFF == GroupPtr->u8AdcExtDMAChanEnable)
  1218. {
  1219. /* DMA Hardware Request was disabled after transfer completed, to avoid overwriting any new results before this gets processed. Re-enable DMA here. */
  1220. (void)Dma_Ip_SetLogicChannelCommand(AdcDmaLogicChId, DMA_IP_CH_SET_HARDWARE_REQUEST);
  1221. }
  1222. }
  1223. }
  1224. }
  1225. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  1226. else
  1227. {
  1228. if (TRUE == IsSoftwareConversion)
  1229. {
  1230. Adc_Ipw_HandleConversionCheckFail(Unit, Group, GroupPtr, u32CoreId);
  1231. }
  1232. }
  1233. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  1234. }
  1235. }
  1236. #if (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF)
  1237. /**
  1238. * @brief This function updates Dma configuration
  1239. * @details This function updates Dma configuration if number of configured channels
  1240. * are greater than number of SC1 register
  1241. *
  1242. * @param[in] DataPtr Adc_ValueGroupType * DataPtr,
  1243. * @param[in] DmaLogicChId Dma logical channel
  1244. * @param[in] NumChannel Number of channel to be converted
  1245. *
  1246. * @return void
  1247. */
  1248. static inline void Adc_Ipw_UpdateDmaConfig
  1249. (
  1250. const Adc_ValueGroupType * DataPtr,
  1251. const uint32 DmaLogicChId,
  1252. uint8 NumChannel
  1253. )
  1254. {
  1255. Dma_Ip_LogicChannelTransferListType LocTransferList[3U];
  1256. LocTransferList[0].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
  1257. LocTransferList[0].Value = (uint32)(DataPtr);
  1258. LocTransferList[1].Param = DMA_IP_CH_SET_SOURCE_SIGNED_LAST_ADDR_ADJ;
  1259. LocTransferList[1].Value = ADC_IPW_GET_COMPLEMENT_OF_2((uint32)NumChannel << 2UL);
  1260. LocTransferList[2].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
  1261. LocTransferList[2].Value = (uint32)NumChannel;
  1262. /* Setting for DMA transfer */
  1263. (void)Dma_Ip_SetLogicChannelTransferList(DmaLogicChId, LocTransferList, 3U);
  1264. (void)Dma_Ip_SetLogicChannelCommand(DmaLogicChId, DMA_IP_CH_SET_HARDWARE_REQUEST);
  1265. }
  1266. static inline void Adc_Ipw_ContinueDmaConversion
  1267. (
  1268. Adc_HwUnitType Unit,
  1269. Adc_GroupType Group,
  1270. const Adc_ChannelIndexType ChannelCount,
  1271. const uint32 AdcDmaLogicChId,
  1272. uint32 u32CoreId
  1273. )
  1274. {
  1275. const Adc_GroupType GroupIndex = Adc_pCfgPtr[u32CoreId]->pGroupIdToIndexMap[Group];
  1276. const Adc_ChannelIndexType NumChannel = ChannelCount - Adc_aGroupStatus[Group].CurrentChannel;
  1277. /* In case of left channels excess maximum allowed channels */
  1278. const uint8 LeftChannel = (uint8)ADC_IPW_CALCULATE_CHAN_NUMBER(NumChannel);
  1279. const Adc_GroupConfigurationType * GroupPtr; /* Pointer to AdcGroup */
  1280. uint16 ResultIndex;
  1281. GroupPtr = &(Adc_pCfgPtr[u32CoreId]->pGroups[GroupIndex]);
  1282. if ((uint8)STD_OFF == GroupPtr->u8AdcExtDMAChanEnable)
  1283. {
  1284. #if (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON)
  1285. if (TRUE == GroupPtr->bStreamResultGroupMultiSets)
  1286. {
  1287. ResultIndex = (Adc_aGroupStatus[Group].ResultIndex * ChannelCount) + Adc_aGroupStatus[Group].CurrentChannel;
  1288. }
  1289. else
  1290. #endif /* (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON) */
  1291. {
  1292. ResultIndex = ((Adc_aGroupStatus[Group].CurrentChannel) * (GroupPtr->NumSamples)) + Adc_aGroupStatus[Group].ResultIndex;
  1293. }
  1294. /* Update DMA configuration for remaining channels */
  1295. Adc_Ipw_UpdateDmaConfig((&(GroupPtr->pResultsBufferPtr[Group][ResultIndex])), AdcDmaLogicChId, LeftChannel);
  1296. }
  1297. /* Configure left channels and start more conversions */
  1298. Adc_Ipw_ConfigureDmaConversion(Unit, Group, PDB_ADC_IP_SOFTWARE_TRIGGER, LeftChannel);
  1299. }
  1300. #endif /* (ADC_OPTIMIZE_ONESHOT_HW_TRIGGER == STD_OFF) */
  1301. #if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
  1302. /**
  1303. * @brief This function checks the conversion result when Limit Check and DMA are enabled.
  1304. * @details This function checks the conversion result when Limit Check and DMA are enabled.
  1305. *
  1306. * @param[in] pGroupPtr The Adc Group Pointer.
  1307. * @param[in] u32CoreId Current CoreID
  1308. *
  1309. * @return Std_ReturnType
  1310. *
  1311. */
  1312. static inline Std_ReturnType Adc_Ipw_CheckGroupConvResultDma
  1313. (
  1314. const Adc_GroupConfigurationType * pGroupPtr,
  1315. uint32 u32CoreId
  1316. )
  1317. {
  1318. Std_ReturnType ReturnValue = (Std_ReturnType)E_OK;
  1319. const Adc_GroupType Group = pGroupPtr->GroupId;
  1320. const Adc_HwUnitType Unit = pGroupPtr->AdcLogicalUnitId;
  1321. Adc_ValueGroupType * pResultData = &(pGroupPtr->pResultsBufferPtr[Group][Adc_aGroupStatus[Group].ResultIndex]);
  1322. Adc_ChannelType HwChannel;
  1323. #if (ADC_SETCHANNEL_API == STD_ON)
  1324. HwChannel = Adc_aRuntimeGroupChannel[Group].pChannel[0];
  1325. #else
  1326. HwChannel = pGroupPtr->pAssignment[0];
  1327. #endif /* (ADC_SETCHANNEL_API == STD_ON) */
  1328. if (
  1329. (TRUE == pGroupPtr->bAdcGroupLimitcheck)
  1330. #if (ADC_SETCHANNEL_API == STD_ON)
  1331. || (TRUE == Adc_aRuntimeGroupChannel[Group].bAdcRuntimeGroupLimitcheck)
  1332. #endif /* ADC_SETCHANNEL_API == STD_ON */
  1333. )
  1334. {
  1335. /* Assumption: because of SWS_Adc_00451, the number of channels configured for a group when limit checking is disabled, must be one.*/
  1336. if (FALSE == Adc_Ipw_CheckConversionValuesInRange(pResultData[0], Unit, HwChannel, u32CoreId))
  1337. {
  1338. /* SWS_Adc_00448 */
  1339. /* Return an error */
  1340. Adc_aGroupStatus[Group].eAlreadyConverted = ADC_ALREADY_CONVERTED;
  1341. Adc_aGroupStatus[Group].bLimitCheckFailed = TRUE;
  1342. pResultData[0] = 0U;
  1343. ReturnValue = (Std_ReturnType) E_NOT_OK;
  1344. }
  1345. else
  1346. {
  1347. Adc_aGroupStatus[Group].bLimitCheckFailed = FALSE;
  1348. }
  1349. }
  1350. return ReturnValue;
  1351. }
  1352. #endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
  1353. #endif /* ADC_DMA_SUPPORTED */
  1354. /**
  1355. * @brief This function read conversion results
  1356. * @details This function read conversion results
  1357. *
  1358. * @param[in] GroupPtr Group Pointer
  1359. * @param[in] pResult Pointer to conversion results
  1360. * @param[in] GroupSamples Number of samples
  1361. * @param[in] Index Current index of result
  1362. * @param[in] ConvResult Conversion result
  1363. *
  1364. * @return void
  1365. */
  1366. static inline void Adc_Ipw_ReadData
  1367. (
  1368. const Adc_GroupConfigurationType * GroupPtr,
  1369. Adc_ValueGroupType * pResult,
  1370. const Adc_StreamNumSampleType GroupSamples,
  1371. const Adc_ChannelIndexType Index,
  1372. const uint16 ConvResult
  1373. )
  1374. {
  1375. #if (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON)
  1376. if (FALSE == GroupPtr->bStreamResultGroupMultiSets)
  1377. {
  1378. #endif /* (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON) */
  1379. pResult[(Index * GroupSamples)] = ConvResult;
  1380. (void)GroupPtr;
  1381. #if (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON)
  1382. }
  1383. else
  1384. {
  1385. pResult[Index] = ConvResult;
  1386. }
  1387. #endif /* (ADC_ENABLE_GROUP_STREAMING_RESULTS_REORDER == STD_ON) */
  1388. }
  1389. /**
  1390. * @brief This function handles the end conversion notification.
  1391. * @details This function handles the end conversion notification.
  1392. *
  1393. * @param[in] PhysicalAdcUnit ADC Hardware Unit
  1394. *
  1395. * @return void
  1396. */
  1397. static inline void Adc_Ipw_EndConversionNotification
  1398. (
  1399. const Adc_HwUnitType PhysicalAdcUnit
  1400. )
  1401. {
  1402. /* Check that ADC unit is assigned to current core partition */
  1403. const volatile uint32 u32CoreId = Adc_GetCoreID();
  1404. const Adc_HwUnitType LogicalHwUnitId = Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.aHwLogicalId[PhysicalAdcUnit];
  1405. const Adc_GroupType SwGroupId = Adc_aUnitStatus[LogicalHwUnitId].SwNormalQueue[0U];
  1406. #if (ADC_HW_TRIGGER_API == STD_ON)
  1407. const Adc_GroupType HwGroupId = Adc_aUnitStatus[LogicalHwUnitId].OngoingHwGroup;
  1408. #endif /* ADC_HW_TRIGGER_API == STD_ON */
  1409. #if (ADC_HW_TRIGGER_API == STD_ON)
  1410. /* Check if requests are available in queue */
  1411. if (ADC_INVALID_HW_GROUP_ID != HwGroupId)
  1412. {
  1413. #ifdef ADC_DMA_SUPPORTED
  1414. if (ADC_DMA == Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.u8Adc_DmaInterruptSoftware[LogicalHwUnitId])
  1415. {
  1416. Adc_Ipw_EndDmaConversion(LogicalHwUnitId, HwGroupId, FALSE, u32CoreId);
  1417. }
  1418. else
  1419. #endif /* ADC_DMA_SUPPORTED */
  1420. {
  1421. Adc_Ipw_EndConversion(LogicalHwUnitId, HwGroupId, FALSE, u32CoreId);
  1422. }
  1423. }
  1424. else
  1425. #endif /* (ADC_HW_TRIGGER_API == STD_ON) */
  1426. if (Adc_aUnitStatus[LogicalHwUnitId].SwNormalQueueIndex > (Adc_QueueIndexType)0U)
  1427. {
  1428. #ifdef ADC_DMA_SUPPORTED
  1429. if (ADC_DMA == Adc_pCfgPtr[u32CoreId]->pAdcIpwConfig->Mapping.u8Adc_DmaInterruptSoftware[LogicalHwUnitId])
  1430. {
  1431. Adc_Ipw_EndDmaConversion(LogicalHwUnitId, SwGroupId, TRUE, u32CoreId);
  1432. }
  1433. else
  1434. #endif /* ADC_DMA_SUPPORTED */
  1435. {
  1436. Adc_Ipw_EndConversion(LogicalHwUnitId, SwGroupId, TRUE, u32CoreId);
  1437. }
  1438. }
  1439. #if (ADC_HW_TRIGGER_API == STD_ON)
  1440. else
  1441. {
  1442. ; /* Empty else branch to avoid MISRA */
  1443. }
  1444. #endif /* (ADC_HW_TRIGGER_API == STD_ON) */
  1445. }
  1446. /*==================================================================================================
  1447. * GLOBAL FUNCTION PROTOTYPES
  1448. ==================================================================================================*/
  1449. /* IAR wants prototypes due to --require-prototypes */
  1450. #ifdef ADC_UNIT_0_ISR_USED
  1451. void Adc_Ipw_Adc0EndConversionNotification(const uint8 ControlChanIdx);
  1452. #endif /* ADC_UNIT_0_ISR_USED */
  1453. #ifdef ADC_UNIT_1_ISR_USED
  1454. void Adc_Ipw_Adc1EndConversionNotification(const uint8 ControlChanIdx);
  1455. #endif /* ADC_UNIT_1_ISR_USED */
  1456. #ifdef ADC_DMA_SUPPORTED
  1457. void Adc_Ipw_Adc0DmaTransferCompleteNotification(void);
  1458. void Adc_Ipw_Adc1DmaTransferCompleteNotification(void);
  1459. #endif /* ADC_DMA_SUPPORTED */
  1460. /*==================================================================================================
  1461. * GLOBAL FUNCTIONS
  1462. ==================================================================================================*/
  1463. /*==================================================================================================
  1464. ADC HW UNIT 0
  1465. ==================================================================================================*/
  1466. #ifdef ADC_UNIT_0_ISR_USED
  1467. /**
  1468. * @brief This function handles the ISR for the conversion done of
  1469. * the ADC Hardware Unit 0.
  1470. * @details The function handles the ISR for the ADC Hardware Unit 0.
  1471. *
  1472. * @return void
  1473. *
  1474. */
  1475. void Adc_Ipw_Adc0EndConversionNotification(const uint8 ControlChanIdx)
  1476. {
  1477. const Adc_HwUnitType PhysicalAdcUnit = 0U;
  1478. (void)ControlChanIdx;
  1479. Adc_Ipw_EndConversionNotification(PhysicalAdcUnit);
  1480. }
  1481. #endif /* ADC_UNIT_0_ISR_USED */
  1482. #ifdef ADC_DMA_SUPPORTED
  1483. /**
  1484. * @brief This function implements the end of DMA transfer notification for
  1485. * ADC Hardware Unit 0.
  1486. * @details This function implements the end of DMA transfer notification for
  1487. * ADC Hardware Unit 0.
  1488. *
  1489. * @return void
  1490. *
  1491. */
  1492. void Adc_Ipw_Adc0DmaTransferCompleteNotification(void)
  1493. {
  1494. const Adc_HwUnitType PhysicalAdcUnit = 0U;
  1495. Adc_Ipw_EndConversionNotification(PhysicalAdcUnit);
  1496. }
  1497. #endif /* ADC_DMA_SUPPORTED */
  1498. /*==================================================================================================
  1499. ADC HW UNIT 1
  1500. ==================================================================================================*/
  1501. #ifdef ADC_UNIT_1_ISR_USED
  1502. /**
  1503. * @brief This function handles the ISR for the conversion done of
  1504. * the ADC Hardware Unit 1.
  1505. * @details The function handles the ISR for the ADC Hardware Unit 1.
  1506. *
  1507. * @return void
  1508. *
  1509. */
  1510. void Adc_Ipw_Adc1EndConversionNotification(const uint8 ControlChanIdx)
  1511. {
  1512. const Adc_HwUnitType PhysicalAdcUnit = 1U;
  1513. (void)ControlChanIdx;
  1514. Adc_Ipw_EndConversionNotification(PhysicalAdcUnit);
  1515. }
  1516. #endif /* ADC_UNIT_1_ISR_USED */
  1517. #ifdef ADC_DMA_SUPPORTED
  1518. /**
  1519. * @brief This function implements the end of DMA transfer notification for
  1520. * ADC Hardware Unit 0.
  1521. * @details This function implements the end of DMA transfer notification for
  1522. * ADC Hardware Unit 0.
  1523. *
  1524. * @return void
  1525. *
  1526. */
  1527. void Adc_Ipw_Adc1DmaTransferCompleteNotification(void)
  1528. {
  1529. const Adc_HwUnitType PhysicalAdcUnit = 1U;
  1530. Adc_Ipw_EndConversionNotification(PhysicalAdcUnit);
  1531. }
  1532. #endif /* ADC_DMA_SUPPORTED */
  1533. #endif /* (defined(ADC_UNIT_0_ISR_USED) || ... */
  1534. #define ADC_STOP_SEC_CODE
  1535. #include "Adc_MemMap.h"
  1536. #ifdef __cplusplus
  1537. }
  1538. #endif
  1539. /** @} */