1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date         Author      Notes
8  * 2010-12-21   onelife     Initial creation for EFM32
9  * 2011-05-06   onelife     Add EFM32 development kit and SPI Flash support
10  * 2011-07-12   onelife     Add prototype for SWO output enable and interrupt
11  *                            context check functions
12  * 2011-12-08   onelife     Add giant gecko development kit support
13  * 2011-12-09   onelife     Add giant gecko support
14  * 2011-12-09   onelife     Add LEUART module support
15  * 2011-12-14   onelife     Add LFXO enabling routine in driver initialization function
16  * 2011-12-20   onelife     Move SPI Auto-CS setting to "rtconfig.h"
17  * 2012-05-15   onelife     Modified to compatible with CMSIS v3
18  */
19 
20 #ifndef __BOARD_H__
21 #define __BOARD_H__
22 
23 #if defined(EFM32G890F128)
24 #elif defined(EFM32G290F128)
25 #elif defined(EFM32G230F128)
26 #elif defined(EFM32GG990F1024)
27 #else
28 #error Unknown MCU type
29 #endif
30 
31 /* Includes ------------------------------------------------------------------*/
32 #include <efm32.h>
33 #include <em_chip.h>
34 #include <em_cmu.h>
35 #include <em_rmu.h>
36 #include <em_emu.h>
37 #include <em_dma.h>
38 #include <em_ebi.h>
39 #include <em_rtc.h>
40 #include <em_timer.h>
41 #include <em_letimer.h>
42 #include <em_gpio.h>
43 #include <em_acmp.h>
44 #include <em_adc.h>
45 #include <em_usart.h>
46 #include <em_leuart.h>
47 #include <em_i2c.h>
48 
49 #include <rtthread.h>
50 
51 #if (defined(EFM32_GXXX_DK) || defined(EFM32GG_DK3750))
52 #include <dvk.h>
53 #endif
54 
55 #include "drv_emu.h"
56 
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /* Exported variables --------------------------------------------------------*/
60 extern volatile rt_uint32_t rt_system_status;
61 
62 /* Exported macro ------------------------------------------------------------*/
63 #ifdef EFM32_DEBUG
64 #define DEBUG_EFM
65 #define DEBUG_EFM_USER
66 #define EFM32_SWO_ENABLE
67 #endif
68 
69 #define EFM32_NO_DATA               (0)
70 #define EFM32_NO_POINTER            (RT_NULL)
71 #define EFM32_NO_OFFSET             (-1)
72 #define EFM32_NO_DMA                (-1)
73 
74 /* SECTION: SPI Flash */
75 #if defined(EFM32_USING_SFLASH)
76 #define SFLASH_CS_PORT              (gpioPortC)
77 #define SFLASH_CS_PIN               (8)
78 #endif
79 
80 /* SECTION: Micro SD */
81 #if defined(EFM32_USING_SPISD)
82  #if defined(EFM32_GXXX_DK)
83  #define SD_CS_PORT                 (gpioPortC)
84  #define SD_CS_PIN                  (8)
85  #elif defined(EFM32GG_DK3750)
86  #define SD_CS_PORT                 (gpioPortE)
87  #define SD_CS_PIN                  (4)
88  #endif
89 #endif
90 
91 /* SECTION: Ethernet */
92 #if defined(EFM32_USING_ETHERNET)
93  #if defined(EFM32_GXXX_DK)
94  #define ETH_CS_PORT                (gpioPortB)
95  #define ETH_CS_PIN                 (6)
96  #elif defined(EFM32GG_DK3750)
97  #define ETH_CS_PORT                (gpioPortD)
98  #define ETH_CS_PIN                 (3)
99  #endif
100 #endif
101 
102 /* SECTION: LCD */
103 #if defined(EFM32_USING_LCD)
104  #if defined(EFM32GG_DK3750)
105  #define LCD_CS_PORT                 (gpioPortD)
106  #define LCD_CS_PIN                  (3)
107  #endif
108 #endif
109 
110 /* SECTION: SYSTEM */
111 #define EFM32_SRAM_END              (SRAM_BASE + SRAM_SIZE)
112 #define EFM32_BASE_PRI_DEFAULT      (0x0UL << 5)
113 #define EFM32_IRQ_PRI_DEFAULT       (0x4UL << 5)
114 
115 /* SECTION: CLOCK */
116 #define EFM32_USING_HFXO
117 #define EFM32_USING_LFXO
118 #if defined(EFM32_USING_HFXO)
119  #if (defined(EFM32_G8XX_STK) || defined(EFM32_GXXX_DK))
120  #define EFM32_HFXO_FREQUENCY       (32000000)
121  #elif defined(EFM32GG_DK3750)
122  #define EFM32_HFXO_FREQUENCY       (48000000)
123  #else
124  #define EFM32_HFXO_FREQUENCY       (00000000)
125  #endif
126 #endif
127 #if defined(EFM32_USING_LFXO)
128  #if (defined(EFM32_G8XX_STK) || defined(EFM32_GXXX_DK))
129  #define EFM32_LETIMER_TOP_100HZ    (41)
130  #elif defined(EFM32GG_DK3750)
131  #define EFM32_LETIMER_TOP_100HZ    (41)
132  #else
133  #define EFM32_LETIMER_TOP_100HZ    (41)
134  #endif
135 #endif
136 
137 /* SECTION: USART */
138 #define USART_RX_BUFFER_SIZE        (64)
139 #define LEUART_RX_BUFFER_SIZE       (64)
140 /* Location count (start from 0) */
141 #if defined(_EFM32_GECKO_FAMILY)
142 #define EFM32_USART_LOCATION_COUNT  (3)
143 #define EFM32_UART_LOCATION_COUNT   (4)
144 #define EFM32_LEUART_LOCATION_COUNT (3)
145 #elif defined(_EFM32_GIANT_FAMILY)
146 #define EFM32_USART_LOCATION_COUNT  (6)
147 #define EFM32_UART_LOCATION_COUNT   (4)
148 #define EFM32_LEUART_LOCATION_COUNT (5)
149 #endif
150 
151 /* SUBSECTION: UART */
152 #define UART_BAUDRATE               (115200)
153 
154 /* SUBSECTION: SPI */
155 /* Max SPI clock: HFPERCLK/2 for master, HFPERCLK/8 for slave */
156 #define SPI_BAUDRATE                (4000000)
157 
158 /* SECTION: I2C */
159 #define IIC_RX_BUFFER_SIZE          (32)
160 #if defined(_EFM32_GECKO_FAMILY)
161 #define EFM32_IIC_LOCATION_COUNT    (4)
162 #elif defined(_EFM32_GIANT_FAMILY)
163 #define EFM32_IIC_LOCATION_COUNT    (7)
164 #endif
165 
166 /* SECTION: ADC */
167 #define ADC_CALI_REF                (adcRef2V5)
168 #define ADC_CALI_CH                 (adcSingleInpCh5)
169 #define ADC_CONVERT_FREQUENCY       (7000000)
170 
171 #if (RT_CONSOLE_DEVICE == EFM_USART0)
172 #define CONSOLE_DEVICE              RT_USART0_NAME
173 #elif (RT_CONSOLE_DEVICE == EFM_USART1)
174 #define CONSOLE_DEVICE              RT_USART1_NAME
175 #elif (RT_CONSOLE_DEVICE == EFM_USART2)
176 #define CONSOLE_DEVICE              RT_USART2_NAME
177 #elif (RT_CONSOLE_DEVICE == EFM_UART0)
178 #define CONSOLE_DEVICE              RT_UART0_NAME
179 #elif (RT_CONSOLE_DEVICE == EFM_UART1)
180 #define CONSOLE_DEVICE              RT_UART1_NAME
181 #elif (RT_CONSOLE_DEVICE == EFM_LEUART0)
182 #define CONSOLE_DEVICE              RT_LEUART0_NAME
183 #elif (RT_CONSOLE_DEVICE == EFM_LEUART1)
184 #define CONSOLE_DEVICE              RT_LEUART1_NAME
185 #else
186 #define CONSOLE_DEVICE              "NONE"
187 #endif
188 
189 
190 /* The following defines should be consistent with those in diskio.h */
191 #define CTRL_SYNC                       0
192 #define GET_SECTOR_COUNT                1
193 #define GET_SECTOR_SIZE                 2
194 #define GET_BLOCK_SIZE                  3
195 #define MMC_GET_TYPE                    10
196 #define MMC_GET_CSD                     11
197 #define MMC_GET_CID                     12
198 #define MMC_GET_OCR                     13
199 #define MMC_GET_SDSTAT                  14
200 /* The above defines should be consistent with those in diskio.h */
201 
202 /* I/O control options */
203 #define RT_DEVICE_CTRL_SD_SYNC          CTRL_SYNC
204 #define RT_DEVICE_CTRL_SD_GET_SCOUNT    GET_SECTOR_COUNT
205 #define RT_DEVICE_CTRL_SD_GET_SSIZE     GET_SECTOR_SIZE
206 #define RT_DEVICE_CTRL_SD_GET_BSIZE     GET_BLOCK_SIZE
207 #define RT_DEVICE_CTRL_SD_GET_TYPE      MMC_GET_TYPE
208 #define RT_DEVICE_CTRL_SD_GET_CSD       MMC_GET_CSD
209 #define RT_DEVICE_CTRL_SD_GET_CID       MMC_GET_CID
210 #define RT_DEVICE_CTRL_SD_GET_OCR       MMC_GET_OCR
211 #define RT_DEVICE_CTRL_SD_GET_SDSTAT    MMC_GET_SDSTAT
212 
213 /*! fixme: move the following define to Rtdef.h */
214 #define RT_DEVICE_CTRL_USART_RBUFFER    (0xF1)      /*!< set USART/UART rx buffer */
215 #define RT_DEVICE_CTRL_LEUART_RBUFFER   (0xF2)      /*!< set LEUART rx buffer */
216 #define RT_DEVICE_CTRL_IIC_SETTING      (0xF3)      /*!< change IIC setting */
217 #define RT_DEVICE_CTRL_TIMER_PERIOD     (0xF4)      /*!< set Timer timeout period */
218 #define RT_DEVICE_CTRL_ADC_MODE         (0xF5)      /*!< change ADC mode */
219 #define RT_DEVICE_CTRL_ADC_RESULT       (0xF6)      /*!< get ADC result */
220 #define RT_DEVICE_CTRL_ACMP_INIT        (0xF7)      /*!< Initialize ACMP */
221 #define RT_DEVICE_CTRL_ACMP_OUTPUT      (0xF8)      /*!< get ACMP output */
222 
223 /* Exported functions ------------------------------------------------------- */
224 void rt_hw_board_init(void);
225 void rt_hw_driver_init(void);
226 rt_uint32_t rt_hw_interrupt_check(void);
227 
228 #endif /*__BOARD_H__ */
229