periph_cpu_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 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 
19 #ifndef PERIPH_CPU_COMMON_H
20 #define PERIPH_CPU_COMMON_H
21 
22 #include "cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
32 #define PROVIDES_PM_OFF
33 
38 #define CPUID_ADDR (&NRF_FICR->DEVICEID[0])
39 
42 #define CPUID_LEN (8U)
43 
49 #ifdef CPU_MODEL_NRF52840XXAA
50 #define GPIO_PIN(x,y) ((x << 5) | y)
51 #else
52 #define GPIO_PIN(x,y) ((x & 0) | y)
53 #endif
54 
58 /* The precise value matters where GPIO_UNDEF is set in registers like
59  * PWM.PSEL.OUT where it is used in sign-extended form to get a UINT32_MAX */
60 #define GPIO_UNDEF (UINT8_MAX)
61 
71 #define GPIO_MODE(oe, ic, pr, dr) (oe | (ic << 1) | (pr << 2) | (dr << 8))
72 
76 #define SPI_HWCS(x) (SPI_CS_UNDEF)
77 
82 #define PERIPH_SPI_NEEDS_INIT_CS
83 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
84 #define PERIPH_SPI_NEEDS_TRANSFER_REG
85 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
86 
88 #ifndef DOXYGEN
89 
93 #define HAVE_GPIO_T
94 typedef uint8_t gpio_t;
106 #define HAVE_GPIO_MODE_T
107 typedef enum {
108  GPIO_IN = GPIO_MODE(0, 0, 0, 0),
109  GPIO_IN_PD = GPIO_MODE(0, 0, 1, 0),
110  GPIO_IN_PU = GPIO_MODE(0, 0, 3, 0),
111  GPIO_IN_OD_PU = GPIO_MODE(0, 0, 3, 6),
112  GPIO_OUT = GPIO_MODE(1, 1, 0, 0),
113  GPIO_OD = (0xff),
114  GPIO_OD_PU = (0xfe)
115 } gpio_mode_t;
122 #define HAVE_GPIO_FLANK_T
123 typedef enum {
124  GPIO_FALLING = 2,
125  GPIO_RISING = 1,
126  GPIO_BOTH = 3
127 } gpio_flank_t;
129 #endif /* ndef DOXYGEN */
130 
134 typedef struct {
135  NRF_TIMER_Type *dev;
136  uint8_t channels;
137  uint8_t bitmode;
138  uint8_t irqn;
139 } timer_conf_t;
140 
141 #ifndef DOXYGEN
142 
146 #define HAVE_SPI_MODE_T
147 typedef enum {
148  SPI_MODE_0 = 0,
149  SPI_MODE_1 = SPI_CONFIG_CPHA_Msk,
150  SPI_MODE_2 = SPI_CONFIG_CPOL_Msk,
151  SPI_MODE_3 = (SPI_CONFIG_CPOL_Msk | SPI_CONFIG_CPHA_Msk)
152 } spi_mode_t;
159 #define HAVE_SPI_CLK_T
160 typedef enum {
161  SPI_CLK_100KHZ = SPI_FREQUENCY_FREQUENCY_K125,
162  SPI_CLK_400KHZ = SPI_FREQUENCY_FREQUENCY_K500,
163  SPI_CLK_1MHZ = SPI_FREQUENCY_FREQUENCY_M1,
164  SPI_CLK_5MHZ = SPI_FREQUENCY_FREQUENCY_M4,
165  SPI_CLK_10MHZ = SPI_FREQUENCY_FREQUENCY_M8
166 } spi_clk_t;
168 #endif /* ndef DOXYGEN */
169 
174 #define NWDT_TIME_LOWER_LIMIT (1)
175 /* Set upper limit to the maximum possible value that could go in CRV register */
176 #define NWDT_TIME_UPPER_LIMIT ((UINT32_MAX >> 15) * US_PER_MS + 1)
177 
187 uint8_t gpio_int_get_exti(gpio_t pin);
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* PERIPH_CPU_COMMON_H */
194 
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
SPI_CLK_100KHZ
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:652
timer_conf_t::irqn
uint8_t irqn
IRQ number of the timer device.
Definition: periph_cpu_common.h:138
GPIO_IN_PD
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:120
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
gpio_int_get_exti
uint8_t gpio_int_get_exti(gpio_t pin)
Retrieve the exti(GPIOTE) channel associated with a gpio.
timer_conf_t::channels
uint8_t channels
number of channels available
Definition: periph_cpu_common.h:136
GPIO_OUT
@ GPIO_OUT
configure as output in push-pull mode
Definition: gpio.h:122
spi_mode_t
spi_mode_t
Available SPI modes, defining the configuration of clock polarity and clock phase.
Definition: spi.h:157
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
SPI_CLK_10MHZ
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:656
GPIO_IN
@ GPIO_IN
configure as input without pull resistor
Definition: gpio.h:119
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
timer_conf_t::dev
NRF_TIMER_Type * dev
timer device
Definition: periph_cpu_common.h:135
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
GPIO_OD_PU
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:125
GPIO_MODE
#define GPIO_MODE(oe, ic, pr, dr)
Generate GPIO mode bitfields.
Definition: periph_cpu_common.h:71
GPIO_BOTH
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:83
timer_conf_t
Timer configuration.
Definition: periph_cpu.h:288
timer_conf_t::bitmode
uint8_t bitmode
counter width
Definition: periph_cpu_common.h:137
gpio_mode_t
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:70
gpio_t
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
SPI_CLK_1MHZ
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:654
SPI_MODE_1
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition: spi.h:159
SPI_MODE_2
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition: spi.h:160