EFR32 Blue Gecko 12 Software Documentation  efr32bg12-doc-5.1.2
bsp_stk.c
Go to the documentation of this file.
1 /***************************************************************************/
16 #include <string.h>
17 #include "em_device.h"
18 #include "em_cmu.h"
19 #include "em_gpio.h"
20 #include "bsp.h"
21 #if defined( BSP_STK_USE_EBI )
22 #include "em_ebi.h"
23 #endif
24 #if defined(BSP_IO_EXPANDER)
25 #include "bsp_stk_ioexp.h"
26 #endif
27 
28 #if defined( BSP_STK )
29 
30 /***************************************************************************/
35 /***************************************************************************/
41 /**************************************************************************/
47 int BSP_Disable(void)
48 {
49  BSP_BccDeInit();
50  BSP_EbiDeInit();
51 
52 #if defined(BSP_IO_EXPANDER)
53  ioexpDisable();
54 #endif
55 
56  return BSP_STATUS_OK;
57 }
60 /**************************************************************************/
68 int BSP_EbiInit(void)
69 {
70 #if defined( BSP_STK_USE_EBI )
71  /* ------------------------------------------ */
72  /* NAND Flash, Bank0, Base Address 0x80000000 */
73  /* Micron flash NAND256W3A */
74  /* ------------------------------------------ */
75 
76  EBI_Init_TypeDef ebiConfig =
77  { ebiModeD8A8, /* 8 bit address, 8 bit data */
78  ebiActiveLow, /* ARDY polarity */
79  ebiActiveLow, /* ALE polarity */
80  ebiActiveLow, /* WE polarity */
81  ebiActiveLow, /* RE polarity */
82  ebiActiveLow, /* CS polarity */
83  ebiActiveLow, /* BL polarity */
84  false, /* disble BL */
85  true, /* enable NOIDLE */
86  false, /* disable ARDY */
87  true, /* disable ARDY timeout */
88  EBI_BANK0, /* enable bank 0 */
89  0, /* no chip select */
90  0, /* addr setup cycles */
91  0, /* addr hold cycles */
92  false, /* disable half cycle ALE strobe */
93  0, /* read setup cycles */
94  2, /* read strobe cycles */
95  1, /* read hold cycles */
96  false, /* disable page mode */
97  false, /* disable prefetch */
98  false, /* disable half cycle REn strobe */
99  0, /* write setup cycles */
100  2, /* write strobe cycles */
101  1, /* write hold cycles */
102  false, /* enable the write buffer */
103  false, /* disable half cycle WEn strobe */
104  ebiALowA24, /* ALB - Low bound, address lines */
105  ebiAHighA26, /* APEN - High bound, address lines */
106  ebiLocation1, /* Use Location 1 */
107  true, /* enable EBI */
108  };
109 
110  /* Enable clocks */
113  CMU_ClockEnable(cmuClock_EBI, true);
114 
115  /* Enable GPIO's */
116  /* ALE and CLE */
117  GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 0);
118  GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);
119 
120  /* WP, CE and R/B */
121  GPIO_PinModeSet(gpioPortD, 13, gpioModePushPull, 0); /* active low write-protect */
122  GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1); /* active low chip-enable */
123  GPIO_PinModeSet(gpioPortD, 15, gpioModeInput, 0); /* ready/busy */
124 
125  /* IO pins */
126  GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
127  GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
128  GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
129  GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
130  GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
131  GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
132  GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
133  GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
134 
135  /* WE and RE */
136  GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 1);
137  GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 1);
138 
139  /* NAND Power Enable */
140  GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);
141 
142  EBI_Init(&ebiConfig);
143  EBI->NANDCTRL = (EBI_NANDCTRL_BANKSEL_BANK0 | EBI_NANDCTRL_EN);
144 
145  return BSP_STATUS_OK;
146 #else
148 #endif
149 }
150 
151 /**************************************************************************/
161 int BSP_EbiDeInit( void )
162 {
163 #if defined( BSP_STK_USE_EBI )
164  return BSP_STATUS_OK;
165 #else
167 #endif
168 }
169 
170 /**************************************************************************/
177 uint32_t BSP_IOExpGetDeviceId( void )
178 {
179 #if defined(BSP_IO_EXPANDER)
180  return ioexpGetDeviceId();
181 #else
182  return 0;
183 #endif
184 }
185 
187 /**************************************************************************/
195 int BSP_Init( uint32_t flags )
196 {
197 #if defined(BSP_IO_EXPANDER)
198  int status;
199 #endif
200 
201  if ( flags & BSP_INIT_BCC )
202  {
203  BSP_BccInit();
204  }
205 
206 #if defined(BSP_IO_EXPANDER)
207  if (flags & BSP_INIT_IOEXP)
208  {
209  status = ioexpEnable();
210  if (status != BSP_STATUS_OK)
211  {
212  return status;
213  }
214  }
215 #endif
216 
217  return BSP_STATUS_OK;
218 }
222 /**************************************************************************/
236 int BSP_PeripheralAccess(BSP_Peripheral_TypeDef perf, bool enable)
237 {
238 #if defined(BSP_IO_EXPANDER)
239  int status = BSP_STATUS_OK;
240 
241  if (enable)
242  {
243  switch (perf)
244  {
245  case BSP_IOEXP_LEDS:
246  status = ioexpWriteReg(BSP_IOEXP_REG_LED_CTRL,
247  BSP_IOEXP_REG_LED_CTRL_DIRECT);
248  break;
249 
250  case BSP_IOEXP_SENSORS:
251  status = ioexpWriteReg(BSP_IOEXP_REG_SENSOR_CTRL, 1);
252  break;
253 
254  case BSP_IOEXP_DISPLAY:
255  /* Cant use VCOM together with the display. */
256  status = ioexpWriteReg(BSP_IOEXP_REG_VCOM_CTRL, 0);
257  if (status == BSP_STATUS_OK)
258  {
259  status = ioexpWriteReg(BSP_IOEXP_REG_DISP_CTRL,
260  BSP_IOEXP_REG_DISP_CTRL_ENABLE
261  | BSP_IOEXP_REG_DISP_CTRL_AUTO_EXTCOMIN);
262  }
263  break;
264 
265  case BSP_IOEXP_VCOM:
266  /* Cant use the display together with VCOM. */
267  status = ioexpWriteReg(BSP_IOEXP_REG_DISP_CTRL, 0);
268  if (status == BSP_STATUS_OK)
269  {
270  status = ioexpWriteReg(BSP_IOEXP_REG_VCOM_CTRL, 1);
271  }
272  break;
273  }
274  }
275  else
276  {
277  switch (perf)
278  {
279  case BSP_IOEXP_LEDS:
280  status = ioexpWriteReg(BSP_IOEXP_REG_LED_CTRL, 0);
281  break;
282 
283  case BSP_IOEXP_SENSORS:
284  status = ioexpWriteReg(BSP_IOEXP_REG_SENSOR_CTRL, 0);
285  break;
286 
287  case BSP_IOEXP_DISPLAY:
288  status = ioexpWriteReg(BSP_IOEXP_REG_DISP_CTRL, 0);
289  break;
290 
291  case BSP_IOEXP_VCOM:
292  status = ioexpWriteReg(BSP_IOEXP_REG_VCOM_CTRL, 0);
293  break;
294  }
295  }
296 
297  return status;
298 #else
299  (void)perf;
300  (void)enable;
301 
303 #endif
304 }
307 /**************************************************************************/
317 float BSP_CurrentGet( void )
318 {
319  BCP_Packet pkt;
320  float *pcurrent;
321 
323  pkt.payloadLength = 0;
324 
325  /* Send Request/Get reply */
326  BSP_BccPacketSend( &pkt );
327  BSP_BccPacketReceive( &pkt );
328 
329  /* Process reply */
330  pcurrent = (float *)pkt.data;
331  if ( pkt.type != BSP_BCP_CURRENT_REPLY )
332  {
333  *pcurrent = 0.0f;
334  }
335 
336  return *pcurrent;
337 }
338 
339 /**************************************************************************/
349 float BSP_VoltageGet( void )
350 {
351  BCP_Packet pkt;
352  float *pvoltage;
353 
355  pkt.payloadLength = 0;
356 
357  /* Send Request/Get reply */
358  BSP_BccPacketSend( &pkt );
359  BSP_BccPacketReceive( &pkt );
360 
361  /* Process reply */
362  pvoltage = (float *)pkt.data;
363  if ( pkt.type != BSP_BCP_VOLTAGE_REPLY )
364  {
365  *pvoltage = 0.0f;
366  }
367 
368  return *pvoltage;
369 }
370 
374 #endif /* BSP_STK */
Clock management unit (CMU) API.
Board support package API definitions.
Board support package API implementation for STK's.
float BSP_CurrentGet(void)
Request AEM (Advanced Energy Monitoring) current from board controller.
Definition: bsp_stk.c:317
BCP Packet Structure - Board controller communication protocol version 2.
Definition: bsp_bcp.h:95
#define BSP_BCP_VOLTAGE_REQ
Definition: bsp_bcp.h:47
uint8_t payloadLength
Definition: bsp_bcp.h:99
#define BSP_BCP_CURRENT_REQ
Definition: bsp_bcp.h:45
#define BSP_INIT_BCC
Definition: bsp.h:54
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define BSP_BCP_CURRENT_REPLY
Definition: bsp_bcp.h:46
#define BSP_STATUS_OK
Definition: bsp.h:45
External Bus Iterface (EBI) peripheral API.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
Definition: em_gpio.c:269
#define BSP_STATUS_NOT_IMPLEMENTED
Definition: bsp.h:47
General Purpose IO (GPIO) peripheral API.
int BSP_BccInit(void)
Initialize board controller communication support (BCC) functionality.
Definition: bsp_bcc.c:89
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1453
uint8_t data[BSP_BCP_PACKET_SIZE]
Definition: bsp_bcp.h:101
#define BSP_BCP_VOLTAGE_REPLY
Definition: bsp_bcp.h:48
int BSP_BccPacketSend(BCP_Packet *pkt)
Send a packet to the board controller.
Definition: bsp_bcc.c:195
#define BSP_INIT_IOEXP
Definition: bsp.h:55
BSP_Peripheral_TypeDef
Definition: bsp.h:117
int BSP_Init(uint32_t flags)
Initialize board support package functionality.
Definition: bsp_dk_3201.c:127
float BSP_VoltageGet(void)
Request AEM (Advanced Energy Monitoring) voltage from board controller.
Definition: bsp_stk.c:349
int BSP_EbiDeInit(void)
Deinitialize the EBI interface for accessing the onboard nandflash.
Definition: bsp_stk.c:161
int BSP_PeripheralAccess(BSP_Peripheral_TypeDef perf, bool enable)
DK Peripheral Access Control Enable or disable access to on-board peripherals through switches and SP...
Definition: bsp_dk_3201.c:461
uint8_t type
Definition: bsp_bcp.h:98
int BSP_EbiInit(void)
Initialize the EBI interface for accessing the onboard nandflash.
Definition: bsp_stk.c:68
int BSP_Disable(void)
Deinitialize board support package functionality. Reverse actions performed by BSP_Init(). This function is a dummy on STK's.
Definition: bsp_dk_3201.c:97
bool BSP_BccPacketReceive(BCP_Packet *pkt)
Get a packet from the board controller.
Definition: bsp_bcc.c:137
int BSP_BccDeInit(void)
Deinitialize board controller communication support (BCC) functionality. Reverse actions performed by...
Definition: bsp_bcc.c:61
uint32_t BSP_IOExpGetDeviceId(void)
Get IO Expander Device id.
Definition: bsp_stk.c:177