46 #include "contiki-net.h" 58 #define CC1200_SPI_CLK_PORT_BASE GPIO_PORT_TO_BASE(SPI0_CLK_PORT) 59 #define CC1200_SPI_CLK_PIN_MASK GPIO_PIN_MASK(SPI0_CLK_PIN) 60 #define CC1200_SPI_MOSI_PORT_BASE GPIO_PORT_TO_BASE(SPI0_TX_PORT) 61 #define CC1200_SPI_MOSI_PIN_MASK GPIO_PIN_MASK(SPI0_TX_PIN) 62 #define CC1200_SPI_MISO_PORT_BASE GPIO_PORT_TO_BASE(SPI0_RX_PORT) 63 #define CC1200_SPI_MISO_PIN_MASK GPIO_PIN_MASK(SPI0_RX_PIN) 64 #define CC1200_SPI_CSN_PORT_BASE GPIO_PORT_TO_BASE(CC1200_SPI_CSN_PORT) 65 #define CC1200_SPI_CSN_PIN_MASK GPIO_PIN_MASK(CC1200_SPI_CSN_PIN) 66 #define CC1200_GDO0_PORT_BASE GPIO_PORT_TO_BASE(CC1200_GDO0_PORT) 67 #define CC1200_GDO0_PIN_MASK GPIO_PIN_MASK(CC1200_GDO0_PIN) 68 #define CC1200_GDO2_PORT_BASE GPIO_PORT_TO_BASE(CC1200_GDO2_PORT) 69 #define CC1200_GDO2_PIN_MASK GPIO_PIN_MASK(CC1200_GDO2_PIN) 70 #define CC1200_RESET_PORT_BASE GPIO_PORT_TO_BASE(CC1200_RESET_PORT) 71 #define CC1200_RESET_PIN_MASK GPIO_PIN_MASK(CC1200_RESET_PIN) 73 #ifndef DEBUG_CC1200_ARCH 74 #define DEBUG_CC1200_ARCH 0 77 #if DEBUG_CC1200_ARCH > 0 78 #define PRINTF(...) printf(__VA_ARGS__) 79 #define BUSYWAIT_UNTIL(cond, max_time) \ 83 while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) {} \ 84 if(!(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time)))) { \ 85 printf("ARCH: Timeout exceeded in line %d!\n", __LINE__); \ 90 #define BUSYWAIT_UNTIL(cond, max_time) while(!cond) 93 extern int cc1200_rx_interrupt(
void);
99 cc1200_rx_interrupt();
103 cc1200_arch_spi_select(
void)
106 GPIO_CLR_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
109 GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK) == 0,
110 RTIMER_SECOND / 100);
114 cc1200_arch_spi_deselect(
void)
117 GPIO_SET_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
121 cc1200_arch_spi_rw_byte(uint8_t c)
123 SPI_WAITFORTx_BEFORE();
124 SPIX_BUF(CC1200_SPI_INSTANCE) = c;
125 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
126 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
127 c = SPIX_BUF(CC1200_SPI_INSTANCE);
133 cc1200_arch_spi_rw(uint8_t *inbuf,
const uint8_t *write_buf, uint16_t len)
138 if((inbuf == NULL && write_buf == NULL) || len <= 0) {
140 }
else if(inbuf == NULL) {
141 for(i = 0; i < len; i++) {
142 SPI_WAITFORTx_BEFORE();
143 SPIX_BUF(CC1200_SPI_INSTANCE) = write_buf[i];
144 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
145 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
146 c = SPIX_BUF(CC1200_SPI_INSTANCE);
150 }
else if(write_buf == NULL) {
151 for(i = 0; i < len; i++) {
152 SPI_WAITFORTx_BEFORE();
153 SPIX_BUF(CC1200_SPI_INSTANCE) = 0;
154 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
155 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
156 inbuf[i] = SPIX_BUF(CC1200_SPI_INSTANCE);
159 for(i = 0; i < len; i++) {
160 SPI_WAITFORTx_BEFORE();
161 SPIX_BUF(CC1200_SPI_INSTANCE) = write_buf[i];
162 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
163 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
164 inbuf[i] = SPIX_BUF(CC1200_SPI_INSTANCE);
172 .handler = cc1200_int_handler,
179 cc1200_arch_gpio0_setup_irq(
int rising)
200 cc1200_arch_gpio2_setup_irq(
int rising)
221 cc1200_arch_gpio0_enable_irq(
void)
229 cc1200_arch_gpio0_disable_irq(
void)
235 cc1200_arch_gpio2_enable_irq(
void)
243 cc1200_arch_gpio2_disable_irq(
void)
249 cc1200_arch_gpio0_read_pin(
void)
251 return (
GPIO_READ_PIN(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK) ? 1 : 0);
255 cc1200_arch_gpio2_read_pin(
void)
257 return GPIO_READ_PIN(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
261 cc1200_arch_gpio3_read_pin(
void)
267 cc1200_arch_init(
void)
273 GPIO_SET_PIN(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
288 cc1200_arch_spi_deselect();
292 GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK),
Datatype for GPIO event handlers.
#define GPIO_ENABLE_INTERRUPT(PORT_BASE, PIN_MASK)
Enable interrupt triggering for pins with PIN_MASK of port with PORT_BASE.
void spix_init(uint8_t spi)
Initialize the SPI bus for the instance given.
Header file for the cc2538 System Control driver.
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE high.
Header file for the cc2538 Synchronous Serial Interface.
Header file with register and macro declarations for the cc2538 GPIO module.
#define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to detect edge.
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE low.
Header file with declarations for the I/O Control module.
Header file with register manipulation macro definitions.
#define GPIO_DETECT_RISING(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to trigger an interrupt on rising edge.
#define GPIO_DETECT_FALLING(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to trigger an interrupt on falling edge.
#define GPIO_READ_PIN(PORT_BASE, PIN_MASK)
Read pins with PIN_MASK of port with PORT_BASE.
void gpio_hal_register_handler(gpio_hal_event_handler_t *handler)
Register a function to be called whenever a pin triggers an event.
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
Enable External Interrupt.
#define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK)
Disable interrupt triggering for pins with PIN_MASK of port with PORT_BASE.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
#define IOC_OVERRIDE_OE
Output Enable.
void spix_cs_init(uint8_t port, uint8_t pin)
Configure a GPIO to be the chip select pin.
#define IOC_OVERRIDE_PUE
Pull Up Enable.
#define GPIO_TRIGGER_SINGLE_EDGE(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to trigger an interrupt on single edge (controlled by G...
#define gpio_hal_pin_to_mask(pin)
Convert a pin to a pin mask.
Header file for the cc2538 SPI driver, including macros for the implementation of the low-level SPI p...
Header file for the GPIO HAL.
Header file for the LED HAL.