71 #define HAL_DUMMY_READ (0x00)
73 #define HAL_TRX_CMD_RW (0xC0)
74 #define HAL_TRX_CMD_RR (0x80)
75 #define HAL_TRX_CMD_FW (0x60)
76 #define HAL_TRX_CMD_FR (0x20)
77 #define HAL_TRX_CMD_SW (0x40)
78 #define HAL_TRX_CMD_SR (0x00)
79 #define HAL_TRX_CMD_RADDRM (0x7F)
81 #define HAL_CALCULATED_CRC_OK (0)
95 static uint16_t hal_system_time = 0;
98 static uint8_t
volatile hal_bat_low_flag;
99 static uint8_t
volatile hal_pll_lock_flag;
148 SPCR = (1 << SPE) | (1 << MSTR);
152 TCCR1B = HAL_TCCR1B_CONFIG;
153 TIFR1 |= (1 << ICF1);
154 HAL_ENABLE_OVERFLOW_INTERRUPT();
168 hal_bat_low_flag = 0;
169 hal_pll_lock_flag = 0;
172 rx_start_callback =
NULL;
173 trx_end_callback =
NULL;
188 return hal_bat_low_flag;
198 hal_bat_low_flag = 0;
209 return trx_end_callback;
220 trx_end_callback = trx_end_callback_handle;
231 trx_end_callback =
NULL;
243 return rx_start_callback;
254 rx_start_callback = rx_start_callback_handle;
265 rx_start_callback =
NULL;
279 return hal_pll_lock_flag;
289 hal_pll_lock_flag = 0;
310 uint8_t register_value = 0;
318 while ((SPSR & (1 << SPIF)) == 0) {;}
319 register_value = SPDR;
321 SPDR = register_value;
322 while ((SPSR & (1 << SPIF)) == 0) {;}
323 register_value = SPDR;
329 return register_value;
353 while ((SPSR & (1 << SPIF)) == 0) {;}
354 uint8_t dummy_read = SPDR;
357 while ((SPSR & (1 << SPIF)) == 0) {;}
381 register_value &= mask;
382 register_value >>= position;
384 return register_value;
405 register_value &= ~mask;
411 value |= register_value;
434 if (!rx_frame && !rx_callback)
443 while ((SPSR & (1 << SPIF)) == 0) {;}
444 uint8_t frame_length = SPDR;
448 while ((SPSR & (1 << SPIF)) == 0) {;}
455 rx_data = (rx_frame->
data);
456 rx_frame->
length = frame_length;
458 rx_callback(frame_length);
462 while ((SPSR & (1 << SPIF)) == 0) {;}
465 uint8_t tempData = SPDR;
469 *rx_data++ = tempData;
471 rx_callback(tempData);
474 crc = _crc_ccitt_update(crc, tempData);
476 while ((SPSR & (1 << SPIF)) == 0) {;}
478 }
while (--frame_length > 0);
482 rx_frame->
lqi = SPDR;
501 rx_frame->
crc =
false;
526 while ((SPSR & (1 << SPIF)) == 0) {;}
527 uint8_t dummy_read = SPDR;
530 while ((SPSR & (1 << SPIF)) == 0) {;}
535 SPDR = *write_buffer++;
538 while ((SPSR & (1 << SPIF)) == 0) {;}
541 }
while (length > 0);
566 while ((SPSR & (1 << SPIF)) == 0) {;}
567 uint8_t dummy_read = SPDR;
571 while ((SPSR & (1 << SPIF)) == 0) {;}
578 while ((SPSR & (1 << SPIF)) == 0) {;}
580 }
while (--length > 0);
605 while ((SPSR & (1 << SPIF)) == 0) {;}
606 uint8_t dummy_read = SPDR;
610 while ((SPSR & (1 << SPIF)) == 0) {;}
616 while ((SPSR & (1 << SPIF)) == 0) {;}
618 }
while (--length > 0);
641 uint32_t isr_timestamp = hal_system_time;
642 isr_timestamp <<= 16;
643 isr_timestamp |= TCNT1;
655 isr_timestamp /= HAL_US_PER_SYMBOL;
656 isr_timestamp &= HAL_SYMBOL_MASK;
658 while ((SPSR & (1 << SPIF)) == 0) {;}
659 uint8_t interrupt_source = SPDR;
661 SPDR = interrupt_source;
662 while ((SPSR & (1 << SPIF)) == 0) {;}
663 interrupt_source = SPDR;
669 if(rx_start_callback !=
NULL){
674 while ((SPSR & (1 << SPIF)) == 0) {;}
675 uint8_t frame_length = SPDR;
678 while ((SPSR & (1 << SPIF)) == 0) {;}
683 rx_start_callback(isr_timestamp, frame_length);
686 if(trx_end_callback !=
NULL){
687 trx_end_callback(isr_timestamp);
701 trx_isr_mask &= ~HAL_BAT_LOW_MASK;
void hal_reset_flags(void)
This function reset the interrupt flags and interrupt event handlers (Callbacks) to their default val...
#define HAL_DD_SCK
Data Direction bit for SCK.
#define DDR_RST
Data Direction Register that corresponds to the port where RST is.
#define HAL_TRX_CMD_FW
Frame Transmit Mode (long mode).
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.
#define RG_IRQ_MASK
Offset for register IRQ_MASK.
#define hal_enable_trx_interrupt()
Enable the interrupt from the radio transceiver.
uint8_t hal_register_read(uint8_t address)
This function reads data from one of the radio transceiver's registers.
#define RG_IRQ_STATUS
Offset for register IRQ_STATUS.
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.
#define HAL_BAT_LOW_MASK
Mask for the BAT_LOW interrupt.
#define HAL_DUMMY_READ
Dummy value for the SPI.
#define HAL_CALCULATED_CRC_OK
CRC calculated over the frame including the CRC field should be 0.
#define HAL_DD_SS
Data Direction bit for SS.
#define HAL_TRX_CMD_SW
SRAM Write.
#define AVR_ENTER_CRITICAL_REGION()
This macro will protect the following code from interrupts.
#define DDR_SLP_TR
Data Direction Register that corresponds to the port where SLP_TR is connected.
#define AVR_LEAVE_CRITICAL_REGION()
This macro must always be used in conjunction with AVR_ENTER_CRITICAL_REGION so that interrupts are e...
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.
#define NULL
The null pointer.
This file contains low-level radio driver code.
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.
#define HAL_SS_LOW()
MACRO for pulling SS low.
uint8_t data[HAL_MAX_FRAME_LENGTH]
Actual frame data.
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.
#define RST
Pin number that corresponds to the RST pin.
#define HAL_TRX_CMD_RR
Register Read (short mode).
void(* hal_trx_end_isr_event_handler_t)(uint32_t const isr_timestamp)
RRX_END event handler callback type.
#define HAL_PLL_LOCK_MASK
Mask for the PLL_LOCK interrupt.
void hal_sram_write(uint8_t address, uint8_t length, uint8_t *data)
Write SRAM.
#define HAL_TRX_CMD_SR
SRAM Read.
This file contains the register definitions for the AT86RF230.
#define HAL_RX_START_MASK
Mask for the RX_START interrupt.
#define HAL_TRX_UR_MASK
Mask for the TRX_UR interrupt.
#define HAL_TRX_CMD_RADDRM
Register Address Mask.
void hal_frame_write(uint8_t *write_buffer, uint8_t length)
This function will download a frame to the radio transceiver's frame buffer.
#define HAL_TRX_CMD_RW
Register Write (short mode).
#define HAL_PLL_UNLOCK_MASK
Mask for the PLL_UNLOCK interrupt.
void RADIO_VECT(void)
ISR for the radio IRQ line, triggered by the input capture.
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.
#define HAL_DDR_SPI
Data Direction Register for PORTB.
#define HAL_PORT_SPI
The SPI module is located on PORTB.
#define HAL_TRX_CMD_FR
Frame Receive Mode (long mode).
void hal_register_write(uint8_t address, uint8_t value)
This function writes a new value to one of the radio transceiver's registers.
#define HAL_DD_MOSI
Data Direction bit for MOSI.
#define SLP_TR
Pin number that corresponds to the SLP_TR pin.
#define HAL_MIN_FRAME_LENGTH
A frame should be at least 3 bytes.
#define HAL_TRX_END_MASK
Mask for the TRX_END interrupt.
#define HAL_SS_HIGH()
MACRO for pulling SS high.
void TIMER1_OVF_vect(void)
Timer Overflow ISR This is the interrupt service routine for timer1 overflow.
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.