cc2538/include/periph_cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2016 Freie Universit├Ąt Berlin
3  * 2017 HAW Hamburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
21 #ifndef PERIPH_CPU_H
22 #define PERIPH_CPU_H
23 
24 #include <stdint.h>
25 #include <stdio.h>
26 
27 #include "cpu.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 #define CPUID_ADDR (&IEEE_ADDR_MSWORD)
37 
40 #define CPUID_LEN (8U)
41 
46 #define HAVE_GPIO_T
47 typedef uint32_t gpio_t;
54 #define PORTNUM_MASK (0x00007000)
55 #define PORTNUM_SHIFT (12U)
56 #define PIN_MASK (0x00000007)
57 #define GPIO_MASK (0xfffff000)
66 #define GPIO_PIN(port, pin) (gpio_t)(((uint32_t)GPIO_A + \
67  (port << PORTNUM_SHIFT)) | pin)
68 
76 static inline cc2538_gpio_t *gpio(gpio_t pin)
77 {
78  return (cc2538_gpio_t *)(pin & GPIO_MASK);
79 }
80 
88 static inline uint8_t gpio_port_num(gpio_t pin)
89 {
90  return (uint8_t)((pin & PORTNUM_MASK) >> PORTNUM_SHIFT) - 1;
91 }
92 
100 static inline uint8_t gpio_pin_num(gpio_t pin)
101 {
102  return (uint8_t)(pin & PIN_MASK);
103 }
104 
112 static inline uint32_t gpio_pin_mask(gpio_t pin)
113 {
114  return (1 << (pin & PIN_MASK));
115 }
116 
124 static inline uint8_t gpio_pp_num(gpio_t pin)
125 {
126  return (uint8_t)((gpio_port_num(pin) * 8) + gpio_pin_num(pin));
127 }
128 
134 static inline void gpio_hw_ctrl(gpio_t pin)
135 {
136  gpio(pin)->AFSEL |= gpio_pin_mask(pin);
137 }
138 
144 static inline void gpio_sw_ctrl(gpio_t pin)
145 {
146  gpio(pin)->AFSEL &= ~gpio_pin_mask(pin);
147 }
148 
152 #define GPIO_UNDEF 99
153 
157 typedef struct {
158  gpio_t scl_pin;
159  gpio_t sda_pin;
160 } i2c_conf_t;
161 
166 #define PERIPH_SPI_NEEDS_INIT_CS
167 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
168 #define PERIPH_SPI_NEEDS_TRANSFER_REG
169 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
170 
176 #define HAVE_GPIO_MODE_T
177 typedef enum {
178  GPIO_IN = ((uint8_t)0x00),
181  GPIO_OUT = ((uint8_t)IOC_OVERRIDE_OE),
182  GPIO_OD = (0xff),
183  GPIO_OD_PU = (0xff)
184 } gpio_mode_t;
191 #define HAVE_SPI_MODE_T
192 typedef enum {
194  SPI_MODE_1 = (SSI_CR0_SPH),
195  SPI_MODE_2 = (SSI_CR0_SPO),
196  SPI_MODE_3 = (SSI_CR0_SPO | SSI_CR0_SPH)
197 } spi_mode_t;
204 #define HAVE_SPI_CLK_T
205 typedef enum {
211 } spi_clk_t;
217 typedef struct {
218  uint8_t cpsr;
219  uint8_t scr;
221 
226 typedef struct {
228  gpio_t mosi_pin;
229  gpio_t miso_pin;
230  gpio_t sck_pin;
231  gpio_t cs_pin;
232 } spi_conf_t;
238 typedef struct {
240  uint_fast8_t channels;
241  uint_fast8_t cfg;
242 } timer_conf_t;
243 
248 #define HAVE_ADC_RES_T
249 typedef enum {
250  ADC_RES_6BIT = (0xa00),
251  ADC_RES_7BIT = (0 << 4),
252  ADC_RES_8BIT = (0xb00),
253  ADC_RES_9BIT = (1 << 4),
254  ADC_RES_10BIT = (2 << 4),
255  ADC_RES_12BIT = (3 << 4),
256  ADC_RES_14BIT = (0xc00),
257  ADC_RES_16BIT = (0xd00),
258 } adc_res_t;
264 typedef gpio_t adc_conf_t;
265 
270 #define SOC_ADC_ADCCON3_EREF (0x000000C0)
271 #define SOC_ADC_ADCCON3_EDIV (0x00000030)
272 #define SOC_ADC_ADCCON3_ECH (0x0000000F)
279 #define SOC_ADC_ADCCON_REF_INT (0 << 6)
280 #define SOC_ADC_ADCCON_REF_EXT (1 << 6)
281 #define SOC_ADC_ADCCON_REF_AVDD5 (2 << 6)
282 #define SOC_ADC_ADCCON_REF_DIFF (3 << 6)
283 #define SOC_ADC_ADCCON_CH_GND (0xC)
289 #define SOC_ADC_ADCCON1_EOC_MASK (0x80)
290 
295 #define SOC_ADC_ADCL_MASK (0x000000FC)
296 #define SOC_ADC_ADCH_MASK (0x000000FF)
297 
303 #define SOCADC_7_BIT_RSHIFT (9U)
304 #define SOCADC_9_BIT_RSHIFT (7U)
305 #define SOCADC_10_BIT_RSHIFT (6U)
306 #define SOCADC_12_BIT_RSHIFT (4U)
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 #include "periph/dev_enums.h"
314 
315 #endif /* PERIPH_CPU_H */
316 
uint_fast8_t channels
number of channels
CPOL=0, CPHA=1.
GPTIMER component registers.
ADC resolution: 7 bit.
I2C configuration options.
gpio_t cs_pin
pin used for CS
static void gpio_hw_ctrl(gpio_t pin)
Helper function to enable gpio hardware control.
ADC resolution: 12 bit.
ADC resolution: 9 bit.
#define PORTNUM_SHIFT
bit shift for GPIO port
#define PORTNUM_MASK
bit mask for GPIO port [0-3]
gpio_t miso_pin
pin used for MISO
gpio_t scl_pin
pin used for SCL
CPOL=0, CPHA=0.
drive the SPI bus with 100KHz
drive the SPI bus with 400KHz
static uint8_t gpio_port_num(gpio_t pin)
Helper function to get port number for gpio pin.
#define PIN_MASK
bit mask for GPIO pin [0-7]
#define IOC_OVERRIDE_PUE
Pull Up Enable.
Definition: cc2538_gpio.h:262
static uint32_t gpio_pin_mask(gpio_t pin)
Helper function to get bit mask for gpio pin number.
static cc2538_gpio_t * gpio(gpio_t pin)
Access GPIO low-level device.
uint_fast8_t cfg
timer config word
not supported by hardware
Device enumerations for backward compatibility with existing peripheral driver implementations.
#define IOC_OVERRIDE_PDE
Pull Down Enable.
Definition: cc2538_gpio.h:263
ADC resolution: 10 bit.
CPOL=1, CPHA=1.
#define GPIO_MASK
bit mask for GPIO port addr
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:69
gpio_t adc_conf_t
ADC configuration wrapper.
not supported by hardware
Datafields for static SPI clock configuration values.
gpio_t sck_pin
pin used for SCK
drive the SPI bus with 5MHz
not supported by hardware
cc2538_reg_t AFSEL
GPIO_A Alternate Function / mode control select register.
Definition: cc2538_gpio.h:206
not supported by hardware
drive the SPI bus with 10MHz
drive the SPI bus with 1MHz
static uint8_t gpio_pin_num(gpio_t pin)
Helper function to get pin number for gpio pin.
#define IOC_OVERRIDE_OE
Output Enable.
Definition: cc2538_gpio.h:261
stdio.h wrapper for MSP430
input, no pull
uint8_t scr
SCR clock divider.
static void gpio_sw_ctrl(gpio_t pin)
Helper function to enable gpio software control.
not supported
gpio_t sda_pin
pin used for SDA
CPOL=1, CPHA=0.
SPI module configuration options.
input, pull-down
cc2538_gptimer_t * dev
timer device
uint8_t cpsr
CPSR clock divider.
Timer configuration data.
GPIO port component registers.
Definition: cc2538_gpio.h:195
gpio_t mosi_pin
pin used for MOSI
SSI component registers.
Definition: cc2538_ssi.h:31
static uint8_t gpio_pp_num(gpio_t pin)
Helper function to get CC2538 gpio number from port and pin.
cc2538_ssi_t * dev
SSI device.