AVR Z-LINKŪ | |||||
The Hardware Abstraction Layer implements all the necessary functionality to interact with the radio transceiver:
Copyright (c) 2006, Atmel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file hal_avr.c.
#include "at86rf230_registermap.h"
#include "compiler.h"
#include "hal.h"
Include dependency graph for hal_avr.c:
Go to the source code of this file.
Defines | |
#define | HAL_CALCULATED_CRC_OK ( 0 ) |
CRC calculated over the frame including the CRC field should be 0. | |
#define | HAL_DUMMY_READ ( 0x00 ) |
Dummy value for the SPI. | |
#define | HAL_TRX_CMD_FR ( 0x20 ) |
Frame Receive Mode (long mode). | |
#define | HAL_TRX_CMD_FW ( 0x60 ) |
Frame Transmit Mode (long mode). | |
#define | HAL_TRX_CMD_RADDRM ( 0x7F ) |
Register Address Mask. | |
#define | HAL_TRX_CMD_RR ( 0x80 ) |
Register Read (short mode). | |
#define | HAL_TRX_CMD_RW ( 0xC0 ) |
Register Write (short mode). | |
#define | HAL_TRX_CMD_SR ( 0x00 ) |
SRAM Read. | |
#define | HAL_TRX_CMD_SW ( 0x40 ) |
SRAM Write. | |
Functions | |
void | hal_clear_bat_low_flag (void) |
This function clears the BAT_LOW flag. | |
void | hal_clear_pll_lock_flag (void) |
This function clears the PLL_LOCK flag. | |
void | hal_clear_pll_unlock_flag (void) |
This function clears the PLL_UNLOCK flag. | |
void | hal_clear_rx_start_event_handler (void) |
Remove event handler reference. | |
void | hal_clear_rx_start_flag (void) |
This function clears the RX_START flag. | |
void | hal_clear_trx_end_event_handler (void) |
Remove event handler reference. | |
void | hal_clear_trx_end_flag (void) |
This function clears the TRX_END flag. | |
void | hal_clear_trx_ur_flag (void) |
This function clears the TRX_UR flag. | |
void | hal_clear_unknown_isr_flag (void) |
This function clears the UNKNOWN_ISR flag. | |
__z void | hal_frame_read (hal_rx_frame_t *rx_frame) |
This function will upload a frame from the radio transceiver's frame buffer. | |
__z void | hal_frame_write (uint8_t *write_buffer, uint8_t length) |
This function will download a frame to the radio transceiver's frame buffer. | |
uint8_t | hal_get_bat_low_flag (void) |
This function returns the current value of the BAT_LOW flag. | |
uint8_t | hal_get_pll_lock_flag (void) |
This function returns the current value of the PLL_LOCK flag. | |
uint8_t | hal_get_pll_unlock_flag (void) |
This function returns the current value of the PLL_UNLOCK flag. | |
uint8_t | hal_get_rx_start_flag (void) |
This function returns the current value of the RX_START flag. | |
uint32_t | hal_get_system_time (void) |
This function returns the system time in symbols, as defined in the IEEE 802.15.4 standard. | |
uint8_t | hal_get_trx_end_flag (void) |
This function returns the current value of the TRX_END flag. | |
uint8_t | hal_get_trx_ur_flag (void) |
This function returns the current value of the TRX_UR flag. | |
uint8_t | hal_get_unknown_isr_flag (void) |
This function returns the current value of the UNKNOWN_ISR flag. | |
void | hal_init (void) |
This function initializes the Hardware Abstraction Layer. | |
uint8_t | hal_register_read (uint8_t address) |
This function reads data from one of the radio transceiver's registers. | |
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_reset_flags (void) |
This function reset the interrupt flags and interrupt event handlers (Callbacks) to their default value. | |
void | hal_set_rx_start_event_handler (hal_trx_isr_event_handler_t rx_start_callback_handle) |
This function is used to set new RX_START event handler, overriding old handler reference. | |
void | hal_set_trx_end_event_handler (hal_trx_isr_event_handler_t trx_end_callback_handle) |
This function is used to set new TRX_END event handler, overriding old handler reference. | |
__z void | hal_sram_read (uint8_t address, uint8_t length, uint8_t *data) |
Read SRAM. | |
__z void | hal_sram_write (uint8_t address, uint8_t length, uint8_t *data) |
Write SRAM. | |
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_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. | |
ISR (TIMER1_OVF_vect) | |
ISR (TIMER1_CAPT_vect) | |
Variables | |
static uint8_t volatile | hal_bat_low_flag |
BAT_LOW flag. | |
static uint8_t volatile | hal_pll_lock_flag |
PLL_LOCK flag. | |
static uint8_t volatile | hal_pll_unlock_flag |
PLL_UNLOCK flag. | |
static uint8_t volatile | hal_rx_start_flag |
RX_START falg;. | |
static uint16_t | hal_system_time |
This is a file internal variable that contains the 16 MSB of the system time. | |
static uint8_t volatile | hal_trx_end_flag |
TRX_END flag. | |
static uint8_t volatile | hal_trx_ur_flag |
TRX_UR flag. | |
static uint8_t volatile | hal_unknown_isr_flag |
Error, unknown interrupt event signaled from the radio transceiver. | |
static hal_trx_isr_event_handler_t | rx_start_callback |
This function is called when a rx_start interrupt is signaled. | |
static hal_trx_isr_event_handler_t | trx_end_callback |
This function is called when a trx_end interrupt is signaled. |
#define HAL_CALCULATED_CRC_OK ( 0 ) |
CRC calculated over the frame including the CRC field should be 0.
Definition at line 79 of file hal_avr.c.
Referenced by hal_frame_read().
#define HAL_DUMMY_READ ( 0x00 ) |
Dummy value for the SPI.
Definition at line 69 of file hal_avr.c.
Referenced by hal_frame_read(), hal_register_read(), hal_sram_read(), and ISR().
#define HAL_TRX_CMD_FR ( 0x20 ) |
Frame Receive Mode (long mode).
Definition at line 74 of file hal_avr.c.
Referenced by hal_frame_read(), and ISR().
#define HAL_TRX_CMD_FW ( 0x60 ) |
Frame Transmit Mode (long mode).
Definition at line 73 of file hal_avr.c.
Referenced by hal_frame_write().
#define HAL_TRX_CMD_RADDRM ( 0x7F ) |
Register Address Mask.
Definition at line 77 of file hal_avr.c.
Referenced by hal_frame_write(), hal_register_read(), and hal_register_write().
#define HAL_TRX_CMD_RR ( 0x80 ) |
Register Read (short mode).
Definition at line 72 of file hal_avr.c.
Referenced by hal_register_read(), and ISR().
#define HAL_TRX_CMD_RW ( 0xC0 ) |
Register Write (short mode).
Definition at line 71 of file hal_avr.c.
Referenced by hal_register_write().
#define HAL_TRX_CMD_SR ( 0x00 ) |
#define HAL_TRX_CMD_SW ( 0x40 ) |
ISR | ( | TIMER1_OVF_vect | ) |
Definition at line 828 of file hal_avr.c.
References hal_system_time.
00828 { 00829 hal_system_time++; 00830 }
ISR | ( | TIMER1_CAPT_vect | ) |
Definition at line 733 of file hal_avr.c.
References hal_bat_low_flag, HAL_DUMMY_READ, hal_pll_lock_flag, hal_pll_unlock_flag, hal_register_read(), hal_register_write(), hal_rx_start_flag, HAL_SS_HIGH, HAL_SS_LOW, hal_system_time, HAL_TRX_CMD_FR, HAL_TRX_CMD_RR, hal_trx_end_flag, hal_trx_ur_flag, hal_unknown_isr_flag, RG_IRQ_MASK, RG_IRQ_STATUS, rx_start_callback, and trx_end_callback.
00733 { 00734 00735 /*Read current system time so that RX_START and TRX_END interrupts can be timestamped.*/ 00736 uint32_t isr_timestamp = hal_system_time; //Read 16 MSB. 00737 isr_timestamp <<= 16; //Shift in place. 00738 isr_timestamp |= TCNT1; //Add 16 LSB. 00739 isr_timestamp /= HAL_US_PER_SYMBOL; //Divide so that we get time in 16us resolution. 00740 isr_timestamp &= HAL_SYMBOL_MASK; 00741 00742 /*Read Interrupt source.*/ 00743 HAL_SS_LOW( ); 00744 00745 /*Send Register address and read register content.*/ 00746 SPDR = RG_IRQ_STATUS | HAL_TRX_CMD_RR; 00747 while ((SPSR & (1 << SPIF)) == 0) {;} 00748 uint8_t register_value = SPDR; 00749 00750 SPDR = HAL_DUMMY_READ; 00751 while ((SPSR & (1 << SPIF)) == 0) {;} 00752 uint8_t interrupt_source = SPDR; 00753 00754 HAL_SS_HIGH( ); 00755 00756 /*Handle the incomming interrupt.*/ 00757 if ((interrupt_source & HAL_RX_START_MASK)) { 00758 00759 hal_rx_start_flag++; //Increment RX_START flag. 00760 00761 if( rx_start_callback != NULL ){ 00762 00763 /*Read Frame length and call rx_start callback.*/ 00764 HAL_SS_LOW( ); 00765 00766 SPDR = HAL_TRX_CMD_FR; 00767 while ((SPSR & (1 << SPIF)) == 0) {;} 00768 uint8_t dummy_read = SPDR; 00769 00770 SPDR = HAL_DUMMY_READ; 00771 while ((SPSR & (1 << SPIF)) == 0) {;} 00772 uint8_t frame_length = SPDR; 00773 00774 HAL_SS_HIGH( ); 00775 00776 rx_start_callback( isr_timestamp, frame_length ); 00777 } 00778 } else if (interrupt_source & HAL_TRX_END_MASK) { 00779 00780 hal_trx_end_flag++; //Increment TRX_END flag. 00781 00782 if( trx_end_callback != NULL ){ 00783 00784 /*Read Frame length and call rx_start callback.*/ 00785 HAL_SS_LOW( ); 00786 00787 SPDR = HAL_TRX_CMD_FR; 00788 while ((SPSR & (1 << SPIF)) == 0) {;} 00789 uint8_t dummy_read = SPDR; 00790 00791 SPDR = HAL_DUMMY_READ; 00792 while ((SPSR & (1 << SPIF)) == 0) {;} 00793 uint8_t frame_length = SPDR; 00794 00795 HAL_SS_HIGH( ); 00796 00797 trx_end_callback( isr_timestamp, frame_length ); 00798 } 00799 } else if (interrupt_source & HAL_TRX_UR_MASK) { 00800 hal_trx_ur_flag++; //Increment TRX_UR flag. 00801 } else if (interrupt_source & HAL_PLL_UNLOCK_MASK) { 00802 hal_pll_unlock_flag++; //Increment PLL_UNLOCK flag. 00803 } else if (interrupt_source & HAL_PLL_LOCK_MASK) { 00804 hal_pll_lock_flag++; //Increment PLL_LOCK flag. 00805 } else if (interrupt_source & HAL_BAT_LOW_MASK) { 00806 00807 //Disable BAT_LOW interrupt to prevent interrupt storm. The interrupt 00808 //will continously be signaled when the supply voltage is less than the 00809 //user defined voltage threshold. 00810 uint8_t trx_isr_mask = hal_register_read( RG_IRQ_MASK ); 00811 trx_isr_mask &= ~HAL_BAT_LOW_MASK; 00812 hal_register_write( RG_IRQ_MASK, trx_isr_mask ); 00813 hal_bat_low_flag++; //Increment BAT_LOW flag. 00814 } else { 00815 hal_unknown_isr_flag++; //Increment UNKNOWN_ISR flag. 00816 } 00817 }
Here is the call graph for this function:
uint8_t volatile hal_bat_low_flag [static] |
BAT_LOW flag.
Definition at line 96 of file hal_avr.c.
Referenced by hal_clear_bat_low_flag(), hal_get_bat_low_flag(), hal_reset_flags(), and ISR().
uint8_t volatile hal_pll_lock_flag [static] |
PLL_LOCK flag.
Definition at line 102 of file hal_avr.c.
Referenced by hal_clear_pll_lock_flag(), hal_get_pll_lock_flag(), hal_reset_flags(), and ISR().
uint8_t volatile hal_pll_unlock_flag [static] |
PLL_UNLOCK flag.
Definition at line 101 of file hal_avr.c.
Referenced by hal_clear_pll_unlock_flag(), hal_get_pll_unlock_flag(), hal_reset_flags(), and ISR().
uint8_t volatile hal_rx_start_flag [static] |
RX_START falg;.
Definition at line 99 of file hal_avr.c.
Referenced by hal_clear_rx_start_flag(), hal_get_rx_start_flag(), hal_reset_flags(), and ISR().
uint16_t hal_system_time [static] |
This is a file internal variable that contains the 16 MSB of the system time.
The system time (32-bit) is the current time in microseconds. For the AVR microcontroller implementation this is solved by using a 16-bit timer (Timer1) with a clock frequency of 1MHz. The hal_system_time is incremented when the 16-bit timer overflows, representing the 16 MSB. The timer value it self (TCNT1) is then the 16 LSB.
Definition at line 93 of file hal_avr.c.
Referenced by hal_get_system_time(), hal_init(), and ISR().
uint8_t volatile hal_trx_end_flag [static] |
TRX_END flag.
Definition at line 98 of file hal_avr.c.
Referenced by hal_clear_trx_end_flag(), hal_get_trx_end_flag(), hal_reset_flags(), and ISR().
uint8_t volatile hal_trx_ur_flag [static] |
TRX_UR flag.
Definition at line 97 of file hal_avr.c.
Referenced by hal_clear_trx_ur_flag(), hal_get_trx_ur_flag(), hal_reset_flags(), and ISR().
uint8_t volatile hal_unknown_isr_flag [static] |
Error, unknown interrupt event signaled from the radio transceiver.
Definition at line 100 of file hal_avr.c.
Referenced by hal_clear_unknown_isr_flag(), hal_get_unknown_isr_flag(), hal_reset_flags(), and ISR().
hal_trx_isr_event_handler_t rx_start_callback [static] |
This function is called when a rx_start interrupt is signaled.
If this function pointer is set to something else than NULL, it will be called when a RX_START event is signaled. The function takes two parameters: timestamp in IEEE 802.15.4 symbols (16 us resolution) and frame length. The event handler will be called in the interrupt domain, so the function must be kept short and not be blocking! Otherwise the system performance will be greatly degraded.
Definition at line 117 of file hal_avr.c.
Referenced by hal_clear_rx_start_event_handler(), hal_reset_flags(), hal_set_rx_start_event_handler(), and ISR().
hal_trx_isr_event_handler_t trx_end_callback [static] |
This function is called when a trx_end interrupt is signaled.
If this function pointer is set to something else than NULL, it will be called when a TRX_END event is signaled. The function takes two parameters: timestamp in IEEE 802.15.4 symbols (16 us resolution) and frame length. The event handler will be called in the interrupt domain, so the function must be kept short and not be blocking! Otherwise the interrupt performance will be greatly degraded.
Definition at line 130 of file hal_avr.c.
Referenced by hal_clear_trx_end_event_handler(), hal_reset_flags(), hal_set_trx_end_event_handler(), and ISR().
Generated on Wed Jul 11 18:16:31 2007 for AVR2001 AT86RF230 Software Programmer's Manual by ![]() |