1 |
595 |
jeremybenn |
/**************************************************************************//**
|
2 |
|
|
* @file
|
3 |
|
|
* @brief EBI implementation of Board Control interface
|
4 |
|
|
* This implementation works for devices w/o LCD display on the
|
5 |
|
|
* MCU module, specifically the EFM32_G2xx_DK development board
|
6 |
|
|
* @author Energy Micro AS
|
7 |
|
|
* @version 1.0.1
|
8 |
|
|
******************************************************************************
|
9 |
|
|
* @section License
|
10 |
|
|
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
11 |
|
|
******************************************************************************
|
12 |
|
|
*
|
13 |
|
|
* This source code is the property of Energy Micro AS. The source and compiled
|
14 |
|
|
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
15 |
|
|
*
|
16 |
|
|
* This copyright notice may not be removed from the source code nor changed.
|
17 |
|
|
*
|
18 |
|
|
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
19 |
|
|
* obligation to support this Software. Energy Micro AS is providing the
|
20 |
|
|
* Software "AS IS", with no express or implied warranties of any kind,
|
21 |
|
|
* including, but not limited to, any implied warranties of merchantability
|
22 |
|
|
* or fitness for any particular purpose or warranties against infringement
|
23 |
|
|
* of any proprietary rights of a third party.
|
24 |
|
|
*
|
25 |
|
|
* Energy Micro AS will not be liable for any consequential, incidental, or
|
26 |
|
|
* special damages, or any other relief, or for any claim by any third party,
|
27 |
|
|
* arising from your use of this Software.
|
28 |
|
|
*
|
29 |
|
|
*****************************************************************************/
|
30 |
|
|
|
31 |
|
|
#include "efm32.h"
|
32 |
|
|
#include "dvk.h"
|
33 |
|
|
#include "dvk_bcregisters.h"
|
34 |
|
|
|
35 |
|
|
/**************************************************************************//**
|
36 |
|
|
* @brief Configure EBI (external bus interface) for Board Control register
|
37 |
|
|
* access
|
38 |
|
|
*****************************************************************************/
|
39 |
|
|
void DVK_EBI_configure(void)
|
40 |
|
|
{
|
41 |
|
|
GPIO_TypeDef *gpio = GPIO;
|
42 |
|
|
EBI_TypeDef *ebi = EBI;
|
43 |
|
|
CMU_TypeDef *cmu = CMU;
|
44 |
|
|
|
45 |
|
|
/* Run time check if we have EBI on-chip capability on this device */
|
46 |
|
|
switch ((DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK) >>
|
47 |
|
|
_DEVINFO_PART_DEVICE_NUMBER_SHIFT)
|
48 |
|
|
{
|
49 |
|
|
/* Only device types EFM32G 280/290/880 and 890 have EBI capability */
|
50 |
|
|
case 280:
|
51 |
|
|
case 290:
|
52 |
|
|
case 880:
|
53 |
|
|
case 890:
|
54 |
|
|
break;
|
55 |
|
|
default:
|
56 |
|
|
/* This device do not have EBI capability - use SPI to interface DVK */
|
57 |
|
|
/* With high probability your project has been configured for an */
|
58 |
|
|
/* incorrect part number. */
|
59 |
|
|
while (1) ;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/* Enable clocks */
|
63 |
|
|
cmu->HFCORECLKEN0 |= CMU_HFCORECLKEN0_EBI;
|
64 |
|
|
cmu->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
|
65 |
|
|
|
66 |
|
|
/* Configure bus connect PC bit 12 active low */
|
67 |
|
|
gpio->P[2].MODEH |=
|
68 |
|
|
GPIO_P_MODEH_MODE12_PUSHPULL;
|
69 |
|
|
|
70 |
|
|
gpio->P[2].DOUT &= ~(1UL << 12);
|
71 |
|
|
|
72 |
|
|
/* Configure GPIO pins as push pull */
|
73 |
|
|
/* EBI AD9..15 */
|
74 |
|
|
gpio->P[0].MODEL |=
|
75 |
|
|
(GPIO_P_MODEL_MODE0_PUSHPULL |
|
76 |
|
|
GPIO_P_MODEL_MODE1_PUSHPULL |
|
77 |
|
|
GPIO_P_MODEL_MODE2_PUSHPULL |
|
78 |
|
|
GPIO_P_MODEL_MODE3_PUSHPULL |
|
79 |
|
|
GPIO_P_MODEL_MODE4_PUSHPULL |
|
80 |
|
|
GPIO_P_MODEL_MODE5_PUSHPULL |
|
81 |
|
|
GPIO_P_MODEL_MODE6_PUSHPULL);
|
82 |
|
|
/* EBI AD8 */
|
83 |
|
|
gpio->P[0].MODEH |=
|
84 |
|
|
GPIO_P_MODEH_MODE15_PUSHPULL;
|
85 |
|
|
/* EBI CS0-CS3 */
|
86 |
|
|
gpio->P[3].MODEH |=
|
87 |
|
|
(GPIO_P_MODEH_MODE9_PUSHPULL |
|
88 |
|
|
GPIO_P_MODEH_MODE10_PUSHPULL |
|
89 |
|
|
GPIO_P_MODEH_MODE11_PUSHPULL |
|
90 |
|
|
GPIO_P_MODEH_MODE12_PUSHPULL);
|
91 |
|
|
/* EBI AD0..7 */
|
92 |
|
|
gpio->P[4].MODEH |=
|
93 |
|
|
(GPIO_P_MODEH_MODE8_PUSHPULL |
|
94 |
|
|
GPIO_P_MODEH_MODE9_PUSHPULL |
|
95 |
|
|
GPIO_P_MODEH_MODE10_PUSHPULL |
|
96 |
|
|
GPIO_P_MODEH_MODE11_PUSHPULL |
|
97 |
|
|
GPIO_P_MODEH_MODE12_PUSHPULL |
|
98 |
|
|
GPIO_P_MODEH_MODE13_PUSHPULL |
|
99 |
|
|
GPIO_P_MODEH_MODE14_PUSHPULL |
|
100 |
|
|
GPIO_P_MODEH_MODE15_PUSHPULL);
|
101 |
|
|
/* EBI ARDY/ALEN/Wen/Ren */
|
102 |
|
|
gpio->P[5].MODEL |=
|
103 |
|
|
(GPIO_P_MODEL_MODE2_PUSHPULL |
|
104 |
|
|
GPIO_P_MODEL_MODE3_PUSHPULL |
|
105 |
|
|
GPIO_P_MODEL_MODE4_PUSHPULL |
|
106 |
|
|
GPIO_P_MODEL_MODE5_PUSHPULL);
|
107 |
|
|
|
108 |
|
|
/* Configure EBI controller */
|
109 |
|
|
/* 16 bit address, 16 bit data mode */
|
110 |
|
|
/* Enable bank 0 address map 0x80000000, FPGA Flash */
|
111 |
|
|
/* Enable bank 1 address map 0x84000000, FPGA SRAM */
|
112 |
|
|
/* Enable bank 2 address map 0x88000000, FPGA TFT Display (SSD2119) */
|
113 |
|
|
/* Enable bank 3 address map 0x8c000000, FPGA Board Control Registers */
|
114 |
|
|
ebi->CTRL =
|
115 |
|
|
EBI_CTRL_MODE_D16A16ALE |
|
116 |
|
|
EBI_CTRL_BANK0EN |
|
117 |
|
|
EBI_CTRL_BANK1EN |
|
118 |
|
|
EBI_CTRL_BANK2EN |
|
119 |
|
|
EBI_CTRL_BANK3EN;
|
120 |
|
|
|
121 |
|
|
/* Setup and hold time */
|
122 |
|
|
ebi->ADDRTIMING = 3 << _EBI_ADDRTIMING_ADDRHOLD_SHIFT | 3 << _EBI_ADDRTIMING_ADDRSET_SHIFT;
|
123 |
|
|
|
124 |
|
|
/* Default values for all write timing registers, read timing conservative */
|
125 |
|
|
ebi->RDTIMING = 7 << _EBI_RDTIMING_RDSTRB_SHIFT | 3 << _EBI_RDTIMING_RDHOLD_SHIFT | 3 << _EBI_RDTIMING_RDSETUP_SHIFT;
|
126 |
|
|
ebi->WRTIMING = 7 << _EBI_WRTIMING_WRSTRB_SHIFT | 3 << _EBI_WRTIMING_WRHOLD_SHIFT | 3 << _EBI_WRTIMING_WRSETUP_SHIFT;
|
127 |
|
|
ebi->POLARITY = _EBI_POLARITY_RESETVALUE;
|
128 |
|
|
|
129 |
|
|
/* Toggle on all chip selects for all banks */
|
130 |
|
|
ebi->ROUTE =
|
131 |
|
|
EBI_ROUTE_CS0PEN |
|
132 |
|
|
EBI_ROUTE_CS1PEN |
|
133 |
|
|
EBI_ROUTE_CS2PEN |
|
134 |
|
|
EBI_ROUTE_CS3PEN |
|
135 |
|
|
EBI_ROUTE_ALEPEN |
|
136 |
|
|
EBI_ROUTE_EBIPEN;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
/**************************************************************************//**
|
141 |
|
|
* @brief Initialize EBI
|
142 |
|
|
* access
|
143 |
|
|
*****************************************************************************/
|
144 |
|
|
void DVK_EBI_init(void)
|
145 |
|
|
{
|
146 |
|
|
uint16_t ebiMagic;
|
147 |
|
|
int ctr;
|
148 |
|
|
volatile int i;
|
149 |
|
|
|
150 |
|
|
/* Configure EBI */
|
151 |
|
|
DVK_EBI_configure();
|
152 |
|
|
/* Verify that EBI access is working, if not kit is in SPI mode and needs to
|
153 |
|
|
* be configured for EBI access */
|
154 |
|
|
ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
|
155 |
|
|
if (ebiMagic != BC_MAGIC_VALUE)
|
156 |
|
|
{
|
157 |
|
|
/* Disable EBI */
|
158 |
|
|
DVK_EBI_disable();
|
159 |
|
|
/* Enable SPI interface */
|
160 |
|
|
DVK_SPI_init();
|
161 |
|
|
/* Set EBI mode - after this SPI access will no longer be available */
|
162 |
|
|
DVK_SPI_writeRegister(BC_CFG, BC_CFG_EBI);
|
163 |
|
|
/* Disable SPI */
|
164 |
|
|
DVK_SPI_disable();
|
165 |
|
|
/* Now setup EBI again */
|
166 |
|
|
DVK_EBI_configure();
|
167 |
|
|
/* Wait until ready */
|
168 |
|
|
ctr = 0;
|
169 |
|
|
do {
|
170 |
|
|
/* Check if FPGA responds */
|
171 |
|
|
ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
|
172 |
|
|
ctr++;
|
173 |
|
|
DVK_EBI_writeRegister(BC_LED, ctr);
|
174 |
|
|
} while (ebiMagic != BC_MAGIC_VALUE);
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
/**************************************************************************//**
|
179 |
|
|
* @brief Disable EBI interface, free all GPIO pins
|
180 |
|
|
*****************************************************************************/
|
181 |
|
|
void DVK_EBI_disable(void)
|
182 |
|
|
{
|
183 |
|
|
GPIO_TypeDef *gpio = GPIO;
|
184 |
|
|
EBI_TypeDef *ebi = EBI;
|
185 |
|
|
CMU_TypeDef *cmu = CMU;
|
186 |
|
|
|
187 |
|
|
/* Toggle off all chip selects for all banks */
|
188 |
|
|
ebi->ROUTE = _EBI_ROUTE_RESETVALUE;
|
189 |
|
|
|
190 |
|
|
/* Disable EBI controller */
|
191 |
|
|
ebi->CTRL = _EBI_CTRL_RESETVALUE;
|
192 |
|
|
|
193 |
|
|
/* Disable EBI clock */
|
194 |
|
|
cmu->HFCORECLKEN0 &= ~(CMU_HFCORECLKEN0_EBI);
|
195 |
|
|
|
196 |
|
|
/* Disable EBI _BC_BUS_CONNECT */
|
197 |
|
|
gpio->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE12_MASK);
|
198 |
|
|
|
199 |
|
|
/* Configure GPIO pins as disabled */
|
200 |
|
|
gpio->P[0].MODEL &= ~(
|
201 |
|
|
_GPIO_P_MODEL_MODE0_MASK |
|
202 |
|
|
_GPIO_P_MODEL_MODE1_MASK |
|
203 |
|
|
_GPIO_P_MODEL_MODE2_MASK |
|
204 |
|
|
_GPIO_P_MODEL_MODE3_MASK |
|
205 |
|
|
_GPIO_P_MODEL_MODE4_MASK |
|
206 |
|
|
_GPIO_P_MODEL_MODE5_MASK |
|
207 |
|
|
_GPIO_P_MODEL_MODE6_MASK);
|
208 |
|
|
gpio->P[0].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
|
209 |
|
|
gpio->P[3].MODEH &= ~(
|
210 |
|
|
_GPIO_P_MODEH_MODE9_MASK|
|
211 |
|
|
_GPIO_P_MODEH_MODE10_MASK|
|
212 |
|
|
_GPIO_P_MODEH_MODE11_MASK|
|
213 |
|
|
_GPIO_P_MODEH_MODE12_MASK
|
214 |
|
|
);
|
215 |
|
|
gpio->P[4].MODEH &= ~(
|
216 |
|
|
_GPIO_P_MODEH_MODE8_MASK |
|
217 |
|
|
_GPIO_P_MODEH_MODE9_MASK |
|
218 |
|
|
_GPIO_P_MODEH_MODE10_MASK |
|
219 |
|
|
_GPIO_P_MODEH_MODE11_MASK |
|
220 |
|
|
_GPIO_P_MODEH_MODE12_MASK |
|
221 |
|
|
_GPIO_P_MODEH_MODE13_MASK |
|
222 |
|
|
_GPIO_P_MODEH_MODE14_MASK |
|
223 |
|
|
_GPIO_P_MODEH_MODE15_MASK);
|
224 |
|
|
gpio->P[5].MODEL &= ~(
|
225 |
|
|
_GPIO_P_MODEL_MODE2_MASK |
|
226 |
|
|
_GPIO_P_MODEL_MODE3_MASK |
|
227 |
|
|
_GPIO_P_MODEL_MODE4_MASK |
|
228 |
|
|
_GPIO_P_MODEL_MODE5_MASK);
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
/**************************************************************************//**
|
232 |
|
|
* @brief Write data into 16-bit board control register
|
233 |
|
|
* @param addr Address to board control register
|
234 |
|
|
* @param data Data to write into register
|
235 |
|
|
*****************************************************************************/
|
236 |
|
|
void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data)
|
237 |
|
|
{
|
238 |
|
|
*addr = data;
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
/**************************************************************************//**
|
242 |
|
|
* @brief Write data into 16-bit board control register
|
243 |
|
|
* @param addr Register to read from
|
244 |
|
|
*****************************************************************************/
|
245 |
|
|
uint16_t DVK_EBI_readRegister(volatile uint16_t *addr)
|
246 |
|
|
{
|
247 |
|
|
return *addr;
|
248 |
|
|
}
|