fsl_flexio.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_FLEXIO_H_
  31. #define _FSL_FLEXIO_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup flexio_driver
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. /*! @brief FlexIO driver version 2.0.1. */
  43. #define FSL_FLEXIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
  44. /*@}*/
  45. /*! @brief Calculate FlexIO timer trigger.*/
  46. #define FLEXIO_TIMER_TRIGGER_SEL_PININPUT(x) ((uint32_t)(x) << 1U)
  47. #define FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(x) (((uint32_t)(x) << 2U) | 0x1U)
  48. #define FLEXIO_TIMER_TRIGGER_SEL_TIMn(x) (((uint32_t)(x) << 2U) | 0x3U)
  49. /*! @brief Define time of timer trigger polarity.*/
  50. typedef enum _flexio_timer_trigger_polarity
  51. {
  52. kFLEXIO_TimerTriggerPolarityActiveHigh = 0x0U, /*!< Active high. */
  53. kFLEXIO_TimerTriggerPolarityActiveLow = 0x1U, /*!< Active low. */
  54. } flexio_timer_trigger_polarity_t;
  55. /*! @brief Define type of timer trigger source.*/
  56. typedef enum _flexio_timer_trigger_source
  57. {
  58. kFLEXIO_TimerTriggerSourceExternal = 0x0U, /*!< External trigger selected. */
  59. kFLEXIO_TimerTriggerSourceInternal = 0x1U, /*!< Internal trigger selected. */
  60. } flexio_timer_trigger_source_t;
  61. /*! @brief Define type of timer/shifter pin configuration.*/
  62. typedef enum _flexio_pin_config
  63. {
  64. kFLEXIO_PinConfigOutputDisabled = 0x0U, /*!< Pin output disabled. */
  65. kFLEXIO_PinConfigOpenDrainOrBidirection = 0x1U, /*!< Pin open drain or bidirectional output enable. */
  66. kFLEXIO_PinConfigBidirectionOutputData = 0x2U, /*!< Pin bidirectional output data. */
  67. kFLEXIO_PinConfigOutput = 0x3U, /*!< Pin output. */
  68. } flexio_pin_config_t;
  69. /*! @brief Definition of pin polarity.*/
  70. typedef enum _flexio_pin_polarity
  71. {
  72. kFLEXIO_PinActiveHigh = 0x0U, /*!< Active high. */
  73. kFLEXIO_PinActiveLow = 0x1U, /*!< Active low. */
  74. } flexio_pin_polarity_t;
  75. /*! @brief Define type of timer work mode.*/
  76. typedef enum _flexio_timer_mode
  77. {
  78. kFLEXIO_TimerModeDisabled = 0x0U, /*!< Timer Disabled. */
  79. kFLEXIO_TimerModeDual8BitBaudBit = 0x1U, /*!< Dual 8-bit counters baud/bit mode. */
  80. kFLEXIO_TimerModeDual8BitPWM = 0x2U, /*!< Dual 8-bit counters PWM mode. */
  81. kFLEXIO_TimerModeSingle16Bit = 0x3U, /*!< Single 16-bit counter mode. */
  82. } flexio_timer_mode_t;
  83. /*! @brief Define type of timer initial output or timer reset condition.*/
  84. typedef enum _flexio_timer_output
  85. {
  86. kFLEXIO_TimerOutputOneNotAffectedByReset = 0x0U, /*!< Logic one when enabled and is not affected by timer
  87. reset. */
  88. kFLEXIO_TimerOutputZeroNotAffectedByReset = 0x1U, /*!< Logic zero when enabled and is not affected by timer
  89. reset. */
  90. kFLEXIO_TimerOutputOneAffectedByReset = 0x2U, /*!< Logic one when enabled and on timer reset. */
  91. kFLEXIO_TimerOutputZeroAffectedByReset = 0x3U, /*!< Logic zero when enabled and on timer reset. */
  92. } flexio_timer_output_t;
  93. /*! @brief Define type of timer decrement.*/
  94. typedef enum _flexio_timer_decrement_source
  95. {
  96. kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput = 0x0U, /*!< Decrement counter on FlexIO clock, Shift clock
  97. equals Timer output. */
  98. kFLEXIO_TimerDecSrcOnTriggerInputShiftTimerOutput = 0x1U, /*!< Decrement counter on Trigger input (both edges),
  99. Shift clock equals Timer output. */
  100. kFLEXIO_TimerDecSrcOnPinInputShiftPinInput = 0x2U, /*!< Decrement counter on Pin input (both edges),
  101. Shift clock equals Pin input. */
  102. kFLEXIO_TimerDecSrcOnTriggerInputShiftTriggerInput = 0x3U, /*!< Decrement counter on Trigger input (both edges),
  103. Shift clock equals Trigger input. */
  104. } flexio_timer_decrement_source_t;
  105. /*! @brief Define type of timer reset condition.*/
  106. typedef enum _flexio_timer_reset_condition
  107. {
  108. kFLEXIO_TimerResetNever = 0x0U, /*!< Timer never reset. */
  109. kFLEXIO_TimerResetOnTimerPinEqualToTimerOutput = 0x2U, /*!< Timer reset on Timer Pin equal to Timer Output. */
  110. kFLEXIO_TimerResetOnTimerTriggerEqualToTimerOutput = 0x3U, /*!< Timer reset on Timer Trigger equal to
  111. Timer Output. */
  112. kFLEXIO_TimerResetOnTimerPinRisingEdge = 0x4U, /*!< Timer reset on Timer Pin rising edge. */
  113. kFLEXIO_TimerResetOnTimerTriggerRisingEdge = 0x6U, /*!< Timer reset on Trigger rising edge. */
  114. kFLEXIO_TimerResetOnTimerTriggerBothEdge = 0x7U, /*!< Timer reset on Trigger rising or falling edge. */
  115. } flexio_timer_reset_condition_t;
  116. /*! @brief Define type of timer disable condition.*/
  117. typedef enum _flexio_timer_disable_condition
  118. {
  119. kFLEXIO_TimerDisableNever = 0x0U, /*!< Timer never disabled. */
  120. kFLEXIO_TimerDisableOnPreTimerDisable = 0x1U, /*!< Timer disabled on Timer N-1 disable. */
  121. kFLEXIO_TimerDisableOnTimerCompare = 0x2U, /*!< Timer disabled on Timer compare. */
  122. kFLEXIO_TimerDisableOnTimerCompareTriggerLow = 0x3U, /*!< Timer disabled on Timer compare and Trigger Low. */
  123. kFLEXIO_TimerDisableOnPinBothEdge = 0x4U, /*!< Timer disabled on Pin rising or falling edge. */
  124. kFLEXIO_TimerDisableOnPinBothEdgeTriggerHigh = 0x5U, /*!< Timer disabled on Pin rising or falling edge provided
  125. Trigger is high. */
  126. kFLEXIO_TimerDisableOnTriggerFallingEdge = 0x6U, /*!< Timer disabled on Trigger falling edge. */
  127. } flexio_timer_disable_condition_t;
  128. /*! @brief Define type of timer enable condition.*/
  129. typedef enum _flexio_timer_enable_condition
  130. {
  131. kFLEXIO_TimerEnabledAlways = 0x0U, /*!< Timer always enabled. */
  132. kFLEXIO_TimerEnableOnPrevTimerEnable = 0x1U, /*!< Timer enabled on Timer N-1 enable. */
  133. kFLEXIO_TimerEnableOnTriggerHigh = 0x2U, /*!< Timer enabled on Trigger high. */
  134. kFLEXIO_TimerEnableOnTriggerHighPinHigh = 0x3U, /*!< Timer enabled on Trigger high and Pin high. */
  135. kFLEXIO_TimerEnableOnPinRisingEdge = 0x4U, /*!< Timer enabled on Pin rising edge. */
  136. kFLEXIO_TimerEnableOnPinRisingEdgeTriggerHigh = 0x5U, /*!< Timer enabled on Pin rising edge and Trigger high. */
  137. kFLEXIO_TimerEnableOnTriggerRisingEdge = 0x6U, /*!< Timer enabled on Trigger rising edge. */
  138. kFLEXIO_TimerEnableOnTriggerBothEdge = 0x7U, /*!< Timer enabled on Trigger rising or falling edge. */
  139. } flexio_timer_enable_condition_t;
  140. /*! @brief Define type of timer stop bit generate condition.*/
  141. typedef enum _flexio_timer_stop_bit_condition
  142. {
  143. kFLEXIO_TimerStopBitDisabled = 0x0U, /*!< Stop bit disabled. */
  144. kFLEXIO_TimerStopBitEnableOnTimerCompare = 0x1U, /*!< Stop bit is enabled on timer compare. */
  145. kFLEXIO_TimerStopBitEnableOnTimerDisable = 0x2U, /*!< Stop bit is enabled on timer disable. */
  146. kFLEXIO_TimerStopBitEnableOnTimerCompareDisable = 0x3U, /*!< Stop bit is enabled on timer compare and timer
  147. disable. */
  148. } flexio_timer_stop_bit_condition_t;
  149. /*! @brief Define type of timer start bit generate condition.*/
  150. typedef enum _flexio_timer_start_bit_condition
  151. {
  152. kFLEXIO_TimerStartBitDisabled = 0x0U, /*!< Start bit disabled. */
  153. kFLEXIO_TimerStartBitEnabled = 0x1U, /*!< Start bit enabled. */
  154. } flexio_timer_start_bit_condition_t;
  155. /*! @brief Define type of timer polarity for shifter control. */
  156. typedef enum _flexio_shifter_timer_polarity
  157. {
  158. kFLEXIO_ShifterTimerPolarityOnPositive = 0x0U, /* Shift on positive edge of shift clock. */
  159. kFLEXIO_ShifterTimerPolarityOnNegitive = 0x1U, /* Shift on negative edge of shift clock. */
  160. } flexio_shifter_timer_polarity_t;
  161. /*! @brief Define type of shifter working mode.*/
  162. typedef enum _flexio_shifter_mode
  163. {
  164. kFLEXIO_ShifterDisabled = 0x0U, /*!< Shifter is disabled. */
  165. kFLEXIO_ShifterModeReceive = 0x1U, /*!< Receive mode. */
  166. kFLEXIO_ShifterModeTransmit = 0x2U, /*!< Transmit mode. */
  167. kFLEXIO_ShifterModeMatchStore = 0x4U, /*!< Match store mode. */
  168. kFLEXIO_ShifterModeMatchContinuous = 0x5U, /*!< Match continuous mode. */
  169. #if defined(FSL_FEATURE_FLEXIO_HAS_STATE_MODE) && FSL_FEATURE_FLEXIO_HAS_STATE_MODE
  170. kFLEXIO_ShifterModeState = 0x6U, /*!< SHIFTBUF contents are used for storing
  171. programmable state attributes. */
  172. #endif /* FSL_FEATURE_FLEXIO_HAS_STATE_MODE */
  173. #if defined(FSL_FEATURE_FLEXIO_HAS_LOGIC_MODE) && FSL_FEATURE_FLEXIO_HAS_LOGIC_MODE
  174. kFLEXIO_ShifterModeLogic = 0x7U, /*!< SHIFTBUF contents are used for implementing
  175. programmable logic look up table. */
  176. #endif /* FSL_FEATURE_FLEXIO_HAS_LOGIC_MODE */
  177. } flexio_shifter_mode_t;
  178. /*! @brief Define type of shifter input source.*/
  179. typedef enum _flexio_shifter_input_source
  180. {
  181. kFLEXIO_ShifterInputFromPin = 0x0U, /*!< Shifter input from pin. */
  182. kFLEXIO_ShifterInputFromNextShifterOutput = 0x1U, /*!< Shifter input from Shifter N+1. */
  183. } flexio_shifter_input_source_t;
  184. /*! @brief Define of STOP bit configuration.*/
  185. typedef enum _flexio_shifter_stop_bit
  186. {
  187. kFLEXIO_ShifterStopBitDisable = 0x0U, /*!< Disable shifter stop bit. */
  188. kFLEXIO_ShifterStopBitLow = 0x2U, /*!< Set shifter stop bit to logic low level. */
  189. kFLEXIO_ShifterStopBitHigh = 0x3U, /*!< Set shifter stop bit to logic high level. */
  190. } flexio_shifter_stop_bit_t;
  191. /*! @brief Define type of START bit configuration.*/
  192. typedef enum _flexio_shifter_start_bit
  193. {
  194. kFLEXIO_ShifterStartBitDisabledLoadDataOnEnable = 0x0U, /*!< Disable shifter start bit, transmitter loads
  195. data on enable. */
  196. kFLEXIO_ShifterStartBitDisabledLoadDataOnShift = 0x1U, /*!< Disable shifter start bit, transmitter loads
  197. data on first shift. */
  198. kFLEXIO_ShifterStartBitLow = 0x2U, /*!< Set shifter start bit to logic low level. */
  199. kFLEXIO_ShifterStartBitHigh = 0x3U, /*!< Set shifter start bit to logic high level. */
  200. } flexio_shifter_start_bit_t;
  201. /*! @brief Define FlexIO shifter buffer type*/
  202. typedef enum _flexio_shifter_buffer_type
  203. {
  204. kFLEXIO_ShifterBuffer = 0x0U, /*!< Shifter Buffer N Register. */
  205. kFLEXIO_ShifterBufferBitSwapped = 0x1U, /*!< Shifter Buffer N Bit Byte Swapped Register. */
  206. kFLEXIO_ShifterBufferByteSwapped = 0x2U, /*!< Shifter Buffer N Byte Swapped Register. */
  207. kFLEXIO_ShifterBufferBitByteSwapped = 0x3U, /*!< Shifter Buffer N Bit Swapped Register. */
  208. #if defined(FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_BYTE_SWAP) && FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_BYTE_SWAP
  209. kFLEXIO_ShifterBufferNibbleByteSwapped = 0x4U, /*!< Shifter Buffer N Nibble Byte Swapped Register. */
  210. #endif /*FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_BYTE_SWAP*/
  211. #if defined(FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_HALF_WORD_SWAP) && FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_HALF_WORD_SWAP
  212. kFLEXIO_ShifterBufferHalfWordSwapped = 0x5U, /*!< Shifter Buffer N Half Word Swapped Register. */
  213. #endif
  214. #if defined(FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_SWAP) && FSL_FEATURE_FLEXIO_HAS_SHFT_BUFFER_NIBBLE_SWAP
  215. kFLEXIO_ShifterBufferNibbleSwapped = 0x6U, /*!< Shifter Buffer N Nibble Swapped Register. */
  216. #endif
  217. } flexio_shifter_buffer_type_t;
  218. /*! @brief Define FlexIO user configuration structure. */
  219. typedef struct _flexio_config_
  220. {
  221. bool enableFlexio; /*!< Enable/disable FlexIO module */
  222. bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode */
  223. bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode */
  224. bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers, fast access requires
  225. the FlexIO clock to be at least twice the frequency of the bus clock. */
  226. } flexio_config_t;
  227. /*! @brief Define FlexIO timer configuration structure. */
  228. typedef struct _flexio_timer_config
  229. {
  230. /* Trigger. */
  231. uint32_t triggerSelect; /*!< The internal trigger selection number using MACROs. */
  232. flexio_timer_trigger_polarity_t triggerPolarity; /*!< Trigger Polarity. */
  233. flexio_timer_trigger_source_t triggerSource; /*!< Trigger Source, internal (see 'trgsel') or external. */
  234. /* Pin. */
  235. flexio_pin_config_t pinConfig; /*!< Timer Pin Configuration. */
  236. uint32_t pinSelect; /*!< Timer Pin number Select. */
  237. flexio_pin_polarity_t pinPolarity; /*!< Timer Pin Polarity. */
  238. /* Timer. */
  239. flexio_timer_mode_t timerMode; /*!< Timer work Mode. */
  240. flexio_timer_output_t timerOutput; /*!< Configures the initial state of the Timer Output and
  241. whether it is affected by the Timer reset. */
  242. flexio_timer_decrement_source_t timerDecrement; /*!< Configures the source of the Timer decrement and the
  243. source of the Shift clock. */
  244. flexio_timer_reset_condition_t timerReset; /*!< Configures the condition that causes the timer counter
  245. (and optionally the timer output) to be reset. */
  246. flexio_timer_disable_condition_t timerDisable; /*!< Configures the condition that causes the Timer to be
  247. disabled and stop decrementing. */
  248. flexio_timer_enable_condition_t timerEnable; /*!< Configures the condition that causes the Timer to be
  249. enabled and start decrementing. */
  250. flexio_timer_stop_bit_condition_t timerStop; /*!< Timer STOP Bit generation. */
  251. flexio_timer_start_bit_condition_t timerStart; /*!< Timer STRAT Bit generation. */
  252. uint32_t timerCompare; /*!< Value for Timer Compare N Register. */
  253. } flexio_timer_config_t;
  254. /*! @brief Define FlexIO shifter configuration structure. */
  255. typedef struct _flexio_shifter_config
  256. {
  257. /* Timer. */
  258. uint32_t timerSelect; /*!< Selects which Timer is used for controlling the
  259. logic/shift register and generating the Shift clock. */
  260. flexio_shifter_timer_polarity_t timerPolarity; /*!< Timer Polarity. */
  261. /* Pin. */
  262. flexio_pin_config_t pinConfig; /*!< Shifter Pin Configuration. */
  263. uint32_t pinSelect; /*!< Shifter Pin number Select. */
  264. flexio_pin_polarity_t pinPolarity; /*!< Shifter Pin Polarity. */
  265. /* Shifter. */
  266. flexio_shifter_mode_t shifterMode; /*!< Configures the mode of the Shifter. */
  267. #if defined(FSL_FEATURE_FLEXIO_HAS_PARALLEL_WIDTH) && FSL_FEATURE_FLEXIO_HAS_PARALLEL_WIDTH
  268. uint32_t parallelWidth; /*!< Configures the parallel width when using parallel mode.*/
  269. #endif /* FSL_FEATURE_FLEXIO_HAS_PARALLEL_WIDTH */
  270. flexio_shifter_input_source_t inputSource; /*!< Selects the input source for the shifter. */
  271. flexio_shifter_stop_bit_t shifterStop; /*!< Shifter STOP bit. */
  272. flexio_shifter_start_bit_t shifterStart; /*!< Shifter START bit. */
  273. } flexio_shifter_config_t;
  274. /*! @brief typedef for FlexIO simulated driver interrupt handler.*/
  275. typedef void (*flexio_isr_t)(void *base, void *handle);
  276. /*******************************************************************************
  277. * API
  278. ******************************************************************************/
  279. #if defined(__cplusplus)
  280. extern "C" {
  281. #endif /*_cplusplus*/
  282. /*!
  283. * @name FlexIO Initialization and De-initialization
  284. * @{
  285. */
  286. /*!
  287. * @brief Gets the default configuration to configure the FlexIO module. The configuration
  288. * can used directly to call the FLEXIO_Configure().
  289. *
  290. * Example:
  291. @code
  292. flexio_config_t config;
  293. FLEXIO_GetDefaultConfig(&config);
  294. @endcode
  295. *
  296. * @param userConfig pointer to flexio_config_t structure
  297. */
  298. void FLEXIO_GetDefaultConfig(flexio_config_t *userConfig);
  299. /*!
  300. * @brief Configures the FlexIO with a FlexIO configuration. The configuration structure
  301. * can be filled by the user or be set with default values by FLEXIO_GetDefaultConfig().
  302. *
  303. * Example
  304. @code
  305. flexio_config_t config = {
  306. .enableFlexio = true,
  307. .enableInDoze = false,
  308. .enableInDebug = true,
  309. .enableFastAccess = false
  310. };
  311. FLEXIO_Configure(base, &config);
  312. @endcode
  313. *
  314. * @param base FlexIO peripheral base address
  315. * @param userConfig pointer to flexio_config_t structure
  316. */
  317. void FLEXIO_Init(FLEXIO_Type *base, const flexio_config_t *userConfig);
  318. /*!
  319. * @brief Gates the FlexIO clock. Call this API to stop the FlexIO clock.
  320. *
  321. * @note After calling this API, call the FLEXO_Init to use the FlexIO module.
  322. *
  323. * @param base FlexIO peripheral base address
  324. */
  325. void FLEXIO_Deinit(FLEXIO_Type *base);
  326. /* @} */
  327. /*!
  328. * @name FlexIO Basic Operation
  329. * @{
  330. */
  331. /*!
  332. * @brief Resets the FlexIO module.
  333. *
  334. * @param base FlexIO peripheral base address
  335. */
  336. void FLEXIO_Reset(FLEXIO_Type *base);
  337. /*!
  338. * @brief Enables the FlexIO module operation.
  339. *
  340. * @param base FlexIO peripheral base address
  341. * @param enable true to enable, false to disable.
  342. */
  343. static inline void FLEXIO_Enable(FLEXIO_Type *base, bool enable)
  344. {
  345. if (enable)
  346. {
  347. base->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
  348. }
  349. else
  350. {
  351. base->CTRL &= ~FLEXIO_CTRL_FLEXEN_MASK;
  352. }
  353. }
  354. #if defined(FSL_FEATURE_FLEXIO_HAS_PIN_STATUS) && FSL_FEATURE_FLEXIO_HAS_PIN_STATUS
  355. /*!
  356. * @brief Reads the input data on each of the FlexIO pins.
  357. *
  358. * @param base FlexIO peripheral base address
  359. * @return FlexIO pin input data
  360. */
  361. static inline uint32_t FLEXIO_ReadPinInput(FLEXIO_Type *base)
  362. {
  363. return base->PIN;
  364. }
  365. #endif /*FSL_FEATURE_FLEXIO_HAS_PIN_STATUS*/
  366. #if defined(FSL_FEATURE_FLEXIO_HAS_STATE_MODE) && FSL_FEATURE_FLEXIO_HAS_STATE_MODE
  367. /*!
  368. * @brief Gets the current state pointer for state mode use.
  369. *
  370. * @param base FlexIO peripheral base address
  371. * @return current State pointer
  372. */
  373. static inline uint8_t FLEXIO_GetShifterState(FLEXIO_Type *base)
  374. {
  375. return ((base->SHIFTSTATE) & FLEXIO_SHIFTSTATE_STATE_MASK);
  376. }
  377. #endif /*FSL_FEATURE_FLEXIO_HAS_STATE_MODE*/
  378. /*!
  379. * @brief Configures the shifter with the shifter configuration. The configuration structure
  380. * covers both the SHIFTCTL and SHIFTCFG registers. To configure the shifter to the proper
  381. * mode, select which timer controls the shifter to shift, whether to generate start bit/stop
  382. * bit, and the polarity of start bit and stop bit.
  383. *
  384. * Example
  385. @code
  386. flexio_shifter_config_t config = {
  387. .timerSelect = 0,
  388. .timerPolarity = kFLEXIO_ShifterTimerPolarityOnPositive,
  389. .pinConfig = kFLEXIO_PinConfigOpenDrainOrBidirection,
  390. .pinPolarity = kFLEXIO_PinActiveLow,
  391. .shifterMode = kFLEXIO_ShifterModeTransmit,
  392. .inputSource = kFLEXIO_ShifterInputFromPin,
  393. .shifterStop = kFLEXIO_ShifterStopBitHigh,
  394. .shifterStart = kFLEXIO_ShifterStartBitLow
  395. };
  396. FLEXIO_SetShifterConfig(base, &config);
  397. @endcode
  398. *
  399. * @param base FlexIO peripheral base address
  400. * @param index Shifter index
  401. * @param shifterConfig Pointer to flexio_shifter_config_t structure
  402. */
  403. void FLEXIO_SetShifterConfig(FLEXIO_Type *base, uint8_t index, const flexio_shifter_config_t *shifterConfig);
  404. /*!
  405. * @brief Configures the timer with the timer configuration. The configuration structure
  406. * covers both the TIMCTL and TIMCFG registers. To configure the timer to the proper
  407. * mode, select trigger source for timer and the timer pin output and the timing for timer.
  408. *
  409. * Example
  410. @code
  411. flexio_timer_config_t config = {
  412. .triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(0),
  413. .triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow,
  414. .triggerSource = kFLEXIO_TimerTriggerSourceInternal,
  415. .pinConfig = kFLEXIO_PinConfigOpenDrainOrBidirection,
  416. .pinSelect = 0,
  417. .pinPolarity = kFLEXIO_PinActiveHigh,
  418. .timerMode = kFLEXIO_TimerModeDual8BitBaudBit,
  419. .timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset,
  420. .timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput,
  421. .timerReset = kFLEXIO_TimerResetOnTimerPinEqualToTimerOutput,
  422. .timerDisable = kFLEXIO_TimerDisableOnTimerCompare,
  423. .timerEnable = kFLEXIO_TimerEnableOnTriggerHigh,
  424. .timerStop = kFLEXIO_TimerStopBitEnableOnTimerDisable,
  425. .timerStart = kFLEXIO_TimerStartBitEnabled
  426. };
  427. FLEXIO_SetTimerConfig(base, &config);
  428. @endcode
  429. *
  430. * @param base FlexIO peripheral base address
  431. * @param index Timer index
  432. * @param timerConfig Pointer to the flexio_timer_config_t structure
  433. */
  434. void FLEXIO_SetTimerConfig(FLEXIO_Type *base, uint8_t index, const flexio_timer_config_t *timerConfig);
  435. /* @} */
  436. /*!
  437. * @name FlexIO Interrupt Operation
  438. * @{
  439. */
  440. /*!
  441. * @brief Enables the shifter status interrupt. The interrupt generates when the corresponding SSF is set.
  442. *
  443. * @param base FlexIO peripheral base address
  444. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  445. * @note For multiple shifter status interrupt enable, for example, two shifter status enable, can calculate
  446. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  447. */
  448. static inline void FLEXIO_EnableShifterStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  449. {
  450. base->SHIFTSIEN |= mask;
  451. }
  452. /*!
  453. * @brief Disables the shifter status interrupt. The interrupt won't generate when the corresponding SSF is set.
  454. *
  455. * @param base FlexIO peripheral base address
  456. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  457. * @note For multiple shifter status interrupt enable, for example, two shifter status enable, can calculate
  458. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  459. */
  460. static inline void FLEXIO_DisableShifterStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  461. {
  462. base->SHIFTSIEN &= ~mask;
  463. }
  464. /*!
  465. * @brief Enables the shifter error interrupt. The interrupt generates when the corresponding SEF is set.
  466. *
  467. * @param base FlexIO peripheral base address
  468. * @param mask The shifter error mask which can be calculated by (1 << shifter index)
  469. * @note For multiple shifter error interrupt enable, for example, two shifter error enable, can calculate
  470. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  471. */
  472. static inline void FLEXIO_EnableShifterErrorInterrupts(FLEXIO_Type *base, uint32_t mask)
  473. {
  474. base->SHIFTEIEN |= mask;
  475. }
  476. /*!
  477. * @brief Disables the shifter error interrupt. The interrupt won't generate when the corresponding SEF is set.
  478. *
  479. * @param base FlexIO peripheral base address
  480. * @param mask The shifter error mask which can be calculated by (1 << shifter index)
  481. * @note For multiple shifter error interrupt enable, for example, two shifter error enable, can calculate
  482. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  483. */
  484. static inline void FLEXIO_DisableShifterErrorInterrupts(FLEXIO_Type *base, uint32_t mask)
  485. {
  486. base->SHIFTEIEN &= ~mask;
  487. }
  488. /*!
  489. * @brief Enables the timer status interrupt. The interrupt generates when the corresponding SSF is set.
  490. *
  491. * @param base FlexIO peripheral base address
  492. * @param mask The timer status mask which can be calculated by (1 << timer index)
  493. * @note For multiple timer status interrupt enable, for example, two timer status enable, can calculate
  494. * the mask by using ((1 << timer index0) | (1 << timer index1))
  495. */
  496. static inline void FLEXIO_EnableTimerStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  497. {
  498. base->TIMIEN |= mask;
  499. }
  500. /*!
  501. * @brief Disables the timer status interrupt. The interrupt won't generate when the corresponding SSF is set.
  502. *
  503. * @param base FlexIO peripheral base address
  504. * @param mask The timer status mask which can be calculated by (1 << timer index)
  505. * @note For multiple timer status interrupt enable, for example, two timer status enable, can calculate
  506. * the mask by using ((1 << timer index0) | (1 << timer index1))
  507. */
  508. static inline void FLEXIO_DisableTimerStatusInterrupts(FLEXIO_Type *base, uint32_t mask)
  509. {
  510. base->TIMIEN &= ~mask;
  511. }
  512. /* @} */
  513. /*!
  514. * @name FlexIO Status Operation
  515. * @{
  516. */
  517. /*!
  518. * @brief Gets the shifter status flags.
  519. *
  520. * @param base FlexIO peripheral base address
  521. * @return Shifter status flags
  522. */
  523. static inline uint32_t FLEXIO_GetShifterStatusFlags(FLEXIO_Type *base)
  524. {
  525. return ((base->SHIFTSTAT) & FLEXIO_SHIFTSTAT_SSF_MASK);
  526. }
  527. /*!
  528. * @brief Clears the shifter status flags.
  529. *
  530. * @param base FlexIO peripheral base address
  531. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  532. * @note For clearing multiple shifter status flags, for example, two shifter status flags, can calculate
  533. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  534. */
  535. static inline void FLEXIO_ClearShifterStatusFlags(FLEXIO_Type *base, uint32_t mask)
  536. {
  537. base->SHIFTSTAT = mask;
  538. }
  539. /*!
  540. * @brief Gets the shifter error flags.
  541. *
  542. * @param base FlexIO peripheral base address
  543. * @return Shifter error flags
  544. */
  545. static inline uint32_t FLEXIO_GetShifterErrorFlags(FLEXIO_Type *base)
  546. {
  547. return ((base->SHIFTERR) & FLEXIO_SHIFTERR_SEF_MASK);
  548. }
  549. /*!
  550. * @brief Clears the shifter error flags.
  551. *
  552. * @param base FlexIO peripheral base address
  553. * @param mask The shifter error mask which can be calculated by (1 << shifter index)
  554. * @note For clearing multiple shifter error flags, for example, two shifter error flags, can calculate
  555. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  556. */
  557. static inline void FLEXIO_ClearShifterErrorFlags(FLEXIO_Type *base, uint32_t mask)
  558. {
  559. base->SHIFTERR = mask;
  560. }
  561. /*!
  562. * @brief Gets the timer status flags.
  563. *
  564. * @param base FlexIO peripheral base address
  565. * @return Timer status flags
  566. */
  567. static inline uint32_t FLEXIO_GetTimerStatusFlags(FLEXIO_Type *base)
  568. {
  569. return ((base->TIMSTAT) & FLEXIO_TIMSTAT_TSF_MASK);
  570. }
  571. /*!
  572. * @brief Clears the timer status flags.
  573. *
  574. * @param base FlexIO peripheral base address
  575. * @param mask The timer status mask which can be calculated by (1 << timer index)
  576. * @note For clearing multiple timer status flags, for example, two timer status flags, can calculate
  577. * the mask by using ((1 << timer index0) | (1 << timer index1))
  578. */
  579. static inline void FLEXIO_ClearTimerStatusFlags(FLEXIO_Type *base, uint32_t mask)
  580. {
  581. base->TIMSTAT = mask;
  582. }
  583. /* @} */
  584. /*!
  585. * @name FlexIO DMA Operation
  586. * @{
  587. */
  588. /*!
  589. * @brief Enables/disables the shifter status DMA. The DMA request generates when the corresponding SSF is set.
  590. *
  591. * @note For multiple shifter status DMA enables, for example, calculate
  592. * the mask by using ((1 << shifter index0) | (1 << shifter index1))
  593. *
  594. * @param base FlexIO peripheral base address
  595. * @param mask The shifter status mask which can be calculated by (1 << shifter index)
  596. * @param enable True to enable, false to disable.
  597. */
  598. static inline void FLEXIO_EnableShifterStatusDMA(FLEXIO_Type *base, uint32_t mask, bool enable)
  599. {
  600. if (enable)
  601. {
  602. base->SHIFTSDEN |= mask;
  603. }
  604. else
  605. {
  606. base->SHIFTSDEN &= ~mask;
  607. }
  608. }
  609. /*!
  610. * @brief Gets the shifter buffer address for the DMA transfer usage.
  611. *
  612. * @param base FlexIO peripheral base address
  613. * @param type Shifter type of flexio_shifter_buffer_type_t
  614. * @param index Shifter index
  615. * @return Corresponding shifter buffer index
  616. */
  617. uint32_t FLEXIO_GetShifterBufferAddress(FLEXIO_Type *base, flexio_shifter_buffer_type_t type, uint8_t index);
  618. /*!
  619. * @brief Registers the handle and the interrupt handler for the FlexIO-simulated peripheral.
  620. *
  621. * @param base Pointer to the FlexIO simulated peripheral type.
  622. * @param handle Pointer to the handler for FlexIO simulated peripheral.
  623. * @param isr FlexIO simulated peripheral interrupt handler.
  624. * @retval kStatus_Success Successfully create the handle.
  625. * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
  626. */
  627. status_t FLEXIO_RegisterHandleIRQ(void *base, void *handle, flexio_isr_t isr);
  628. /*!
  629. * @brief Unregisters the handle and the interrupt handler for the FlexIO-simulated peripheral.
  630. *
  631. * @param base Pointer to the FlexIO simulated peripheral type.
  632. * @retval kStatus_Success Successfully create the handle.
  633. * @retval kStatus_OutOfRange The FlexIO type/handle/ISR table out of range.
  634. */
  635. status_t FLEXIO_UnregisterHandleIRQ(void *base);
  636. /* @} */
  637. #if defined(__cplusplus)
  638. }
  639. #endif /*_cplusplus*/
  640. /*@}*/
  641. #endif /*_FSL_FLEXIO_H_*/