1 /**************************************************************************//**
2  * @file     ebi.h
3  * @version  V3.00
4  * @brief    External Bus Interface(EBI) driver header file
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8  *****************************************************************************/
9 #ifndef __EBI_H__
10 #define __EBI_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 
18 /** @addtogroup Standard_Driver Standard Driver
19   @{
20 */
21 
22 /** @addtogroup EBI_Driver EBI Driver
23   @{
24 */
25 
26 /** @addtogroup EBI_EXPORTED_CONSTANTS EBI Exported Constants
27   @{
28 */
29 /*---------------------------------------------------------------------------------------------------------*/
30 /*  Miscellaneous Constant Definitions                                                                     */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define EBI_BANK0_BASE_ADDR     0x60000000UL /*!< EBI bank0 base address \hideinitializer */
33 #define EBI_BANK1_BASE_ADDR     0x60100000UL /*!< EBI bank1 base address \hideinitializer */
34 #define EBI_BANK2_BASE_ADDR     0x60200000UL /*!< EBI bank2 base address \hideinitializer */
35 #define EBI_BANK0_BASE_ADDR_NS  0x70000000UL /*!< EBI bank0 base address for Non-Secure \hideinitializer */
36 #define EBI_BANK1_BASE_ADDR_NS  0x70100000UL /*!< EBI bank1 base address for Non-Secure \hideinitializer */
37 #define EBI_BANK2_BASE_ADDR_NS  0x70200000UL /*!< EBI bank2 base address for Non-Secure \hideinitializer */
38 #define EBI_MAX_SIZE            0x00100000UL /*!< Maximum EBI size for each bank is 1 MB \hideinitializer */
39 
40 /*---------------------------------------------------------------------------------------------------------*/
41 /*  Constants for EBI bank number                                                                          */
42 /*---------------------------------------------------------------------------------------------------------*/
43 #define EBI_BANK0               0UL    /*!< EBI bank 0 \hideinitializer */
44 #define EBI_BANK1               1UL    /*!< EBI bank 1 \hideinitializer */
45 #define EBI_BANK2               2UL    /*!< EBI bank 2 \hideinitializer */
46 
47 /*---------------------------------------------------------------------------------------------------------*/
48 /*  Constants for EBI data bus width                                                                       */
49 /*---------------------------------------------------------------------------------------------------------*/
50 #define EBI_BUSWIDTH_8BIT       8UL   /*!< EBI bus width is 8-bit \hideinitializer */
51 #define EBI_BUSWIDTH_16BIT      16UL  /*!< EBI bus width is 16-bit \hideinitializer */
52 
53 /*---------------------------------------------------------------------------------------------------------*/
54 /*  Constants for EBI CS Active Level                                                                      */
55 /*---------------------------------------------------------------------------------------------------------*/
56 #define EBI_CS_ACTIVE_LOW       0UL    /*!< EBI CS active level is low \hideinitializer */
57 #define EBI_CS_ACTIVE_HIGH      1UL    /*!< EBI CS active level is high \hideinitializer */
58 
59 /*---------------------------------------------------------------------------------------------------------*/
60 /*  Constants for EBI MCLK divider and Timing                                                              */
61 /*---------------------------------------------------------------------------------------------------------*/
62 #define EBI_MCLKDIV_1           0x0UL /*!< EBI output clock(MCLK) is HCLK/1 \hideinitializer */
63 #define EBI_MCLKDIV_2           0x1UL /*!< EBI output clock(MCLK) is HCLK/2 \hideinitializer */
64 #define EBI_MCLKDIV_4           0x2UL /*!< EBI output clock(MCLK) is HCLK/4 \hideinitializer */
65 #define EBI_MCLKDIV_8           0x3UL /*!< EBI output clock(MCLK) is HCLK/8 \hideinitializer */
66 #define EBI_MCLKDIV_16          0x4UL /*!< EBI output clock(MCLK) is HCLK/16 \hideinitializer */
67 #define EBI_MCLKDIV_32          0x5UL /*!< EBI output clock(MCLK) is HCLK/32 \hideinitializer */
68 #define EBI_MCLKDIV_64          0x6UL /*!< EBI output clock(MCLK) is HCLK/64 \hideinitializer */
69 #define EBI_MCLKDIV_128         0x7UL /*!< EBI output clock(MCLK) is HCLK/128 \hideinitializer */
70 
71 #define EBI_TIMING_FASTEST      0x0UL /*!< EBI timing is the fastest \hideinitializer */
72 #define EBI_TIMING_VERYFAST     0x1UL /*!< EBI timing is very fast \hideinitializer */
73 #define EBI_TIMING_FAST         0x2UL /*!< EBI timing is fast \hideinitializer */
74 #define EBI_TIMING_NORMAL       0x3UL /*!< EBI timing is normal \hideinitializer */
75 #define EBI_TIMING_SLOW         0x4UL /*!< EBI timing is slow \hideinitializer */
76 #define EBI_TIMING_VERYSLOW     0x5UL /*!< EBI timing is very slow \hideinitializer */
77 #define EBI_TIMING_SLOWEST      0x6UL /*!< EBI timing is the slowest \hideinitializer */
78 
79 #define EBI_OPMODE_NORMAL       0x0UL                 /*!< EBI bus operate in normal mode \hideinitializer */
80 #define EBI_OPMODE_CACCESS      (EBI_CTL_CACCESS_Msk) /*!< EBI bus operate in Continuous Data Access mode \hideinitializer */
81 #define EBI_OPMODE_ADSEPARATE   (EBI_CTL_ADSEPEN_Msk) /*!< EBI bus operate in AD Separate mode \hideinitializer */
82 
83 /**@}*/ /* end of group EBI_EXPORTED_CONSTANTS */
84 
85 
86 /** @addtogroup EBI_EXPORTED_FUNCTIONS EBI Exported Functions
87   @{
88 */
89 
90 /**
91   * @brief      Read 8-bit data on EBI bank0
92   *
93   * @param[in]  ebi         The pointer of EBI module.
94   * @param[in]  u32Addr     The data address on EBI bank0.
95   *
96   * @return     8-bit Data
97   *
98   * @details    This macro is used to read 8-bit data from specify address on EBI bank0.
99   * \hideinitializer
100   */
101 #define EBI0_READ_DATA8(ebi, u32Addr)               (*((volatile unsigned char *)((((ebi)==EBI_S)? EBI_BANK0_BASE_ADDR:EBI_BANK0_BASE_ADDR_NS)+(u32Addr))))
102 
103 /**
104   * @brief      Write 8-bit data to EBI bank0
105   *
106   * @param[in]  ebi         The pointer of EBI module.
107   * @param[in]  u32Addr     The data address on EBI bank0.
108   * @param[in]  u32Data     Specify data to be written.
109   *
110   * @return     None
111   *
112   * @details    This macro is used to write 8-bit data to specify address on EBI bank0.
113   * \hideinitializer
114   */
115 #define EBI0_WRITE_DATA8(ebi, u32Addr, u32Data)     (*((volatile unsigned char *)((((ebi)==EBI_S)? EBI_BANK0_BASE_ADDR:EBI_BANK0_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
116 
117 /**
118   * @brief      Read 16-bit data on EBI bank0
119   *
120   * @param[in]  ebi         The pointer of EBI module.
121   * @param[in]  u32Addr     The data address on EBI bank0.
122   *
123   * @return     16-bit Data
124   *
125   * @details    This macro is used to read 16-bit data from specify address on EBI bank0.
126   * \hideinitializer
127   */
128 #define EBI0_READ_DATA16(ebi, u32Addr)              (*((volatile unsigned short *)((((ebi)==EBI_S)? EBI_BANK0_BASE_ADDR:EBI_BANK0_BASE_ADDR_NS)+(u32Addr))))
129 
130 /**
131   * @brief      Write 16-bit data to EBI bank0
132   *
133   * @param[in]  ebi         The pointer of EBI module.
134   * @param[in]  u32Addr     The data address on EBI bank0.
135   * @param[in]  u32Data     Specify data to be written.
136   *
137   * @return     None
138   *
139   * @details    This macro is used to write 16-bit data to specify address on EBI bank0.
140   * \hideinitializer
141   */
142 #define EBI0_WRITE_DATA16(ebi, u32Addr, u32Data)    (*((volatile unsigned short *)((((ebi)==EBI_S)? EBI_BANK0_BASE_ADDR:EBI_BANK0_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
143 
144 /**
145   * @brief      Read 32-bit data on EBI bank0
146   *
147   * @param[in]  ebi         The pointer of EBI module.
148   * @param[in]  u32Addr     The data address on EBI bank0.
149   *
150   * @return     32-bit Data
151   *
152   * @details    This macro is used to read 32-bit data from specify address on EBI bank0.
153   * \hideinitializer
154   */
155 #define EBI0_READ_DATA32(ebi, u32Addr)              (*((volatile unsigned int *)((((ebi)==EBI_S)? EBI_BANK0_BASE_ADDR:EBI_BANK0_BASE_ADDR_NS)+(u32Addr))))
156 
157 /**
158   * @brief      Write 32-bit data to EBI bank0
159   *
160   * @param[in]  ebi         The pointer of EBI module.
161   * @param[in]  u32Addr     The data address on EBI bank0.
162   * @param[in]  u32Data     Specify data to be written.
163   *
164   * @return     None
165   *
166   * @details    This macro is used to write 32-bit data to specify address on EBI bank0.
167   * \hideinitializer
168   */
169 #define EBI0_WRITE_DATA32(ebi, u32Addr, u32Data)    (*((volatile unsigned int *)((((ebi)==EBI_S)? EBI_BANK0_BASE_ADDR:EBI_BANK0_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
170 
171 /**
172   * @brief      Read 8-bit data on EBI bank1
173   *
174   * @param[in]  ebi         The pointer of EBI module.
175   * @param[in]  u32Addr     The data address on EBI bank1.
176   *
177   * @return     8-bit Data
178   *
179   * @details    This macro is used to read 8-bit data from specify address on EBI bank1.
180   * \hideinitializer
181   */
182 #define EBI1_READ_DATA8(ebi, u32Addr)               (*((volatile unsigned char *)((((ebi)==EBI_S)? EBI_BANK1_BASE_ADDR:EBI_BANK1_BASE_ADDR_NS)+(u32Addr))))
183 
184 /**
185   * @brief      Write 8-bit data to EBI bank1
186   *
187   * @param[in]  ebi         The pointer of EBI module.
188   * @param[in]  u32Addr     The data address on EBI bank1.
189   * @param[in]  u32Data     Specify data to be written.
190   *
191   * @return     None
192   *
193   * @details    This macro is used to write 8-bit data to specify address on EBI bank1.
194   * \hideinitializer
195   */
196 #define EBI1_WRITE_DATA8(ebi, u32Addr, u32Data)     (*((volatile unsigned char *)((((ebi)==EBI_S)? EBI_BANK1_BASE_ADDR:EBI_BANK1_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
197 
198 /**
199   * @brief      Read 16-bit data on EBI bank1
200   *
201   * @param[in]  ebi         The pointer of EBI module.
202   * @param[in]  u32Addr     The data address on EBI bank1.
203   *
204   * @return     16-bit Data
205   *
206   * @details    This macro is used to read 16-bit data from specify address on EBI bank1.
207   * \hideinitializer
208   */
209 #define EBI1_READ_DATA16(ebi, u32Addr)              (*((volatile unsigned short *)((((ebi)==EBI_S)? EBI_BANK1_BASE_ADDR:EBI_BANK1_BASE_ADDR_NS)+(u32Addr))))
210 
211 /**
212   * @brief      Write 16-bit data to EBI bank1
213   *
214   * @param[in]  ebi         The pointer of EBI module.
215   * @param[in]  u32Addr     The data address on EBI bank1.
216   * @param[in]  u32Data     Specify data to be written.
217   *
218   * @return     None
219   *
220   * @details    This macro is used to write 16-bit data to specify address on EBI bank1.
221   * \hideinitializer
222   */
223 #define EBI1_WRITE_DATA16(ebi, u32Addr, u32Data)    (*((volatile unsigned short *)((((ebi)==EBI_S)? EBI_BANK1_BASE_ADDR:EBI_BANK1_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
224 
225 /**
226   * @brief      Read 32-bit data on EBI bank1
227   *
228   * @param[in]  ebi         The pointer of EBI module.
229   * @param[in]  u32Addr     The data address on EBI bank1.
230   *
231   * @return     32-bit Data
232   *
233   * @details    This macro is used to read 32-bit data from specify address on EBI bank1.
234   * \hideinitializer
235   */
236 #define EBI1_READ_DATA32(ebi, u32Addr)              (*((volatile unsigned int *)((((ebi)==EBI_S)? EBI_BANK1_BASE_ADDR:EBI_BANK1_BASE_ADDR_NS)+(u32Addr))))
237 
238 /**
239   * @brief      Write 32-bit data to EBI bank1
240   *
241   * @param[in]  ebi         The pointer of EBI module.
242   * @param[in]  u32Addr     The data address on EBI bank1.
243   * @param[in]  u32Data     Specify data to be written.
244   *
245   * @return     None
246   *
247   * @details    This macro is used to write 32-bit data to specify address on EBI bank1.
248   * \hideinitializer
249   */
250 #define EBI1_WRITE_DATA32(ebi, u32Addr, u32Data)    (*((volatile unsigned int *)((((ebi)==EBI_S)? EBI_BANK1_BASE_ADDR:EBI_BANK1_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
251 
252 /**
253   * @brief      Read 8-bit data on EBI bank2
254   *
255   * @param[in]  ebi         The pointer of EBI module.
256   * @param[in]  u32Addr     The data address on EBI bank2.
257   *
258   * @return     8-bit Data
259   *
260   * @details    This macro is used to read 8-bit data from specify address on EBI bank2.
261   * \hideinitializer
262   */
263 #define EBI2_READ_DATA8(ebi, u32Addr)               (*((volatile unsigned char *)((((ebi)==EBI_S)? EBI_BANK2_BASE_ADDR:EBI_BANK2_BASE_ADDR_NS)+(u32Addr))))
264 
265 /**
266   * @brief      Write 8-bit data to EBI bank2
267   *
268   * @param[in]  ebi         The pointer of EBI module.
269   * @param[in]  u32Addr     The data address on EBI bank2.
270   * @param[in]  u32Data     Specify data to be written.
271   *
272   * @return     None
273   *
274   * @details    This macro is used to write 8-bit data to specify address on EBI bank2.
275   * \hideinitializer
276   */
277 #define EBI2_WRITE_DATA8(ebi, u32Addr, u32Data)     (*((volatile unsigned char *)((((ebi)==EBI_S)? EBI_BANK2_BASE_ADDR:EBI_BANK2_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
278 
279 /**
280   * @brief      Read 16-bit data on EBI bank2
281   *
282   * @param[in]  ebi         The pointer of EBI module.
283   * @param[in]  u32Addr     The data address on EBI bank2.
284   *
285   * @return     16-bit Data
286   *
287   * @details    This macro is used to read 16-bit data from specify address on EBI bank2.
288   */
289 #define EBI2_READ_DATA16(ebi, u32Addr)              (*((volatile unsigned short *)((((ebi)==EBI_S)? EBI_BANK2_BASE_ADDR:EBI_BANK2_BASE_ADDR_NS)+(u32Addr))))
290 
291 /**
292   * @brief      Write 16-bit data to EBI bank2
293   *
294   * @param[in]  ebi         The pointer of EBI module.
295   * @param[in]  u32Addr     The data address on EBI bank2.
296   * @param[in]  u32Data     Specify data to be written.
297   *
298   * @return     None
299   *
300   * @details    This macro is used to write 16-bit data to specify address on EBI bank2.
301   * \hideinitializer
302   */
303 #define EBI2_WRITE_DATA16(ebi, u32Addr, u32Data)    (*((volatile unsigned short *)((((ebi)==EBI_S)? EBI_BANK2_BASE_ADDR:EBI_BANK2_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
304 
305 /**
306   * @brief      Read 32-bit data on EBI bank2
307   *
308   * @param[in]  ebi         The pointer of EBI module.
309   * @param[in]  u32Addr     The data address on EBI bank2.
310   *
311   * @return     32-bit Data
312   *
313   * @details    This macro is used to read 32-bit data from specify address on EBI bank2.
314   * \hideinitializer
315   */
316 #define EBI2_READ_DATA32(ebi, u32Addr)              (*((volatile unsigned int *)((((ebi)==EBI_S)? EBI_BANK2_BASE_ADDR:EBI_BANK2_BASE_ADDR_NS)+(u32Addr))))
317 /**
318   * @brief      Write 32-bit data to EBI bank2
319   *
320   * @param[in]  ebi         The pointer of EBI module.
321   * @param[in]  u32Addr     The data address on EBI bank2.
322   * @param[in]  u32Data     Specify data to be written.
323   *
324   * @return     None
325   *
326   * @details    This macro is used to write 32-bit data to specify address on EBI bank2.
327   * \hideinitializer
328   */
329 #define EBI2_WRITE_DATA32(ebi, u32Addr, u32Data)    (*((volatile unsigned int *)((((ebi)==EBI_S)? EBI_BANK2_BASE_ADDR:EBI_BANK2_BASE_ADDR_NS)+(u32Addr))) = (u32Data))
330 
331 /**
332   * @brief      Enable EBI Write Buffer
333   *
334   * @param[in]  ebi         The pointer of EBI module.
335   *
336   * @return     None
337   *
338   * @details    This macro is used to improve EBI write operation for all EBI banks.
339   * \hideinitializer
340   */
341 #define EBI_ENABLE_WRITE_BUFFER(ebi)                ((ebi)->CTL0 |= EBI_CTL_WBUFEN_Msk)
342 
343 /**
344   * @brief      Disable EBI Write Buffer
345   *
346   * @param[in]  ebi         The pointer of EBI module.
347   *
348   * @return     None
349   *
350   * @details    This macro is used to disable EBI write buffer function.
351   * \hideinitializer
352   */
353 #define EBI_DISABLE_WRITE_BUFFER(ebi)               ((ebi)->CTL0 &= ~EBI_CTL_WBUFEN_Msk)
354 
355 void EBI_Open(uint32_t u32Bank, uint32_t u32DataWidth, uint32_t u32TimingClass, uint32_t u32BusMode, uint32_t u32CSActiveLevel);
356 void EBI_Close(uint32_t u32Bank);
357 void EBI_SetBusTiming(uint32_t u32Bank, uint32_t u32TimingConfig, uint32_t u32MclkDiv);
358 
359 /**@}*/ /* end of group EBI_EXPORTED_FUNCTIONS */
360 
361 /**@}*/ /* end of group EBI_Driver */
362 
363 /**@}*/ /* end of group Standard_Driver */
364 
365 #ifdef __cplusplus
366 }
367 #endif
368 
369 #endif /* __EBI_H__ */
370