periph_cpu.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015-2016 Freie Universität Berlin
3  * SPDX-FileCopyrightText: 2017 HAW Hamburg
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
20 #include <stdint.h>
21 #include <stdio.h>
22 
23 #include "vendor/hw_soc_adc.h"
24 
25 #include "cpu.h"
26 #include "vendor/hw_ssi.h"
27 #include "vendor/hw_uart.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 #define CPUID_ADDR (&IEEE_ADDR_MSWORD)
37 
41 #define CPUID_LEN (8U)
42 
47 #define HAVE_GPIO_T
48 typedef uint32_t gpio_t;
55 #define PM_NUM_MODES (5)
61 #define GPIO_UNDEF (0xffffffff)
62 
66 #define GPIO_MUX_NONE (0xff)
73 #define GPIO_PIN(port, pin) (gpio_t)(((uint32_t)GPIO_BASE + \
74  (port << GPIO_PORTNUM_SHIFT)) | pin)
75 
83 void gpio_init_af(gpio_t pin, uint8_t sel, uint8_t over);
84 
93 void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func);
94 
99 #define PERIPH_I2C_NEED_READ_REG
100 #define PERIPH_I2C_NEED_READ_REGS
101 #define PERIPH_I2C_NEED_WRITE_REG
102 #define PERIPH_I2C_NEED_WRITE_REGS
105 #ifndef DOXYGEN
110 #define HAVE_I2C_SPEED_T
111 typedef enum {
112  I2C_SPEED_LOW = 0x01,
113  I2C_SPEED_NORMAL = 100000U,
114  I2C_SPEED_FAST = 400000U,
115  I2C_SPEED_FAST_PLUS = 0x02,
116  I2C_SPEED_HIGH = 0x03,
117 } i2c_speed_t;
119 #endif /* ndef DOXYGEN */
120 
124 typedef struct {
125  i2c_speed_t speed;
126  gpio_t scl_pin;
127  gpio_t sda_pin;
128 } i2c_conf_t;
129 
134 #define PERIPH_SPI_NEEDS_INIT_CS
135 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
136 #define PERIPH_SPI_NEEDS_TRANSFER_REG
137 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
140 #ifndef DOXYGEN
145 #define HAVE_GPIO_MODE_T
146 typedef enum {
147  GPIO_IN = ((uint8_t)OVERRIDE_DISABLE),
148  GPIO_IN_ANALOG = ((uint8_t)OVERRIDE_ANALOG),
149  GPIO_IN_PD = ((uint8_t)OVERRIDE_PULLDOWN),
150  GPIO_IN_PU = ((uint8_t)OVERRIDE_PULLUP),
151  GPIO_OUT = ((uint8_t)OVERRIDE_ENABLE),
152  GPIO_OD = (0xfe),
153  GPIO_OD_PU = (0xff)
154 } gpio_mode_t;
156 #endif /* ndef DOXYGEN */
157 
162 typedef struct {
164  gpio_t rx_pin;
165  gpio_t tx_pin;
166 #ifdef MODULE_PERIPH_UART_HW_FC
167  gpio_t cts_pin;
168  gpio_t rts_pin;
169 #endif
170 } uart_conf_t;
173 #ifndef DOXYGEN
178 #define HAVE_UART_PARITY_T
179 typedef enum {
180  UART_PARITY_NONE = 0,
181  UART_PARITY_EVEN = (UART_LCRH_PEN | UART_LCRH_EPS),
182  UART_PARITY_ODD = UART_LCRH_PEN,
183  UART_PARITY_MARK = (UART_LCRH_PEN | UART_LCRH_SPS),
184  UART_PARITY_SPACE = (UART_LCRH_PEN | UART_LCRH_EPS | UART_LCRH_SPS)
185 } uart_parity_t;
192 #define HAVE_UART_DATA_BITS_T
193 typedef enum {
194  UART_DATA_BITS_5 = (0 << UART_LCRH_WLEN_S),
195  UART_DATA_BITS_6 = (1 << UART_LCRH_WLEN_S),
196  UART_DATA_BITS_7 = (2 << UART_LCRH_WLEN_S),
197  UART_DATA_BITS_8 = (3 << UART_LCRH_WLEN_S),
205 #define HAVE_UART_STOP_BITS_T
206 typedef enum {
207  UART_STOP_BITS_1 = 0,
208  UART_STOP_BITS_2 = UART_LCRH_STP2,
215 #ifndef UART_TXBUF_SIZE
216 #define UART_TXBUF_SIZE (64)
217 #endif
218 
222 #define SPI_CS_UNDEF (GPIO_UNDEF)
223 
224 #ifndef DOXYGEN
229 #define HAVE_SPI_CS_T
230 typedef uint32_t spi_cs_t;
232 #endif
233 
238 #define HAVE_SPI_MODE_T
239 typedef enum {
240  SPI_MODE_0 = 0,
241  SPI_MODE_1 = (SSI_CR0_SPH),
242  SPI_MODE_2 = (SSI_CR0_SPO),
243  SPI_MODE_3 = (SSI_CR0_SPO | SSI_CR0_SPH)
244 } spi_mode_t;
251 #define HAVE_SPI_CLK_T
252 typedef enum {
253  SPI_CLK_100KHZ = 0,
254  SPI_CLK_400KHZ = 1,
255  SPI_CLK_1MHZ = 2,
256  SPI_CLK_5MHZ = 3,
257  SPI_CLK_10MHZ = 4
258 } spi_clk_t;
260 #endif /* ndef DOXYGEN */
261 
265 typedef struct {
266  uint8_t cpsr;
267  uint8_t scr;
269 
270 #ifndef BOARD_HAS_SPI_CLK_CONF
278 static const spi_clk_conf_t spi_clk_config[] = {
279  { .cpsr = 64, .scr = 4 }, /* 100khz */
280  { .cpsr = 16, .scr = 4 }, /* 400khz */
281  { .cpsr = 32, .scr = 0 }, /* 1.0MHz */
282  { .cpsr = 2, .scr = 2 }, /* 5.3MHz */
283  { .cpsr = 2, .scr = 1 } /* 8.0MHz */
284 };
285 #endif /* BOARD_HAS_SPI_CLK_CONF */
286 
291 typedef struct {
292  uint8_t num;
293  gpio_t mosi_pin;
294  gpio_t miso_pin;
295  gpio_t sck_pin;
297 } spi_conf_t;
306 typedef struct {
307  uint_fast8_t chn;
308  uint_fast8_t cfg;
309 } timer_conf_t;
310 
311 #ifndef DOXYGEN
316 #define HAVE_ADC_RES_T
317 typedef enum {
318  ADC_RES_6BIT = (0xa00),
319  ADC_RES_7BIT = (0 << 4),
320  ADC_RES_8BIT = (0xb00),
321  ADC_RES_9BIT = (1 << 4),
322  ADC_RES_10BIT = (2 << 4),
323  ADC_RES_12BIT = (3 << 4),
324  ADC_RES_14BIT = (0xc00),
325  ADC_RES_16BIT = (0xd00),
326 } adc_res_t;
328 #endif /* ndef DOXYGEN */
329 
333 typedef gpio_t adc_conf_t;
334 
339 #define SOC_ADC_ADCCON3_EREF_INT (0 << SOC_ADC_ADCCON3_EREF_S)
340 #define SOC_ADC_ADCCON3_EREF_EXT (1 << SOC_ADC_ADCCON3_EREF_S)
341 #define SOC_ADC_ADCCON3_EREF_AVDD5 (2 << SOC_ADC_ADCCON3_EREF_S)
342 #define SOC_ADC_ADCCON3_EREF_DIFF (3 << SOC_ADC_ADCCON3_EREF_S)
349 #define SOCADC_7_BIT_RSHIFT (9U)
350 #define SOCADC_9_BIT_RSHIFT (7U)
351 #define SOCADC_10_BIT_RSHIFT (6U)
352 #define SOCADC_12_BIT_RSHIFT (4U)
359 #define RTT_DEV SMWDTHROSC
360 #define RTT_IRQ SM_TIMER_ALT_IRQn
361 #define RTT_IRQ_PRIO 1
362 #define RTT_ISR isr_sleepmode
363 #define RTT_MAX_VALUE (0xffffffff)
364 #define RTT_FREQUENCY (CLOCK_OSC32K)
365 /* When setting a new compare value, the value must be at least 5 more
366  than the current sleep timer value. Otherwise, the timer compare
367  event may be lost. */
368 #define RTT_MIN_OFFSET (5U)
375 /* Limits are in clock cycles according to data sheet.
376  As the WDT is clocked by a 32 kHz clock and supports 4 intervals */
377 #define NWDT_TIME_LOWER_LIMIT (2U)
378 #define NWDT_TIME_UPPER_LIMIT (1000U)
381 #ifdef __cplusplus
382 }
383 #endif
384 
@ GPIO_OUT
select GPIO MASK as output
Definition: periph_cpu.h:161
@ GPIO_IN
select GPIO MASK as input
Definition: periph_cpu.h:160
i2c_speed_t
Definition: periph_cpu.h:272
spi_clk_t
Definition: periph_cpu.h:348
void gpio_init_af(gpio_t pin, uint8_t sel, uint8_t over)
Configure an alternate function for the given pin.
void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func)
Configure an alternate function for the given pin.
gpio_t adc_conf_t
ADC configuration wrapper.
Definition: periph_cpu.h:333
static const spi_clk_conf_t spi_clk_config[]
Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz)
Definition: periph_cpu.h:278
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:91
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:92
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition: adc.h:98
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition: adc.h:94
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition: adc.h:97
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition: adc.h:93
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition: adc.h:95
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition: adc.h:96
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
@ GPIO_OD
configure as output in open-drain mode without pull resistor
Definition: gpio.h:123
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition: gpio.h:121
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:125
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:120
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:274
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition: periph_cpu.h:276
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition: periph_cpu.h:273
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition: periph_cpu.h:278
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: periph_cpu.h:275
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:135
@ SPI_MODE_0
CPOL=0, CPHA=0.
Definition: periph_cpu.h:43
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition: periph_cpu.h:45
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition: periph_cpu.h:44
@ SPI_MODE_3
CPOL=1, CPHA=1.
Definition: periph_cpu.h:46
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:353
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: periph_cpu.h:352
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: periph_cpu.h:350
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:351
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:349
@ UART_PARITY_SPACE
space parity
Definition: periph_cpu.h:506
@ UART_PARITY_NONE
no parity
Definition: periph_cpu.h:502
@ UART_PARITY_EVEN
even parity
Definition: periph_cpu.h:503
@ UART_PARITY_ODD
odd parity
Definition: periph_cpu.h:504
@ UART_PARITY_MARK
mark parity
Definition: periph_cpu.h:505
@ UART_STOP_BITS_2
2 stop bits
Definition: periph_cpu.h:535
@ UART_STOP_BITS_1
1 stop bit
Definition: periph_cpu.h:534
@ UART_DATA_BITS_6
6 data bits
Definition: periph_cpu.h:519
@ UART_DATA_BITS_5
5 data bits
Definition: periph_cpu.h:518
@ UART_DATA_BITS_7
7 data bits
Definition: periph_cpu.h:520
@ UART_DATA_BITS_8
8 data bits
Definition: periph_cpu.h:521
spi_mode_t
Support SPI modes.
Definition: periph_cpu.h:42
uart_parity_t
Definition of possible parity modes.
Definition: periph_cpu.h:501
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition: periph_cpu.h:533
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: periph_cpu.h:517
UART component registers.
Definition: cc2538_uart.h:28
I2C configuration structure.
Definition: periph_cpu.h:295
Datafields for static SPI clock configuration values.
Definition: periph_cpu.h:265
uint8_t cpsr
CPSR clock divider.
Definition: periph_cpu.h:266
uint8_t scr
SCR clock divider.
Definition: periph_cpu.h:267
SPI device configuration.
Definition: periph_cpu.h:333
uint8_t num
number of SSI device, i.e.
Definition: periph_cpu.h:292
spi_cs_t cs_pin
pin used for CS
Definition: periph_cpu.h:296
Timer device configuration.
Definition: periph_cpu.h:260
uint_fast8_t cfg
timer config word
Definition: periph_cpu.h:308
uint_fast8_t chn
number of channels
Definition: periph_cpu.h:307
UART device configuration.
Definition: periph_cpu.h:214
cc2538_uart_t * dev
pointer to the used UART device
Definition: periph_cpu.h:163