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