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__) 83 extern int cc1200_rx_interrupt(
void);
89 cc1200_rx_interrupt();
93 cc1200_arch_spi_select(
void)
96 GPIO_CLR_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
99 GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK) == 0,
104 cc1200_arch_spi_deselect(
void)
107 GPIO_SET_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
111 cc1200_arch_spi_rw_byte(uint8_t c)
113 SPI_WAITFORTx_BEFORE();
114 SPIX_BUF(CC1200_SPI_INSTANCE) = c;
115 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
116 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
117 c = SPIX_BUF(CC1200_SPI_INSTANCE);
123 cc1200_arch_spi_rw(uint8_t *inbuf,
const uint8_t *write_buf, uint16_t len)
128 if((inbuf == NULL && write_buf == NULL) || len <= 0) {
130 }
else if(inbuf == NULL) {
131 for(i = 0; i < len; i++) {
132 SPI_WAITFORTx_BEFORE();
133 SPIX_BUF(CC1200_SPI_INSTANCE) = write_buf[i];
134 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
135 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
136 c = SPIX_BUF(CC1200_SPI_INSTANCE);
140 }
else if(write_buf == NULL) {
141 for(i = 0; i < len; i++) {
142 SPI_WAITFORTx_BEFORE();
143 SPIX_BUF(CC1200_SPI_INSTANCE) = 0;
144 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
145 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
146 inbuf[i] = SPIX_BUF(CC1200_SPI_INSTANCE);
149 for(i = 0; i < len; i++) {
150 SPI_WAITFORTx_BEFORE();
151 SPIX_BUF(CC1200_SPI_INSTANCE) = write_buf[i];
152 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
153 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
154 inbuf[i] = SPIX_BUF(CC1200_SPI_INSTANCE);
162 .handler = cc1200_int_handler,
169 cc1200_arch_gpio0_setup_irq(
int rising)
190 cc1200_arch_gpio2_setup_irq(
int rising)
211 cc1200_arch_gpio0_enable_irq(
void)
219 cc1200_arch_gpio0_disable_irq(
void)
225 cc1200_arch_gpio2_enable_irq(
void)
233 cc1200_arch_gpio2_disable_irq(
void)
239 cc1200_arch_gpio0_read_pin(
void)
241 return (
GPIO_READ_PIN(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK) ? 1 : 0);
245 cc1200_arch_gpio2_read_pin(
void)
247 return GPIO_READ_PIN(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
251 cc1200_arch_gpio3_read_pin(
void)
257 cc1200_arch_init(
void)
263 GPIO_SET_PIN(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
278 cc1200_arch_spi_deselect();
282 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.
#define RTIMER_BUSYWAIT_UNTIL(cond, max_time)
Busy-wait until a condition for at most max_time.
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 RTIMER_SECOND
Number of rtimer ticks for 1 second.
#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.