fsl_flexbus.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_FLEXBUS_H_
  35. #define _FSL_FLEXBUS_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup flexbus
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @name Driver version */
  45. /*@{*/
  46. #define FSL_FLEXBUS_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */
  47. /*@}*/
  48. /*!
  49. * @brief Defines port size for FlexBus peripheral.
  50. */
  51. typedef enum _flexbus_port_size
  52. {
  53. kFLEXBUS_4Bytes = 0x00U, /*!< 32-bit port size */
  54. kFLEXBUS_1Byte = 0x01U, /*!< 8-bit port size */
  55. kFLEXBUS_2Bytes = 0x02U /*!< 16-bit port size */
  56. } flexbus_port_size_t;
  57. /*!
  58. * @brief Defines number of cycles to hold address and attributes for FlexBus peripheral.
  59. */
  60. typedef enum _flexbus_write_address_hold
  61. {
  62. kFLEXBUS_Hold1Cycle = 0x00U, /*!< Hold address and attributes one cycles after FB_CSn negates on writes */
  63. kFLEXBUS_Hold2Cycles = 0x01U, /*!< Hold address and attributes two cycles after FB_CSn negates on writes */
  64. kFLEXBUS_Hold3Cycles = 0x02U, /*!< Hold address and attributes three cycles after FB_CSn negates on writes */
  65. kFLEXBUS_Hold4Cycles = 0x03U /*!< Hold address and attributes four cycles after FB_CSn negates on writes */
  66. } flexbus_write_address_hold_t;
  67. /*!
  68. * @brief Defines number of cycles to hold address and attributes for FlexBus peripheral.
  69. */
  70. typedef enum _flexbus_read_address_hold
  71. {
  72. kFLEXBUS_Hold1Or0Cycles = 0x00U, /*!< Hold address and attributes 1 or 0 cycles on reads */
  73. kFLEXBUS_Hold2Or1Cycles = 0x01U, /*!< Hold address and attributes 2 or 1 cycles on reads */
  74. kFLEXBUS_Hold3Or2Cycle = 0x02U, /*!< Hold address and attributes 3 or 2 cycles on reads */
  75. kFLEXBUS_Hold4Or3Cycle = 0x03U /*!< Hold address and attributes 4 or 3 cycles on reads */
  76. } flexbus_read_address_hold_t;
  77. /*!
  78. * @brief Address setup for FlexBus peripheral.
  79. */
  80. typedef enum _flexbus_address_setup
  81. {
  82. kFLEXBUS_FirstRisingEdge = 0x00U, /*!< Assert FB_CSn on first rising clock edge after address is asserted */
  83. kFLEXBUS_SecondRisingEdge = 0x01U, /*!< Assert FB_CSn on second rising clock edge after address is asserted */
  84. kFLEXBUS_ThirdRisingEdge = 0x02U, /*!< Assert FB_CSn on third rising clock edge after address is asserted */
  85. kFLEXBUS_FourthRisingEdge = 0x03U, /*!< Assert FB_CSn on fourth rising clock edge after address is asserted */
  86. } flexbus_address_setup_t;
  87. /*!
  88. * @brief Defines byte-lane shift for FlexBus peripheral.
  89. */
  90. typedef enum _flexbus_bytelane_shift
  91. {
  92. kFLEXBUS_NotShifted = 0x00U, /*!< Not shifted. Data is left-justified on FB_AD */
  93. kFLEXBUS_Shifted = 0x01U, /*!< Shifted. Data is right justified on FB_AD */
  94. } flexbus_bytelane_shift_t;
  95. /*!
  96. * @brief Defines multiplex group1 valid signals.
  97. */
  98. typedef enum _flexbus_multiplex_group1_signal
  99. {
  100. kFLEXBUS_MultiplexGroup1_FB_ALE = 0x00U, /*!< FB_ALE */
  101. kFLEXBUS_MultiplexGroup1_FB_CS1 = 0x01U, /*!< FB_CS1 */
  102. kFLEXBUS_MultiplexGroup1_FB_TS = 0x02U, /*!< FB_TS */
  103. } flexbus_multiplex_group1_t;
  104. /*!
  105. * @brief Defines multiplex group2 valid signals.
  106. */
  107. typedef enum _flexbus_multiplex_group2_signal
  108. {
  109. kFLEXBUS_MultiplexGroup2_FB_CS4 = 0x00U, /*!< FB_CS4 */
  110. kFLEXBUS_MultiplexGroup2_FB_TSIZ0 = 0x01U, /*!< FB_TSIZ0 */
  111. kFLEXBUS_MultiplexGroup2_FB_BE_31_24 = 0x02U, /*!< FB_BE_31_24 */
  112. } flexbus_multiplex_group2_t;
  113. /*!
  114. * @brief Defines multiplex group3 valid signals.
  115. */
  116. typedef enum _flexbus_multiplex_group3_signal
  117. {
  118. kFLEXBUS_MultiplexGroup3_FB_CS5 = 0x00U, /*!< FB_CS5 */
  119. kFLEXBUS_MultiplexGroup3_FB_TSIZ1 = 0x01U, /*!< FB_TSIZ1 */
  120. kFLEXBUS_MultiplexGroup3_FB_BE_23_16 = 0x02U, /*!< FB_BE_23_16 */
  121. } flexbus_multiplex_group3_t;
  122. /*!
  123. * @brief Defines multiplex group4 valid signals.
  124. */
  125. typedef enum _flexbus_multiplex_group4_signal
  126. {
  127. kFLEXBUS_MultiplexGroup4_FB_TBST = 0x00U, /*!< FB_TBST */
  128. kFLEXBUS_MultiplexGroup4_FB_CS2 = 0x01U, /*!< FB_CS2 */
  129. kFLEXBUS_MultiplexGroup4_FB_BE_15_8 = 0x02U, /*!< FB_BE_15_8 */
  130. } flexbus_multiplex_group4_t;
  131. /*!
  132. * @brief Defines multiplex group5 valid signals.
  133. */
  134. typedef enum _flexbus_multiplex_group5_signal
  135. {
  136. kFLEXBUS_MultiplexGroup5_FB_TA = 0x00U, /*!< FB_TA */
  137. kFLEXBUS_MultiplexGroup5_FB_CS3 = 0x01U, /*!< FB_CS3 */
  138. kFLEXBUS_MultiplexGroup5_FB_BE_7_0 = 0x02U, /*!< FB_BE_7_0 */
  139. } flexbus_multiplex_group5_t;
  140. /*!
  141. * @brief Configuration structure that the user needs to set.
  142. */
  143. typedef struct _flexbus_config
  144. {
  145. uint8_t chip; /*!< Chip FlexBus for validation */
  146. uint8_t waitStates; /*!< Value of wait states */
  147. uint32_t chipBaseAddress; /*!< Chip base address for using FlexBus */
  148. uint32_t chipBaseAddressMask; /*!< Chip base address mask */
  149. bool writeProtect; /*!< Write protected */
  150. bool burstWrite; /*!< Burst-Write enable */
  151. bool burstRead; /*!< Burst-Read enable */
  152. bool byteEnableMode; /*!< Byte-enable mode support */
  153. bool autoAcknowledge; /*!< Auto acknowledge setting */
  154. bool extendTransferAddress; /*!< Extend transfer start/extend address latch enable */
  155. bool secondaryWaitStates; /*!< Secondary wait states number */
  156. flexbus_port_size_t portSize; /*!< Port size of transfer */
  157. flexbus_bytelane_shift_t byteLaneShift; /*!< Byte-lane shift enable */
  158. flexbus_write_address_hold_t writeAddressHold; /*!< Write address hold or deselect option */
  159. flexbus_read_address_hold_t readAddressHold; /*!< Read address hold or deselect option */
  160. flexbus_address_setup_t addressSetup; /*!< Address setup setting */
  161. flexbus_multiplex_group1_t group1MultiplexControl; /*!< FlexBus Signal Group 1 Multiplex control */
  162. flexbus_multiplex_group2_t group2MultiplexControl; /*!< FlexBus Signal Group 2 Multiplex control */
  163. flexbus_multiplex_group3_t group3MultiplexControl; /*!< FlexBus Signal Group 3 Multiplex control */
  164. flexbus_multiplex_group4_t group4MultiplexControl; /*!< FlexBus Signal Group 4 Multiplex control */
  165. flexbus_multiplex_group5_t group5MultiplexControl; /*!< FlexBus Signal Group 5 Multiplex control */
  166. } flexbus_config_t;
  167. /*******************************************************************************
  168. * API
  169. ******************************************************************************/
  170. #if defined(__cplusplus)
  171. extern "C" {
  172. #endif /* __cplusplus */
  173. /*!
  174. * @name FlexBus functional operation
  175. * @{
  176. */
  177. /*!
  178. * @brief Initializes and configures the FlexBus module.
  179. *
  180. * This function enables the clock gate for FlexBus module.
  181. * Only chip 0 is validated and set to known values. Other chips are disabled.
  182. * Note that in this function, certain parameters, depending on external memories, must
  183. * be set before using the FLEXBUS_Init() function.
  184. * This example shows how to set up the uart_state_t and the
  185. * flexbus_config_t parameters and how to call the FLEXBUS_Init function by passing
  186. * in these parameters.
  187. @code
  188. flexbus_config_t flexbusConfig;
  189. FLEXBUS_GetDefaultConfig(&flexbusConfig);
  190. flexbusConfig.waitStates = 2U;
  191. flexbusConfig.chipBaseAddress = 0x60000000U;
  192. flexbusConfig.chipBaseAddressMask = 7U;
  193. FLEXBUS_Init(FB, &flexbusConfig);
  194. @endcode
  195. *
  196. * @param base FlexBus peripheral address.
  197. * @param config Pointer to the configuration structure
  198. */
  199. void FLEXBUS_Init(FB_Type *base, const flexbus_config_t *config);
  200. /*!
  201. * @brief De-initializes a FlexBus instance.
  202. *
  203. * This function disables the clock gate of the FlexBus module clock.
  204. *
  205. * @param base FlexBus peripheral address.
  206. */
  207. void FLEXBUS_Deinit(FB_Type *base);
  208. /*!
  209. * @brief Initializes the FlexBus configuration structure.
  210. *
  211. * This function initializes the FlexBus configuration structure to default value. The default
  212. * values are.
  213. @code
  214. fbConfig->chip = 0;
  215. fbConfig->writeProtect = 0;
  216. fbConfig->burstWrite = 0;
  217. fbConfig->burstRead = 0;
  218. fbConfig->byteEnableMode = 0;
  219. fbConfig->autoAcknowledge = true;
  220. fbConfig->extendTransferAddress = 0;
  221. fbConfig->secondaryWaitStates = 0;
  222. fbConfig->byteLaneShift = kFLEXBUS_NotShifted;
  223. fbConfig->writeAddressHold = kFLEXBUS_Hold1Cycle;
  224. fbConfig->readAddressHold = kFLEXBUS_Hold1Or0Cycles;
  225. fbConfig->addressSetup = kFLEXBUS_FirstRisingEdge;
  226. fbConfig->portSize = kFLEXBUS_1Byte;
  227. fbConfig->group1MultiplexControl = kFLEXBUS_MultiplexGroup1_FB_ALE;
  228. fbConfig->group2MultiplexControl = kFLEXBUS_MultiplexGroup2_FB_CS4 ;
  229. fbConfig->group3MultiplexControl = kFLEXBUS_MultiplexGroup3_FB_CS5;
  230. fbConfig->group4MultiplexControl = kFLEXBUS_MultiplexGroup4_FB_TBST;
  231. fbConfig->group5MultiplexControl = kFLEXBUS_MultiplexGroup5_FB_TA;
  232. @endcode
  233. * @param config Pointer to the initialization structure.
  234. * @see FLEXBUS_Init
  235. */
  236. void FLEXBUS_GetDefaultConfig(flexbus_config_t *config);
  237. /*! @}*/
  238. #if defined(__cplusplus)
  239. }
  240. #endif /* __cplusplus */
  241. /*! @}*/
  242. #endif /* _FSL_FLEXBUS_H_ */