1 /* 2 * Copyright 2020-2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef ADC_SAR_IP_H 8 #define ADC_SAR_IP_H 9 10 /** 11 * @file 12 * 13 * @addtogroup adc_sar_ip Adc Sar IPL 14 * @{ 15 */ 16 17 #ifdef __cplusplus 18 extern "C"{ 19 #endif 20 21 /*================================================================================================== 22 * INCLUDE FILES 23 * 1) system and project includes 24 * 2) needed interfaces from external units 25 * 3) internal and external interfaces from this unit 26 ==================================================================================================*/ 27 #include "Adc_Sar_Ip_Types.h" 28 #include "Adc_Sar_Ip_Cfg.h" 29 30 /*================================================================================================== 31 * SOURCE FILE VERSION INFORMATION 32 ==================================================================================================*/ 33 #define ADC_SAR_IP_VENDOR_ID 43 34 #define ADC_SAR_IP_AR_RELEASE_MAJOR_VERSION 4 35 #define ADC_SAR_IP_AR_RELEASE_MINOR_VERSION 7 36 #define ADC_SAR_IP_AR_RELEASE_REVISION_VERSION 0 37 #define ADC_SAR_IP_SW_MAJOR_VERSION 3 38 #define ADC_SAR_IP_SW_MINOR_VERSION 0 39 #define ADC_SAR_IP_SW_PATCH_VERSION 0 40 41 /*================================================================================================== 42 * FILE VERSION CHECKS 43 ==================================================================================================*/ 44 /* Check if Adc_Sar_Ip.h file and Adc_Sar_Ip_Types.h file are of the same vendor */ 45 #if (ADC_SAR_IP_VENDOR_ID != ADC_SAR_IP_VENDOR_ID_TYPES) 46 #error "Adc_Sar_Ip.h and Adc_Sar_Ip_Types.h have different vendor ids" 47 #endif 48 49 /* Check if Adc_Sar_Ip.h file and Adc_Sar_Ip_Types.h file are of the same Autosar version */ 50 #if ((ADC_SAR_IP_AR_RELEASE_MAJOR_VERSION != ADC_SAR_IP_AR_RELEASE_MAJOR_VERSION_TYPES) || \ 51 (ADC_SAR_IP_AR_RELEASE_MINOR_VERSION != ADC_SAR_IP_AR_RELEASE_MINOR_VERSION_TYPES) || \ 52 (ADC_SAR_IP_AR_RELEASE_REVISION_VERSION != ADC_SAR_IP_AR_RELEASE_REVISION_VERSION_TYPES) \ 53 ) 54 #error "AutoSar Version Numbers of Adc_Sar_Ip.h and Adc_Sar_Ip_Types.h are different" 55 #endif 56 57 /* Check if Adc_Sar_Ip.h file and Adc_Sar_Ip_Types.h file are of the same Software version */ 58 #if ((ADC_SAR_IP_SW_MAJOR_VERSION != ADC_SAR_IP_SW_MAJOR_VERSION_TYPES) || \ 59 (ADC_SAR_IP_SW_MINOR_VERSION != ADC_SAR_IP_SW_MINOR_VERSION_TYPES) || \ 60 (ADC_SAR_IP_SW_PATCH_VERSION != ADC_SAR_IP_SW_PATCH_VERSION_TYPES) \ 61 ) 62 #error "Software Version Numbers of Adc_Sar_Ip.h and Adc_Sar_Ip_Types.h are different" 63 #endif 64 65 /* Check if Adc_Sar_Ip.h file and Adc_Sar_Ip_Cfg.h file are of the same vendor */ 66 #if (ADC_SAR_IP_VENDOR_ID != ADC_SAR_IP_VENDOR_ID_CFG) 67 #error "Adc_Sar_Ip.h and Adc_Sar_Ip_Cfg.h have different vendor ids" 68 #endif 69 70 /* Check if Adc_Sar_Ip.h file and Adc_Sar_Ip_Cfg.h file are of the same Autosar version */ 71 #if ((ADC_SAR_IP_AR_RELEASE_MAJOR_VERSION != ADC_SAR_IP_AR_RELEASE_MAJOR_VERSION_CFG) || \ 72 (ADC_SAR_IP_AR_RELEASE_MINOR_VERSION != ADC_SAR_IP_AR_RELEASE_MINOR_VERSION_CFG) || \ 73 (ADC_SAR_IP_AR_RELEASE_REVISION_VERSION != ADC_SAR_IP_AR_RELEASE_REVISION_VERSION_CFG) \ 74 ) 75 #error "AutoSar Version Numbers of Adc_Sar_Ip.h and Adc_Sar_Ip_Cfg.h are different" 76 #endif 77 78 /* Check if Adc_Sar_Ip.h file and Adc_Sar_Ip_Cfg.h file are of the same Software version */ 79 #if ((ADC_SAR_IP_SW_MAJOR_VERSION != ADC_SAR_IP_SW_MAJOR_VERSION_CFG) || \ 80 (ADC_SAR_IP_SW_MINOR_VERSION != ADC_SAR_IP_SW_MINOR_VERSION_CFG) || \ 81 (ADC_SAR_IP_SW_PATCH_VERSION != ADC_SAR_IP_SW_PATCH_VERSION_CFG) \ 82 ) 83 #error "Software Version Numbers of Adc_Sar_Ip.h and Adc_Sar_Ip_Cfg.h are different" 84 #endif 85 86 /*================================================================================================== 87 * DEFINITIONS 88 ==================================================================================================*/ 89 /*! 90 * @brief Macros for status and notification flags 91 * 92 * These flags map to internal hardware flags in different registers, but are 93 * grouped together for convenience. 94 * 95 */ 96 #define ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN ((uint32)1U << 0U) 97 #define ADC_SAR_IP_NOTIF_FLAG_NORMAL_EOC ((uint32)1U << 1U) 98 #define ADC_SAR_IP_NOTIF_FLAG_INJECTED_ENDCHAIN ((uint32)1U << 2U) 99 #define ADC_SAR_IP_NOTIF_FLAG_INJECTED_EOC ((uint32)1U << 3U) 100 #define ADC_SAR_IP_NOTIF_FLAG_CTU_EOC ((uint32)1U << 4U) 101 #define ADC_SAR_IP_STATUS_FLAG_NORMAL_ENDCHAIN ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN 102 #define ADC_SAR_IP_STATUS_FLAG_NORMAL_EOC ADC_SAR_IP_NOTIF_FLAG_NORMAL_EOC 103 #define ADC_SAR_IP_STATUS_FLAG_INJECTED_ENDCHAIN ADC_SAR_IP_NOTIF_FLAG_INJECTED_ENDCHAIN 104 #define ADC_SAR_IP_STATUS_FLAG_INJECTED_EOC ADC_SAR_IP_NOTIF_FLAG_INJECTED_EOC 105 #define ADC_SAR_IP_STATUS_FLAG_CTU_EOC ADC_SAR_IP_NOTIF_FLAG_CTU_EOC 106 #define ADC_SAR_IP_STATUS_FLAG_CALIBRATED ((uint32)1U << 5U) 107 #define ADC_SAR_IP_STATUS_FLAG_NORMAL_STARTED ((uint32)1U << 6U) 108 #define ADC_SAR_IP_STATUS_FLAG_INJECTED_STARTED ((uint32)1U << 7U) 109 #define ADC_SAR_IP_STATUS_FLAG_INJECTED_ABORTED ((uint32)1U << 8U) 110 #define ADC_SAR_IP_STATUS_FLAG_CTU_STARTED ((uint32)1U << 9U) 111 #define ADC_SAR_IP_STATUS_FLAG_AUTOCLOCKOFF ((uint32)1U << 10U) 112 113 #define ADC_SAR_IP_STATUS_FLAG_ALL (ADC_SAR_IP_STATUS_FLAG_NORMAL_EOC | \ 114 ADC_SAR_IP_STATUS_FLAG_NORMAL_ENDCHAIN | \ 115 ADC_SAR_IP_STATUS_FLAG_INJECTED_EOC | \ 116 ADC_SAR_IP_STATUS_FLAG_INJECTED_ENDCHAIN | \ 117 ADC_SAR_IP_STATUS_FLAG_CTU_EOC | \ 118 ADC_SAR_IP_STATUS_FLAG_CALIBRATED | \ 119 ADC_SAR_IP_STATUS_FLAG_NORMAL_STARTED | \ 120 ADC_SAR_IP_STATUS_FLAG_INJECTED_STARTED | \ 121 ADC_SAR_IP_STATUS_FLAG_INJECTED_ABORTED | \ 122 ADC_SAR_IP_STATUS_FLAG_CTU_STARTED | \ 123 ADC_SAR_IP_STATUS_FLAG_AUTOCLOCKOFF \ 124 ) 125 #define ADC_SAR_IP_NOTIF_FLAG_ALL (ADC_SAR_IP_NOTIF_FLAG_NORMAL_EOC | \ 126 ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN | \ 127 ADC_SAR_IP_NOTIF_FLAG_INJECTED_EOC | \ 128 ADC_SAR_IP_NOTIF_FLAG_INJECTED_ENDCHAIN | \ 129 ADC_SAR_IP_NOTIF_FLAG_CTU_EOC \ 130 ) 131 132 133 /*! 134 * @brief Macros for channel notifications 135 * 136 * These notification flags map to internal hardware flags in different registers, 137 * but are grouped together for convenience. 138 * 139 */ 140 #define ADC_SAR_IP_CHAN_NOTIF_EOC ((uint32)1U << 0U) 141 #define ADC_SAR_IP_CHAN_NOTIF_WDG ((uint32)1U << 1U) 142 143 #define ADC_SAR_IP_CHAN_NOTIF_FLAG_ALL (ADC_SAR_IP_CHAN_NOTIF_EOC | \ 144 ADC_SAR_IP_CHAN_NOTIF_WDG \ 145 ) 146 147 148 /*! 149 * @brief Macros for watchdog registers 150 * 151 * These macros help decode and compose bit mask for watchdog functionality 152 * 153 */ 154 #define ADC_SAR_IP_WDG_HIGH_FLAG ((uint8)1U << 1U) 155 #define ADC_SAR_IP_WDG_LOW_FLAG ((uint8)1U << 0U) 156 157 /*================================================================================================== 158 FUNCTION PROTOTYPES 159 ==================================================================================================*/ 160 #define ADC_START_SEC_CODE 161 #include "Adc_MemMap.h" 162 163 /*! 164 * @brief Return the address of the specified data register 165 * 166 * This function returns the address of the specified data register 167 * 168 * @param[in] u32Instance - ADC instance number 169 * @param[in] u32ChannelIndex - adc channel of the Hw unit 170 * @return status: 171 * - value of the address of the data for the specified channel 172 */ 173 uint32 Adc_Sar_Ip_GetDataAddress(uint32 u32Instance, 174 uint32 u32ChannelIndex); 175 176 /*! 177 * @brief Initialize ADC_SAR module 178 * 179 * This function initializes the ADC_SAR module by configuring all 180 * available features. 181 * 182 * @param[in] u32Instance - ADC instance number 183 * @param[in] pConfig - configuration struct pointer 184 * @return status: 185 * - ADC_SAR_IP_STATUS_SUCCESS: init successful 186 * - ADC_SAR_IP_STATUS_TIMEOUT: init step timed out 187 */ 188 Adc_Sar_Ip_StatusType Adc_Sar_Ip_Init(const uint32 u32Instance, 189 const Adc_Sar_Ip_ConfigType * const pConfig); 190 191 /*! 192 * @brief Deinitialize ADC_SAR module 193 * 194 * This function resets the ADC internal registers to default values. 195 * 196 * @param[in] u32Instance - ADC instance number 197 * @return status: 198 * - ADC_SAR_IP_STATUS_SUCCESS: deinit successful 199 * - ADC_SAR_IP_STATUS_TIMEOUT: deinit step timed out 200 */ 201 Adc_Sar_Ip_StatusType Adc_Sar_Ip_Deinit(const uint32 u32Instance); 202 203 /*! 204 * @brief Configures the converter chains the given configuration structure 205 * 206 * This function configures the ADC Normal and Injected Chains with the options 207 * provided in the structure. 208 * 209 * @param[in] u32Instance - ADC instance number 210 * @param[in] pChansIdxMask - channel configuration structure 211 * @param[in] pChainType - conversion chain (Normal or Injected) 212 * @return void 213 */ 214 void Adc_Sar_Ip_ChainConfig(const uint32 u32Instance, 215 const Adc_Sar_Ip_ChansIdxMaskType * const pChansIdxMask, 216 const Adc_Sar_Ip_ConvChainType pChainType); 217 218 /*! 219 * @brief Enable a channel 220 * 221 * This function enables a channel in a specified conversion chain 222 * 223 * @param[in] u32Instance - ADC instance number 224 * @param[in] pChainType - conversion chain (Normal or Injected) 225 * @param[in] u32ChnIdx - channel 0 226 * @return void 227 */ 228 void Adc_Sar_Ip_EnableChannel(const uint32 u32Instance, 229 const Adc_Sar_Ip_ConvChainType pChainType, 230 const uint32 u32ChnIdx); 231 232 /*! 233 * @brief Disable a channel 234 * 235 * This function disables a channel in a specified conversion chain 236 * 237 * @param[in] u32Instance - ADC instance number 238 * @param[in] pChainType - conversion chain (Normal or Injected) 239 * @param[in] u32ChnIdx - channel 0 240 * @return void 241 */ 242 void Adc_Sar_Ip_DisableChannel(const uint32 u32Instance, 243 const Adc_Sar_Ip_ConvChainType pChainType, 244 const uint32 u32ChnIdx); 245 246 #if (ADC_SAR_IP_SET_RESOLUTION == STD_ON) 247 /*! 248 * @brief Set conversion resolution 249 * 250 * This function sets the conversion resolution (number of bits per conversion data) 251 * 252 * @param[in] u32Instance - ADC instance number 253 * @param[in] eResolution - conversion resolution 254 * @return void 255 */ 256 void Adc_Sar_Ip_SetResolution(const uint32 u32Instance, 257 const Adc_Sar_Ip_Resolution eResolution); 258 #endif /* (ADC_SAR_IP_SET_RESOLUTION == STD_ON) */ 259 260 /*! 261 * @brief Start conversion 262 * 263 * This function starts a conversion channel (Normal or Injected) 264 * 265 * @param[in] u32Instance - ADC instance number 266 * @param[in] pChainType - conversion chain (Normal or Injected) 267 * @return void 268 */ 269 void Adc_Sar_Ip_StartConversion(const uint32 u32Instance, 270 const Adc_Sar_Ip_ConvChainType pChainType); 271 272 /*! 273 * @brief Get the status flags 274 * 275 * This function returns the status flags of the ADC. 276 * 277 * @param[in] u32Instance - ADC instance number 278 * @return the status flag bit-mask 279 */ 280 uint32 Adc_Sar_Ip_GetStatusFlags(const uint32 u32Instance); 281 282 /*! 283 * @brief Clear the status flags 284 * 285 * This function clears the status flags of the ADC. 286 * 287 * @param[in] u32Instance - ADC instance number 288 * @param[in] u32Mask - bit-mask of flags to clear 289 * @return void 290 */ 291 void Adc_Sar_Ip_ClearStatusFlags(const uint32 u32Instance, 292 const uint32 u32Mask); 293 294 /*! 295 * @brief Self test 296 * 297 * This function executes a self test on the ADC instance. 298 * 299 * @param[in] u32Instance - ADC instance number 300 * @return status: 301 * - ADC_SAR_IP_STATUS_SUCCESS: self testing successful 302 * - ADC_SAR_IP_STATUS_TIMEOUT: self testing step timed out 303 */ 304 Adc_Sar_Ip_StatusType Adc_Sar_Ip_SelfTest(const uint32 u32Instance); 305 306 /*! 307 * @brief Get conversion results for a conversion chain 308 * 309 * This function gets the conversion results for the selected Conversion Chain. 310 * 311 * @param[in] u32Instance - ADC instance number 312 * @param[in] pChainType - conversion chain (Normal, Injected or CTU) 313 * @param[in] u32Length - the length of the buffer 314 * @param[out] pResults - the output buffer 315 * @return the number of values written in the buffer (max length) 316 */ 317 uint32 Adc_Sar_Ip_GetConvDataToArray(const uint32 u32Instance, 318 const Adc_Sar_Ip_ConvChainType pChainType, 319 const uint32 u32Length, 320 uint16 * const pResults); 321 322 /*! 323 * @brief Get conversion results for a conversion chain with extended information 324 * 325 * This function gets the conversion results for the selected Conversion Chain, with 326 * extended information about each conversion result (channel index, valid an overwritten 327 * properties and conversion data). This function should be used in case of configurations 328 * with overlapping channel lists in different chains, resulting in overwrite of conversion 329 * data when a higher priority chain is executed before all data was read. 330 * 331 * @param[in] u32Instance - ADC instance number 332 * @param[in] pChainType - conversion chain (Normal, Injected or CTU) 333 * @param[in] u32Length - the length of the buffer 334 * @param[out] pResults - the output buffer 335 * @return the number of values written in the buffer (max length) 336 */ 337 uint32 Adc_Sar_Ip_GetConvResultsToArray(const uint32 u32Instance, 338 const Adc_Sar_Ip_ConvChainType pChainType, 339 const uint32 u32Length, 340 Adc_Sar_Ip_ChanResultType * const pResults); 341 342 /*! 343 * @brief Return the result of the conversion 344 * 345 * This function returns the result of the conversion for a single channel 346 * 347 * @param [in] u32Instance - ADC instance number 348 * @param [in] u32ChnIdx - channel 0 349 * @return conversion data 350 */ 351 uint16 Adc_Sar_Ip_GetConvData(const uint32 u32Instance, 352 const uint32 u32ChnIdx); 353 354 /*! 355 * @brief Return the result and the status of the conversion 356 * 357 * This function returns the result and the status of the conversion 358 * for a single channel 359 * 360 * @param [in] u32Instance - ADC instance number 361 * @param [in] u32ChnIdx - channel 0 362 * @param [in] pChainType - conversion chain (Normal, Injected or CTU) 363 * @param [out] pResult - pointer to the buffer where the result will be written 364 * @return void 365 */ 366 void Adc_Sar_Ip_GetConvResult(const uint32 u32Instance, 367 const uint32 u32ChnIdx, 368 const Adc_Sar_Ip_ConvChainType pChainType, 369 Adc_Sar_Ip_ChanResultType * const pResult); 370 371 /*! 372 * @brief Perform Calibration of the ADC 373 * 374 * This function performs a calibration of the ADC. The maximum input clock 375 * frequency for the ADC is 80 MHz, checked with assertions if DEV_ASSERT is 376 * enabled. After calibration, the ADC is left in Powerup state (PWDN bit is clear). 377 * 378 * @param[in] u32Instance - ADC instance number 379 * @return the calibration result 380 * - ADC_SAR_IP_STATUS_SUCCESS: calibration successful 381 * - ADC_SAR_IP_STATUS_TIMEOUT: calibration step timed out 382 * - ADC_SAR_IP_STATUS_ERROR: calibration failed 383 */ 384 Adc_Sar_Ip_StatusType Adc_Sar_Ip_DoCalibration(const uint32 u32Instance); 385 386 /*! 387 * @brief Power up the ADC 388 * 389 * This function enables the ADC (disables the Power Down feature). 390 * 391 * @param[in] u32Instance - ADC instance number 392 * @return status: 393 * - ADC_SAR_IP_STATUS_SUCCESS: power up successful 394 * - ADC_SAR_IP_STATUS_TIMEOUT: power up failed 395 */ 396 Adc_Sar_Ip_StatusType Adc_Sar_Ip_Powerup(const uint32 u32Instance); 397 398 /*! 399 * @brief Power down the ADC 400 * 401 * This function disables the ADC (enables the Power Down feature). 402 * 403 * @param[in] u32Instance - ADC instance number 404 * @return status: 405 * - ADC_SAR_IP_STATUS_SUCCESS: power down successful 406 * - ADC_SAR_IP_STATUS_TIMEOUT: power down failed 407 */ 408 Adc_Sar_Ip_StatusType Adc_Sar_Ip_Powerdown(const uint32 u32Instance); 409 410 #if ( \ 411 (STD_ON == ADC_SAR_IP_ECH_ENABLED) || (STD_ON == ADC_SAR_IP_JECH_ENABLED) || \ 412 (STD_ON == ADC_SAR_IP_EOC_ENABLED) || \ 413 ((FEATURE_ADC_HAS_CTU == 1U) && (STD_ON == ADC_SAR_IP_EOCTU_ENABLED)) \ 414 ) 415 /*! 416 * @brief Enable ADC interrupts 417 * 418 * This function enables ADC interrupts. 419 * 420 * @param[in] u32Instance - ADC instance number 421 * @param[in] u32NotificationMask - mask of interrupts to enable (of status flags) 422 * @return void 423 */ 424 void Adc_Sar_Ip_EnableNotifications(const uint32 u32Instance, 425 const uint32 u32NotificationMask); 426 427 /*! 428 * @brief Disable ADC interrupts 429 * 430 * This function disables ADC interrupts. 431 * 432 * @param[in] u32Instance - ADC instance number 433 * @param[in] u32NotificationMask - mask of interrupts to disable (of status flags) 434 * @return void 435 */ 436 void Adc_Sar_Ip_DisableNotifications(const uint32 u32Instance, 437 const uint32 u32NotificationMask); 438 #endif /* (STD_ON == ADC_SAR_IP_ECH_ENABLED) .. */ 439 440 #if ((STD_ON == ADC_SAR_IP_WDG_ENABLED) || (STD_ON == ADC_SAR_IP_EOC_ENABLED)) 441 /*! 442 * @brief Enable ADC interrupt for a channel 443 * 444 * This function enables interrupt generation on End of Conversion and watchdog 445 * events for a single channel. 446 * The mask parameter can be set using the defines provided in the driver header 447 * file that have the pattern ADC_SAR_IP_CHAN_NOTIF_... e.g. ADC_SAR_IP_CHAN_NOTIF_EOC. 448 * 449 * @param[in] u32Instance - ADC instance number 450 * @param[in] u32ChnIdx - channel 0 451 * @param[in] u32Mask - mask selecting targeted events 452 * @return void 453 */ 454 void Adc_Sar_Ip_EnableChannelNotifications(const uint32 u32Instance, 455 const uint32 u32ChnIdx, 456 const uint32 u32Mask); 457 458 /*! 459 * @brief Disable ADC interrupt for a channel 460 * 461 * This function disables interrupt generation on End of Conversion and watchdog 462 * events for a single channel. 463 * The mask parameter can be set using the defines provided in the driver header 464 * file that have the pattern ADC_SAR_IP_CHAN_NOTIF_... e.g. ADC_SAR_IP_CHAN_NOTIF_EOC. 465 * 466 * @param[in] u32Instance - ADC instance number 467 * @param[in] u32ChnIdx - channel 0 468 * @param[in] u32Mask - mask selecting targeted events 469 * @return void 470 */ 471 void Adc_Sar_Ip_DisableChannelNotifications(const uint32 u32Instance, 472 const uint32 u32ChnIdx, 473 const uint32 u32Mask); 474 #endif /* ((STD_ON == ADC_SAR_IP_WDG_ENABLED) || (STD_ON == ADC_SAR_IP_EOC_ENABLED)) */ 475 476 /*! 477 * @brief Set the ADC clocks 478 * 479 * This function initializes the ADC clock configuration. 480 * 481 * @param[in] u32Instance - ADC instance number 482 * @param[in] pConfig - the clock configuration 483 * @return status: 484 * - ADC_SAR_IP_STATUS_SUCCESS: set successful 485 * - ADC_SAR_IP_STATUS_TIMEOUT: power up or down sequence timed out 486 */ 487 Adc_Sar_Ip_StatusType Adc_Sar_Ip_SetClockMode(const uint32 u32Instance, 488 const Adc_Sar_Ip_ClockConfigType * const pConfig); 489 490 #if FEATURE_ADC_HAS_CONVERSION_TIMING 491 /*! 492 * @brief Set the sample times 493 * 494 * This function sets the sample times for each channnel group. 495 * Note: aSampleTimes must contain the sample times in order of the channel 496 * groups, e.g. sample time for the channel group 1 must be on the first position. 497 * 498 * @param[in] u32Instance - ADC instance number 499 * @param[in] aSampleTimes - array with size ADC_SAR_IP_NUM_GROUP_CHAN containing sample times for each channel group 500 * @return void 501 */ 502 void Adc_Sar_Ip_SetSampleTimes(const uint32 u32Instance, 503 const uint8 * const aSampleTimes); 504 #endif /* FEATURE_ADC_HAS_CONVERSION_TIMING */ 505 506 #if FEATURE_ADC_HAS_AVERAGING 507 /*! 508 * @brief Configure averaging 509 * 510 * This function enables averaging and selects the number of conversions to average. 511 * The mask parameter should be set using the Adc_Sar_Ip_AvgSelectType enum elements 512 * that have the pattern ADC_SAR_IP_AVG_... e.g. ADC_SAR_IP_AVG_4_CONV. 513 * 514 * @param[in] u32Instance - ADC instance number 515 * @param[in] bAvgEn - enable or disable averaging 516 * @param[in] eAvgSel - selects number of conversions to average 517 * @return void 518 */ 519 void Adc_Sar_Ip_SetAveraging(const uint32 u32Instance, 520 const boolean bAvgEn, 521 const Adc_Sar_Ip_AvgSelectType eAvgSel); 522 #endif /* FEATURE_ADC_HAS_AVERAGING */ 523 524 /*! 525 * @brief Abort ongoing conversion 526 * 527 * This function aborts an ongoing conversion. 528 * 529 * @param[in] u32Instance - ADC instance number 530 * @return void 531 */ 532 void Adc_Sar_Ip_AbortConversion(const uint32 u32Instance); 533 534 /*! 535 * @brief Abort ongoing chain conversion 536 * 537 * This function aborts an ongoing chain of conversions. 538 * If scan(continuos) mode is selected, then bAllowRestart selects whether 539 * the abort command restarts the chain or stops it. For one shot conversion, 540 * this should be FALSE. 541 * 542 * @param[in] u32Instance - ADC instance number 543 * @param[in] bBlocking - wait and check that the ongoing conversion has stopped 544 * @param[in] bAllowRestart - restart continuos conversion instead of aborting 545 * @return status: 546 * - ADC_SAR_IP_STATUS_SUCCESS: abort successful 547 * - ADC_SAR_IP_STATUS_TIMEOUT: ongoing conversion could not be stopped 548 * @return void 549 */ 550 Adc_Sar_Ip_StatusType Adc_Sar_Ip_AbortChain(const uint32 u32Instance, 551 const boolean bBlocking, 552 const boolean bAllowRestart); 553 554 #if FEATURE_ADC_HAS_PRESAMPLING 555 /*! 556 * @brief Set the Presampling Source for the channel group 557 * 558 * This function configures the Presampling Source for a channel group. 559 * 560 * @param[in] u32Instance - ADC instance number 561 * @param[in] pChanGroup - the channel group 562 * @param[in] pPresampleSource - the presampling source 563 * @return void 564 */ 565 void Adc_Sar_Ip_SetPresamplingSource(const uint32 u32Instance, 566 const Adc_Sar_Ip_ChanGroupType pChanGroup, 567 const Adc_Sar_Ip_PresamplingSourceType pPresampleSource); 568 569 /*! 570 * @brief Enable Presampling on one channel 571 * 572 * This function enables the Presampling on one channel of the ADC. 573 * 574 * @param[in] u32Instance - ADC instance number 575 * @param[in] u32ChnIdx - channel 0 576 * @return void 577 */ 578 void Adc_Sar_Ip_EnableChannelPresampling(const uint32 u32Instance, 579 const uint32 u32ChnIdx); 580 581 /*! 582 * @brief Disable Presampling on one channel 583 * 584 * This function disables the Presampling on one channel of the ADC. 585 * 586 * @param[in] u32Instance - ADC instance number 587 * @param[in] u32ChnIdx - channel 0 588 * @return void 589 */ 590 void Adc_Sar_Ip_DisableChannelPresampling(const uint32 u32Instance, 591 const uint32 u32ChnIdx); 592 593 /*! 594 * @brief Enable Conversion Presampled Data 595 * 596 * This function enables bypass of the Sampling Phase, resulting in a conversion 597 * of the presampled data. This is available only for channels that have presampling 598 * enabled. 599 * 600 * @param[in] u32Instance - ADC instance number 601 * @return void 602 */ 603 void Adc_Sar_Ip_EnablePresampleConversion(const uint32 u32Instance); 604 605 /*! 606 * @brief Disable Conversion of Presampled Data 607 * 608 * This function disables Sampling Phase bypass. 609 * 610 * @param[in] u32Instance - ADC instance number 611 * @return void 612 */ 613 void Adc_Sar_Ip_DisablePresampleConversion(const uint32 u32Instance); 614 #endif /* FEATURE_ADC_HAS_PRESAMPLING */ 615 616 /*! 617 * @brief Enable DMA Requests 618 * 619 * This function enables requests to DMA from ADC 620 * 621 * @param[in] u32Instance - ADC instance number 622 * @return void 623 */ 624 void Adc_Sar_Ip_EnableDma(const uint32 u32Instance); 625 626 /*! 627 * @brief Disable DMA Requests 628 * 629 * This function disables requests to DMA from ADC 630 * 631 * @param[in] u32Instance - ADC instance number 632 * @return void 633 */ 634 void Adc_Sar_Ip_DisableDma(const uint32 u32Instance); 635 636 /*! 637 * @brief Enable DMA on one channel 638 * 639 * This function enables DMA requests triggered by End of Conversion event from 640 * a selected channel. 641 * 642 * @param[in] u32Instance - ADC instance number 643 * @param[in] u32ChnIdx - channel 0 644 * @return void 645 */ 646 void Adc_Sar_Ip_EnableChannelDma(const uint32 u32Instance, 647 const uint32 u32ChnIdx); 648 649 /*! 650 * @brief Disable DMA on one channel 651 * 652 * This function disables DMA requests triggered by End of Conversion event from 653 * a selected channel. 654 * 655 * @param[in] u32Instance - ADC instance number 656 * @param[in] u32ChnIdx - channel 0 657 * @return void 658 */ 659 void Adc_Sar_Ip_DisableChannelDma(const uint32 u32Instance, 660 const uint32 u32ChnIdx); 661 662 /*! 663 * @brief Disable DMA on all channels 664 * 665 * This function disables DMA requests triggered by End of Conversion event from 666 * all channels. 667 * 668 * @param[in] u32Instance - ADC instance number 669 * @return void 670 */ 671 void Adc_Sar_Ip_DisableChannelDmaAll(const uint32 u32Instance); 672 673 /*! 674 * @brief Set DMA Request Clear Source 675 * 676 * This function selects the DMA Request Flag Clear Source. 677 * 678 * @param[in] u32Instance - ADC instance number 679 * @param[in] pDmaClear - the clear source for DMA Requests (Ack from DMA Controller or 680 read of data registers) 681 * @return void 682 */ 683 void Adc_Sar_Ip_SetDmaClearSource(const uint32 u32Instance, 684 const Adc_Sar_Ip_ClearSourceType pDmaClear); 685 686 #if (STD_ON == ADC_SAR_IP_WDG_ENABLED) 687 /*! 688 * @brief Configure watchdog threshold register 689 * 690 * This function configures the high/low thresholds for a certain register. 691 * 692 * @param [in] u32Instance - ADC instance number 693 * @param [in] u8RegisterIdx - the index of the register 694 * @param [in] pThresholdValues - the threshold values 695 * @return void 696 */ 697 void Adc_Sar_Ip_SetWdgThreshold(const uint32 u32Instance, 698 const uint8 u8RegisterIdx, 699 const Adc_Sar_Ip_WdgThresholdType * const pThresholdValues); 700 #endif /* (STD_ON == ADC_SAR_IP_WDG_ENABLED) */ 701 702 /*! 703 * @brief Configure conversion mode 704 * 705 * This function configures the used conversion mode. 706 * Note: The selected ADC instance must be in the IDLE state. 707 * 708 * @param [in] u32Instance - ADC instance number 709 * @param [in] eConvMode - selected conversion mode 710 * @return void 711 */ 712 void Adc_Sar_Ip_SetConversionMode(const uint32 u32Instance, 713 const Adc_Sar_Ip_ConvModeType eConvMode); 714 715 #if FEATURE_ADC_HAS_CTU 716 /*! 717 * @brief Configure CTU mode 718 * 719 * This function configures the CTU mode and enable. 720 * 721 * @param [in] u32Instance - ADC instance number 722 * @param [in] eCtuMode - selected CTU mode 723 * @return status: 724 * - ADC_SAR_IP_STATUS_SUCCESS: set successful 725 * - ADC_SAR_IP_STATUS_TIMEOUT: power up or down sequence timed out 726 */ 727 Adc_Sar_Ip_StatusType Adc_Sar_Ip_SetCtuMode(const uint32 u32Instance, 728 const Adc_Sar_Ip_CtuModeType eCtuMode); 729 #endif /* FEATURE_ADC_HAS_CTU */ 730 731 #if (ADC_SAR_IP_EXTERNAL_TRIGGER_ENABLE) 732 #if (FEATURE_ADC_HAS_INJ_EXT_TRIGGER || FEATURE_ADC_HAS_EXT_TRIGGER) 733 /*! 734 * @brief Configure external trigger 735 * 736 * This function configures the external trigger. 737 * 738 * @param [in] u32Instance - ADC instance number 739 * @param [in] eTriggerEdge - selected external trigger type 740 * @param [in] eTrggerSrc - selects normal, auxiliary normal or injected trigger 741 * @return void 742 */ 743 void Adc_Sar_Ip_SetExternalTrigger(const uint32 u32Instance, 744 const Adc_Sar_Ip_ExtTriggerEdgeType eTriggerEdge, 745 const Adc_Sar_Ip_ExtTriggerSourceType eTrggerSrc); 746 #endif /* (FEATURE_ADC_HAS_INJ_EXT_TRIGGER || FEATURE_ADC_HAS_EXT_TRIGGER) */ 747 #endif /* (ADC_SAR_IP_EXTERNAL_TRIGGER_ENABLE) */ 748 749 #if FEATURE_ADC_HAS_TEMPSENSE_CHN 750 #if (ADC_SAR_IP_TEMPSENSE_ENABLED == STD_ON) 751 /*! 752 * @brief Calculates the temperature on chip from the provided parameter. 753 * 754 * This function calculate the temperature on chip from the provided parameter 755 * Note: u16AdcVref and u16TempSenseVsupply parameters must be in fixed point format 756 * (1 bit for the sign, 11 bits for the integer part and 4 bits for the decimal part) 757 * 758 * @param [in] u32AdcInstance - Adc instance number 759 * @param [in] u32TempInstance - TempSense instance number 760 * @param [in] u16TempSenseAdcConvData - data measured on the ADC internal channel 761 * corresponding to TempSense, with 12 bit resolution 762 * @return uint16: The temperature on chip in degrees C, expressed in fixed point format 763 */ 764 uint16 Adc_Sar_Ip_TempSenseCalculateTemp(const uint32 u32AdcInstance, 765 const uint32 u32TempInstance, 766 const uint16 u16TempSenseAdcConvData); 767 768 /*! 769 * @brief Get the temperature on chip directly. 770 * 771 * This function starts a normal software conversion on tempsense channel with One-shot mode 772 * and calculates the temperature on chip from the data conversion. At the end, tempsense 773 * channel will be disabled. The previous initialized configuration may be affected by 774 * calling this function 775 * Note: u16AdcVref and u16TempSenseVsupply parameters must be in fixed point format 776 * (1 bit for the sign, 11 bits for the integer part and 4 bits for the decimal part). 777 * The function is synchronous: waits until the ADC conversion completes or timeout occurs 778 * 779 * @param [in] u32AdcInstance - Adc instance number 780 * @param [in] u32TempInstance - TempSense instance number 781 * @param [out] pTempSenseVal - The temperature on chip in degrees C, expressed in fixed point format 782 * @return status: 783 * - ADC_SAR_IP_STATUS_SUCCESS: Get temperature successfully 784 * - ADC_SAR_IP_STATUS_TIMEOUT: Adc conversion did not complete 785 */ 786 Adc_Sar_Ip_StatusType Adc_Sar_Ip_TempSenseGetTemp(const uint32 u32AdcInstance, 787 const uint32 u32TempInstance, 788 uint16 * const pTempSenseVal); 789 790 /*! 791 * @brief Enables the temperature sensor 792 * 793 * This function enables the temperature sensor. 794 * 795 * @param [in] u32Instance - TempSense instance number 796 * @return void 797 */ 798 void Adc_Sar_Ip_TempSenseEnable(const uint32 u32Instance); 799 800 /*! 801 * @brief Disables the temperature sensor 802 * 803 * This function disables the temperature sensor. 804 * 805 * @param [in] u32Instance - TempSense instance number 806 * @return void 807 */ 808 void Adc_Sar_Ip_TempSenseDisable(const uint32 u32Instance); 809 #endif /* (ADC_SAR_IP_TEMPSENSE_ENABLED == STD_ON) */ 810 #endif /* FEATURE_ADC_HAS_TEMPSENSE_CHN */ 811 812 #define ADC_STOP_SEC_CODE 813 #include "Adc_MemMap.h" 814 815 #ifdef __cplusplus 816 } 817 #endif 818 819 /** @} */ 820 821 #endif /* ADC_SAR_IP_H */ 822