59 #include "contiki-conf.h"
63 #define TRIG1 DDRB |= 0x04, PINB |= 0x04
64 #define TRIG2 DDRD |= 0x80, PIND |= 0x80
83 #define ATMEGA128RFA1 4
89 #if RCB_REVISION == RCB_B
94 # define MOSIPIN (0x02)
95 # define MISOPIN (0x03)
96 # define SCKPIN (0x01)
98 # define RSTPIN (0x05)
100 # define IRQPIN (0x04)
102 # define SLPTRPIN (0x04)
104 # define USARTVECT USART1_RX_vect
106 # define HAS_SPARE_TIMER
108 #elif HARWARE_REVISION == ZIGBIT
111 # define SSPIN (0x00)
113 # define MOSIPIN (0x02)
114 # define MISOPIN (0x03)
115 # define SCKPIN (0x01)
117 # define RSTPIN (0x07)
119 # define IRQPIN (0x05)
121 # define SLPTRPIN (0x04)
123 # define TXCWPIN (0x07)
125 # define USARTVECT USART1_RX_vect
129 #elif INGA_REVISION == INGA_12
132 # define SSPIN (0x04)
134 # define MOSIPIN (0x05)
135 # define MISOPIN (0x06)
136 # define SCKPIN (0x07)
138 # define RSTPIN (0x01)
140 # define IRQPIN (0x06)
142 # define SLPTRPIN (0x03)
144 # define TXCWPIN (0x00)
146 # define USARTVECT USART0_RX_vect
149 # define HAS_SPARE_TIMER
151 #elif RAVEN_REVISION == RAVEN_D
154 # define SSPIN (0x04)
156 # define MOSIPIN (0x05)
157 # define MISOPIN (0x06)
158 # define SCKPIN (0x07)
160 # define RSTPIN (0x01)
162 # define IRQPIN (0x06)
164 # define SLPTRPIN (0x03)
166 # define TXCWPIN (0x00)
168 # define USARTVECT USART1_RX_vect
171 # define HAS_SPARE_TIMER
173 #elif RAVEN_REVISION == RAVENUSB_C
176 # define SSPIN (0x00)
178 # define MOSIPIN (0x02)
179 # define MISOPIN (0x03)
180 # define SCKPIN (0x01)
182 # define RSTPIN (0x05)
184 # define IRQPIN (0x04)
186 # define SLPTRPIN (0x04)
188 # define TXCWPIN (0x07)
190 # define USARTVECT USART1_RX_vect
193 # define HAS_SPARE_TIMER
195 #elif HARWARE_REVISION == ATMEGA128RFA1
199 # define SSPIN (0x04)
201 # define MOSIPIN (0x05)
202 # define MISOPIN (0x06)
203 # define SCKPIN (0x07)
205 # define RSTPIN (0x01)
207 # define IRQPIN (0x06)
209 # define SLPTRPIN (0x03)
211 # define TXCWPIN (0x00)
213 # define SLPTRPORT TRXPR
216 # define USARTVECT USART1_RX_vect
219 # define HAS_SPARE_TIMER
221 #elif CONTIKI_TARGET_MULLE
238 # define HAS_SPARE_TIMER
241 #elif HARWARE_REVISION == IRIS
244 # define SSPIN (0x00)
246 # define MOSIPIN (0x02)
247 # define MISOPIN (0x03)
248 # define SCKPIN (0x01)
250 # define RSTPIN (0x06)
252 # define IRQPIN (0x04)
254 # define SLPTRPIN (0x07)
258 # define USARTVECT USART1_RX_vect
263 #error "Platform undefined in hal.h"
269 #define SSPORT SPIPORT
273 #define SCKPORT SPIPORT
277 #define MOSIPORT SPIPORT
281 #define MISOPORT SPIPORT
296 #define CAT(x, y) x##y
297 #define CAT2(x, y, z) x##y##z
298 #define DDR(x) CAT(DDR, x)
299 #define PORT(x) CAT(PORT, x)
300 #define PIN(x) CAT(PIN, x)
301 #define UCSR(num, let) CAT2(UCSR,num,let)
302 #define RXEN(x) CAT(RXEN,x)
303 #define TXEN(x) CAT(TXEN,x)
304 #define TXC(x) CAT(TXC,x)
305 #define RXC(x) CAT(RXC,x)
306 #define RXCIE(x) CAT(RXCIE,x)
307 #define UCSZ(x,y) CAT2(UCSZ,x,y)
308 #define UBRR(x,y) CAT2(UBRR,x,y)
309 #define UDRE(x) CAT(UDRE,x)
310 #define UDRIE(x) CAT(UDRIE,x)
311 #define UDR(x) CAT(UDR,x)
312 #define TCNT(x) CAT(TCNT,x)
313 #define TIMSK(x) CAT(TIMSK,x)
314 #define TCCR(x,y) CAT2(TCCR,x,y)
315 #define COM(x,y) CAT2(COM,x,y)
316 #define OCR(x,y) CAT2(OCR,x,y)
317 #define CS(x,y) CAT2(CS,x,y)
318 #define WGM(x,y) CAT2(WGM,x,y)
319 #define OCIE(x,y) CAT2(OCIE,x,y)
320 #define COMPVECT(x) CAT2(TIMER,x,_COMPA_vect)
321 #define UDREVECT(x) CAT2(USART,x,_UDRE_vect)
322 #define RXVECT(x) CAT2(USART,x,_RX_vect)
326 #if defined(CONTIKI_TARGET_MULLE)
327 #define CAT(x, y) x##y.BYTE
328 #define CAT2(x, y, z) x##y##z.BYTE
329 #define DDR(x) CAT(PD, x)
330 #define PORT(x) CAT(P, x)
331 #define PIN(x) CAT(P, x)
332 #define UCSR(num, let) CAT2(UCSR,num,let)
333 #define RXEN(x) CAT(RXEN,x)
334 #define TXEN(x) CAT(TXEN,x)
335 #define TXC(x) CAT(TXC,x)
336 #define RXC(x) CAT(RXC,x)
337 #define RXCIE(x) CAT(RXCIE,x)
338 #define UCSZ(x,y) CAT2(UCSZ,x,y)
339 #define UBRR(x,y) CAT2(UBRR,x,y)
340 #define UDRE(x) CAT(UDRE,x)
341 #define UDRIE(x) CAT(UDRIE,x)
342 #define UDR(x) CAT(UDR,x)
343 #define TCNT(x) CAT(TCNT,x)
344 #define TIMSK(x) CAT(TIMSK,x)
345 #define TCCR(x,y) CAT2(TCCR,x,y)
346 #define COM(x,y) CAT2(COM,x,y)
347 #define OCR(x,y) CAT2(OCR,x,y)
348 #define CS(x,y) CAT2(CS,x,y)
349 #define WGM(x,y) CAT2(WGM,x,y)
350 #define OCIE(x,y) CAT2(OCIE,x,y)
351 #define COMPVECT(x) CAT2(TIMER,x,_COMPA_vect)
352 #define UDREVECT(x) CAT2(USART,x,_UDRE_vect)
353 #define RXVECT(x) CAT2(USART,x,_RX_vect)
364 #if defined(__AVR_ATmega128RFA1__)
366 #define hal_set_rst_low( ) ( TRXPR &= ~( 1 << TRXRST ) )
367 #define hal_set_rst_high( ) ( TRXPR |= ( 1 << TRXRST ) )
368 #define hal_set_slptr_high( ) ( TRXPR |= ( 1 << SLPTR ) )
369 #define hal_set_slptr_low( ) ( TRXPR &= ~( 1 << SLPTR ) )
371 #define hal_get_slptr( ) ( TRXPR & ( 1 << SLPTR ) )
374 #define SLP_TR SLPTRPIN
375 #define DDR_SLP_TR DDR( SLPTRPORT )
376 #define PORT_SLP_TR PORT( SLPTRPORT )
377 #define PIN_SLP_TR PIN( SLPTRPORT )
378 #define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) )
379 #define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) )
381 #define hal_get_slptr( ) ( PIN_SLP_TR & ( 1 << SLP_TR ) )
383 #define DDR_RST DDR( RSTPORT )
384 #define PORT_RST PORT( RSTPORT )
385 #define PIN_RST PIN( RSTPORT )
386 #define hal_set_rst_high( ) ( PORT_RST |= ( 1 << RST ) )
387 #define hal_set_rst_low( ) ( PORT_RST &= ~( 1 << RST ) )
388 #define hal_get_rst( ) ( ( PIN_RST & ( 1 << RST ) ) >> RST )
389 #define HAL_SS_PIN SSPIN
390 #define HAL_SCK_PIN SCKPIN
391 #define HAL_MOSI_PIN MOSIPIN
392 #define HAL_MISO_PIN MISOPIN
393 #define HAL_PORT_SPI PORT( SPIPORT )
394 #define HAL_PORT_SS PORT( SSPORT )
395 #define HAL_PORT_SCK PORT( SCKPORT )
396 #define HAL_PORT_MOSI PORT( MOSIPORT )
397 #define HAL_PORT_MISO PORT( MISOPORT )
398 #define HAL_DDR_SPI DDR( SPIPORT )
399 #define HAL_DDR_SS DDR( SSPORT )
400 #define HAL_DDR_SCK DDR( SCKPORT )
401 #define HAL_DDR_MOSI DDR( MOSIPORT )
402 #define HAL_DDR_MISO DDR( MISOPORT )
403 #define HAL_DD_SS SSPIN
404 #define HAL_DD_SCK SCKPIN
405 #define HAL_DD_MOSI MOSIPIN
406 #define HAL_DD_MISO MISOPIN
412 #define HAL_SS_HIGH( ) (HAL_PORT_SS |= ( 1 << HAL_SS_PIN ))
413 #define HAL_SS_LOW( ) (HAL_PORT_SS &= ~( 1 << HAL_SS_PIN ))
423 #if ( F_CPU == 16000000UL )
424 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS12 ) )
425 #define HAL_US_PER_SYMBOL ( 1 )
426 #define HAL_SYMBOL_MASK ( 0xFFFFffff )
427 #elif ( F_CPU == 8000000UL )
428 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) | ( 1 << CS10 ) )
429 #define HAL_US_PER_SYMBOL ( 2 )
430 #define HAL_SYMBOL_MASK ( 0x7FFFffff )
431 #elif ( F_CPU == 4000000UL )
432 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) | ( 1 << CS10 ) )
433 #define HAL_US_PER_SYMBOL ( 1 )
434 #define HAL_SYMBOL_MASK ( 0xFFFFffff )
435 #elif ( F_CPU == 1000000UL )
436 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) )
437 #define HAL_US_PER_SYMBOL ( 2 )
438 #define HAL_SYMBOL_MASK ( 0x7FFFffff )
440 #error "Clock speed not supported."
443 #if HARWARE_REVISION == ZIGBIT
445 #define RADIO_VECT INT5_vect
446 #define HAL_ENABLE_RADIO_INTERRUPT( ) { ( EIMSK |= ( 1 << INT5 ) ) ; EICRB |= 0x0C ; PORTE &= ~(1<<PE5); DDRE &= ~(1<<DDE5); }
447 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( EIMSK &= ~( 1 << INT5 ) )
449 #define RADIO_VECT TIMER1_CAPT_vect
451 #define HAL_ENABLE_RADIO_INTERRUPT( ) ( TIMSK1 |= ( 1 << ICIE1 ) )
452 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( TIMSK1 &= ~( 1 << ICIE1 ) )
455 #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 |= ( 1 << TOIE1 ) )
456 #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 &= ~( 1 << TOIE1 ) )
459 #define HAL_ENTER_CRITICAL_REGION( ) {uint8_t volatile saved_sreg = SREG; cli( )
463 #define HAL_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg;}
467 #define HAL_ENABLE_RADIO_INTERRUPT( ) ( INT1IC.BYTE |= 1 )
468 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( INT1IC.BYTE &= ~(1) )
470 #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( TB4IC.BYTE = 1 )
471 #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( TB4IC.BYTE = 0 )
474 #define HAL_ENTER_CRITICAL_REGION( ) MULLE_ENTER_CRITICAL_REGION( )
478 #define HAL_LEAVE_CRITICAL_REGION( ) MULLE_LEAVE_CRITICAL_REGION( )
485 #define hal_enable_trx_interrupt( ) HAL_ENABLE_RADIO_INTERRUPT( )
491 #define hal_disable_trx_interrupt( ) HAL_DISABLE_RADIO_INTERRUPT( )
498 #define HAL_BAT_LOW_MASK ( 0x80 )
499 #define HAL_TRX_UR_MASK ( 0x40 )
500 #define HAL_TRX_END_MASK ( 0x08 )
501 #define HAL_RX_START_MASK ( 0x04 )
502 #define HAL_PLL_UNLOCK_MASK ( 0x02 )
503 #define HAL_PLL_LOCK_MASK ( 0x01 )
505 #define HAL_MIN_FRAME_LENGTH ( 0x03 )
506 #define HAL_MAX_FRAME_LENGTH ( 0x7F )
527 typedef void (*rx_callback_t) (uint16_t data);
548 #if defined(__AVR_ATmega128RFA1__)
550 #define hal_register_read(address) address
556 #define hal_register_write(address, value) address=value
574 void hal_sram_read( uint8_t address, uint8_t length, uint8_t *data );
575 void hal_sram_write( uint8_t address, uint8_t length, uint8_t *data );
577 #ifndef RF230_CONF_RX_BUFFERS
578 #define RF230_CONF_RX_BUFFERS 1