periph_cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2017 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef PERIPH_CPU_H
21 #define PERIPH_CPU_H
22 
23 #include "kernel_defines.h"
24 #include "mutex.h"
25 
26 #include "cpu_conf.h"
27 
28 #include "em_adc.h"
29 #include "em_cmu.h"
30 #include "em_device.h"
31 #include "em_gpio.h"
32 #include "em_timer.h"
33 #include "em_usart.h"
34 #include "em_wdog.h"
35 #if defined(_SILICON_LABS_32B_SERIES_0)
36 #include "em_dac.h"
37 #endif
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
47 #define ADC_MODE(x, y) ((y << 4) | x)
48 
52 #define ADC_MODE_UNDEF(x) (ADC_MODE(x, 15))
53 
54 #ifndef DOXYGEN
55 
59 #define HAVE_ADC_RES_T
60 typedef enum {
61  ADC_RES_6BIT = ADC_MODE(adcRes6Bit, 0),
62  ADC_RES_8BIT = ADC_MODE(adcRes8Bit, 0),
63  ADC_RES_10BIT = ADC_MODE(adcRes12Bit, 2),
64  ADC_RES_12BIT = ADC_MODE(adcRes12Bit, 0),
67 } adc_res_t;
69 #endif /* ndef DOXYGEN */
70 
74 typedef struct {
75  ADC_TypeDef *dev;
76  CMU_Clock_TypeDef cmu;
77 } adc_conf_t;
78 
82 typedef struct {
83  uint8_t dev;
84 #if defined(_SILICON_LABS_32B_SERIES_0)
85  ADC_SingleInput_TypeDef input;
86 #elif defined(_SILICON_LABS_32B_SERIES_1)
87  ADC_PosSel_TypeDef input;
88 #endif
89  ADC_Ref_TypeDef reference;
90  ADC_AcqTime_TypeDef acq_time;
92 
96 #define CPUID_LEN (8U)
97 
101 #define CLOCK_CORECLOCK SystemCoreClock
102 
103 #if defined(DAC_COUNT) && DAC_COUNT > 0
104 
107 typedef struct {
108  DAC_TypeDef *dev;
109  CMU_Clock_TypeDef cmu;
110 } dac_conf_t;
111 
115 typedef struct {
116  uint8_t dev;
117  uint8_t index;
118  DAC_Ref_TypeDef ref;
119 } dac_chan_conf_t;
120 #endif
121 
126 #define HAVE_GPIO_T
127 typedef uint32_t gpio_t;
133 #define GPIO_UNDEF (0xffffffff)
134 
138 #define GPIO_PIN(x, y) ((gpio_t) ((x << 4) | y))
139 
143 #define GPIO_MODE(x, y) ((x << 1) | y)
144 
148 enum {
149 #if (_GPIO_PORT_A_PIN_COUNT > 0)
150  PA = gpioPortA,
151 #endif
152 #if (_GPIO_PORT_B_PIN_COUNT > 0)
153  PB = gpioPortB,
154 #endif
155 #if (_GPIO_PORT_C_PIN_COUNT > 0)
156  PC = gpioPortC,
157 #endif
158 #if (_GPIO_PORT_D_PIN_COUNT > 0)
159  PD = gpioPortD,
160 #endif
161 #if (_GPIO_PORT_E_PIN_COUNT > 0)
162  PE = gpioPortE,
163 #endif
164 #if (_GPIO_PORT_F_PIN_COUNT > 0)
165  PF = gpioPortF,
166 #endif
167 #if (_GPIO_PORT_G_PIN_COUNT > 0)
168  PG = gpioPortG,
169 #endif
170 #if (_GPIO_PORT_H_PIN_COUNT > 0)
171  PH = gpioPortH,
172 #endif
173 #if (_GPIO_PORT_I_PIN_COUNT > 0)
174  PI = gpioPortI,
175 #endif
176 #if (_GPIO_PORT_J_PIN_COUNT > 0)
177  PJ = gpioPortJ,
178 #endif
179 #if (_GPIO_PORT_K_PIN_COUNT > 0)
180  PK = gpioPortK
181 #endif
182 };
183 
184 #ifndef DOXYGEN
185 
189 #define HAVE_GPIO_MODE_T
190 typedef enum {
191  GPIO_IN = GPIO_MODE(gpioModeInput, 0),
192  GPIO_IN_PD = GPIO_MODE(gpioModeInputPull, 0),
193  GPIO_IN_PU = GPIO_MODE(gpioModeInputPull, 1),
194  GPIO_OUT = GPIO_MODE(gpioModePushPull, 0),
195  GPIO_OD = GPIO_MODE(gpioModeWiredAnd, 1),
196  GPIO_OD_PU = GPIO_MODE(gpioModeWiredAndPullUp, 1),
197 } gpio_mode_t;
204 #define HAVE_GPIO_FLANK_T
205 typedef enum {
206  GPIO_FALLING = 2,
207  GPIO_RISING = 1,
208  GPIO_BOTH = 3
209 } gpio_flank_t;
211 #endif /* ndef DOXYGEN */
212 
217 #define HAVE_HWCRYPTO_AES128
218 #ifdef AES_CTRL_AES256
219 #define HAVE_HWCRYPTO_AES256
220 #endif
221 #if defined(_SILICON_LABS_32B_SERIES_1)
222 #define HAVE_HWCRYPTO_SHA1
223 #define HAVE_HWCRYPTO_SHA256
224 #endif
225 
227 #ifndef DOXYGEN
228 
232 #define HAVE_I2C_SPEED_T
233 typedef enum {
234  I2C_SPEED_LOW = 10000,
235  I2C_SPEED_NORMAL = 100000,
236  I2C_SPEED_FAST = 400000,
237  I2C_SPEED_FAST_PLUS = 1000000,
238  I2C_SPEED_HIGH = 3400000,
239 } i2c_speed_t;
241 #endif /* ndef DOXYGEN */
242 
246 typedef struct {
247  I2C_TypeDef *dev;
248  gpio_t sda_pin;
249  gpio_t scl_pin;
250  uint32_t loc;
251  CMU_Clock_TypeDef cmu;
253  uint32_t speed;
254 } i2c_conf_t;
255 
260 #define PERIPH_I2C_NEED_READ_REG
261 #define PERIPH_I2C_NEED_WRITE_REG
262 
264 #ifndef DOXYGEN
265 
269 #define HAVE_PWM_MODE_T
270 typedef enum {
271  PWM_LEFT = timerModeUp, /*< use left aligned PWM */
272  PWM_RIGHT = timerModeDown, /*< use right aligned PWM */
273  PWM_CENTER = timerModeUp /*< not supported, use left aligned */
274 } pwm_mode_t;
276 #endif /* ndef DOXYGEN */
277 
281 typedef struct {
282  uint8_t index;
283  gpio_t pin;
284  uint32_t loc;
286 
290 typedef struct {
291  TIMER_TypeDef *dev;
292  CMU_Clock_TypeDef cmu;
294  uint8_t channels;
296 } pwm_conf_t;
297 
298 #ifndef DOXYGEN
299 
303 #define HAVE_SPI_MODE_T
304 typedef enum {
305  SPI_MODE_0 = usartClockMode0,
306  SPI_MODE_1 = usartClockMode1,
307  SPI_MODE_2 = usartClockMode2,
308  SPI_MODE_3 = usartClockMode3
309 } spi_mode_t;
316 #define HAVE_SPI_CLK_T
317 typedef enum {
318  SPI_CLK_100KHZ = 100000,
319  SPI_CLK_400KHZ = 400000,
320  SPI_CLK_1MHZ = 1000000,
321  SPI_CLK_5MHZ = 5000000,
322  SPI_CLK_10MHZ = 10000000
323 } spi_clk_t;
325 #endif /* ndef DOXYGEN */
326 
330 typedef struct {
331  USART_TypeDef *dev;
332  gpio_t mosi_pin;
333  gpio_t miso_pin;
334  gpio_t clk_pin;
335  uint32_t loc;
336  CMU_Clock_TypeDef cmu;
338 } spi_dev_t;
339 
344 #define PERIPH_SPI_NEEDS_INIT_CS
345 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
346 #define PERIPH_SPI_NEEDS_TRANSFER_REG
347 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
348 
357 typedef struct {
358  void *dev;
359  CMU_Clock_TypeDef cmu;
360 } timer_dev_t;
361 
362 typedef struct {
366  uint8_t channel_numof;
367 } timer_conf_t;
374 #ifndef CONFIG_EFM32_XTIMER_USE_LETIMER
375 #define CONFIG_EFM32_XTIMER_USE_LETIMER 0
376 #endif
377 
378 
382 #ifndef DOXYGEN
383 
387 #define HAVE_UART_PARITY_T
388 typedef enum {
389  UART_PARITY_NONE = 0,
390  UART_PARITY_ODD = 1,
391  UART_PARITY_EVEN = 2,
392  UART_PARITY_MARK = 3,
393  UART_PARITY_SPACE = 4,
394 } uart_parity_t;
401 #define HAVE_UART_DATA_BITS_T
402 typedef enum {
403  UART_DATA_BITS_5 = 5,
404  UART_DATA_BITS_6 = 6,
405  UART_DATA_BITS_7 = 7,
406  UART_DATA_BITS_8 = 8,
414 #define HAVE_UART_STOP_BITS_T
415 typedef enum {
416  UART_STOP_BITS_1 = 2,
417  UART_STOP_BITS_2 = 4,
420 #endif /* ndef DOXYGEN */
421 
422 typedef struct {
423  void *dev;
424  gpio_t rx_pin;
425  gpio_t tx_pin;
426  uint32_t loc;
427  CMU_Clock_TypeDef cmu;
429 } uart_conf_t;
430 
434 #define PROVIDES_PM_LAYERED_OFF
435 
439 #define PM_NUM_MODES (2U)
440 
445 #define WDT_CLOCK_HZ (1000U)
446 
447 #define NWDT_TIME_LOWER_LIMIT ((1U << (3U + wdogPeriod_9)) + 1U)
448 #define NWDT_TIME_UPPER_LIMIT ((1U << (3U + wdogPeriod_256k)) + 1U)
449 
450 #ifdef _SILICON_LABS_32B_SERIES_1
451 #define WDT_TIME_LOWER_LIMIT NWDT_TIME_LOWER_LIMIT
452 #define WDT_TIME_UPPER_LIMIT NWDT_TIME_UPPER_LIMIT
453 #endif
454 
455 #define WDT_HAS_STOP (1U)
456 
458 #ifdef __cplusplus
459 }
460 #endif
461 
462 #endif /* PERIPH_CPU_H */
463 
SPI_CLK_400KHZ
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: periph_cpu.h:653
SPI_MODE_3
@ SPI_MODE_3
CPOL=1, CPHA=1.
Definition: spi.h:161
UART_PARITY_NONE
@ UART_PARITY_NONE
no parity
Definition: uart.h:127
UART_DATA_BITS_5
@ UART_DATA_BITS_5
5 data bits
Definition: uart.h:140
spi_dev_t::dev
USART_TypeDef * dev
USART device used.
Definition: periph_cpu.h:331
pwm_chan_conf_t
PWM channel configuration.
Definition: periph_cpu.h:281
SPI_CLK_100KHZ
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:652
ADC_RES_6BIT
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition: adc.h:94
PC
@ PC
port C
Definition: periph_cpu.h:150
timer_dev_t::cmu
CMU_Clock_TypeDef cmu
the device CMU channel
Definition: periph_cpu.h:359
uart_stop_bits_t
uart_stop_bits_t
Definition of possible stop bits lengths in a UART frame.
Definition: uart.h:151
I2C_SPEED_LOW
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition: i2c.h:176
timer_conf_t::irq
IRQn_Type irq
number of the higher timer IRQ channel
Definition: periph_cpu.h:365
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
GPIO_IN_PD
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:120
UART_STOP_BITS_2
@ UART_STOP_BITS_2
2 stop bits
Definition: uart.h:153
adc_chan_conf_t
ADC channel configuration.
Definition: periph_cpu.h:82
SPI_MODE_0
@ SPI_MODE_0
CPOL=0, CPHA=0.
Definition: spi.h:158
GPIO_OD
@ GPIO_OD
configure as output in open-drain mode without pull resistor
Definition: gpio.h:123
i2c_conf_t::loc
uint32_t loc
location of I2C pins
Definition: periph_cpu.h:250
I2C_SPEED_NORMAL
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: i2c.h:177
PD
@ PD
port D
Definition: periph_cpu.h:151
IRQn_Type
enum IRQn IRQn_Type
Interrupt Number Definition.
adc_conf_t::dev
ADC_TypeDef * dev
ADC device used.
Definition: periph_cpu.h:75
UART_DATA_BITS_8
@ UART_DATA_BITS_8
8 data bits
Definition: uart.h:143
ADC_RES_14BIT
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition: adc.h:98
adc_res_t
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:93
i2c_conf_t::irq
IRQn_Type irq
the devices base IRQ channel
Definition: periph_cpu.h:252
timer_conf_t::channel_numof
uint8_t channel_numof
number of channels per timer
Definition: periph_cpu.h:366
spi_dev_t::loc
uint32_t loc
location of USART pins
Definition: periph_cpu.h:335
timer_dev_t::dev
void * dev
TIMER_TypeDef or LETIMER_TypeDef device used.
Definition: periph_cpu.h:358
timer_dev_t
Define timer configuration values.
Definition: periph_cpu.h:357
spi_dev_t
SPI device configuration.
Definition: periph_cpu.h:330
pwm_conf_t::channel
const pwm_chan_conf_t * channel
pointer to first channel config
Definition: periph_cpu.h:295
spi_dev_t::clk_pin
gpio_t clk_pin
pin used for CLK
Definition: periph_cpu.h:334
GPIO_OUT
@ GPIO_OUT
configure as output in push-pull mode
Definition: gpio.h:122
ADC_RES_16BIT
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition: adc.h:99
ADC_MODE_UNDEF
#define ADC_MODE_UNDEF(x)
Internal define to note that resolution is not supported.
Definition: periph_cpu.h:52
UART_DATA_BITS_6
@ UART_DATA_BITS_6
6 data bits
Definition: uart.h:141
uart_conf_t::loc
uint32_t loc
location of UART pins
Definition: periph_cpu.h:426
timer_conf_t::prescaler
timer_dev_t prescaler
the lower neighboring timer (not initialized for LETIMER)
Definition: periph_cpu.h:363
cpu_conf.h
Implementation specific CPU configuration options.
uart_parity_t
uart_parity_t
Definition of possible parity modes.
Definition: uart.h:126
i2c_speed_t
i2c_speed_t
Default mapping of I2C bus speed values.
Definition: i2c.h:175
spi_mode_t
spi_mode_t
Available SPI modes, defining the configuration of clock polarity and clock phase.
Definition: spi.h:157
ADC_RES_8BIT
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition: adc.h:95
uart_conf_t::irq
IRQn_Type irq
the devices base IRQ channel
Definition: periph_cpu.h:428
pwm_chan_conf_t::loc
uint32_t loc
location of the pin
Definition: periph_cpu.h:284
GPIO_FALLING
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:81
GPIO_IN_PU
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition: gpio.h:121
GPIO_RISING
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:82
PB
@ PB
port B
Definition: periph_cpu.h:149
GPIO_MODE
#define GPIO_MODE(x, y)
Internal macro for combining pin mode (x) and pull-up/down (y).
Definition: periph_cpu.h:143
pwm_conf_t
PWM device configuration.
Definition: periph_cpu_common.h:153
PWM_LEFT
@ PWM_LEFT
left aligned PWM
Definition: periph_cpu.h:160
PA
@ PA
port A
Definition: periph_cpu.h:148
pwm_chan_conf_t::index
uint8_t index
TIMER channel to use.
Definition: periph_cpu.h:282
adc_chan_conf_t::acq_time
ADC_AcqTime_TypeDef acq_time
channel acquisition time
Definition: periph_cpu.h:90
SPI_CLK_10MHZ
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:656
spi_clk_t
uint32_t spi_clk_t
SPI clock type.
Definition: periph_cpu.h:662
GPIO_IN
@ GPIO_IN
configure as input without pull resistor
Definition: gpio.h:119
uart_conf_t
UART device configuration.
Definition: periph_cpu.h:166
SPI_CLK_5MHZ
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: periph_cpu.h:655
gpio_flank_t
gpio_flank_t
Definition: periph_cpu.h:80
dac_conf_t
DAC line configuration data.
Definition: periph_cpu.h:518
GPIO_OD_PU
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:125
UART_PARITY_SPACE
@ UART_PARITY_SPACE
space parity
Definition: uart.h:131
PWM_RIGHT
@ PWM_RIGHT
right aligned PWM
Definition: periph_cpu.h:161
spi_dev_t::irq
IRQn_Type irq
the devices base IRQ channel
Definition: periph_cpu.h:337
uart_conf_t::dev
void * dev
UART, USART or LEUART device used.
Definition: periph_cpu.h:423
GPIO_BOTH
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:83
UART_PARITY_EVEN
@ UART_PARITY_EVEN
even parity
Definition: uart.h:128
i2c_conf_t::speed
uint32_t speed
the bus speed
Definition: periph_cpu.h:253
timer_conf_t
Timer configuration.
Definition: periph_cpu.h:288
pwm_conf_t::irq
IRQn_Type irq
the devices base IRQ channel
Definition: periph_cpu.h:293
adc_conf_t
gpio_t adc_conf_t
ADC configuration wrapper.
Definition: periph_cpu.h:315
mutex.h
Mutex for thread synchronization.
spi_dev_t::cmu
CMU_Clock_TypeDef cmu
the device CMU channel
Definition: periph_cpu.h:336
adc_chan_conf_t::dev
uint8_t dev
device index
Definition: periph_cpu.h:83
pwm_conf_t::cmu
CMU_Clock_TypeDef cmu
the device CMU channel
Definition: periph_cpu.h:292
ADC_MODE
#define ADC_MODE(x, y)
Internal macro for combining ADC resolution (x) with number of shifts (y).
Definition: periph_cpu.h:47
spi_dev_t::miso_pin
gpio_t miso_pin
pin used for MISO
Definition: periph_cpu.h:333
gpio_mode_t
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:70
ADC_RES_10BIT
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition: adc.h:96
UART_DATA_BITS_7
@ UART_DATA_BITS_7
7 data bits
Definition: uart.h:142
uart_conf_t::cmu
CMU_Clock_TypeDef cmu
the device CMU channel
Definition: periph_cpu.h:427
ADC_RES_12BIT
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition: adc.h:97
pwm_chan_conf_t::pin
gpio_t pin
pin used for pwm
Definition: periph_cpu.h:283
UART_PARITY_MARK
@ UART_PARITY_MARK
mark parity
Definition: uart.h:130
UART_STOP_BITS_1
@ UART_STOP_BITS_1
1 stop bit
Definition: uart.h:152
uart_data_bits_t
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: uart.h:139
UART_PARITY_ODD
@ UART_PARITY_ODD
odd parity
Definition: uart.h:129
gpio_t
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
I2C_SPEED_FAST_PLUS
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition: i2c.h:179
spi_dev_t::mosi_pin
gpio_t mosi_pin
pin used for MOSI
Definition: periph_cpu.h:332
SPI_CLK_1MHZ
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:654
timer_conf_t::timer
timer_dev_t timer
the higher numbered timer
Definition: periph_cpu.h:364
I2C_SPEED_FAST
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: i2c.h:178
pwm_mode_t
pwm_mode_t
Definition: periph_cpu.h:159
pwm_conf_t::dev
TIMER_TypeDef * dev
TIMER device used.
Definition: periph_cpu.h:291
I2C_SPEED_HIGH
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition: i2c.h:180
adc_chan_conf_t::reference
ADC_Ref_TypeDef reference
channel voltage reference
Definition: periph_cpu.h:89
i2c_conf_t::dev
I2C_TypeDef * dev
USART device used.
Definition: periph_cpu.h:247
SPI_MODE_1
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition: spi.h:159
adc_conf_t::cmu
CMU_Clock_TypeDef cmu
the device CMU channel
Definition: periph_cpu.h:76
i2c_conf_t::cmu
CMU_Clock_TypeDef cmu
the device CMU channel
Definition: periph_cpu.h:251
PWM_CENTER
@ PWM_CENTER
not supported
Definition: periph_cpu.h:162
pwm_conf_t::channels
uint8_t channels
the number of available channels
Definition: periph_cpu.h:294
SPI_MODE_2
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition: spi.h:160