58 #include <avr/interrupt.h>
59 #include <util/crc16.h>
60 #include "contiki-conf.h"
64 #define TRIG1 DDRB |= 0x04, PINB |= 0x04
65 #define TRIG2 DDRD |= 0x80, PIND |= 0x80
87 #if PLATFORM_TYPE == RCB_B
92 # define MOSIPIN (0x02)
93 # define MISOPIN (0x03)
94 # define SCKPIN (0x01)
96 # define RSTPIN (0x05)
98 # define IRQPIN (0x04)
100 # define SLPTRPIN (0x04)
102 # define USARTVECT USART1_RX_vect
104 # define HAS_SPARE_TIMER
106 #elif PLATFORM_TYPE == ZIGBIT
109 # define SSPIN (0x00)
111 # define MOSIPIN (0x02)
112 # define MISOPIN (0x03)
113 # define SCKPIN (0x01)
115 # define RSTPIN (0x07)
117 # define IRQPIN (0x05)
119 # define SLPTRPIN (0x04)
121 # define TXCWPIN (0x07)
123 # define USARTVECT USART1_RX_vect
128 #elif RAVEN_REVISION == RAVEN_D
131 # define SSPIN (0x04)
133 # define MOSIPIN (0x05)
134 # define MISOPIN (0x06)
135 # define SCKPIN (0x07)
137 # define RSTPIN (0x01)
139 # define IRQPIN (0x06)
141 # define SLPTRPIN (0x03)
143 # define TXCWPIN (0x00)
145 # define USARTVECT USART1_RX_vect
148 # define HAS_SPARE_TIMER
150 #elif RAVEN_REVISION == RAVENUSB_C
153 # define SSPIN (0x00)
155 # define MOSIPIN (0x02)
156 # define MISOPIN (0x03)
157 # define SCKPIN (0x01)
159 # define RSTPIN (0x05)
161 # define IRQPIN (0x04)
163 # define SLPTRPIN (0x04)
165 # define TXCWPIN (0x07)
167 # define USARTVECT USART1_RX_vect
170 # define HAS_SPARE_TIMER
172 #elif PLATFORM_TYPE == IRIS
175 # define SSPIN (0x00)
177 # define MOSIPIN (0x02)
178 # define MISOPIN (0x03)
179 # define SCKPIN (0x01)
181 # define RSTPIN (0x06)
183 # define IRQPIN (0x04)
185 # define SLPTRPIN (0x07)
189 # define USARTVECT USART1_RX_vect
194 #error "Platform undefined in hal.h"
209 #define CAT(x, y) x##y
210 #define CAT2(x, y, z) x##y##z
211 #define DDR(x) CAT(DDR, x)
212 #define PORT(x) CAT(PORT, x)
213 #define PIN(x) CAT(PIN, x)
214 #define UCSR(num, let) CAT2(UCSR,num,let)
215 #define RXEN(x) CAT(RXEN,x)
216 #define TXEN(x) CAT(TXEN,x)
217 #define TXC(x) CAT(TXC,x)
218 #define RXC(x) CAT(RXC,x)
219 #define RXCIE(x) CAT(RXCIE,x)
220 #define UCSZ(x,y) CAT2(UCSZ,x,y)
221 #define UBRR(x,y) CAT2(UBRR,x,y)
222 #define UDRE(x) CAT(UDRE,x)
223 #define UDRIE(x) CAT(UDRIE,x)
224 #define UDR(x) CAT(UDR,x)
225 #define TCNT(x) CAT(TCNT,x)
226 #define TIMSK(x) CAT(TIMSK,x)
227 #define TCCR(x,y) CAT2(TCCR,x,y)
228 #define COM(x,y) CAT2(COM,x,y)
229 #define OCR(x,y) CAT2(OCR,x,y)
230 #define CS(x,y) CAT2(CS,x,y)
231 #define WGM(x,y) CAT2(WGM,x,y)
232 #define OCIE(x,y) CAT2(OCIE,x,y)
233 #define COMPVECT(x) CAT2(TIMER,x,_COMPA_vect)
234 #define UDREVECT(x) CAT2(USART,x,_UDRE_vect)
235 #define RXVECT(x) CAT2(USART,x,_RX_vect)
244 #define SLP_TR SLPTRPIN
245 #define DDR_SLP_TR DDR( SLPTRPORT )
246 #define PORT_SLP_TR PORT( SLPTRPORT )
247 #define PIN_SLP_TR PIN( SLPTRPORT )
248 #define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) )
249 #define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) )
250 #define hal_get_slptr( ) ( ( PIN_SLP_TR & ( 1 << SLP_TR ) ) >> SLP_TR )
252 #define DDR_RST DDR( RSTPORT )
253 #define PORT_RST PORT( RSTPORT )
254 #define PIN_RST PIN( RSTPORT )
255 #define hal_set_rst_high( ) ( PORT_RST |= ( 1 << RST ) )
256 #define hal_set_rst_low( ) ( PORT_RST &= ~( 1 << RST ) )
257 #define hal_get_rst( ) ( ( PIN_RST & ( 1 << RST ) ) >> RST )
258 #define HAL_SS_PIN SSPIN
259 #define HAL_PORT_SPI PORT( SPIPORT )
260 #define HAL_DDR_SPI DDR( SPIPORT )
261 #define HAL_DD_SS SSPIN
262 #define HAL_DD_SCK SCKPIN
263 #define HAL_DD_MOSI MOSIPIN
264 #define HAL_DD_MISO MISOPIN
268 #define HAL_SS_HIGH( ) (HAL_PORT_SPI |= ( 1 << HAL_SS_PIN ))
269 #define HAL_SS_LOW( ) (HAL_PORT_SPI &= ~( 1 << HAL_SS_PIN ))
278 #if ( F_CPU == 16000000UL )
279 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS12 ) )
280 #define HAL_US_PER_SYMBOL ( 1 )
281 #define HAL_SYMBOL_MASK ( 0xFFFFffff )
282 #elif ( F_CPU == 8000000UL )
283 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) | ( 1 << CS10 ) )
284 #define HAL_US_PER_SYMBOL ( 2 )
285 #define HAL_SYMBOL_MASK ( 0x7FFFffff )
286 #elif ( F_CPU == 4000000UL )
287 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) | ( 1 << CS10 ) )
288 #define HAL_US_PER_SYMBOL ( 1 )
289 #define HAL_SYMBOL_MASK ( 0xFFFFffff )
290 #elif ( F_CPU == 1000000UL )
291 #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) )
292 #define HAL_US_PER_SYMBOL ( 2 )
293 #define HAL_SYMBOL_MASK ( 0x7FFFffff )
295 #error "Clock speed not supported."
298 #if PLATFORM_TYPE == ZIGBIT
300 #define RADIO_VECT INT5_vect
301 #define HAL_ENABLE_RADIO_INTERRUPT( ) { ( EIMSK |= ( 1 << INT5 ) ) ; EICRB |= 0x0C ; PORTE &= ~(1<<PE5); DDRE &= ~(1<<DDE5); }
302 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( EIMSK &= ~( 1 << INT5 ) )
304 #define RADIO_VECT TIMER1_CAPT_vect
305 #define HAL_ENABLE_RADIO_INTERRUPT( ) ( TIMSK1 |= ( 1 << ICIE1 ) )
306 #define HAL_DISABLE_RADIO_INTERRUPT( ) ( TIMSK1 &= ~( 1 << ICIE1 ) )
309 #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 |= ( 1 << TOIE1 ) )
310 #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 &= ~( 1 << TOIE1 ) )
313 #define AVR_ENTER_CRITICAL_REGION( ) {uint8_t volatile saved_sreg = SREG; cli( )
317 #define AVR_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg;}
322 #define hal_enable_trx_interrupt( ) HAL_ENABLE_RADIO_INTERRUPT( )
328 #define hal_disable_trx_interrupt( ) HAL_DISABLE_RADIO_INTERRUPT( )
335 #define HAL_BAT_LOW_MASK ( 0x80 )
336 #define HAL_TRX_UR_MASK ( 0x40 )
337 #define HAL_TRX_END_MASK ( 0x08 )
338 #define HAL_RX_START_MASK ( 0x04 )
339 #define HAL_PLL_UNLOCK_MASK ( 0x02 )
340 #define HAL_PLL_LOCK_MASK ( 0x01 )
342 #define HAL_MIN_FRAME_LENGTH ( 0x03 )
343 #define HAL_MAX_FRAME_LENGTH ( 0x7F )
364 typedef void (*rx_callback_t) (uint16_t data);
391 void hal_sram_read( uint8_t address, uint8_t length, uint8_t *data );
392 void hal_sram_write( uint8_t address, uint8_t length, uint8_t *data );
void hal_reset_flags(void)
This function reset the interrupt flags and interrupt event handlers (Callbacks) to their default val...
uint8_t hal_get_bat_low_flag(void)
This function returns the current value of the BAT_LOW flag.
uint8_t lqi
LQI value for received frame.
uint8_t hal_register_read(uint8_t address)
This function reads data from one of the radio transceiver's registers.
void hal_clear_pll_lock_flag(void)
This function clears the PLL_LOCK flag.
void hal_clear_bat_low_flag(void)
This function clears the BAT_LOW flag.
hal_trx_end_isr_event_handler_t hal_get_trx_end_event_handler(void)
This function is used to set new TRX_END event handler, overriding old handler reference.
void hal_clear_rx_start_event_handler(void)
Remove event handler reference.
uint8_t length
Length of frame.
uint8_t hal_get_pll_lock_flag(void)
This function returns the current value of the PLL_LOCK flag.
uint8_t hal_subregister_read(uint8_t address, uint8_t mask, uint8_t position)
This function reads the value of a specific subregister.
void hal_init(void)
This function initializes the Hardware Abstraction Layer.
This struct defines the rx data container.
void hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value)
This function writes a new value to one of the radio transceiver's subregisters.
void hal_sram_read(uint8_t address, uint8_t length, uint8_t *data)
Read SRAM.
bool crc
Flag - did CRC pass for received frame?
void hal_frame_read(hal_rx_frame_t *rx_frame, rx_callback_t rx_callback)
This function will upload a frame from the radio transceiver's frame buffer.
void(* hal_trx_end_isr_event_handler_t)(uint32_t const isr_timestamp)
RRX_END event handler callback type.
void hal_sram_write(uint8_t address, uint8_t length, uint8_t *data)
Write SRAM.
void hal_frame_write(uint8_t *write_buffer, uint8_t length)
This function will download a frame to the radio transceiver's frame buffer.
void hal_set_rx_start_event_handler(hal_rx_start_isr_event_handler_t rx_start_callback_handle)
This function is used to set new RX_START event handler, overriding old handler reference.
hal_rx_start_isr_event_handler_t hal_get_rx_start_event_handler(void)
This function returns the active RX_START event handler.
#define HAL_MAX_FRAME_LENGTH
A frame should no more than 127 bytes.
void hal_clear_trx_end_event_handler(void)
Remove event handler reference.
void hal_register_write(uint8_t address, uint8_t value)
This function writes a new value to one of the radio transceiver's registers.
void hal_set_trx_end_event_handler(hal_trx_end_isr_event_handler_t trx_end_callback_handle)
This function is used to set new TRX_END event handler, overriding old handler reference.
void(* hal_rx_start_isr_event_handler_t)(uint32_t const isr_timestamp, uint8_t const frame_length)
RX_START event handler callback type.