periph_cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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_H
20 #define PERIPH_CPU_H
21 
22 #include "periph_conf.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
31 #if !defined(CPUID_LEN) || defined(DOXYGEN)
32 # define CPUID_LEN (4U)
33 #endif
34 
38 #if !defined(PM_NUM_MODES) || defined(DOXYGEN)
39 # define PM_NUM_MODES (1U)
40 #endif
41 
45 #define PROVIDES_PM_LAYERED_OFF
46 
47 /* GPIO configuration only if the module is available (=Linux) */
48 #if defined(MODULE_PERIPH_GPIO_LINUX) || defined(DOXYGEN)
49 # include <linux/gpio.h>
50 
51 /* MARK: - GPIO Configuration */
59 # define GPIO_PORT_SHIFT (24)
60 
64 # define GPIO_PIN(port, pin) (gpio_t)((port << GPIO_PORT_SHIFT) | pin)
65 
69 # define HAVE_GPIO_MODE_T
73 # if !defined(GPIOHANDLE_REQUEST_PULL_DOWN) || defined(DOXYGEN)
74 # define GPIOHANDLE_REQUEST_PULL_DOWN (0xFF)
75 # endif
79 # if !defined(GPIOHANDLE_REQUEST_PULL_UP) || defined(DOXYGEN)
80 # define GPIOHANDLE_REQUEST_PULL_UP (0xFF)
81 # endif
82 
91 typedef enum {
92  GPIO_IN = GPIOHANDLE_REQUEST_INPUT,
93  GPIO_IN_PD = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_PULL_DOWN,
94  GPIO_IN_PU = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_PULL_UP,
95  GPIO_OUT = GPIOHANDLE_REQUEST_OUTPUT,
96  GPIO_OD = GPIOHANDLE_REQUEST_OPEN_DRAIN,
97  GPIO_OD_PU = GPIOHANDLE_REQUEST_OPEN_DRAIN | GPIOHANDLE_REQUEST_PULL_UP
98 } gpio_mode_t;
99 
103 # define HAVE_GPIO_FLANK_T
104 
108 typedef enum {
109  GPIO_FALLING = GPIOEVENT_EVENT_FALLING_EDGE,
110  GPIO_RISING = GPIOEVENT_EVENT_RISING_EDGE,
115 #elif defined(MODULE_PERIPH_GPIO_MOCK)
116 
122 typedef struct {
123  int value;
124  int mode;
125  int flank;
126  void (*cb)(void *arg);
127  void *arg;
128 } gpio_mock_t;
129 
130 # define GPIO_UNDEF 0
131 
132 # if !defined(GPIO_PORT_MAX) || defined(DOXYGEN)
133 # define GPIO_PORT_MAX (16)
134 # endif
135 
136 # if !defined(GPIO_PIN_MAX) || defined(DOXYGEN)
137 # define GPIO_PIN_MAX (32)
138 # endif
139 
143 extern gpio_mock_t gpio_mock[GPIO_PORT_MAX][GPIO_PIN_MAX];
144 
145 # define HAVE_GPIO_T
149 typedef gpio_mock_t* gpio_t;
150 
155 # define GPIO_PIN(port, pin) \
156  (((port >= 0) && (pin >= 0) && (port < GPIO_PORT_MAX) && (pin < GPIO_PIN_MAX)) \
157  ? &gpio_mock[port][pin] \
158  : GPIO_UNDEF)
159 
160 #endif /* MODULE_PERIPH_GPIO_LINUX | DOXYGEN */
161 
165 #define PERIPH_TIMER_PROVIDES_SET
166 
167 /* MARK: - Power management configuration*/
172 #define PROVIDES_PM_OFF
173 #define PROVIDES_PM_SET_LOWEST
176 /* Configuration for the wrapper around the Linux SPI API (periph_spidev_linux)
177  *
178  * Needs to go here, otherwise the SPI_NEEDS_ are defined after inclusion of
179  * spi.h.
180  */
181 #if defined(MODULE_PERIPH_SPIDEV_LINUX) || defined(DOXYGEN)
182 /* MARK: - SPI Configuration */
190 # define PERIPH_SPI_NEEDS_TRANSFER_BYTE
194 # define PERIPH_SPI_NEEDS_TRANSFER_REG
198 # define PERIPH_SPI_NEEDS_TRANSFER_REGS
199 
200 # ifndef DOXYGEN
204 # define HAVE_SPI_CLK_T
211 typedef enum {
212  SPI_CLK_100KHZ = (100000U),
213  SPI_CLK_400KHZ = (400000U),
214  SPI_CLK_1MHZ = (1000000U),
215  SPI_CLK_5MHZ = (5000000U),
216  SPI_CLK_10MHZ = (10000000U)
217 } spi_clk_t;
218 # endif /* ndef DOXYGEN */
220 #endif /* MODULE_PERIPH_SPI | DOXYGEN */
221 
225 #if !defined(EEPROM_SIZE) || defined(DOXYGEN)
226 # define EEPROM_SIZE (1024U) /* 1kB */
227 #endif
228 
229 #ifdef MODULE_PERIPH_CAN
230 # include "candev_linux.h"
231 #endif
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif /* PERIPH_CPU_H */
gpio_flank_t
Definition: periph_cpu.h:180
@ GPIO_OUT
select GPIO MASK as output
Definition: periph_cpu.h:165
@ GPIO_IN
select GPIO MASK as input
Definition: periph_cpu.h:164
spi_clk_t
Definition: periph_cpu.h:352
Peripheral MCU configuration for the Zigduino board.
Implementation of simulated CAN controller driver using SocketCAN on Linux.
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:91
#define GPIOHANDLE_REQUEST_PULL_UP
Pull-up.
Definition: periph_cpu.h:80
#define GPIOHANDLE_REQUEST_PULL_DOWN
Pull-down.
Definition: periph_cpu.h:74
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:92
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:109
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:110
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:111
@ GPIO_OD
configure as output in open-drain mode without pull resistor
Definition: gpio.h:124
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition: gpio.h:122
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:126
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:121
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:357
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: periph_cpu.h:356
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: periph_cpu.h:354
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:355
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:353