periph_cpu.h
8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
* Copyright (C) 2015-2016 Freie Universität Berlin
* 2017 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_cc2538
* @{
*
* @file
* @brief CPU specific definitions for internal peripheral handling
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Sebastian Meiling <s@mlng.net>
*/
#ifndef PERIPH_CPU_H
#define PERIPH_CPU_H
#include <stdint.h>
#include <stdio.h>
#include "cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Starting offset of CPU_ID
*/
#define CPUID_ADDR (&IEEE_ADDR_MSWORD)
/**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (8U)
/**
* @brief Define a custom type for GPIO pins
* @{
*/
#define HAVE_GPIO_T
typedef uint32_t gpio_t;
/** @} */
/**
* @name Power management configuration
* @{
*/
#define PROVIDES_PM_SET_LOWEST_CORTEXM
/** @} */
/**
* @name Internal GPIO shift and masking
* @{
*/
#define PORTNUM_MASK (0x00007000) /**< bit mask for GPIO port [0-3] */
#define PORTNUM_SHIFT (12U) /**< bit shift for GPIO port */
#define PIN_MASK (0x00000007) /**< bit mask for GPIO pin [0-7] */
#define GPIO_MASK (0xfffff000) /**< bit mask for GPIO port addr */
/** @} */
/**
* @brief Define a custom GPIO_PIN macro
*
* For the CC2538, we use OR the gpio ports base register address with the
* actual pin number.
*/
#define GPIO_PIN(port, pin) (gpio_t)(((uint32_t)GPIO_A + \
(port << PORTNUM_SHIFT)) | pin)
/**
* @brief Access GPIO low-level device
*
* @param[in] pin gpio pin
*
* @return pointer to gpio low level device address
*/
static inline cc2538_gpio_t *gpio(gpio_t pin)
{
return (cc2538_gpio_t *)(pin & GPIO_MASK);
}
/**
* @brief Helper function to get port number for gpio pin
*
* @param[in] pin gpio pin
*
* @return port number of gpio pin, [0=A - 3=D]
*/
static inline uint8_t gpio_port_num(gpio_t pin)
{
return (uint8_t)((pin & PORTNUM_MASK) >> PORTNUM_SHIFT) - 1;
}
/**
* @brief Helper function to get pin number for gpio pin
*
* @param[in] pin gpio pin
*
* @return pin number of gpio pin, [0 - 7]
*/
static inline uint8_t gpio_pin_num(gpio_t pin)
{
return (uint8_t)(pin & PIN_MASK);
}
/**
* @brief Helper function to get bit mask for gpio pin number
*
* @param[in] pin gpio pin
*
* @return bit mask for gpio pin number, 2^[0 - 7]
*/
static inline uint32_t gpio_pin_mask(gpio_t pin)
{
return (1 << (pin & PIN_MASK));
}
/**
* @brief Helper function to get CC2538 gpio number from port and pin
*
* @param[in] pin gpio pin
*
* @return number of gpio pin, [0 - 31]
*/
static inline uint8_t gpio_pp_num(gpio_t pin)
{
return (uint8_t)((gpio_port_num(pin) * 8) + gpio_pin_num(pin));
}
/**
* @brief Configure an alternate function for the given pin
*
* @param[in] pin gpio pin
* @param[in] sel Setting for IOC select register, (-1) to ignore
* @param[in] over Setting for IOC override register, (-1) to ignore
*/
void gpio_init_af(gpio_t pin, int sel, int over);
/**
* @brief Define a custom GPIO_UNDEF value
*/
#define GPIO_UNDEF 99
/**
* @brief I2C configuration options
*/
typedef struct {
gpio_t scl_pin; /**< pin used for SCL */
gpio_t sda_pin; /**< pin used for SDA */
} i2c_conf_t;
/**
* @name declare needed generic SPI functions
* @{
*/
#define PERIPH_SPI_NEEDS_INIT_CS
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
#define PERIPH_SPI_NEEDS_TRANSFER_REG
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
/** @} */
/**
* @name Override the default GPIO mode settings
* @{
*/
#define HAVE_GPIO_MODE_T
typedef enum {
GPIO_IN = ((uint8_t)0x00), /**< input, no pull */
GPIO_IN_PD = ((uint8_t)IOC_OVERRIDE_PDE), /**< input, pull-down */
GPIO_IN_PU = ((uint8_t)IOC_OVERRIDE_PUE), /**< input, pull-up */
GPIO_OUT = ((uint8_t)IOC_OVERRIDE_OE), /**< output */
GPIO_OD = (0xff), /**< not supported */
GPIO_OD_PU = (0xff) /**< not supported */
} gpio_mode_t;
/** @} */
/**
* @name Override SPI mode settings
* @{
*/
#define HAVE_SPI_MODE_T
typedef enum {
SPI_MODE_0 = 0, /**< CPOL=0, CPHA=0 */
SPI_MODE_1 = (SSI_CR0_SPH), /**< CPOL=0, CPHA=1 */
SPI_MODE_2 = (SSI_CR0_SPO), /**< CPOL=1, CPHA=0 */
SPI_MODE_3 = (SSI_CR0_SPO | SSI_CR0_SPH) /**< CPOL=1, CPHA=1 */
} spi_mode_t;
/** @ */
/**
* @name Override SPI clock settings
* @{
*/
#define HAVE_SPI_CLK_T
typedef enum {
SPI_CLK_100KHZ = 0, /**< drive the SPI bus with 100KHz */
SPI_CLK_400KHZ = 1, /**< drive the SPI bus with 400KHz */
SPI_CLK_1MHZ = 2, /**< drive the SPI bus with 1MHz */
SPI_CLK_5MHZ = 3, /**< drive the SPI bus with 5MHz */
SPI_CLK_10MHZ = 4 /**< drive the SPI bus with 10MHz */
} spi_clk_t;
/** @} */
/**
* @brief Datafields for static SPI clock configuration values
*/
typedef struct {
uint8_t cpsr; /**< CPSR clock divider */
uint8_t scr; /**< SCR clock divider */
} spi_clk_conf_t;
/**
* @name SPI configuration data structure
* @{
*/
typedef struct {
cc2538_ssi_t *dev; /**< SSI device */
gpio_t mosi_pin; /**< pin used for MOSI */
gpio_t miso_pin; /**< pin used for MISO */
gpio_t sck_pin; /**< pin used for SCK */
gpio_t cs_pin; /**< pin used for CS */
} spi_conf_t;
/** @} */
/**
* @brief Timer configuration
*
* General purpose timers (GPT[0-3]) are configured consecutively and in order
* (without gaps) starting from GPT0, i.e. if multiple timers are enabled.
*/
typedef struct {
uint_fast8_t chn; /**< number of channels */
uint_fast8_t cfg; /**< timer config word */
} timer_conf_t;
/**
* @name Override resolution options
* @{
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (0xa00), /**< not supported by hardware */
ADC_RES_7BIT = (0 << 4), /**< ADC resolution: 7 bit */
ADC_RES_8BIT = (0xb00), /**< not supported by hardware */
ADC_RES_9BIT = (1 << 4), /**< ADC resolution: 9 bit */
ADC_RES_10BIT = (2 << 4), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (3 << 4), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xc00), /**< not supported by hardware */
ADC_RES_16BIT = (0xd00), /**< not supported by hardware */
} adc_res_t;
/** @} */
/**
* @brief ADC configuration wrapper
*/
typedef gpio_t adc_conf_t;
/**
* @name SOC_ADC_ADCCON3 register bit masks
* @{
*/
#define SOC_ADC_ADCCON3_EREF (0x000000C0) /**< Reference voltage for extra */
#define SOC_ADC_ADCCON3_EDIV (0x00000030) /**< Decimation rate for extra */
#define SOC_ADC_ADCCON3_ECH (0x0000000F) /**< Single channel select */
/** @} */
/**
* @name SOC_ADC_ADCCONx registers field values
* @{
*/
#define SOC_ADC_ADCCON_REF_INT (0 << 6) /**< Internal reference */
#define SOC_ADC_ADCCON_REF_EXT (1 << 6) /**< External reference on AIN7 pin */
#define SOC_ADC_ADCCON_REF_AVDD5 (2 << 6) /**< AVDD5 pin */
#define SOC_ADC_ADCCON_REF_DIFF (3 << 6) /**< External reference on AIN6-AIN7 differential input */
#define SOC_ADC_ADCCON_CH_GND (0xC) /**< GND */
/** @} */
/**
* @brief Mask to check end-of-conversion (EOC) bit
*/
#define SOC_ADC_ADCCON1_EOC_MASK (0x80)
/**
* @name Masks for ADC raw data
* @{
*/
#define SOC_ADC_ADCL_MASK (0x000000FC)
#define SOC_ADC_ADCH_MASK (0x000000FF)
/** @} */
/**
* @name Bit shift for data per ADC resolution
* @{
*/
#define SOCADC_7_BIT_RSHIFT (9U) /**< Mask for getting data( 7 bits ENOB) */
#define SOCADC_9_BIT_RSHIFT (7U) /**< Mask for getting data( 9 bits ENOB) */
#define SOCADC_10_BIT_RSHIFT (6U) /**< Mask for getting data(10 bits ENOB) */
#define SOCADC_12_BIT_RSHIFT (4U) /**< Mask for getting data(12 bits ENOB) */
/** @} */
#ifdef __cplusplus
}
#endif
#include "periph/dev_enums.h"
#endif /* PERIPH_CPU_H */
/** @} */