Adc_Ip.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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. * @addtogroup adc_ip Adc IPL
  28. * @{
  29. */
  30. #include "Adc_Ip.h"
  31. #include "Adc_Ip_HwAccess.h"
  32. #include "SchM_Adc.h"
  33. #include "OsIf.h"
  34. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  35. #include "Devassert.h"
  36. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  37. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  38. /* USER_MODE_REG_PROT_ENABLED is defined for Base sanity check in RegLockMacros.h */
  39. #define USER_MODE_REG_PROT_ENABLED (ADC_IP_ENABLE_USER_MODE_SUPPORT)
  40. #include "RegLockMacros.h"
  41. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  42. /*******************************************************************************
  43. * Source file version information
  44. ******************************************************************************/
  45. #define ADC_IP_VENDOR_ID_C 43
  46. #define ADC_IP_AR_RELEASE_MAJOR_VERSION_C 4
  47. #define ADC_IP_AR_RELEASE_MINOR_VERSION_C 4
  48. #define ADC_IP_AR_RELEASE_REVISION_VERSION_C 0
  49. #define ADC_IP_SW_MAJOR_VERSION_C 1
  50. #define ADC_IP_SW_MINOR_VERSION_C 0
  51. #define ADC_IP_SW_PATCH_VERSION_C 0
  52. /*******************************************************************************
  53. * File version checks
  54. ******************************************************************************/
  55. /* Check if Adc_Ip.c file and Adc_Ip.h file are of the same vendor */
  56. #if (ADC_IP_VENDOR_ID_C != ADC_IP_VENDOR_ID_H)
  57. #error "Adc_Ip.c and Adc_Ip.h have different vendor ids"
  58. #endif
  59. /* Check if Adc_Ip.c file and Adc_Ip.h file are of the same Autosar version */
  60. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_C != ADC_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  61. (ADC_IP_AR_RELEASE_MINOR_VERSION_C != ADC_IP_AR_RELEASE_MINOR_VERSION_H) || \
  62. (ADC_IP_AR_RELEASE_REVISION_VERSION_C != ADC_IP_AR_RELEASE_REVISION_VERSION_H) \
  63. )
  64. #error "AutoSar Version Numbers of Adc_Ip.c and Adc_Ip.h are different"
  65. #endif
  66. /* Check if Adc_Ip.c file and Adc_Ip.h file are of the same Software version */
  67. #if ((ADC_IP_SW_MAJOR_VERSION_C != ADC_IP_SW_MAJOR_VERSION_H) || \
  68. (ADC_IP_SW_MINOR_VERSION_C != ADC_IP_SW_MINOR_VERSION_H) || \
  69. (ADC_IP_SW_PATCH_VERSION_C != ADC_IP_SW_PATCH_VERSION_H) \
  70. )
  71. #error "Software Version Numbers of Adc_Ip.c and Adc_Ip.h are different"
  72. #endif
  73. /* Check if Adc_Ip.c file and Adc_Ip_HwAccess.h file are of the same vendor */
  74. #if (ADC_IP_VENDOR_ID_C != ADC_IP_VENDOR_ID_HWACCESS_H)
  75. #error "Adc_Ip.c and Adc_Ip_HwAccess.h have different vendor ids"
  76. #endif
  77. /* Check if Adc_Ip.c file and Adc_Ip_HwAccess.h file are of the same Autosar version */
  78. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_C != ADC_IP_AR_RELEASE_MAJOR_VERSION_HWACCESS_H) || \
  79. (ADC_IP_AR_RELEASE_MINOR_VERSION_C != ADC_IP_AR_RELEASE_MINOR_VERSION_HWACCESS_H) || \
  80. (ADC_IP_AR_RELEASE_REVISION_VERSION_C != ADC_IP_AR_RELEASE_REVISION_VERSION_HWACCESS_H) \
  81. )
  82. #error "AutoSar Version Numbers of Adc_Ip.c and Adc_Ip_HwAccess.h are different"
  83. #endif
  84. /* Check if Adc_Ip.c file and Adc_Ip_HwAccess.h file are of the same Software version */
  85. #if ((ADC_IP_SW_MAJOR_VERSION_C != ADC_IP_SW_MAJOR_VERSION_HWACCESS_H) || \
  86. (ADC_IP_SW_MINOR_VERSION_C != ADC_IP_SW_MINOR_VERSION_HWACCESS_H) || \
  87. (ADC_IP_SW_PATCH_VERSION_C != ADC_IP_SW_PATCH_VERSION_HWACCESS_H) \
  88. )
  89. #error "Software Version Numbers of Adc_Ip.c and Adc_Ip_HwAccess.h are different"
  90. #endif
  91. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  92. /* Check if Adc_Ip.c file and OsIf.h file are of the same Autosar version */
  93. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  94. (ADC_IP_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION) \
  95. )
  96. #error "AutoSar Version Numbers of Adc_Ip.c and OsIf.h are different"
  97. #endif
  98. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  99. /* Checks against RegLockMacros.h */
  100. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
  101. (ADC_IP_AR_RELEASE_MINOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION))
  102. #error "AutoSar Version Numbers of Adc_Ip.c and RegLockMacros.h are different"
  103. #endif
  104. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  105. /* Check if Adc_Ip.c and SchM_Adc.h are of the same Autosar version */
  106. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_C != SCHM_ADC_AR_RELEASE_MAJOR_VERSION) || \
  107. (ADC_IP_AR_RELEASE_MINOR_VERSION_C != SCHM_ADC_AR_RELEASE_MINOR_VERSION) \
  108. )
  109. #error "AutoSar Version Numbers of Adc_Ip.c and SchM_Adc.h are different"
  110. #endif
  111. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  112. /* Check if Adc_Ip.c and Devassert.h are of the same Autosar version */
  113. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  114. (ADC_IP_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION) \
  115. )
  116. #error "AutoSar Version Numbers of Adc_Ip.c and Devassert.h are different"
  117. #endif
  118. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  119. #endif /* DISABLE_MCAL_INTERMODULE_ASR_CHECK */
  120. /*******************************************************************************
  121. * Pre-check
  122. ******************************************************************************/
  123. #ifndef MCAL_ENABLE_USER_MODE_SUPPORT
  124. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  125. #error MCAL_ENABLE_USER_MODE_SUPPORT is not enabled. For running ADC in user mode the MCAL_ENABLE_USER_MODE_SUPPORT needs to be defined
  126. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  127. #endif /* ifndef MCAL_ENABLE_USER_MODE_SUPPORT */
  128. /*******************************************************************************
  129. * Local function prototypes
  130. ******************************************************************************/
  131. #define ADC_START_SEC_CODE
  132. #include "Adc_MemMap.h"
  133. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  134. static void ADC_SetSupplyMonitoringEnable_TrustedCall(const boolean SupplyEnable);
  135. static void ADC_SetSupplyMonitoringEnable(const boolean SupplyEnable);
  136. static void ADC_ConfigSupplyMonitoringChannel_TrustedCall(const uint32 SupplyChannel);
  137. static void ADC_ConfigSupplyMonitoringChannel(const uint32 SupplyChannel);
  138. static void ADC_ResetSupplyMonitoringChannel_TrustedCall(void);
  139. static void ADC_ResetSupplyMonitoringChannel(void);
  140. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  141. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  142. static void ADC_SetTriggerSourceSelect_TrustedCall(const uint32 Instance, const uint8 TriggerSource);
  143. static void ADC_SetTriggerSourceSelect(const uint32 Instance, const uint8 TriggerSource);
  144. static void ADC_SetPretriggerSourceSelect_TrustedCall(const uint32 Instance, const uint8 PretriggerSource);
  145. static void ADC_SetPretriggerSourceSelect(const uint32 Instance, const uint8 PretriggerSource);
  146. static void ADC_SetSoftwarePretrigger_TrustedCall(const uint32 Instance, const uint8 SoftwarePretrigger);
  147. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  148. #define ADC_STOP_SEC_CODE
  149. #include "Adc_MemMap.h"
  150. /*******************************************************************************
  151. * Variables
  152. ******************************************************************************/
  153. #define ADC_START_SEC_CONST_UNSPECIFIED
  154. #include "Adc_MemMap.h"
  155. /* Table of Base addresses for ADC instances. */
  156. static ADC_Type * const AdcBase[ADC_INSTANCE_COUNT] = IP_ADC_BASE_PTRS;
  157. #define ADC_STOP_SEC_CONST_UNSPECIFIED
  158. #include "Adc_MemMap.h"
  159. #define ADC_START_SEC_VAR_CLEARED_UNSPECIFIED
  160. #include "Adc_MemMap.h"
  161. /* Global state structure */
  162. static Adc_Ip_StateStructType AdcIpState[ADC_INSTANCE_COUNT];
  163. #define ADC_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  164. #include "Adc_MemMap.h"
  165. #define ADC_START_SEC_CODE
  166. #include "Adc_MemMap.h"
  167. /*FUNCTION**********************************************************************
  168. *
  169. * Function Name : Adc_DoCalibration_SetParams
  170. * Description : This function configures averaging, sample time, input clock and trigger
  171. * mode for Adc_Ip_DoCalibration service.
  172. *
  173. * END**************************************************************************/
  174. static inline void Adc_DoCalibration_SetParams(ADC_Type * const Base, const Adc_Ip_ClockConfigType * const Config, const Adc_Ip_TrigType TriggerMode);
  175. static inline void Adc_DoCalibration_SetParams(ADC_Type * const Base, const Adc_Ip_ClockConfigType * const Config, const Adc_Ip_TrigType TriggerMode)
  176. {
  177. /* Configure averaging */
  178. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_29();
  179. Adc_HwAcc_SetAveraging(Base, Config->AvgEn, Config->AvgSel);
  180. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_29();
  181. /* Configure trigger mode */
  182. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_24();
  183. Adc_HwAcc_SetTriggerMode(Base, TriggerMode);
  184. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_24();
  185. /* Configure sample time */
  186. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_15();
  187. Adc_HwAcc_SetSampleTime(Base, Config->SampleTime);
  188. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_15();
  189. /* Configure input clock */
  190. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_13();
  191. Adc_HwAcc_SetClock(Base, Config->ClockDivide, Config->InputClock);
  192. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_13();
  193. }
  194. /*FUNCTION**********************************************************************
  195. *
  196. * Function Name : Adc_Ip_Init
  197. * Description : This function initializes the ADC module by configuring all
  198. * available features.
  199. *
  200. * @implements Adc_Ip_Init_Activity
  201. * END**************************************************************************/
  202. void Adc_Ip_Init(const uint32 Instance, const Adc_Ip_ConfigType * const Config)
  203. {
  204. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  205. DevAssert(Instance < ADC_INSTANCE_COUNT);
  206. DevAssert(Config != NULL_PTR);
  207. DevAssert(Config->NumChannels <= ADC_MAX_CHAN_COUNT);
  208. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  209. ADC_Type * const Base = AdcBase[Instance];
  210. uint32 SC2Reg = 0u;
  211. uint32 SC2ClearMask = 0u;
  212. uint8 Index;
  213. Adc_HwAcc_SetClock(Base, Config->ClockDivide, Config->InputClock);
  214. Adc_HwAcc_SetSampleTime(Base, Config->SampleTime);
  215. Adc_HwAcc_SetAveraging(Base, Config->AvgEn, Config->AvgSel);
  216. Adc_Ip_SetResolution(Instance, Config->Resolution);
  217. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  218. ADC_SetTriggerSourceSelect(Instance, Config->TriggerSel);
  219. ADC_SetPretriggerSourceSelect(Instance, Config->PretriggerSel);
  220. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  221. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  222. if (Instance == 0U)
  223. {
  224. ADC_SetSupplyMonitoringEnable(Config->SupplyMonitoringEnable);
  225. }
  226. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  227. /* Configure trigger mode */
  228. SC2ClearMask |= ADC_SC2_ADTRG_MASK;
  229. SC2Reg |= ADC_SC2_ADTRG(Config->TriggerMode);
  230. /* Configure DMA enable */
  231. if (Config->DmaEnable)
  232. {
  233. SC2Reg |= ADC_SC2_DMAEN_MASK;
  234. }
  235. else
  236. {
  237. SC2ClearMask |= ADC_SC2_DMAEN_MASK;
  238. }
  239. /* Configure voltage reference selector */
  240. SC2ClearMask |= ADC_SC2_REFSEL_MASK;
  241. SC2Reg |= ADC_SC2_REFSEL(Config->VoltageRef);
  242. /* Configure compare enables and values */
  243. SC2ClearMask |= ADC_SC2_ACFE_MASK | ADC_SC2_ACFGT_MASK | ADC_SC2_ACREN_MASK;
  244. SC2Reg |= ADC_SC2_ACFE(Config->CompareEnable ? 1u : 0u);
  245. SC2Reg |= ADC_SC2_ACFGT(Config->CompareGreaterThanEnable ? 1u : 0u);
  246. SC2Reg |= ADC_SC2_ACREN(Config->CompareRangeFuncEnable ? 1u : 0u);
  247. Base->CV[0u] = ADC_CV_CV(Config->CompVal1);
  248. Base->CV[1u] = ADC_CV_CV(Config->CompVal2);
  249. Adc_HwAcc_SetSC2Reg(Base, SC2ClearMask, SC2Reg);
  250. Adc_HwAcc_SetUserGainAndOffset(Base, Config->UsrGain, Config->UsrOffset);
  251. Adc_Ip_SetContinuousMode(Instance, Config->ContinuousConvEnable);
  252. if (Config->ChannelConfigs != NULL_PTR)
  253. {
  254. for (Index = 0u; Index < Config->NumChannels; Index++)
  255. {
  256. Adc_Ip_ConfigChannel(Instance, &(Config->ChannelConfigs[Index]));
  257. }
  258. }
  259. AdcIpState[Instance].ConversionCompleteNotification = Config->ConversionCompleteNotification;
  260. AdcIpState[Instance].CalibrationClockDivide = Config->CalibrationClockDivide;
  261. AdcIpState[Instance].Init = TRUE;
  262. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  263. AdcIpState[Instance].PretriggerSel = Config->PretriggerSel;
  264. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  265. }
  266. /*FUNCTION**********************************************************************
  267. *
  268. * Function Name : Adc_Ip_DeInit
  269. * Description : This function resets the ADC internal registers to default values.
  270. *
  271. * @implements Adc_Ip_Deinit_Activity
  272. * END**************************************************************************/
  273. void Adc_Ip_DeInit(const uint32 Instance)
  274. {
  275. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  276. DevAssert(Instance < ADC_INSTANCE_COUNT);
  277. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  278. Adc_Ip_ConfigType DefaultConfig;
  279. Adc_Ip_ChanConfigType ChannelConfigs[ADC_MAX_CHAN_COUNT];
  280. uint8 Index;
  281. DefaultConfig.ClockDivide = ADC_IP_CLK_FULL_BUS;
  282. DefaultConfig.CalibrationClockDivide = ADC_IP_CLK_EIGHTH_BUS;
  283. DefaultConfig.InputClock = ADC_IP_CLK_ALT_1;
  284. DefaultConfig.SampleTime = ADC_IP_DEFAULT_SAMPLE_TIME;
  285. DefaultConfig.AvgEn = FALSE;
  286. DefaultConfig.AvgSel = ADC_IP_AVG_4_CONV;
  287. DefaultConfig.Resolution = ADC_IP_RESOLUTION_8BIT;
  288. DefaultConfig.TriggerMode = ADC_IP_TRIGGER_SOFTWARE;
  289. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  290. DefaultConfig.PretriggerSel = ADC_IP_PRETRIGGER_SEL_PDB;
  291. DefaultConfig.TriggerSel = ADC_IP_TRIGGER_SEL_PDB;
  292. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  293. DefaultConfig.DmaEnable = FALSE;
  294. DefaultConfig.VoltageRef = ADC_IP_VOLTAGEREF_VREF;
  295. DefaultConfig.ContinuousConvEnable = FALSE;
  296. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  297. DefaultConfig.SupplyMonitoringEnable = FALSE;
  298. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  299. DefaultConfig.CompareEnable = FALSE;
  300. DefaultConfig.CompareGreaterThanEnable = FALSE;
  301. DefaultConfig.CompareRangeFuncEnable = FALSE;
  302. DefaultConfig.CompVal1 = 0u;
  303. DefaultConfig.CompVal2 = 0u;
  304. DefaultConfig.UsrGain = ADC_IP_DEFAULT_USER_GAIN;
  305. DefaultConfig.UsrOffset = 0u;
  306. DefaultConfig.NumChannels = ADC_MAX_CHAN_COUNT;
  307. for (Index = 0u; Index < ADC_MAX_CHAN_COUNT; Index++)
  308. {
  309. ChannelConfigs[Index].ChnIdx = Index;
  310. ChannelConfigs[Index].Channel = ADC_IP_INPUTCHAN_DISABLED;
  311. ChannelConfigs[Index].InterruptEnable = FALSE;
  312. }
  313. DefaultConfig.ChannelConfigs = ChannelConfigs;
  314. DefaultConfig.ConversionCompleteNotification = NULL_PTR;
  315. Adc_Ip_Init(Instance, &DefaultConfig);
  316. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  317. if (Instance == 0U)
  318. {
  319. ADC_ResetSupplyMonitoringChannel();
  320. }
  321. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  322. AdcIpState[Instance].Init = FALSE;
  323. }
  324. /*FUNCTION**********************************************************************
  325. *
  326. * Function Name : Adc_Ip_SetAveraging
  327. * Description : This function enables averaging and selects the number of
  328. * conversions to average.
  329. * The mask parameter should be set using the Adc_Ip_AvgSelectType enum elements
  330. * that have the pattern ADC_IP_AVG_... e.g. ADC_IP_AVG_4_CONV.
  331. *
  332. * @implements Adc_Ip_SetAveraging_Activity
  333. * END**************************************************************************/
  334. void Adc_Ip_SetAveraging(const uint32 Instance, const boolean AvgEn, const Adc_Ip_AvgSelectType AvgSel)
  335. {
  336. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  337. DevAssert(Instance < ADC_INSTANCE_COUNT);
  338. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  339. ADC_Type * const Base = AdcBase[Instance];
  340. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_27();
  341. Adc_HwAcc_SetAveraging(Base, AvgEn, AvgSel);
  342. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_27();
  343. }
  344. /*FUNCTION**********************************************************************
  345. *
  346. * Function Name : Adc_Ip_SetSampleTime
  347. * Description : This function sets the sample time for selected ADC instance.
  348. *
  349. * @implements Adc_Ip_SetSampleTime_Activity
  350. * END**************************************************************************/
  351. void Adc_Ip_SetSampleTime(const uint32 Instance, const uint8 SampleTime)
  352. {
  353. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  354. DevAssert(Instance < ADC_INSTANCE_COUNT);
  355. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  356. ADC_Type * const Base = AdcBase[Instance];
  357. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_16();
  358. Adc_HwAcc_SetSampleTime(Base, SampleTime);
  359. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_16();
  360. }
  361. /*FUNCTION**********************************************************************
  362. *
  363. * Function Name : Adc_Ip_EnableDma
  364. * Description : This function enables DMA.
  365. *
  366. * @implements Adc_Ip_EnableDma_Activity
  367. * END**************************************************************************/
  368. void Adc_Ip_EnableDma(const uint32 Instance)
  369. {
  370. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  371. DevAssert(Instance < ADC_INSTANCE_COUNT);
  372. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  373. ADC_Type * const Base = AdcBase[Instance];
  374. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_26();
  375. Base->SC2 |= ADC_SC2_DMAEN_MASK;
  376. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_26();
  377. }
  378. /*FUNCTION**********************************************************************
  379. *
  380. * Function Name : Adc_Ip_DisableDma
  381. * Description : This function disables DMA.
  382. *
  383. * @implements Adc_Ip_DisableDma_Activity
  384. * END**************************************************************************/
  385. void Adc_Ip_DisableDma(const uint32 Instance)
  386. {
  387. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  388. DevAssert(Instance < ADC_INSTANCE_COUNT);
  389. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  390. ADC_Type * const Base = AdcBase[Instance];
  391. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_22();
  392. Base->SC2 &= ~(ADC_SC2_DMAEN_MASK);
  393. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_22();
  394. }
  395. /*FUNCTION**********************************************************************
  396. *
  397. * Function Name : Adc_Ip_SetTriggerMode
  398. * Description : This function enables either hardware or software trigger.
  399. *
  400. * @implements Adc_Ip_SetTriggerMode_Activity
  401. * END**************************************************************************/
  402. void Adc_Ip_SetTriggerMode(const uint32 Instance, const Adc_Ip_TrigType TriggerMode)
  403. {
  404. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  405. DevAssert(Instance < ADC_INSTANCE_COUNT);
  406. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  407. ADC_Type * const Base = AdcBase[Instance];
  408. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_23();
  409. Adc_HwAcc_SetTriggerMode(Base, TriggerMode);
  410. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_23();
  411. }
  412. /*FUNCTION**********************************************************************
  413. *
  414. * Function Name : Adc_Ip_SetContinuousMode
  415. * Description : This function switches between ADC continuous conversion mode
  416. * and one shot mode.
  417. *
  418. * @implements Adc_Ip_SetContinuousMode_Activity
  419. * END**************************************************************************/
  420. void Adc_Ip_SetContinuousMode(const uint32 Instance, const boolean ContinuousModeEnable)
  421. {
  422. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  423. DevAssert(Instance < ADC_INSTANCE_COUNT);
  424. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  425. ADC_Type * const Base = AdcBase[Instance];
  426. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_30();
  427. uint32 Sc3Reg = Base->SC3;
  428. Sc3Reg &= ~(ADC_SC3_ADCO_MASK);
  429. Sc3Reg |= ADC_SC3_ADCO(ContinuousModeEnable ? 1u : 0u);
  430. Base->SC3 = Sc3Reg;
  431. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_30();
  432. }
  433. /*FUNCTION**********************************************************************
  434. *
  435. * Function Name : Adc_Ip_SetResolution
  436. * Description : This function sets ADC module resolution.
  437. *
  438. * @implements Adc_Ip_SetResolution_Activity
  439. * END**************************************************************************/
  440. void Adc_Ip_SetResolution(const uint32 Instance, const Adc_Ip_ResolutionType Resolution)
  441. {
  442. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  443. DevAssert(Instance < ADC_INSTANCE_COUNT);
  444. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  445. ADC_Type * const Base = AdcBase[Instance];
  446. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_10();
  447. uint32 Cfg1Reg = Base->CFG1;
  448. Cfg1Reg &= ~(ADC_CFG1_MODE_MASK);
  449. Cfg1Reg |= ADC_CFG1_MODE(Resolution);
  450. Base->CFG1 = Cfg1Reg;
  451. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_10();
  452. }
  453. /*FUNCTION**********************************************************************
  454. *
  455. * Function Name : Adc_Ip_SetClockMode
  456. * Description : This function initializes the ADC clock configuration.
  457. *
  458. * @implements Adc_Ip_SetClockMode_Activity
  459. * END**************************************************************************/
  460. void Adc_Ip_SetClockMode(const uint32 Instance, const Adc_Ip_ClockConfigType * const Config)
  461. {
  462. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  463. DevAssert(Instance < ADC_INSTANCE_COUNT);
  464. DevAssert(Config != NULL_PTR);
  465. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  466. ADC_Type * const Base = AdcBase[Instance];
  467. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_11();
  468. Adc_HwAcc_SetClock(Base, Config->ClockDivide, Config->InputClock);
  469. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_11();
  470. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_14();
  471. Adc_HwAcc_SetSampleTime(Base, Config->SampleTime);
  472. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_14();
  473. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_28();
  474. Adc_HwAcc_SetAveraging(Base, Config->AvgEn, Config->AvgSel);
  475. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_28();
  476. }
  477. /*FUNCTION**********************************************************************
  478. *
  479. * Function Name : Adc_Ip_ConfigChannel
  480. * Description : Configures the selected control channel with the given
  481. * configuration structure.
  482. *
  483. * When Software Trigger mode is enabled, configuring control channel index 0,
  484. * implicitly triggers a new conversion on the selected ADC input channel.
  485. * Therefore, Adc_Ip_ConfigChannel can be used for sw-triggering conversions.
  486. *
  487. * Configuring any control channel while it is actively controlling a conversion
  488. * (sw or hw triggered) will implicitly abort the on-going conversion.
  489. *
  490. * @implements Adc_Ip_ConfigChannel_Activity
  491. * END**************************************************************************/
  492. void Adc_Ip_ConfigChannel(const uint32 Instance, const Adc_Ip_ChanConfigType * const ChanConfig)
  493. {
  494. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  495. DevAssert(Instance < ADC_INSTANCE_COUNT);
  496. DevAssert(ChanConfig != NULL_PTR);
  497. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  498. DevAssert((Instance == 0u) || ((uint32)ChanConfig->Channel < (uint32)ADC_IP_INPUTCHAN_SUPPLY_VDD));
  499. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  500. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  501. ADC_Type * const Base = AdcBase[Instance];
  502. Adc_Ip_InputChannelType InputChanDemapped;
  503. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  504. /* Internal supply monitor channels need special configuration */
  505. if (ChanConfig->Channel >= ADC_IP_INPUTCHAN_SUPPLY_VDD)
  506. {
  507. /* De-map ADC_IP_INPUTCHAN_SUPPLY_ into actual index. */
  508. const uint32 SupplyChannel = (uint32)ChanConfig->Channel - (uint32)ADC_IP_INPUTCHAN_SUPPLY_VDD;
  509. ADC_ConfigSupplyMonitoringChannel(SupplyChannel);
  510. /* Supply monitor channels are measured on ADC internal input channel 0 */
  511. InputChanDemapped = ADC_IP_INPUTCHAN_INT0;
  512. }
  513. else
  514. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  515. {
  516. InputChanDemapped = ChanConfig->Channel;
  517. }
  518. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_21();
  519. Adc_HwAcc_SetChannel(Base, ChanConfig->ChnIdx, InputChanDemapped, ChanConfig->InterruptEnable);
  520. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_21();
  521. /* Also update in state structure */
  522. AdcIpState[Instance].ChannelConfig[ChanConfig->ChnIdx] = ChanConfig->Channel;
  523. }
  524. /*FUNCTION**********************************************************************
  525. *
  526. * Function Name : Adc_Ip_SetDisabledChannel
  527. * Description : This function sets the input channel of the selected control
  528. * channel to ADC_IP_INPUTCHAN_DISABLED. If WithTimeout is TRUE then the
  529. * function will also wait for the register to be updated.
  530. * Note: the control channel index is the numeric index of SC1x
  531. * (e.g. SC1A has index 0), not the input channel.
  532. *
  533. * @implements Adc_Ip_SetDisabledChannel_Activity
  534. * END**************************************************************************/
  535. Adc_Ip_StatusType Adc_Ip_SetDisabledChannel(const uint32 Instance, const uint8 ControlChanIdx, const boolean WithTimeout)
  536. {
  537. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  538. DevAssert(Instance < ADC_INSTANCE_COUNT);
  539. DevAssert(ControlChanIdx < ADC_MAX_CHAN_COUNT);
  540. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  541. ADC_Type * const Base = AdcBase[Instance];
  542. Adc_Ip_StatusType Status = ADC_IP_STATUS_SUCCESS;
  543. uint32 TimeoutTicks = OsIf_MicrosToTicks(ADC_IP_TIMEOUT_VAL, ADC_IP_TIMEOUT_TYPE);
  544. uint32 CurrentTicks = OsIf_GetCounter(ADC_IP_TIMEOUT_TYPE);
  545. uint32 ElapsedTicks = 0u;
  546. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_17();
  547. /* Set input channel select to disabled */
  548. SC1(Base, ControlChanIdx) |= ADC_SC1_ADCH_MASK;
  549. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_17();
  550. if (WithTimeout == TRUE)
  551. {
  552. while (((SC1(Base, ControlChanIdx) & ADC_SC1_ADCH_MASK) != ADC_SC1_ADCH_MASK) && (ElapsedTicks < TimeoutTicks))
  553. {
  554. ElapsedTicks += OsIf_GetElapsed(&CurrentTicks, ADC_IP_TIMEOUT_TYPE);
  555. }
  556. if (ElapsedTicks >= TimeoutTicks)
  557. {
  558. Status = ADC_IP_STATUS_TIMEOUT;
  559. }
  560. }
  561. return Status;
  562. }
  563. /*FUNCTION**********************************************************************
  564. *
  565. * Function Name : Adc_Ip_StartConversion
  566. * Description : This function starts a software conversion on the selected
  567. * input channel by writing the given values to the SC1A register.
  568. * The result can be read with Adc_Ip_GetConvData with index 0.
  569. * Note: hardware configuration on the control channel with index 0 will be
  570. * overwritten.
  571. * Note: this will not work if hardware triggered mode is selected.
  572. *
  573. * @implements Adc_Ip_StartConversion_Activity
  574. * END**************************************************************************/
  575. void Adc_Ip_StartConversion(const uint32 Instance, Adc_Ip_InputChannelType InputChannel, const boolean InterruptEnable)
  576. {
  577. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  578. DevAssert(Instance < ADC_INSTANCE_COUNT);
  579. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  580. ADC_Type * const Base = AdcBase[Instance];
  581. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_18();
  582. /* Configure SC1A register */
  583. Adc_HwAcc_SetChannel(Base, 0u, InputChannel, InterruptEnable);
  584. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_18();
  585. }
  586. /*FUNCTION**********************************************************************
  587. *
  588. * Function Name : Adc_Ip_GetConvActiveFlag
  589. * Description : Reads and return conversion active flag status.
  590. *
  591. * @implements Adc_Ip_GetConvActiveFlag_Activity
  592. * END**************************************************************************/
  593. boolean Adc_Ip_GetConvActiveFlag(const uint32 Instance)
  594. {
  595. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  596. DevAssert(Instance < ADC_INSTANCE_COUNT);
  597. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  598. const ADC_Type * const Base = AdcBase[Instance];
  599. uint32 Sc2Reg = Base->SC2;
  600. Sc2Reg = (Sc2Reg & ADC_SC2_ADACT_MASK) >> ADC_SC2_ADACT_SHIFT;
  601. return (Sc2Reg != 0u) ? TRUE : FALSE;
  602. }
  603. /*FUNCTION**********************************************************************
  604. *
  605. * Function Name : Adc_Ip_GetChanInterrupt
  606. * Description : This function checks and returns if the selected control
  607. * channel has the interrupt flag set.
  608. *
  609. * @implements Adc_Ip_GetChanInterrupt_Activity
  610. * END**************************************************************************/
  611. boolean Adc_Ip_GetChanInterrupt(const uint32 Instance, const uint8 ControlChanIdx)
  612. {
  613. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  614. DevAssert(Instance < ADC_INSTANCE_COUNT);
  615. DevAssert(ControlChanIdx < ADC_MAX_CHAN_COUNT);
  616. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  617. const ADC_Type * const Base = AdcBase[Instance];
  618. const uint32 Sc1Reg = SC1(Base, ControlChanIdx);
  619. return Adc_HwAcc_GetAIEN(Sc1Reg);
  620. }
  621. /*FUNCTION**********************************************************************
  622. *
  623. * Function Name : Adc_Ip_GetConvCompleteFlag
  624. * Description : This function returns the value of the conversion
  625. * complete(COCO) flag of a given channel.
  626. *
  627. * @implements Adc_Ip_GetConvCompleteFlag_Activity
  628. * END**************************************************************************/
  629. boolean Adc_Ip_GetConvCompleteFlag(const uint32 Instance, const uint8 ControlChanIdx)
  630. {
  631. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  632. DevAssert(Instance < ADC_INSTANCE_COUNT);
  633. DevAssert(ControlChanIdx < ADC_MAX_CHAN_COUNT);
  634. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  635. const ADC_Type * const Base = AdcBase[Instance];
  636. const uint32 Sc1Reg = SC1(Base, ControlChanIdx);
  637. return Adc_HwAcc_GetCOCO(Sc1Reg);
  638. }
  639. /*FUNCTION**********************************************************************
  640. *
  641. * Function Name : Adc_Ip_GetConvData
  642. * Description : This function retrieves the last conversion result for the
  643. * selected control channel. This function does no validity check on the result.
  644. * In order to check if the result is valid, the user must call
  645. * Adc_Ip_GetConvCompleteFlag function before this one.
  646. *
  647. * @implements Adc_Ip_GetConvData_Activity
  648. * END**************************************************************************/
  649. uint16 Adc_Ip_GetConvData(const uint32 Instance, const uint8 ControlChanIdx)
  650. {
  651. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  652. DevAssert(Instance < ADC_INSTANCE_COUNT);
  653. DevAssert(ControlChanIdx < ADC_MAX_CHAN_COUNT);
  654. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  655. const ADC_Type * const Base = AdcBase[Instance];
  656. return Adc_HwAcc_GetData(Base, ControlChanIdx);
  657. }
  658. /*FUNCTION**********************************************************************
  659. *
  660. * Function Name : Adc_Ip_DoCalibration
  661. * Description : This function performs a calibration of the ADC. The input
  662. * clock frequency for calibration must be less than or equal to half of the maximum
  663. * specified frequency (50Mhz) and greater than minimum specified frequency (20Mhz).
  664. *
  665. * @implements Adc_Ip_DoCalibration_Activity
  666. * END**************************************************************************/
  667. Adc_Ip_StatusType Adc_Ip_DoCalibration(const uint32 Instance)
  668. {
  669. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  670. DevAssert(Instance < ADC_INSTANCE_COUNT);
  671. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  672. ADC_Type * const Base = AdcBase[Instance];
  673. Adc_Ip_StatusType Status = ADC_IP_STATUS_SUCCESS;
  674. Adc_Ip_TrigType TriggerMode;
  675. uint32 TimeoutTicks = OsIf_MicrosToTicks(ADC_IP_TIMEOUT_VAL, ADC_IP_TIMEOUT_TYPE);
  676. uint32 CurrentTicks = OsIf_GetCounter(ADC_IP_TIMEOUT_TYPE);
  677. uint32 ElapsedTicks = 0u;
  678. uint32 Reg;
  679. Adc_Ip_ClockConfigType PreClockConfig;
  680. Adc_Ip_ClockConfigType CalClockConfig;
  681. /* Store settings before calibration */
  682. Reg = Base->SC3;
  683. PreClockConfig.AvgEn = ((Reg & ADC_SC3_AVGE_MASK) != 0u) ? TRUE : FALSE;
  684. PreClockConfig.AvgSel = Adc_HwAcc_GetAverageSelect(Reg);
  685. Reg = Base->CFG2;
  686. PreClockConfig.SampleTime = (uint8) ((Reg & ADC_CFG2_SMPLTS_MASK) >> ADC_CFG2_SMPLTS_SHIFT);
  687. TriggerMode = Adc_HwAcc_GetTriggerMode(Base->SC2);
  688. Reg = Base->CFG1;
  689. PreClockConfig.ClockDivide = Adc_HwAcc_GetClockDivide(Reg);
  690. PreClockConfig.InputClock = Adc_HwAcc_GetInputClock(Reg);
  691. CalClockConfig.AvgEn = TRUE;
  692. CalClockConfig.AvgSel = ADC_IP_AVG_32_CONV;
  693. CalClockConfig.SampleTime = ADC_IP_DEFAULT_SAMPLE_TIME;
  694. CalClockConfig.ClockDivide = AdcIpState[Instance].CalibrationClockDivide;
  695. CalClockConfig.InputClock = PreClockConfig.InputClock;
  696. /* Prepare required settings for calibration. */
  697. Adc_DoCalibration_SetParams(Base, &CalClockConfig, ADC_IP_TRIGGER_SOFTWARE);
  698. Base->CLPS = 0u;
  699. Base->CLP3 = 0u;
  700. Base->CLP2 = 0u;
  701. Base->CLP1 = 0u;
  702. Base->CLP0 = 0u;
  703. Base->CLPX = 0u;
  704. Base->CLP9 = 0u;
  705. /* Start calibration by writing to the calibration field */
  706. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_29();
  707. Reg = Base->SC3;
  708. Reg &= ~(ADC_SC3_CAL_MASK);
  709. Reg |= ADC_SC3_CAL(1u);
  710. Base->SC3 = Reg;
  711. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_29();
  712. /* Wait for the calibration to finish */
  713. while (((Base->SC3 & ADC_SC3_CAL_MASK) != 0u) && (ElapsedTicks < TimeoutTicks))
  714. {
  715. ElapsedTicks += OsIf_GetElapsed(&CurrentTicks, ADC_IP_TIMEOUT_TYPE);
  716. }
  717. if (ElapsedTicks >= TimeoutTicks)
  718. {
  719. Status = ADC_IP_STATUS_TIMEOUT;
  720. }
  721. /* Revert settings as same as before calibration. */
  722. Adc_DoCalibration_SetParams(Base, &PreClockConfig, TriggerMode);
  723. /* Clear COCO flag */
  724. (void) R(Base, 0u);
  725. return Status;
  726. }
  727. /*FUNCTION**********************************************************************
  728. *
  729. * Function Name : Adc_Ip_ClearLatchedTriggers
  730. * Description : This function clears all trigger latched flags of the ADC instance.
  731. * This function must be called after the hardware trigger source for the ADC
  732. * has been deactivated.
  733. *
  734. * @implements Adc_Ip_ClearLatchedTriggers_Activity
  735. * END**************************************************************************/
  736. Adc_Ip_StatusType Adc_Ip_ClearLatchedTriggers(const uint32 Instance)
  737. {
  738. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  739. DevAssert(Instance < ADC_INSTANCE_COUNT);
  740. DevAssert(Instance != 0u);
  741. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  742. ADC_Type * const Base = AdcBase[Instance];
  743. Adc_Ip_StatusType Status = ADC_IP_STATUS_SUCCESS;
  744. uint32 TimeoutTicks = OsIf_MicrosToTicks(ADC_IP_TIMEOUT_VAL, ADC_IP_TIMEOUT_TYPE);
  745. uint32 CurrentTicks = OsIf_GetCounter(ADC_IP_TIMEOUT_TYPE);
  746. uint32 ElapsedTicks = 0u;
  747. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_12();
  748. /* Write bit to clear latched triggers */
  749. Base->CFG1 |= ADC_CFG1_CLRLTRG(0x01u);
  750. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_12();
  751. /* Wait for latched triggers to be cleared */
  752. while (((Base->SC2 & ADC_SC2_TRGSTLAT_MASK) != 0u) && (ElapsedTicks < TimeoutTicks))
  753. {
  754. ElapsedTicks += OsIf_GetElapsed(&CurrentTicks, ADC_IP_TIMEOUT_TYPE);
  755. }
  756. if (ElapsedTicks >= TimeoutTicks)
  757. {
  758. Status = ADC_IP_STATUS_TIMEOUT;
  759. }
  760. return Status;
  761. }
  762. /*FUNCTION**********************************************************************
  763. *
  764. * Function Name : Adc_Ip_EnableChannelNotification
  765. * Description : This function enables the notification for the selected channel.
  766. * Note : It's required to read result data in user notification in order to clear the COCO flags and avoid ISR getting invoked repeatedly
  767. *
  768. * @implements Adc_Ip_EnableChannelNotification_Activity
  769. * END**************************************************************************/
  770. void Adc_Ip_EnableChannelNotification(const uint32 Instance, const uint8 ControlChanIdx)
  771. {
  772. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  773. DevAssert(Instance < ADC_INSTANCE_COUNT);
  774. DevAssert(ControlChanIdx < ADC_MAX_CHAN_COUNT);
  775. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  776. ADC_Type * const Base = AdcBase[Instance];
  777. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_19();
  778. SC1(Base, ControlChanIdx) |= ADC_SC1_AIEN_MASK;
  779. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_19();
  780. }
  781. /*FUNCTION**********************************************************************
  782. *
  783. * Function Name : Adc_Ip_DisableChannelNotification
  784. * Description : This function disables the notification for the selected channel.
  785. *
  786. * @implements Adc_Ip_DisableChannelNotification_Activity
  787. * END**************************************************************************/
  788. void Adc_Ip_DisableChannelNotification(const uint32 Instance, const uint8 ControlChanIdx)
  789. {
  790. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  791. DevAssert(Instance < ADC_INSTANCE_COUNT);
  792. DevAssert(ControlChanIdx < ADC_MAX_CHAN_COUNT);
  793. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  794. ADC_Type * const Base = AdcBase[Instance];
  795. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_20();
  796. SC1(Base, ControlChanIdx) &= ~(ADC_SC1_AIEN_MASK);
  797. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_20();
  798. }
  799. /*FUNCTION**********************************************************************
  800. *
  801. * Function Name : Adc_Ip_ClearTrigErrReg
  802. * Description : This function clears all trigger error flags of the ADC instance.
  803. *
  804. * @implements Adc_Ip_ClearTrigErrReg_Activity
  805. * END**************************************************************************/
  806. void Adc_Ip_ClearTrigErrReg(const uint32 Instance)
  807. {
  808. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  809. DevAssert(Instance < ADC_INSTANCE_COUNT);
  810. DevAssert(Instance != 0u);
  811. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  812. ADC_Type * const Base = AdcBase[Instance];
  813. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_25();
  814. Base->SC2 |= ADC_SC2_TRGSTERR_MASK;
  815. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_25();
  816. }
  817. /*FUNCTION**********************************************************************
  818. *
  819. * Function Name : Adc_Ip_GetTrigErrReg
  820. * Description : This function returns all trigger error flags of the ADC instance.
  821. *
  822. * @implements Adc_Ip_GetTrigErrReg_Activity
  823. * END**************************************************************************/
  824. uint32 Adc_Ip_GetTrigErrReg(const uint32 Instance)
  825. {
  826. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  827. DevAssert(Instance < ADC_INSTANCE_COUNT);
  828. DevAssert(Instance != 0u);
  829. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  830. const ADC_Type * const Base = AdcBase[Instance];
  831. return (Base->SC2 & ADC_SC2_TRGSTERR_MASK) >> ADC_SC2_TRGSTERR_SHIFT;
  832. }
  833. /*FUNCTION*********************************************************************
  834. *
  835. * Function Name : Adc_Ip_GetDataAddress
  836. * Description : Returns the address of the specified Rn register.
  837. *
  838. * @implements Adc_Ip_GetDataAddress_Activity
  839. *END*************************************************************************/
  840. uint32 Adc_Ip_GetDataAddress(const uint32 Instance, const uint8 Index)
  841. {
  842. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  843. DevAssert(Instance < ADC_INSTANCE_COUNT);
  844. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  845. return (uint32)&(R(AdcBase[Instance], Index));
  846. }
  847. /*FUNCTION**********************************************************************
  848. *
  849. * Function Name : Adc_Ip_GetChanData
  850. * Description : This function retrieves the last conversion result for the
  851. * selected input channel, by looking which control channel was configured
  852. * with it. If multiple control channels are configured simultaneously with
  853. * the same requested input channel, the result of the first control channel
  854. * found will be returned. If no control channel is configured with the given
  855. * input channel then ADC_IP_STATUS_ERROR will be returned.
  856. * This function does no validity check on the result.
  857. * In order to check if the result is valid, the user must call
  858. * Adc_Ip_GetConvCompleteFlag function before this one.
  859. *
  860. * @implements Adc_Ip_GetChanData_Activity
  861. * END**************************************************************************/
  862. Adc_Ip_StatusType Adc_Ip_GetChanData(const uint32 Instance, const Adc_Ip_InputChannelType Channel, uint16 * const Result)
  863. {
  864. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  865. DevAssert(Instance < ADC_INSTANCE_COUNT);
  866. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  867. DevAssert((Instance == 0u) || ((uint32)Channel < (uint32)ADC_IP_INPUTCHAN_SUPPLY_VDD));
  868. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  869. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  870. const ADC_Type * const Base = AdcBase[Instance];
  871. Adc_Ip_StatusType Status = ADC_IP_STATUS_SUCCESS;
  872. uint16 Temp = 0u;
  873. uint8 ControlChanIdx;
  874. boolean Found = FALSE;
  875. for (ControlChanIdx = 0u; ControlChanIdx < ADC_MAX_CHAN_COUNT; ControlChanIdx++)
  876. {
  877. if (AdcIpState[Instance].ChannelConfig[ControlChanIdx] == Channel)
  878. {
  879. Found = TRUE;
  880. break;
  881. }
  882. }
  883. if (Found == TRUE)
  884. {
  885. Temp = (uint16) R(Base, ControlChanIdx);
  886. Temp = (uint16) ((Temp & ADC_R_D_MASK) >> ADC_R_D_SHIFT);
  887. }
  888. else
  889. {
  890. Status = ADC_IP_STATUS_ERROR;
  891. }
  892. *Result = Temp;
  893. return Status;
  894. }
  895. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  896. /*FUNCTION**********************************************************************
  897. *
  898. * Function Name : Adc_Ip_SetSoftwarePretrigger
  899. * Description : This function sets the software pretrigger source for
  900. * an ADC instance.
  901. *
  902. * @implements Adc_Ip_SetSoftwarePretrigger_Activity
  903. * END**************************************************************************/
  904. void Adc_Ip_SetSoftwarePretrigger(const uint32 Instance, const Adc_Ip_SoftwarePretriggerType SoftwarePretrigger)
  905. {
  906. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  907. DevAssert(Instance < ADC_INSTANCE_COUNT);
  908. /* If SW Pretrigger Select is not enabled, the SW pretriggers will be ignored by ADC. */
  909. DevAssert(AdcIpState[Instance].PretriggerSel == ADC_IP_PRETRIGGER_SEL_SW);
  910. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  911. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  912. OsIf_Trusted_Call2params(ADC_SetSoftwarePretrigger_TrustedCall, Instance, (uint8)SoftwarePretrigger);
  913. #else
  914. ADC_SetSoftwarePretrigger_TrustedCall(Instance, (uint8)SoftwarePretrigger);
  915. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  916. }
  917. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  918. /*FUNCTION*********************************************************************
  919. *
  920. * Function Name : Adc_Ip_IRQHandler
  921. * Description : Handles Adc interrupts.
  922. * Note : It's required to read result data in user notification in order to clear the COCO flags and avoid ISR getting invoked repeatedly
  923. *
  924. * @implements Adc_Ip_IRQHandler_Activity
  925. *END*************************************************************************/
  926. /* The IAR build wants to see function prototypes */
  927. void Adc_Ip_IRQHandler(const uint32 Instance);
  928. void Adc_Ip_IRQHandler(const uint32 Instance)
  929. {
  930. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  931. DevAssert(Instance < ADC_INSTANCE_COUNT);
  932. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  933. const ADC_Type * const Base = AdcBase[Instance];
  934. uint32 Sc1Reg;
  935. uint8 ControlChanIdx;
  936. boolean ChanIntFlag = FALSE;
  937. boolean ChanCocoFlag = FALSE;
  938. /* NOTE: CPR_RTD_00028 wasn't fulfilled in because ISR cannot distinguish if an interrupt is spurious or if conversion was initiated on purpose with AIEN = 0
  939. * The reasons are:
  940. * - There is a single interrupt line for all COCO flags
  941. * - It is a valid usecase to have COCO flag set but AIEN=0 (e.g. in HLD only interrupt for last channel in group is enabled)
  942. * - Clearing of COCO flag is only done by reading the result register - COCO is not w1c
  943. */
  944. /* Check if the Adc unit is initialized and if the interrupt is not NULL
  945. * first since all channels use the same callback */
  946. if ((AdcIpState[Instance].Init == TRUE) &&
  947. (AdcIpState[Instance].ConversionCompleteNotification != NULL_PTR))
  948. {
  949. for (ControlChanIdx = 0u; ControlChanIdx < ADC_MAX_CHAN_COUNT; ControlChanIdx++)
  950. {
  951. Sc1Reg = SC1(Base, ControlChanIdx);
  952. ChanIntFlag = Adc_HwAcc_GetAIEN(Sc1Reg);
  953. ChanCocoFlag = Adc_HwAcc_GetCOCO(Sc1Reg);
  954. /* Check if the interrupt was spurrios by checking if the interrupt
  955. * is enabled and equivalent conversion has finished */
  956. if ((TRUE == ChanIntFlag) && (TRUE == ChanCocoFlag))
  957. {
  958. AdcIpState[Instance].ConversionCompleteNotification(ControlChanIdx);
  959. }
  960. else if ((ADC_IP_INPUTCHAN_DISABLED == AdcIpState[Instance].ChannelConfig[ControlChanIdx]) && (TRUE == ChanCocoFlag))
  961. {
  962. /* This will only clear the obvious spurious COCO flags. If the flag will be spuriously set on active channels it will not be caught by this. */
  963. (void)Adc_HwAcc_GetData(Base, ControlChanIdx);
  964. }
  965. else
  966. {
  967. ; /* Empty else branch to avoid MISRA */
  968. }
  969. }
  970. }
  971. else
  972. {
  973. for (ControlChanIdx = 0u; ControlChanIdx < ADC_MAX_CHAN_COUNT; ControlChanIdx++)
  974. {
  975. /* Do a dummy read to clear the COCO flags */
  976. (void)Adc_HwAcc_GetData(Base, ControlChanIdx);
  977. }
  978. }
  979. }
  980. #if (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON)
  981. static void ADC_SetSupplyMonitoringEnable_TrustedCall(const boolean SupplyEnable)
  982. {
  983. /* Set or clear ADC_SUPPLY field of CHIPCTL register from SIM based on SupplyEnable */
  984. if (SupplyEnable == TRUE)
  985. {
  986. IP_SIM->CHIPCTL |= SIM_CHIPCTL_ADC_SUPPLYEN_MASK;
  987. }
  988. else
  989. {
  990. IP_SIM->CHIPCTL &= ~SIM_CHIPCTL_ADC_SUPPLYEN_MASK;
  991. }
  992. }
  993. /*FUNCTION**********************************************************************
  994. *
  995. * Function Name : ADC_SetSupplyMonitoringEnable
  996. * Description : This function enable supply monitoring for the internal channels
  997. * on SIM registers
  998. *
  999. * END**************************************************************************/
  1000. static void ADC_SetSupplyMonitoringEnable(const boolean SupplyEnable)
  1001. {
  1002. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  1003. OsIf_Trusted_Call1param(ADC_SetSupplyMonitoringEnable_TrustedCall, SupplyEnable);
  1004. #else
  1005. ADC_SetSupplyMonitoringEnable_TrustedCall(SupplyEnable);
  1006. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  1007. }
  1008. static void ADC_ConfigSupplyMonitoringChannel_TrustedCall(const uint32 SupplyChannel)
  1009. {
  1010. #if (ADC_IP_DEV_ERROR_DETECT == STD_ON)
  1011. DevAssert((IP_SIM->CHIPCTL & SIM_CHIPCTL_ADC_SUPPLYEN_MASK) != 0UL);
  1012. #endif /* (ADC_IP_DEV_ERROR_DETECT == STD_ON) */
  1013. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_32();
  1014. uint32 Reg = IP_SIM->CHIPCTL;
  1015. Reg &= ~SIM_CHIPCTL_ADC_SUPPLY_MASK;
  1016. Reg |= SIM_CHIPCTL_ADC_SUPPLY(SupplyChannel);
  1017. IP_SIM->CHIPCTL = Reg;
  1018. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_32();
  1019. }
  1020. /*FUNCTION**********************************************************************
  1021. *
  1022. * Function Name : ADC_ConfigSupplyMonitoringChannel
  1023. * Description : This function configures the internal channels on on SIM registers
  1024. *
  1025. * END**************************************************************************/
  1026. static void ADC_ConfigSupplyMonitoringChannel(const uint32 SupplyChannel)
  1027. {
  1028. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  1029. OsIf_Trusted_Call1param(ADC_ConfigSupplyMonitoringChannel_TrustedCall, SupplyChannel);
  1030. #else
  1031. ADC_ConfigSupplyMonitoringChannel_TrustedCall(SupplyChannel);
  1032. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  1033. }
  1034. static void ADC_ResetSupplyMonitoringChannel_TrustedCall(void)
  1035. {
  1036. /* Clear ADC supply mask from CHIPCTL of SIM register */
  1037. IP_SIM->CHIPCTL &= ~SIM_CHIPCTL_ADC_SUPPLY_MASK;
  1038. }
  1039. /*FUNCTION**********************************************************************
  1040. *
  1041. * Function Name : ADC_ResetSupplyMonitoringChannel
  1042. * Description : This function resets the muxing for ADC channel on SIM register to reset value
  1043. *
  1044. * END**************************************************************************/
  1045. static void ADC_ResetSupplyMonitoringChannel(void)
  1046. {
  1047. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  1048. OsIf_Trusted_Call(ADC_ResetSupplyMonitoringChannel_TrustedCall);
  1049. #else
  1050. ADC_ResetSupplyMonitoringChannel_TrustedCall();
  1051. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  1052. }
  1053. #endif /* (ADC_IP_SUPPLY_MONITORING_ENABLED == STD_ON) */
  1054. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  1055. /*FUNCTION**********************************************************************
  1056. *
  1057. * Function Name : ADC_SetTriggerSourceSelect
  1058. * Description : This function selects trigger source for an ADC instance
  1059. *
  1060. * END**************************************************************************/
  1061. static void ADC_SetTriggerSourceSelect(const uint32 Instance, const uint8 TriggerSource)
  1062. {
  1063. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  1064. OsIf_Trusted_Call2params(ADC_SetTriggerSourceSelect_TrustedCall, Instance, TriggerSource);
  1065. #else
  1066. ADC_SetTriggerSourceSelect_TrustedCall(Instance, TriggerSource);
  1067. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  1068. }
  1069. static void ADC_SetTriggerSourceSelect_TrustedCall(const uint32 Instance, const uint8 TriggerSource)
  1070. {
  1071. uint32 Reg = (uint32)IP_SIM->ADCOPT;
  1072. #if (ADC_INSTANCE_COUNT > 1u)
  1073. switch (Instance)
  1074. {
  1075. case 0u:
  1076. {
  1077. #endif /* (ADC_INSTANCE_COUNT > 1u) */
  1078. Reg &= ~SIM_ADCOPT_ADC0TRGSEL_MASK;
  1079. Reg |= SIM_ADCOPT_ADC0TRGSEL(TriggerSource);
  1080. #if (ADC_INSTANCE_COUNT > 1u)
  1081. break;
  1082. }
  1083. case 1u:
  1084. {
  1085. Reg &= ~SIM_ADCOPT_ADC1TRGSEL_MASK;
  1086. Reg |= SIM_ADCOPT_ADC1TRGSEL(TriggerSource);
  1087. break;
  1088. }
  1089. default:
  1090. {
  1091. ; /* no-op */
  1092. break;
  1093. }
  1094. }
  1095. #else
  1096. (void)Instance;
  1097. #endif /* (ADC_INSTANCE_COUNT > 1u) */
  1098. IP_SIM->ADCOPT = Reg;
  1099. }
  1100. /*FUNCTION**********************************************************************
  1101. *
  1102. * Function Name : ADC_SetPretriggerSourceSelect
  1103. * Description : This function selects pretrigger source for an ADC instance
  1104. *
  1105. * END**************************************************************************/
  1106. static void ADC_SetPretriggerSourceSelect(const uint32 Instance, const uint8 PretriggerSource)
  1107. {
  1108. #if (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT)
  1109. OsIf_Trusted_Call2params(ADC_SetPretriggerSourceSelect_TrustedCall, Instance, PretriggerSource);
  1110. #else
  1111. ADC_SetPretriggerSourceSelect_TrustedCall(Instance, PretriggerSource);
  1112. #endif /* (STD_ON == ADC_IP_ENABLE_USER_MODE_SUPPORT) */
  1113. }
  1114. static void ADC_SetPretriggerSourceSelect_TrustedCall(const uint32 Instance, const uint8 PretriggerSource)
  1115. {
  1116. uint32 Reg = (uint32)IP_SIM->ADCOPT;
  1117. #if (ADC_INSTANCE_COUNT > 1u)
  1118. switch (Instance)
  1119. {
  1120. case 0u:
  1121. {
  1122. #endif /* (ADC_INSTANCE_COUNT > 1u) */
  1123. Reg &= ~SIM_ADCOPT_ADC0PRETRGSEL_MASK;
  1124. Reg |= SIM_ADCOPT_ADC0PRETRGSEL(PretriggerSource);
  1125. #if (ADC_INSTANCE_COUNT > 1u)
  1126. break;
  1127. }
  1128. case 1u:
  1129. {
  1130. Reg &= ~SIM_ADCOPT_ADC1PRETRGSEL_MASK;
  1131. Reg |= SIM_ADCOPT_ADC1PRETRGSEL(PretriggerSource);
  1132. break;
  1133. }
  1134. default:
  1135. {
  1136. ; /* no-op */
  1137. break;
  1138. }
  1139. }
  1140. #else
  1141. (void)Instance;
  1142. #endif /* (ADC_INSTANCE_COUNT > 1u) */
  1143. IP_SIM->ADCOPT = Reg;
  1144. }
  1145. /*FUNCTION**********************************************************************
  1146. *
  1147. * Function Name : ADC_SetSoftwarePretrigger_TrustedCall
  1148. * Description : This function writes the software pretrigger source to be
  1149. * configured for an ADC instance
  1150. *
  1151. * END**************************************************************************/
  1152. static void ADC_SetSoftwarePretrigger_TrustedCall(const uint32 Instance, const uint8 SoftwarePretrigger)
  1153. {
  1154. SchM_Enter_Adc_ADC_EXCLUSIVE_AREA_31();
  1155. uint32 Reg = (uint32)IP_SIM->ADCOPT;
  1156. #if (ADC_INSTANCE_COUNT > 1u)
  1157. switch (Instance)
  1158. {
  1159. case 0u:
  1160. {
  1161. #endif /* (ADC_INSTANCE_COUNT > 1u) */
  1162. Reg &= ~SIM_ADCOPT_ADC0SWPRETRG_MASK;
  1163. Reg |= SIM_ADCOPT_ADC0SWPRETRG(SoftwarePretrigger);
  1164. #if (ADC_INSTANCE_COUNT > 1u)
  1165. break;
  1166. }
  1167. case 1u:
  1168. {
  1169. Reg &= ~SIM_ADCOPT_ADC1SWPRETRG_MASK;
  1170. Reg |= SIM_ADCOPT_ADC1SWPRETRG(SoftwarePretrigger);
  1171. break;
  1172. }
  1173. default:
  1174. {
  1175. ; /* no-op */
  1176. break;
  1177. }
  1178. }
  1179. #else
  1180. (void)Instance;
  1181. #endif /* (ADC_INSTANCE_COUNT > 1u) */
  1182. IP_SIM->ADCOPT = Reg;
  1183. SchM_Exit_Adc_ADC_EXCLUSIVE_AREA_31();
  1184. }
  1185. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  1186. #define ADC_STOP_SEC_CODE
  1187. #include "Adc_MemMap.h"
  1188. /** @} */