fsl_flexbus.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_FLEXBUS_H_
  31. #define _FSL_FLEXBUS_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup flexbus
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. #define FSL_FLEXBUS_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */
  43. /*@}*/
  44. /*!
  45. * @brief Defines port size for FlexBus peripheral.
  46. */
  47. typedef enum _flexbus_port_size
  48. {
  49. kFLEXBUS_4Bytes = 0x00U, /*!< 32-bit port size */
  50. kFLEXBUS_1Byte = 0x01U, /*!< 8-bit port size */
  51. kFLEXBUS_2Bytes = 0x02U /*!< 16-bit port size */
  52. } flexbus_port_size_t;
  53. /*!
  54. * @brief Defines number of cycles to hold address and attributes for FlexBus peripheral.
  55. */
  56. typedef enum _flexbus_write_address_hold
  57. {
  58. kFLEXBUS_Hold1Cycle = 0x00U, /*!< Hold address and attributes one cycles after FB_CSn negates on writes */
  59. kFLEXBUS_Hold2Cycles = 0x01U, /*!< Hold address and attributes two cycles after FB_CSn negates on writes */
  60. kFLEXBUS_Hold3Cycles = 0x02U, /*!< Hold address and attributes three cycles after FB_CSn negates on writes */
  61. kFLEXBUS_Hold4Cycles = 0x03U /*!< Hold address and attributes four cycles after FB_CSn negates on writes */
  62. } flexbus_write_address_hold_t;
  63. /*!
  64. * @brief Defines number of cycles to hold address and attributes for FlexBus peripheral.
  65. */
  66. typedef enum _flexbus_read_address_hold
  67. {
  68. kFLEXBUS_Hold1Or0Cycles = 0x00U, /*!< Hold address and attributes 1 or 0 cycles on reads */
  69. kFLEXBUS_Hold2Or1Cycles = 0x01U, /*!< Hold address and attributes 2 or 1 cycles on reads */
  70. kFLEXBUS_Hold3Or2Cycle = 0x02U, /*!< Hold address and attributes 3 or 2 cycles on reads */
  71. kFLEXBUS_Hold4Or3Cycle = 0x03U /*!< Hold address and attributes 4 or 3 cycles on reads */
  72. } flexbus_read_address_hold_t;
  73. /*!
  74. * @brief Address setup for FlexBus peripheral.
  75. */
  76. typedef enum _flexbus_address_setup
  77. {
  78. kFLEXBUS_FirstRisingEdge = 0x00U, /*!< Assert FB_CSn on first rising clock edge after address is asserted */
  79. kFLEXBUS_SecondRisingEdge = 0x01U, /*!< Assert FB_CSn on second rising clock edge after address is asserted */
  80. kFLEXBUS_ThirdRisingEdge = 0x02U, /*!< Assert FB_CSn on third rising clock edge after address is asserted */
  81. kFLEXBUS_FourthRisingEdge = 0x03U, /*!< Assert FB_CSn on fourth rising clock edge after address is asserted */
  82. } flexbus_address_setup_t;
  83. /*!
  84. * @brief Defines byte-lane shift for FlexBus peripheral.
  85. */
  86. typedef enum _flexbus_bytelane_shift
  87. {
  88. kFLEXBUS_NotShifted = 0x00U, /*!< Not shifted. Data is left-justified on FB_AD */
  89. kFLEXBUS_Shifted = 0x01U, /*!< Shifted. Data is right justified on FB_AD */
  90. } flexbus_bytelane_shift_t;
  91. /*!
  92. * @brief Defines multiplex group1 valid signals.
  93. */
  94. typedef enum _flexbus_multiplex_group1_signal
  95. {
  96. kFLEXBUS_MultiplexGroup1_FB_ALE = 0x00U, /*!< FB_ALE */
  97. kFLEXBUS_MultiplexGroup1_FB_CS1 = 0x01U, /*!< FB_CS1 */
  98. kFLEXBUS_MultiplexGroup1_FB_TS = 0x02U, /*!< FB_TS */
  99. } flexbus_multiplex_group1_t;
  100. /*!
  101. * @brief Defines multiplex group2 valid signals.
  102. */
  103. typedef enum _flexbus_multiplex_group2_signal
  104. {
  105. kFLEXBUS_MultiplexGroup2_FB_CS4 = 0x00U, /*!< FB_CS4 */
  106. kFLEXBUS_MultiplexGroup2_FB_TSIZ0 = 0x01U, /*!< FB_TSIZ0 */
  107. kFLEXBUS_MultiplexGroup2_FB_BE_31_24 = 0x02U, /*!< FB_BE_31_24 */
  108. } flexbus_multiplex_group2_t;
  109. /*!
  110. * @brief Defines multiplex group3 valid signals.
  111. */
  112. typedef enum _flexbus_multiplex_group3_signal
  113. {
  114. kFLEXBUS_MultiplexGroup3_FB_CS5 = 0x00U, /*!< FB_CS5 */
  115. kFLEXBUS_MultiplexGroup3_FB_TSIZ1 = 0x01U, /*!< FB_TSIZ1 */
  116. kFLEXBUS_MultiplexGroup3_FB_BE_23_16 = 0x02U, /*!< FB_BE_23_16 */
  117. } flexbus_multiplex_group3_t;
  118. /*!
  119. * @brief Defines multiplex group4 valid signals.
  120. */
  121. typedef enum _flexbus_multiplex_group4_signal
  122. {
  123. kFLEXBUS_MultiplexGroup4_FB_TBST = 0x00U, /*!< FB_TBST */
  124. kFLEXBUS_MultiplexGroup4_FB_CS2 = 0x01U, /*!< FB_CS2 */
  125. kFLEXBUS_MultiplexGroup4_FB_BE_15_8 = 0x02U, /*!< FB_BE_15_8 */
  126. } flexbus_multiplex_group4_t;
  127. /*!
  128. * @brief Defines multiplex group5 valid signals.
  129. */
  130. typedef enum _flexbus_multiplex_group5_signal
  131. {
  132. kFLEXBUS_MultiplexGroup5_FB_TA = 0x00U, /*!< FB_TA */
  133. kFLEXBUS_MultiplexGroup5_FB_CS3 = 0x01U, /*!< FB_CS3 */
  134. kFLEXBUS_MultiplexGroup5_FB_BE_7_0 = 0x02U, /*!< FB_BE_7_0 */
  135. } flexbus_multiplex_group5_t;
  136. /*!
  137. * @brief Configuration structure that the user needs to set.
  138. */
  139. typedef struct _flexbus_config
  140. {
  141. uint8_t chip; /*!< Chip FlexBus for validation */
  142. uint8_t waitStates; /*!< Value of wait states */
  143. uint32_t chipBaseAddress; /*!< Chip base address for using FlexBus */
  144. uint32_t chipBaseAddressMask; /*!< Chip base address mask */
  145. bool writeProtect; /*!< Write protected */
  146. bool burstWrite; /*!< Burst-Write enable */
  147. bool burstRead; /*!< Burst-Read enable */
  148. bool byteEnableMode; /*!< Byte-enable mode support */
  149. bool autoAcknowledge; /*!< Auto acknowledge setting */
  150. bool extendTransferAddress; /*!< Extend transfer start/extend address latch enable */
  151. bool secondaryWaitStates; /*!< Secondary wait states number */
  152. flexbus_port_size_t portSize; /*!< Port size of transfer */
  153. flexbus_bytelane_shift_t byteLaneShift; /*!< Byte-lane shift enable */
  154. flexbus_write_address_hold_t writeAddressHold; /*!< Write address hold or deselect option */
  155. flexbus_read_address_hold_t readAddressHold; /*!< Read address hold or deselect option */
  156. flexbus_address_setup_t addressSetup; /*!< Address setup setting */
  157. flexbus_multiplex_group1_t group1MultiplexControl; /*!< FlexBus Signal Group 1 Multiplex control */
  158. flexbus_multiplex_group2_t group2MultiplexControl; /*!< FlexBus Signal Group 2 Multiplex control */
  159. flexbus_multiplex_group3_t group3MultiplexControl; /*!< FlexBus Signal Group 3 Multiplex control */
  160. flexbus_multiplex_group4_t group4MultiplexControl; /*!< FlexBus Signal Group 4 Multiplex control */
  161. flexbus_multiplex_group5_t group5MultiplexControl; /*!< FlexBus Signal Group 5 Multiplex control */
  162. } flexbus_config_t;
  163. /*******************************************************************************
  164. * API
  165. ******************************************************************************/
  166. #if defined(__cplusplus)
  167. extern "C" {
  168. #endif /* __cplusplus */
  169. /*!
  170. * @name FlexBus functional operation
  171. * @{
  172. */
  173. /*!
  174. * @brief Initializes and configures the FlexBus module.
  175. *
  176. * This function enables the clock gate for FlexBus module.
  177. * Only chip 0 is validated and set to known values. Other chips are disabled.
  178. * Note that in this function, certain parameters, depending on external memories, must
  179. * be set before using the FLEXBUS_Init() function.
  180. * This example shows how to set up the uart_state_t and the
  181. * flexbus_config_t parameters and how to call the FLEXBUS_Init function by passing
  182. * in these parameters.
  183. @code
  184. flexbus_config_t flexbusConfig;
  185. FLEXBUS_GetDefaultConfig(&flexbusConfig);
  186. flexbusConfig.waitStates = 2U;
  187. flexbusConfig.chipBaseAddress = 0x60000000U;
  188. flexbusConfig.chipBaseAddressMask = 7U;
  189. FLEXBUS_Init(FB, &flexbusConfig);
  190. @endcode
  191. *
  192. * @param base FlexBus peripheral address.
  193. * @param config Pointer to the configuration structure
  194. */
  195. void FLEXBUS_Init(FB_Type *base, const flexbus_config_t *config);
  196. /*!
  197. * @brief De-initializes a FlexBus instance.
  198. *
  199. * This function disables the clock gate of the FlexBus module clock.
  200. *
  201. * @param base FlexBus peripheral address.
  202. */
  203. void FLEXBUS_Deinit(FB_Type *base);
  204. /*!
  205. * @brief Initializes the FlexBus configuration structure.
  206. *
  207. * This function initializes the FlexBus configuration structure to default value. The default
  208. * values are.
  209. @code
  210. fbConfig->chip = 0;
  211. fbConfig->writeProtect = 0;
  212. fbConfig->burstWrite = 0;
  213. fbConfig->burstRead = 0;
  214. fbConfig->byteEnableMode = 0;
  215. fbConfig->autoAcknowledge = true;
  216. fbConfig->extendTransferAddress = 0;
  217. fbConfig->secondaryWaitStates = 0;
  218. fbConfig->byteLaneShift = kFLEXBUS_NotShifted;
  219. fbConfig->writeAddressHold = kFLEXBUS_Hold1Cycle;
  220. fbConfig->readAddressHold = kFLEXBUS_Hold1Or0Cycles;
  221. fbConfig->addressSetup = kFLEXBUS_FirstRisingEdge;
  222. fbConfig->portSize = kFLEXBUS_1Byte;
  223. fbConfig->group1MultiplexControl = kFLEXBUS_MultiplexGroup1_FB_ALE;
  224. fbConfig->group2MultiplexControl = kFLEXBUS_MultiplexGroup2_FB_CS4 ;
  225. fbConfig->group3MultiplexControl = kFLEXBUS_MultiplexGroup3_FB_CS5;
  226. fbConfig->group4MultiplexControl = kFLEXBUS_MultiplexGroup4_FB_TBST;
  227. fbConfig->group5MultiplexControl = kFLEXBUS_MultiplexGroup5_FB_TA;
  228. @endcode
  229. * @param config Pointer to the initialization structure.
  230. * @see FLEXBUS_Init
  231. */
  232. void FLEXBUS_GetDefaultConfig(flexbus_config_t *config);
  233. /*! @}*/
  234. #if defined(__cplusplus)
  235. }
  236. #endif /* __cplusplus */
  237. /*! @}*/
  238. #endif /* _FSL_FLEXBUS_H_ */