Adc_Ip.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. #ifndef ADC_IP_H
  25. #define ADC_IP_H
  26. /**
  27. * @file
  28. *
  29. * @addtogroup adc_ip Adc IPL
  30. * @{
  31. */
  32. #include "Adc_Ip_Types.h"
  33. #include "Adc_Ip_Cfg.h"
  34. /*==================================================================================================
  35. * SOURCE FILE VERSION INFORMATION
  36. ==================================================================================================*/
  37. #define ADC_IP_VENDOR_ID_H 43
  38. #define ADC_IP_AR_RELEASE_MAJOR_VERSION_H 4
  39. #define ADC_IP_AR_RELEASE_MINOR_VERSION_H 4
  40. #define ADC_IP_AR_RELEASE_REVISION_VERSION_H 0
  41. #define ADC_IP_SW_MAJOR_VERSION_H 1
  42. #define ADC_IP_SW_MINOR_VERSION_H 0
  43. #define ADC_IP_SW_PATCH_VERSION_H 0
  44. /*==================================================================================================
  45. * FILE VERSION CHECKS
  46. ==================================================================================================*/
  47. /* Check if Adc_Ip.h file and Adc_Ip_Types.h file are of the same vendor */
  48. #if (ADC_IP_VENDOR_ID_H != ADC_IP_VENDOR_ID_TYPES_H)
  49. #error "Adc_Ip.h and Adc_Ip_Types.h have different vendor ids"
  50. #endif
  51. /* Check if Adc_Ip.h file and Adc_Ip_Types.h file are of the same Autosar version */
  52. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_H != ADC_IP_AR_RELEASE_MAJOR_VERSION_TYPES_H) || \
  53. (ADC_IP_AR_RELEASE_MINOR_VERSION_H != ADC_IP_AR_RELEASE_MINOR_VERSION_TYPES_H) || \
  54. (ADC_IP_AR_RELEASE_REVISION_VERSION_H != ADC_IP_AR_RELEASE_REVISION_VERSION_TYPES_H) \
  55. )
  56. #error "AutoSar Version Numbers of Adc_Ip.h and Adc_Ip_Types.h are different"
  57. #endif
  58. /* Check if Adc_Ip.h file and Adc_Ip_Types.h file are of the same Software version */
  59. #if ((ADC_IP_SW_MAJOR_VERSION_H != ADC_IP_SW_MAJOR_VERSION_TYPES_H) || \
  60. (ADC_IP_SW_MINOR_VERSION_H != ADC_IP_SW_MINOR_VERSION_TYPES_H) || \
  61. (ADC_IP_SW_PATCH_VERSION_H != ADC_IP_SW_PATCH_VERSION_TYPES_H) \
  62. )
  63. #error "Software Version Numbers of Adc_Ip.h and Adc_Ip_Types.h are different"
  64. #endif
  65. /* Check if Adc_Ip.h file and Adc_Ip_Cfg.h file are of the same vendor */
  66. #if (ADC_IP_VENDOR_ID_H != ADC_IP_VENDOR_ID_CFG_H)
  67. #error "Adc_Ip.h and Adc_Ip_Cfg.h have different vendor ids"
  68. #endif
  69. /* Check if Adc_Ip.h file and Adc_Ip_Cfg.h file are of the same Autosar version */
  70. #if ((ADC_IP_AR_RELEASE_MAJOR_VERSION_H != ADC_IP_AR_RELEASE_MAJOR_VERSION_CFG_H) || \
  71. (ADC_IP_AR_RELEASE_MINOR_VERSION_H != ADC_IP_AR_RELEASE_MINOR_VERSION_CFG_H) || \
  72. (ADC_IP_AR_RELEASE_REVISION_VERSION_H != ADC_IP_AR_RELEASE_REVISION_VERSION_CFG_H) \
  73. )
  74. #error "AutoSar Version Numbers of Adc_Ip.h and Adc_Ip_Cfg.h are different"
  75. #endif
  76. /* Check if Adc_Ip.h file and Adc_Ip_Cfg.h file are of the same Software version */
  77. #if ((ADC_IP_SW_MAJOR_VERSION_H != ADC_IP_SW_MAJOR_VERSION_CFG_H) || \
  78. (ADC_IP_SW_MINOR_VERSION_H != ADC_IP_SW_MINOR_VERSION_CFG_H) || \
  79. (ADC_IP_SW_PATCH_VERSION_H != ADC_IP_SW_PATCH_VERSION_CFG_H) \
  80. )
  81. #error "Software Version Numbers of Adc_Ip.h and Adc_Ip_Cfg.h are different"
  82. #endif
  83. /*==================================================================================================
  84. * DEFINITIONS
  85. ==================================================================================================*/
  86. /*******************************************************************************
  87. * API
  88. ******************************************************************************/
  89. #if defined (__cplusplus)
  90. extern "C" {
  91. #endif
  92. #define ADC_START_SEC_CODE
  93. #include "Adc_MemMap.h"
  94. /*!
  95. * @brief Initialize ADC module
  96. *
  97. * This function initializes the ADC module by configuring all
  98. * available features.
  99. *
  100. * @param[in] Instance - ADC instance number
  101. * @param[in] config - configuration struct pointer
  102. * @return void
  103. */
  104. void Adc_Ip_Init(const uint32 Instance, const Adc_Ip_ConfigType * const Config);
  105. /*!
  106. * @brief Deinitialize ADC module
  107. *
  108. * This function resets the ADC internal registers to default values.
  109. *
  110. * @param[in] Instance - ADC instance number
  111. * @return void
  112. */
  113. void Adc_Ip_DeInit(const uint32 Instance);
  114. /*!
  115. * @brief Configure averaging
  116. *
  117. * This function enables averaging and selects the number of conversions to average.
  118. * The mask parameter should be set using the Adc_Ip_AvgSelectType enum elements
  119. * that have the pattern ADC_IP_AVG_... e.g. ADC_IP_AVG_4_CONV.
  120. *
  121. * @param[in] Instance - ADC instance number
  122. * @param[in] AvgEn - enable or disable averaging
  123. * @param[in] AvgSel - selects number of conversions to average
  124. * @return void
  125. */
  126. void Adc_Ip_SetAveraging(const uint32 Instance, const boolean AvgEn, const Adc_Ip_AvgSelectType AvgSel);
  127. /*!
  128. * @brief Configure sample time
  129. *
  130. * This function sets the sample time for selected ADC instance.
  131. *
  132. * @param[in] Instance - ADC instance number
  133. * @param[in] SampleTime - sample time
  134. * @return void
  135. */
  136. void Adc_Ip_SetSampleTime(const uint32 Instance, const uint8 SampleTime);
  137. /*!
  138. * @brief Enable DMA
  139. *
  140. * This function enables DMA.
  141. *
  142. * @param[in] Instance - ADC instance number
  143. * @return void
  144. */
  145. void Adc_Ip_EnableDma(const uint32 Instance);
  146. /*!
  147. * @brief Disable DMA
  148. *
  149. * This function disables DMA.
  150. *
  151. * @param[in] Instance - ADC instance number
  152. * @return void
  153. */
  154. void Adc_Ip_DisableDma(const uint32 Instance);
  155. /*!
  156. * @brief Switch between hardware and software trigger
  157. *
  158. * This function enables either hardware or software trigger.
  159. *
  160. * @param[in] Instance - ADC instance number
  161. * @param[in] TriggerMode - selected trigger mode(sw/hw)
  162. * @return void
  163. */
  164. void Adc_Ip_SetTriggerMode(const uint32 Instance, const Adc_Ip_TrigType TriggerMode);
  165. /*!
  166. * @brief Switch between continuous and one shot conversion mode
  167. *
  168. * This function switches between ADC continuous conversion mode and one shot mode.
  169. *
  170. * @param[in] Instance - ADC instance number
  171. * @param[in] ContinuousModeEnable - mode to set: continuous(TRUE) or one shot(FALSE)
  172. * @return void
  173. */
  174. void Adc_Ip_SetContinuousMode(const uint32 Instance, const boolean ContinuousModeEnable);
  175. /*!
  176. * @brief Set ADC module resolution
  177. *
  178. * This function sets ADC module resolution.
  179. *
  180. * @param[in] Instance - ADC instance number
  181. * @param[in] Resolution - resolution value
  182. * @return void
  183. */
  184. void Adc_Ip_SetResolution(const uint32 Instance, const Adc_Ip_ResolutionType Resolution);
  185. /*!
  186. * @brief Set the ADC clock values
  187. *
  188. * This function initializes the ADC clock configuration.
  189. *
  190. * @param[in] Instance - ADC instance number
  191. * @param[in] Config - the clock configuration
  192. * @return void
  193. */
  194. void Adc_Ip_SetClockMode(const uint32 Instance, const Adc_Ip_ClockConfigType * const Config);
  195. /*!
  196. * @brief Configure the selected control channel with the given
  197. * configuration structure
  198. *
  199. * When Software Trigger mode is enabled, configuring control channel index 0,
  200. * implicitly triggers a new conversion on the selected ADC input channel.
  201. * Therefore, Adc_Ip_ConfigChannel can be used for sw-triggering conversions.
  202. *
  203. * Configuring any control channel while it is actively controlling a conversion
  204. * (sw or hw triggered) will implicitly abort the on-going conversion.
  205. *
  206. * @param[in] Instance - ADC instance number
  207. * @param[in] ChanConfig - configuration structure
  208. * @return void
  209. */
  210. void Adc_Ip_ConfigChannel(const uint32 Instance, const Adc_Ip_ChanConfigType * const ChanConfig);
  211. /*!
  212. * @brief Disable selected channel
  213. *
  214. * This function sets the input channel of the selected control channel to
  215. * ADC_IP_INPUTCHAN_DISABLED. If WithTimeout is TRUE then the function will
  216. * also wait for the register to be updated.
  217. * Note: the control channel index is the numeric index of SC1x
  218. * (e.g. SC1A has index 0), not the input channel.
  219. *
  220. * @param[in] Instance - ADC instance number
  221. * @param[in] ControlChanIdx - control channel index
  222. * @param[in] WithTimeout - enables loop that checks if the register was updated
  223. * @return Adc_Ip_StatusType
  224. */
  225. Adc_Ip_StatusType Adc_Ip_SetDisabledChannel(const uint32 Instance, const uint8 ControlChanIdx, const boolean WithTimeout);
  226. /*!
  227. * @brief Start a software triggered conversion
  228. *
  229. * This function starts a software conversion on the selected input channel by
  230. * writing the values given to the SC1A register.
  231. * Note: hardware configuration on the control channel with index 0 will be
  232. * overwritten.
  233. * Note: this will not work if hardware triggered mode is selected.
  234. *
  235. * @param[in] Instance - ADC instance number
  236. * @param[in] InputChannel - channel index
  237. * @param[in] InterruptEnable - enables end of conversion interrupt
  238. * @return void
  239. */
  240. void Adc_Ip_StartConversion(const uint32 Instance, Adc_Ip_InputChannelType InputChannel, const boolean InterruptEnable);
  241. /*!
  242. * @brief Read and return conversion active flag status.
  243. *
  244. * @param[in] Instance - ADC instance number
  245. * @return conversion active flag status
  246. */
  247. boolean Adc_Ip_GetConvActiveFlag(const uint32 Instance);
  248. /*!
  249. * @brief Check if selected channel has interrupt set
  250. *
  251. * This function checks and returns if the selected control channel has the
  252. * interrupt flag set.
  253. * Note: the control channel index is the numeric index of SC1x
  254. * (e.g. SC1A has index 0), not the input channel.
  255. *
  256. * @param[in] Instance - ADC instance number
  257. * @param[in] ControlChanIdx - control channel index
  258. * @return TRUE if channel has interrupt set or FALSE otherwise
  259. */
  260. boolean Adc_Ip_GetChanInterrupt(const uint32 Instance, const uint8 ControlChanIdx);
  261. /*!
  262. * @brief Get the value of conversion complete flag of a channel
  263. *
  264. * This function returns the value of the conversion complete(COCO) flag of a
  265. * given channel.
  266. * Note: the control channel index is the numeric index of SC1x
  267. * (e.g. SC1A has index 0), not the input channel.
  268. *
  269. * @param[in] Instance - ADC instance number
  270. * @param[in] ControlChanIdx - control channel index
  271. * @return value of conversion complete flag
  272. */
  273. boolean Adc_Ip_GetConvCompleteFlag(const uint32 Instance, const uint8 ControlChanIdx);
  274. /*!
  275. * @brief Get the last result for the selected control channel
  276. *
  277. * This function retrieves the last conversion result for the selected control
  278. * channel. This function does no validity check on the result. In order to
  279. * check if the result is valid, the user must call Adc_Ip_GetConvCompleteFlag
  280. * function before this one.
  281. * Note: the control channel index is the numeric index of SC1x
  282. * (e.g. SC1A has index 0), not the input channel.
  283. *
  284. * @param[in] Instance - ADC instance number
  285. * @param[in] ControlChanIdx - control channel index
  286. * @return conversion result
  287. */
  288. uint16 Adc_Ip_GetConvData(const uint32 Instance, const uint8 ControlChanIdx);
  289. /*!
  290. * @brief Perform calibration of the ADC module
  291. *
  292. * This function performs a calibration of the ADC module. The input clock frequency
  293. * for calibration must be less than or equal to half of the maximum specified
  294. * frequency (50Mhz) and greater than minimum specified frequency (20Mhz).
  295. * Please refer to Datasheet for more details
  296. *
  297. * @param[in] Instance - ADC instance number
  298. * @return the calibration result
  299. * - ADC_IP_STATUS_SUCCESS: calibration successful
  300. * - ADC_IP_STATUS_TIMEOUT: calibration step timed out
  301. */
  302. Adc_Ip_StatusType Adc_Ip_DoCalibration(const uint32 Instance);
  303. /*!
  304. * @brief Clear latched triggers under processing
  305. *
  306. * This function clears all trigger latched flags of the ADC instance.
  307. * This function must be called after the hardware trigger source for the ADC has been deactivated.
  308. *
  309. * @param[in] Instance - ADC instance number
  310. * @return clearing status
  311. * - ADC_IP_STATUS_SUCCESS: operation successful
  312. * - ADC_IP_STATUS_TIMEOUT: operation timed out
  313. */
  314. Adc_Ip_StatusType Adc_Ip_ClearLatchedTriggers(const uint32 Instance);
  315. /*!
  316. * @brief Enable channel notification
  317. *
  318. * This function enables the notification for the selected channel.
  319. * Note: the control channel index is the numeric index of SC1x
  320. * (e.g. SC1A has index 0), not the input channel.
  321. * Note: It's required to read result data in user notification in order to clear the COCO flags and avoid ISR getting invoked repeatedly
  322. *
  323. * @param[in] Instance - ADC instance number
  324. * @param[in] ControlChanIdx - control channel index
  325. * @return void
  326. */
  327. void Adc_Ip_EnableChannelNotification(const uint32 Instance, const uint8 ControlChanIdx);
  328. /*!
  329. * @brief Disable channel notification
  330. *
  331. * This function disables the notification for the selected channel.
  332. * Note: the control channel index is the numeric index of SC1x
  333. * (e.g. SC1A has index 0), not the input channel.
  334. *
  335. * @param[in] Instance - ADC instance number
  336. * @param[in] ControlChanIdx - control channel index
  337. * @return void
  338. */
  339. void Adc_Ip_DisableChannelNotification(const uint32 Instance, const uint8 ControlChanIdx);
  340. /*!
  341. * @brief Clear all trigger error flags
  342. *
  343. * This function clears all trigger error flags of the ADC instance.
  344. *
  345. * @param[in] Instance - ADC instance number
  346. * @return void
  347. */
  348. void Adc_Ip_ClearTrigErrReg(const uint32 Instance);
  349. /*!
  350. * @brief Get all trigger error flags
  351. *
  352. * This function returns all trigger error flags of the ADC instance.
  353. *
  354. * @param[in] Instance - ADC instance number
  355. * @return trigger error flags bit-mask
  356. */
  357. uint32 Adc_Ip_GetTrigErrReg(const uint32 Instance);
  358. /*!
  359. * @brief Return the address of the specified data register
  360. *
  361. * This function returns the address of the specified data register
  362. *
  363. * @param[in] Instance - ADC instance number
  364. * @param[in] Index - ADC channel of the Hw unit
  365. * @return status:
  366. * - value of the address of the data for the specified channel
  367. */
  368. uint32 Adc_Ip_GetDataAddress(const uint32 Instance, const uint8 Index);
  369. /*!
  370. * @brief Get the last result for the selected control channel
  371. *
  372. * This function retrieves the last conversion result for the selected input
  373. * channel, by looking which control channel was configured with it. If multiple
  374. * control channels are configured simultaneously with the same requested input
  375. * channel, the result of the first control channel found will be returned.
  376. * If no control channel is configured with the given input channel then
  377. * ADC_IP_STATUS_ERROR will be returned.
  378. * This function does no validity check on the result. In order to check if
  379. * the result is valid, the user must call Adc_Ip_GetConvCompleteFlag function
  380. * before this one.
  381. *
  382. * @param[in] Instance - ADC instance number
  383. * @param[in] Channel - input channel
  384. * @param[out] Result - pointer to the buffer where the result will be written
  385. * @return status
  386. */
  387. Adc_Ip_StatusType Adc_Ip_GetChanData(const uint32 Instance, const Adc_Ip_InputChannelType Channel, uint16 * const Result);
  388. #if (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON)
  389. /*!
  390. * @brief Set software pretrigger source
  391. *
  392. * This function sets the software pretrigger source for an ADC instance.
  393. * Note: Pretrigger source must be set to software in order to use this.
  394. * Note: Software pretriggering is available only for ADC control channels 0-3(A-D).
  395. *
  396. * @param[in] Instance - ADC instance number
  397. * @param[in] SoftwarePretrigger - selected software pretrigger
  398. */
  399. void Adc_Ip_SetSoftwarePretrigger(const uint32 Instance, const Adc_Ip_SoftwarePretriggerType SoftwarePretrigger);
  400. #endif /* (ADC_IP_ENABLE_SIM_SOURCE_SELECTION == STD_ON) */
  401. #define ADC_STOP_SEC_CODE
  402. #include "Adc_MemMap.h"
  403. #if defined (__cplusplus)
  404. }
  405. #endif
  406. /** @} */
  407. #endif /* ADC_IP_H */