romapi_adc.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * @brief ADC ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __ROMAPI_ADC_H_
  32. #define __ROMAPI_ADC_H_
  33. #include "hw_adc_rom_api.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /** @defgroup ROMAPI_ADC_WRAPPER CHIP: ADC ROM Driver wrapper functions
  38. * @ingroup ROMAPI_5410X
  39. * @{
  40. */
  41. /**
  42. * @brief Get memory size in bytes needed for ADC driver context
  43. * @return Size in bytes needed for the ROM driver
  44. */
  45. uint32_t ROM_ADC_GetMemSize(void);
  46. /**
  47. * @brief Initialize ADC ROM Driver
  48. * @param pMem : Pointer to memory area for driver context
  49. * @param baseAddr : Base address of the ADC peripheral
  50. * @param pUserData : Pointer to User Data
  51. * @return Pointer to the device context handle or NULL on alignment failure
  52. * @note Parameter @a pMem must be a pointer to word aligned memory
  53. * if the pointer is not word aligned (4-Byte) the function returns
  54. * NULL.
  55. */
  56. ADC_HANDLE_T ROM_ADC_Init(void *pMem, uint32_t baseAddr, void *pUserData);
  57. /**
  58. * @brief Configure the ADC peripheral
  59. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  60. * @param pCfg : Pointer to configuration structure #ADC_CFG_T
  61. * @return Always returns LPC_OK
  62. */
  63. ErrorCode_t ROM_ADC_Configure(ADC_HANDLE_T hADC, const ADC_CFG_T *pCfg);
  64. /**
  65. * @brief Calibrate ADC upon startup or wakeup after powerdown
  66. * @pre ADC must be Initialized and Configured
  67. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  68. * @param sysclk_freq : Frequency of the system
  69. * @return Result of calibrarion operation
  70. * @retval LPC_OK Calibration is successful
  71. * @retval ERR_ADC_NO_POWER Unable to powerup ADC
  72. * @retval ERR_TIME_OUT Calibration operation timed-out
  73. */
  74. ErrorCode_t ROM_ADC_Calibrate(ADC_HANDLE_T hADC, uint32_t sysclk_freq);
  75. /**
  76. * @brief Start the ADC peripheral
  77. * @pre ADC must be properly initialized, Configured and Calibrated
  78. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  79. * @param seqIndex : Index of the sequence to start must be one of #ADC_SEQ_A or #ADC_SEQ_B
  80. * @param pBuf : Pointer to buffer (see note below)
  81. * @param szBuf : Size of buffer (see note below)
  82. * @return Result of the start operation
  83. * @retval LPC_OK Successfully started ADC sampling on given sequence or
  84. * given buffer is queued successfully (when called from #ADC_BUFFER_DONE
  85. * callback handler)
  86. * @retval ERR_ADC_INVALID_SEQUENCE Parameter @a seqIndex is not one of #ADC_SEQ_A or #ADC_SEQ_B
  87. * @retval ERR_BUSY Already a buffer is active and swap buffer is also configured
  88. * @note The size of the buffer must be M x N where M is the number of channels enabled in
  89. * sequence @a seqIndex, and N is the number of samples to be converted.
  90. * The buffer provided by @a pBuf must be of size M x N x sizeof(uint16_t) bytes(for non-DMA).
  91. * Assume that channels 1, 3, 4, 8 are enabled in sequence @a seqIndex and number of
  92. * samples to be collected is N, the buffer will be filled with DATA_1[0], DATA_3[0],
  93. * DATA_4[0], DATA_8[0], ... , DATA_1[N], DATA_3[N], DATA_4[N], DATA_8[N], note
  94. * that the order in which the channels are enabled does not matter they will always be
  95. * filled up in ascending order.
  96. */
  97. ErrorCode_t ROM_ADC_StartConversion(ADC_HANDLE_T hADC, ADC_SEQ_INDEX_T seqIndex, void *pBuf, size_t szBuf);
  98. /**
  99. * @brief Handler to handle ADC events
  100. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  101. * @param hEvent : Type of the event
  102. * @return Event handling results
  103. * @retval LPC_OK Event successfully handled
  104. * @retval ERR_ADC_INVALID_SEQUENCE Event is not for the given sequence
  105. * @retval ERR_FAILED Internal ADC error (Channel enabled but no data available)
  106. * @retval ERR_ADC_PARAM Invaild event parameter for @a hEvent
  107. */
  108. ErrorCode_t ROM_ADC_Handler(ADC_HANDLE_T hADC, ADC_HEVENT_T hEvent);
  109. /**
  110. * @brief Registers a callback function associated with an event
  111. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  112. * @param cbIndex : Index of the call-back function (Associated with an event)
  113. * @param pCbFunc : Pointer to callback function
  114. * @return Success or failure
  115. * @retval LPC_OK Callback successfully registered
  116. * @retval ERR_ADC_PARAM Invaild event parameter for @a cbIndex
  117. */
  118. ErrorCode_t ROM_ADC_RegisterCB(ADC_HANDLE_T hADC, ADC_CBINDEX_T cbIndex, void (*pCbFunc)(ADC_HANDLE_T,
  119. ADC_CBINDEX_T,
  120. void *));
  121. /**
  122. * @brief Setup high and low threshold values for threshold 0, 1
  123. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  124. * @param valThr0 : Threshold 0 value (bits 31-16 has high value, bits 15-0 has low value)
  125. * @param valThr1 : Threshold 1 value (bits 31-16 has high value, bits 15-0 has low value)
  126. * @return Nothing
  127. */
  128. void ROM_ADC_SetThreshold(ADC_HANDLE_T hADC, uint32_t valThr0, uint32_t valThr1);
  129. /**
  130. * @brief Configure a single channel
  131. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  132. * @param chanNum : Channel number
  133. * @param chanOpts : Options for the channel
  134. * @return LPC_OK on success, ERR_ADC_PARAM if @a chanNum is invalid
  135. */
  136. ErrorCode_t ROM_ADC_ConfigureCh(ADC_HANDLE_T hADC, uint32_t chanNum, uint32_t chanOpts);
  137. /**
  138. * @brief Stop the conversion in progress
  139. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  140. * @param seqIndex : Sequence that needs to be stopped
  141. * @return LPC_OK on success, ERR_ADC_INVALID_SEQUENCE if @a seqIndex is invalid
  142. */
  143. ErrorCode_t ROM_ADC_StopConversion(ADC_HANDLE_T hADC, ADC_SEQ_INDEX_T seqIndex);
  144. /**
  145. * @brief Generate software trigger for given sequence
  146. * @param hADC : Handle to ADC obtained using ROM_ADC_Init()
  147. * @param seqIndex : Sequence that needs to be triggered
  148. * @return LPC_OK on success, ERR_ADC_INVALID_SEQUENCE if @a seqIndex is invalid
  149. */
  150. ErrorCode_t ROM_ADC_SwTrigger(ADC_HANDLE_T hADC, ADC_SEQ_INDEX_T seqIndex);
  151. /**
  152. * @brief Return the ADC ROM driver version
  153. * @return Driver version number
  154. * @note The returned driver version number consists of a major and minor
  155. * number, with the minor number in the lower 8 bits and the major number in
  156. * the upper 8 bits.
  157. */
  158. uint16_t ROM_ADC_GetDriverVersion(void);
  159. /**
  160. * @}
  161. */
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* __ROMAPI_ADC_H_ */