41 #include "cc1120-arch.h"
42 #include "cc1120-const.h"
47 #include "isr_compat.h"
51 #define LEDS_ON(x) leds_on(x)
53 static uint8_t enabled;
56 #define BUSYWAIT_UNTIL(cond, max_time) \
60 while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))); \
68 cc1120_arch_init(
void)
71 cc1120_arch_pin_init();
77 CC1120_GDO0_PORT(
SEL) &= ~BV(CC1120_GDO0_PIN);
78 CC1120_GDO0_PORT(DIR) &= ~BV(CC1120_GDO0_PIN);
79 CC1120_GDO0_PORT(REN) |= BV(CC1120_GDO0_PIN);
80 CC1120_GDO0_PORT(OUT) &= ~BV(CC1120_GDO0_PIN);
83 CC1120_GDO0_PORT(IES) &= ~BV(CC1120_GDO0_PIN);
91 CC1120_GDO3_PORT(
SEL) &= ~BV(CC1120_GDO3_PIN);
92 CC1120_GDO3_PORT(DIR) &= ~BV(CC1120_GDO3_PIN);
93 CC1120_GDO3_PORT(REN) |= BV(CC1120_GDO3_PIN);
94 CC1120_GDO3_PORT(OUT) &= ~BV(CC1120_GDO3_PIN);
101 cc1120_arch_pin_init(
void)
104 CC2420_PWR_PORT(DIR) |= BV(CC2420_PWR_PIN);
105 CC2420_PWR_PORT(OUT) &= ~BV(CC2420_PWR_PIN);
106 CC2420_CSN_PORT(DIR) |= BV(CC2420_CSN_PIN);
107 CC2420_CSN_PORT(OUT) |= BV(CC2420_CSN_PIN);
108 CC2420_RESET_PORT(DIR) |= BV(CC2420_RESET_PIN);
109 CC2420_RESET_PORT(OUT) |= BV(CC2420_RESET_PIN);
112 CC1120_SPI_CSN_PORT(DIR) |= BV(CC1120_SPI_CSN_PIN);
113 CC1120_SPI_CSN_PORT(
SEL) &= ~BV(CC1120_SPI_CSN_PIN);
114 CC1120_SPI_CSN_PORT(OUT) |= BV(CC1120_SPI_CSN_PIN);
117 CC1120_RESET_PORT(DIR) |= BV(CC1120_RESET_PIN);
118 CC1120_RESET_PORT(
SEL) &= ~BV(CC1120_RESET_PIN);
119 CC1120_RESET_PORT(OUT) |= BV(CC1120_RESET_PIN);
125 cc1120_arch_reset(
void)
127 CC1120_SPI_CSN_PORT(OUT) |= BV(CC1120_SPI_CSN_PIN);
128 CC1120_RESET_PORT(OUT) &= ~BV(CC1120_RESET_PIN);
130 CC1120_RESET_PORT(OUT) |= BV(CC1120_RESET_PIN);
136 cc1120_arch_spi_enabled(
void)
142 cc1120_arch_spi_enable(
void)
150 CC1120_SPI_CSN_PORT(OUT) &= ~BV(CC1120_SPI_CSN_PIN);
155 while(CC1120_SPI_MISO_PORT(IN) & BV(CC1120_SPI_MISO_PIN))
157 if(RTIMER_CLOCK_LT((t0 + CC1120_EN_TIMEOUT),
RTIMER_NOW()) )
163 (void) cc1120_arch_spi_rw_byte(CC1120_STROBE_SNOP);
164 CC1120_SPI_CSN_PORT(OUT) |= BV(CC1120_SPI_CSN_PIN);
166 CC1120_SPI_CSN_PORT(OUT) &= ~BV(CC1120_SPI_CSN_PIN);
185 cc1120_arch_spi_disable(
void)
190 CC1120_SPI_CSN_PORT(OUT) |= BV(CC1120_SPI_CSN_PIN);
198 cc1120_arch_spi_rw_byte(uint8_t val)
200 SPI_WAITFORTx_BEFORE();
209 cc1120_arch_txfifo_load(uint8_t *packet, uint8_t packet_length)
213 status = cc1120_arch_spi_rw_byte(CC1120_FIFO_ACCESS | CC1120_BURST_BIT | CC1120_WRITE_BIT);
214 cc1120_arch_spi_rw_byte(packet_length);
216 for(i = 0; i < packet_length; i++)
219 cc1120_arch_spi_rw_byte(packet[i]);
228 cc1120_arch_rxfifo_read(uint8_t *packet, uint8_t packet_length)
232 (void) cc1120_arch_spi_rw_byte(CC1120_FIFO_ACCESS | CC1120_BURST_BIT | CC1120_READ_BIT);
234 for(i = 0; i < packet_length; i++)
237 packet[i] = cc1120_arch_spi_rw_byte(0);
245 cc1120_arch_read_cca(
void)
260 cc1120_arch_read_gpio2(
void)
262 if(CC1120_GDO3_PORT(IN) & BV(CC1120_GDO3_PIN))
273 cc1120_arch_read_gpio3(
void)
275 if(CC1120_GDO3_PORT(IN) & BV(CC1120_GDO3_PIN))
292 cc1120_arch_interrupt_enable(
void)
295 CC1120_GDO0_PORT(IFG) &= ~BV(CC1120_GDO0_PIN);
297 CC1120_GDO0_PORT(IE) |= BV(CC1120_GDO0_PIN);
302 cc1120_arch_interrupt_disable(
void)
305 CC1120_GDO0_PORT(IE) &= ~BV(CC1120_GDO0_PIN);
307 CC1120_GDO0_PORT(IFG) &= ~BV(CC1120_GDO0_PIN);
311 cc1120_arch_interrupt_acknowledge(
void)
314 CC1120_GDO0_PORT(IE) &= ~BV(CC1120_GDO0_PIN);
316 CC1120_GDO0_PORT(IFG) &= ~BV(CC1120_GDO0_PIN);
318 CC1120_GDO0_PORT(IE) |= BV(CC1120_GDO0_PIN);
#define RTIMER_NOW()
Get the current clock time.
void watchdog_periodic(void)
Writes the WDT clear sequence.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.