60 #include "contiki-conf.h"
80 #define ATMEGA128RFA1 6
82 #if PLATFORM_TYPE == RCB_B
87 # define MOSIPIN (0x02)
88 # define MISOPIN (0x03)
89 # define SCKPIN (0x01)
91 # define RSTPIN (0x05)
93 # define IRQPIN (0x04)
95 # define SLPTRPIN (0x04)
97 #elif PLATFORM_TYPE == ZIGBIT
100 # define SSPIN (0x00)
102 # define MOSIPIN (0x02)
103 # define MISOPIN (0x03)
104 # define SCKPIN (0x01)
106 # define RSTPIN (0x07)
108 # define IRQPIN (0x05)
110 # define SLPTRPIN (0x04)
112 #elif INGA_REVISION == INGA_V12
115 # define SSPIN (0x04)
117 # define MOSIPIN (0x05)
118 # define MISOPIN (0x06)
119 # define SCKPIN (0x07)
121 # define RSTPIN (0x01)
123 # define IRQPIN (0x06)
125 # define SLPTRPIN (0x03)
127 # define TXCWPIN (0x00)
129 # define USARTVECT USART0_RX_vect
132 # define HAS_SPARE_TIMER
134 #elif PLATFORM_TYPE == RAVEN_D
137 # define SSPIN (0x04)
139 # define MOSIPIN (0x05)
140 # define MISOPIN (0x06)
141 # define SCKPIN (0x07)
143 # define RSTPIN (0x01)
145 # define IRQPIN (0x06)
147 # define SLPTRPIN (0x03)
149 #elif PLATFORM_TYPE == RAVENUSB_C
152 # define SSPIN (0x00)
154 # define MOSIPIN (0x02)
155 # define MISOPIN (0x03)
156 # define SCKPIN (0x01)
158 # define RSTPIN (0x05)
160 # define IRQPIN (0x04)
162 # define SLPTRPIN (0x04)
164 #elif PLATFORM_TYPE == ATMEGA128RFA1
166 # define SLPTRPORT TRXPR
169 #elif CONTIKI_TARGET_MULLE
186 #elif PLATFORM_TYPE == IRIS
189 # define SSPIN (0x00)
191 # define MOSIPIN (0x02)
192 # define MISOPIN (0x03)
193 # define SCKPIN (0x01)
195 # define RSTPIN (0x06)
197 # define IRQPIN (0x04)
199 # define SLPTRPIN (0x07)
200 #elif defined(__AVR_ATxmega256A3BU__) || defined(__AVR_ATxmega256A3__) || defined(__AVR_ATxmega256A3U__) || defined(__AVR_ATxmega256A3B__)
204 #error "PLATFORM_TYPE undefined in hal.h"
210 #define SSPORT SPIPORT
214 #define SCKPORT SPIPORT
218 #define MOSIPORT SPIPORT
222 #define MISOPORT SPIPORT
236 #if defined(__AVR_XMEGA__)
237 #define CAT(x, y) x##y
239 #define CAT_DIR(x, y) x##y .DIR
240 #define CAT_OUT(x,y) x##y .OUT
241 #define CAT_IN(x,y) x##y .IN
243 #define CAT2(x, y, z) x##y##z
245 #define CAT2_DIR(x, y, z) x##y##z .DIR
246 #define CAT2_IN(x, y, z) x##y##z .IN
247 #define CAT2_OUT(x, y, z) x##y##z .OUT
249 #define DDR(x) CAT_DIR(PORT, x)
250 #define PORT(x) CAT_OUT(PORT, x)
251 #define PIN(x) CAT_OUT(PORT, x) // Pin is used for READ operations only
252 #define UCSR(num, let) CAT2(UCSR,num,let)
253 #define RXEN(x) CAT(RXEN,x)
254 #define TXEN(x) CAT(TXEN,x)
255 #define TXC(x) CAT(TXC,x)
256 #define RXC(x) CAT(RXC,x)
257 #define RXCIE(x) CAT(RXCIE,x)
258 #define UCSZ(x,y) CAT2(UCSZ,x,y)
259 #define UBRR(x,y) CAT2(UBRR,x,y)
260 #define UDRE(x) CAT(UDRE,x)
261 #define UDRIE(x) CAT(UDRIE,x)
262 #define UDR(x) CAT(UDR,x)
263 #define TCNT(x) CAT(TCNT,x)
264 #define TIMSK(x) CAT(TIMSK,x)
265 #define TCCR(x,y) CAT2(TCCR,x,y)
266 #define COM(x,y) CAT2(COM,x,y)
267 #define OCR(x,y) CAT2(OCR,x,y)
268 #define CS(x,y) CAT2(CS,x,y)
269 #define WGM(x,y) CAT2(WGM,x,y)
270 #define OCIE(x,y) CAT2(OCIE,x,y)
271 #define COMPVECT(x) CAT2(TIMER,x,_COMPA_vect)
272 #define UDREVECT(x) CAT2(USART,x,_UDRE_vect)
273 #define RXVECT(x) CAT2(USART,x,_RX_vect)
274 #elif defined(__AVR__)
275 #define CAT(x, y) x##y
276 #define DDR(x) CAT(DDR, x)
277 #define PORT(x) CAT(PORT, x)
278 #define PIN(x) CAT(PIN, x)
282 #if defined(CONTIKI_TARGET_MULLE)
283 #define CAT(x, y) x##y.BYTE
284 #define DDR(x) CAT(PD, x)
285 #define PORT(x) CAT(P, x)
286 #define PIN(x) CAT(P, x)
297 #if defined(__AVR_ATmega128RFA1__)
299 #define hal_set_rst_low( ) ( TRXPR &= ~( 1 << TRXRST ) )
300 #define hal_set_rst_high( ) ( TRXPR |= ( 1 << TRXRST ) )
301 #define hal_set_slptr_high( ) ( TRXPR |= ( 1 << SLPTR ) )
302 #define hal_set_slptr_low( ) ( TRXPR &= ~( 1 << SLPTR ) )
303 #define hal_get_slptr( ) ( TRXPR & ( 1 << SLPTR ) )
305 #elif defined(__AVR_XMEGA__)
306 #define SLP_TR SLPTRPIN
307 #define DDR_SLP_TR DDR( SLPTRPORT )
308 #define PORT_SLP_TR PORT( SLPTRPORT )
309 #define PIN_SLP_TR PIN( SLPTRPORT )
310 #define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) )
311 #define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) )
313 #define hal_get_slptr( ) ( PIN_SLP_TR & ( 1 << SLP_TR ) )
316 #define DDR_RST DDR( RSTPORT )
317 #define PORT_RST PORT( RSTPORT )
318 #define PIN_RST PIN( RSTPORT )
319 #define hal_set_rst_high( ) ( PORT_RST |= ( 1 << RSTPIN ) )
320 #define hal_set_rst_low( ) ( PORT_RST &= ~( 1 << RSTPIN ) )
321 #define hal_get_rst( ) ( ( PIN_RST & ( 1 << RSTPIN ) ) >> RST )
322 #define HAL_SS_PIN SSPIN
323 #define HAL_SCK_PIN SCKPIN
324 #define HAL_MOSI_PIN MOSIPIN
325 #define HAL_MISO_PIN MISOPIN
326 #define HAL_PORT_SPI PORT( SPIPORT )
327 #define HAL_PORT_SS PORT( SSPORT )
328 #define HAL_PORT_SCK PORT( SCKPORT )
329 #define HAL_PORT_MOSI PORT( MOSIPORT )
330 #define HAL_PORT_MISO PORT( MISOPORT )
331 #define HAL_DDR_SPI DDR( SPIPORT )
332 #define HAL_DDR_SS DDR( SSPORT )
333 #define HAL_DDR_SCK DDR( SCKPORT )
334 #define HAL_DDR_MOSI DDR( MOSIPORT )
335 #define HAL_DDR_MISO DDR( MISOPORT )
336 #define HAL_DD_SS SSPIN
337 #define HAL_DD_SCK SCKPIN
338 #define HAL_DD_MOSI MOSIPIN
339 #define HAL_DD_MISO MISOPIN
343 #define SLP_TR SLPTRPIN
344 #define DDR_SLP_TR DDR( SLPTRPORT )
345 #define PORT_SLP_TR PORT( SLPTRPORT )
346 #define PIN_SLP_TR PIN( SLPTRPORT )
347 #define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) )
348 #define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) )
349 #define hal_get_slptr( ) ( PIN_SLP_TR & ( 1 << SLP_TR ) )
351 #define DDR_RST DDR( RSTPORT )
352 #define PORT_RST PORT( RSTPORT )
353 #define PIN_RST PIN( RSTPORT )
354 #define hal_set_rst_high( ) ( PORT_RST |= ( 1 << RST ) )
355 #define hal_set_rst_low( ) ( PORT_RST &= ~( 1 << RST ) )
356 #define hal_get_rst( ) ( ( PIN_RST & ( 1 << RST ) ) >> RST )
357 #define HAL_SS_PIN SSPIN
358 #define HAL_SCK_PIN SCKPIN
359 #define HAL_MOSI_PIN MOSIPIN
360 #define HAL_MISO_PIN MISOPIN
361 #define HAL_PORT_SPI PORT( SPIPORT )
362 #define HAL_PORT_SS PORT( SSPORT )
363 #define HAL_PORT_SCK PORT( SCKPORT )
364 #define HAL_PORT_MOSI PORT( MOSIPORT )
365 #define HAL_PORT_MISO PORT( MISOPORT )
366 #define HAL_DDR_SPI DDR( SPIPORT )
367 #define HAL_DDR_SS DDR( SSPORT )
368 #define HAL_DDR_SCK DDR( SCKPORT )
369 #define HAL_DDR_MOSI DDR( MOSIPORT )
370 #define HAL_DDR_MISO DDR( MISOPORT )
371 #define HAL_DD_SS SSPIN
372 #define HAL_DD_SCK SCKPIN
373 #define HAL_DD_MOSI MOSIPIN
374 #define HAL_DD_MISO MISOPIN
380 #define HAL_SS_HIGH( ) (HAL_PORT_SS |= ( 1 << HAL_SS_PIN ))
381 #define HAL_SS_LOW( ) (HAL_PORT_SS &= ~( 1 << HAL_SS_PIN ))
383 #if defined(__AVR_XMEGA__)
385 #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( )
386 #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( )
388 #define HAL_ENTER_CRITICAL_REGION( ) {uint8_t volatile saved_sreg = SREG; cli( )
389 #define HAL_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg; }
392 #define RADIO_VECT PORTC_INT0_vect
393 #define HAL_ENABLE_RADIO_INTERRUPT( ) { PORTC.INTCTRL = (PORTC.INTCTRL & 0xC) | 0x2; PORTC.INT0MASK = (1 << IRQPIN); PORTC.DIR = (0xFF & (~(1 << IRQPIN))); PORTC.PIN2CTRL = (PORTC.PIN2CTRL & (~0x7)) | 0x1; PORTC.INTFLAGS = 1; }
394 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( PORTC.INTCTRL = (PORTC.INTCTRL & (~0x2)); )
396 #elif defined(__AVR__)
398 #if PLATFORM_TYPE == ZIGBIT
400 #define RADIO_VECT INT5_vect
401 #define HAL_ENABLE_RADIO_INTERRUPT( ) { ( EIMSK |= ( 1 << INT5 ) ) ; EICRB |= 0x0C ; PORTE &= ~(1<<PE5); DDRE &= ~(1<<DDE5); }
402 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( EIMSK &= ~( 1 << INT5 ) )
404 #define RADIO_VECT TIMER1_CAPT_vect
406 #define HAL_ENABLE_RADIO_INTERRUPT( ) { TCCR1B = ( 1 << ICES1 ) | ( 1 << CS10 ); TIFR1 |= (1 << ICF1); TIMSK1 |= ( 1 << ICIE1 ) ; }
407 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( TIMSK1 &= ~( 1 << ICIE1 ) )
410 #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 |= ( 1 << TOIE1 ) )
411 #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 &= ~( 1 << TOIE1 ) )
414 #define HAL_ENTER_CRITICAL_REGION( ) {uint8_t volatile saved_sreg = SREG; cli( )
418 #define HAL_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg;}
422 #define HAL_ENABLE_RADIO_INTERRUPT( ) ( INT1IC.BYTE |= 1 )
423 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( INT1IC.BYTE &= ~(1) )
425 #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( TB4IC.BYTE = 1 )
426 #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( TB4IC.BYTE = 0 )
429 #define HAL_ENTER_CRITICAL_REGION( ) MULLE_ENTER_CRITICAL_REGION( )
433 #define HAL_LEAVE_CRITICAL_REGION( ) MULLE_LEAVE_CRITICAL_REGION( )
440 #define hal_enable_trx_interrupt( ) HAL_ENABLE_RADIO_INTERRUPT( )
446 #define hal_disable_trx_interrupt( ) HAL_DISABLE_RADIO_INTERRUPT( )
453 #define HAL_BAT_LOW_MASK ( 0x80 )
454 #define HAL_TRX_UR_MASK ( 0x40 )
455 #define HAL_TRX_END_MASK ( 0x08 )
456 #define HAL_RX_START_MASK ( 0x04 )
457 #define HAL_PLL_UNLOCK_MASK ( 0x02 )
458 #define HAL_PLL_LOCK_MASK ( 0x01 )
460 #define HAL_MIN_FRAME_LENGTH ( 0x03 )
461 #define HAL_MAX_FRAME_LENGTH ( 0x7F )
481 #if defined(__AVR_ATmega128RFA1__)
483 #define hal_register_read(address) address
489 #define hal_register_write(address, value) address=value
505 void hal_sram_read( uint8_t address, uint8_t length, uint8_t *data );
506 void hal_sram_write( uint8_t address, uint8_t length, uint8_t *data );
508 #ifndef RF230_CONF_RX_BUFFERS
509 #define RF230_CONF_RX_BUFFERS 1