41 #include "cc1120-arch.h"
42 #include "cc1120-const.h"
55 #define LEDS_ON(x) leds_on(x)
61 static uint8_t enabled;
64 #define BUSYWAIT_UNTIL(cond, max_time) \
68 while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))); \
71 #define CC1200_SPI_CLK_PORT_BASE GPIO_PORT_TO_BASE(SPI0_CLK_PORT)
72 #define CC1200_SPI_CLK_PIN_MASK GPIO_PIN_MASK(SPI0_CLK_PIN)
73 #define CC1200_SPI_MOSI_PORT_BASE GPIO_PORT_TO_BASE(SPI0_TX_PORT)
74 #define CC1200_SPI_MOSI_PIN_MASK GPIO_PIN_MASK(SPI0_TX_PIN)
75 #define CC1200_SPI_MISO_PORT_BASE GPIO_PORT_TO_BASE(SPI0_RX_PORT)
76 #define CC1200_SPI_MISO_PIN_MASK GPIO_PIN_MASK(SPI0_RX_PIN)
77 #define CC1200_SPI_CSN_PORT_BASE GPIO_PORT_TO_BASE(CC1200_SPI_CSN_PORT)
78 #define CC1200_SPI_CSN_PIN_MASK GPIO_PIN_MASK(CC1200_SPI_CSN_PIN)
79 #define CC1200_GDO0_PORT_BASE GPIO_PORT_TO_BASE(CC1200_GDO0_PORT)
80 #define CC1200_GDO0_PIN_MASK GPIO_PIN_MASK(CC1200_GDO0_PIN)
81 #define CC1200_GDO2_PORT_BASE GPIO_PORT_TO_BASE(CC1200_GDO2_PORT)
82 #define CC1200_GDO2_PIN_MASK GPIO_PIN_MASK(CC1200_GDO2_PIN)
83 #define CC1200_RESET_PORT_BASE GPIO_PORT_TO_BASE(CC1200_RESET_PORT)
84 #define CC1200_RESET_PIN_MASK GPIO_PIN_MASK(CC1200_RESET_PIN)
86 #if CC1120INTDEBUG || DEBUG
87 #define PRINTFINT(...) printf(__VA_ARGS__)
89 #define PRINTFINT(...) do {} while (0)
94 cc1120_debug_pin_cca(uint8_t val)
104 cc1120_debug_pin_rx(uint8_t val)
117 cc1120_int_handler(uint8_t port, uint8_t pin)
119 PRINTFINT(
"\n\tInt\n");
121 cc1120_interrupt_handler();
132 cc1120_driver.get_value(RADIO_PARAM_POWER_MODE, &res);
134 return res != RADIO_POWER_MODE_ON;
139 cc1120_arch_init(
void)
145 GPIO_SET_PIN(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
164 cc1120_arch_spi_disable();
168 GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK),
171 #if CC1120_DEBUG_PINS
190 cc1120_arch_pin_init(
void)
207 cc1120_arch_reset(
void)
209 cc1120_arch_spi_disable();
212 GPIO_CLR_PIN(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
214 GPIO_SET_PIN(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
220 cc1120_arch_spi_enabled(
void)
226 cc1120_arch_spi_enable(
void)
234 GPIO_CLR_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
239 while(
GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK))
241 if(RTIMER_CLOCK_LT((t0 + CC1120_EN_TIMEOUT),
RTIMER_NOW()) )
247 (void) cc1120_arch_spi_rw_byte(CC1120_STROBE_SNOP);
248 GPIO_SET_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
250 GPIO_CLR_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
269 cc1120_arch_spi_disable(
void)
272 GPIO_SET_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK);
279 cc1120_arch_spi_rw_byte(uint8_t val)
281 SPI_WAITFORTx_BEFORE();
282 SPIX_BUF(CC1200_SPI_INSTANCE) = val;
283 SPIX_WAITFOREOTx(CC1200_SPI_INSTANCE);
284 SPIX_WAITFOREORx(CC1200_SPI_INSTANCE);
285 return SPIX_BUF(CC1200_SPI_INSTANCE);
290 cc1120_arch_txfifo_load(uint8_t *packet, uint8_t packet_length)
294 status = cc1120_arch_spi_rw_byte(CC1120_FIFO_ACCESS | CC1120_BURST_BIT | CC1120_WRITE_BIT);
295 cc1120_arch_spi_rw_byte(packet_length);
297 for(i = 0; i < packet_length; i++)
300 cc1120_arch_spi_rw_byte(packet[i]);
309 cc1120_arch_rxfifo_read(uint8_t *packet, uint8_t packet_length)
313 (void) cc1120_arch_spi_rw_byte(CC1120_FIFO_ACCESS | CC1120_BURST_BIT | CC1120_READ_BIT);
315 for(i = 0; i < packet_length; i++)
318 packet[i] = cc1120_arch_spi_rw_byte(0);
326 cc1120_arch_read_cca(
void)
341 cc1120_arch_read_gpio2(
void)
343 return GPIO_READ_PIN(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
347 cc1120_arch_read_gpio3(
void)
359 cc1120_arch_interrupt_enable(
void)
361 PRINTFINT(
"\nInterrupt Enabled\n");
370 cc1120_arch_interrupt_disable(
void)
372 PRINTFINT(
"\nInterrupt Disabled\n");
380 cc1120_arch_interrupt_acknowledge(
void)
#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 ADC_SENSORS_ADC2_PIN
ADC2 to PA4.
#define GPIO_ENABLE_INTERRUPT(PORT_BASE, PIN_MASK)
Enable interrupt triggering for pins with PIN_MASK of port with PORT_BASE.
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
#define ADC_SENSORS_ADC1_PIN
ADC1 to PA5.
#define IOC_OVERRIDE_DIS
Override Disabled.
Header file for the cc2538 SPI driver, including macros for the implementation of the low-level SPI p...
#define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to detect edge.
#define RTIMER_NOW()
Get the current clock time.
#define IOC_OVERRIDE_OE
Output Enable.
void spix_init(uint8_t spi)
Initialize the SPI bus for the instance given.
#define GPIO_READ_PIN(PORT_BASE, PIN_MASK)
Read pins with PIN_MASK of port with PORT_BASE.
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE low.
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE high.
void spix_cs_init(uint8_t port, uint8_t pin)
Configure a GPIO to be the chip select pin.
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
Header file with declarations for the I/O Control module.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define GPIO_PORT_TO_BASE(PORT)
Converts a port number to the port base address.
Header file for the cc2538 System Control driver.
Header file for the cc2538 Synchronous Serial Interface.
#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.
void lpm_register_peripheral(lpm_periph_permit_pm1_func_t permit_pm1_func)
Register a peripheral function which will get called by the LPM module to get 'permission' to drop to...
static bool lpm_permit_pm1(void)
Callback to allow Low Power Modes 1 and 2.
void nvic_interrupt_enable(uint32_t intr)
Enables interrupt intr.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
#define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK)
Disable interrupt triggering for pins 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.
void gpio_register_callback(gpio_callback_t f, uint8_t port, uint8_t pin)
Register GPIO callback.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
#define ADC_SENSORS_PORT
ADC GPIO control port.