hal.h File Reference

This file contains low-level radio driver code. More...

#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/crc16.h>
#include "contiki-conf.h"

Go to the source code of this file.

Data Structures

struct  hal_rx_frame_t
 This struct defines the rx data container. More...

Defines

#define HAL_SS_HIGH()   (HAL_PORT_SPI |= ( 1 << HAL_SS_PIN ))
 MACRO for pulling SS high.
#define HAL_SS_LOW()   (HAL_PORT_SPI &= ~( 1 << HAL_SS_PIN ))
 MACRO for pulling SS low.
#define RADIO_VECT   TIMER1_CAPT_vect
 Macros defined for HAL_TIMER1.
#define AVR_ENTER_CRITICAL_REGION()   {uint8_t volatile saved_sreg = SREG; cli( )
 This macro will protect the following code from interrupts.
#define AVR_LEAVE_CRITICAL_REGION()   SREG = saved_sreg;}
 This macro must always be used in conjunction with AVR_ENTER_CRITICAL_REGION so that interrupts are enabled again.
#define hal_enable_trx_interrupt()   HAL_ENABLE_RADIO_INTERRUPT( )
 Enable the interrupt from the radio transceiver.
#define hal_disable_trx_interrupt()   HAL_DISABLE_RADIO_INTERRUPT( )
 Disable the interrupt from the radio transceiver.
This is the list of pin configurations needed for a given platform.

Change these values to port to other platforms.



#define RAVEN_D   4
#define RAVENUSB_C   1
#define RCB_B   2
#define ZIGBIT   3
Macros used to generate read register names from platform-specific definitions of ports.

The various CAT macros (DDR, PORT, and PIN) are used to assign port/pin/DDR names to various macro variables.

The variables are assigned based on the specific connections made in the hardware. For example TCCR(TICKTIMER,A) can be used in place of TCCR0A if TICKTIMER is defined as 0.



#define CAT(x, y)   x##y
#define CAT2(x, y, z)   x##y##z
#define DDR(x)   CAT(DDR, x)
#define PORT(x)   CAT(PORT, x)
#define PIN(x)   CAT(PIN, x)
#define UCSR(num, let)   CAT2(UCSR,num,let)
#define RXEN(x)   CAT(RXEN,x)
#define TXEN(x)   CAT(TXEN,x)
#define TXC(x)   CAT(TXC,x)
#define RXC(x)   CAT(RXC,x)
#define RXCIE(x)   CAT(RXCIE,x)
#define UCSZ(x, y)   CAT2(UCSZ,x,y)
#define UBRR(x, y)   CAT2(UBRR,x,y)
#define UDRE(x)   CAT(UDRE,x)
#define UDRIE(x)   CAT(UDRIE,x)
#define UDR(x)   CAT(UDR,x)
#define TCNT(x)   CAT(TCNT,x)
#define TIMSK(x)   CAT(TIMSK,x)
#define TCCR(x, y)   CAT2(TCCR,x,y)
#define COM(x, y)   CAT2(COM,x,y)
#define OCR(x, y)   CAT2(OCR,x,y)
#define CS(x, y)   CAT2(CS,x,y)
#define WGM(x, y)   CAT2(WGM,x,y)
#define OCIE(x, y)   CAT2(OCIE,x,y)
#define COMPVECT(x)   CAT2(TIMER,x,_COMPA_vect)
#define UDREVECT(x)   CAT2(USART,x,_UDRE_vect)
#define RXVECT(x)   CAT2(USART,x,_RX_vect)
Pin macros

These macros convert the platform-specific pin defines into names and functions that the source code can directly use.



#define SLP_TR   SLPTRPIN
 Pin number that corresponds to the SLP_TR pin.
#define DDR_SLP_TR   DDR( SLPTRPORT )
 Data Direction Register that corresponds to the port where SLP_TR is connected.
#define PORT_SLP_TR   PORT( SLPTRPORT )
 Port (Write Access) where SLP_TR is connected.
#define PIN_SLP_TR   PIN( SLPTRPORT )
 Pin (Read Access) where SLP_TR is connected.
#define hal_set_slptr_high()   ( PORT_SLP_TR |= ( 1 << SLP_TR ) )
 This macro pulls the SLP_TR pin high.
#define hal_set_slptr_low()   ( PORT_SLP_TR &= ~( 1 << SLP_TR ) )
 This macro pulls the SLP_TR pin low.
#define hal_get_slptr()   ( ( PIN_SLP_TR & ( 1 << SLP_TR ) ) >> SLP_TR )
 Read current state of the SLP_TR pin (High/Low).
#define RST   RSTPIN
 Pin number that corresponds to the RST pin.
#define DDR_RST   DDR( RSTPORT )
 Data Direction Register that corresponds to the port where RST is.
#define PORT_RST   PORT( RSTPORT )
 Port (Write Access) where RST is connected.
#define PIN_RST   PIN( RSTPORT )
 Pin (Read Access) where RST is connected.
#define hal_set_rst_high()   ( PORT_RST |= ( 1 << RST ) )
 This macro pulls the RST pin high.
#define hal_set_rst_low()   ( PORT_RST &= ~( 1 << RST ) )
 This macro pulls the RST pin low.
#define hal_get_rst()   ( ( PIN_RST & ( 1 << RST ) ) >> RST )
 Read current state of the RST pin (High/Low).
#define HAL_SS_PIN   SSPIN
 The slave select pin.
#define HAL_PORT_SPI   PORT( SPIPORT )
 The SPI module is located on PORTB.
#define HAL_DDR_SPI   DDR( SPIPORT )
 Data Direction Register for PORTB.
#define HAL_DD_SS   SSPIN
 Data Direction bit for SS.
#define HAL_DD_SCK   SCKPIN
 Data Direction bit for SCK.
#define HAL_DD_MOSI   MOSIPIN
 Data Direction bit for MOSI.
#define HAL_DD_MISO   MISOPIN
 Data Direction bit for MISO.
Macros for radio operation.



#define HAL_BAT_LOW_MASK   ( 0x80 )
 Mask for the BAT_LOW interrupt.
#define HAL_TRX_UR_MASK   ( 0x40 )
 Mask for the TRX_UR interrupt.
#define HAL_TRX_END_MASK   ( 0x08 )
 Mask for the TRX_END interrupt.
#define HAL_RX_START_MASK   ( 0x04 )
 Mask for the RX_START interrupt.
#define HAL_PLL_UNLOCK_MASK   ( 0x02 )
 Mask for the PLL_UNLOCK interrupt.
#define HAL_PLL_LOCK_MASK   ( 0x01 )
 Mask for the PLL_LOCK interrupt.
#define HAL_MIN_FRAME_LENGTH   ( 0x03 )
 A frame should be at least 3 bytes.
#define HAL_MAX_FRAME_LENGTH   ( 0x7F )
 A frame should no more than 127 bytes.

Typedefs

typedef void(* hal_rx_start_isr_event_handler_t )(uint32_t const isr_timestamp, uint8_t const frame_length)
 RX_START event handler callback type.
typedef void(* hal_trx_end_isr_event_handler_t )(uint32_t const isr_timestamp)
 RRX_END event handler callback type.

Functions

void hal_init (void)
 This function initializes the Hardware Abstraction Layer.
void hal_reset_flags (void)
 This function reset the interrupt flags and interrupt event handlers (Callbacks) to their default value.
uint8_t hal_get_bat_low_flag (void)
 This function returns the current value of the BAT_LOW 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_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_clear_trx_end_event_handler (void)
 Remove event 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.
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.
void hal_clear_rx_start_event_handler (void)
 Remove event handler reference.
uint8_t hal_get_pll_lock_flag (void)
 This function returns the current value of the PLL_LOCK flag.
void hal_clear_pll_lock_flag (void)
 This function clears the PLL_LOCK flag.
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.
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.
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_frame_write (uint8_t *write_buffer, uint8_t length)
 This function will download a frame to the radio transceiver's frame buffer.
void hal_sram_read (uint8_t address, uint8_t length, uint8_t *data)
 Read SRAM.
void hal_sram_write (uint8_t address, uint8_t length, uint8_t *data)
 Write SRAM.

Detailed Description

This file contains low-level radio driver code.

Id
hal.h,v 1.5 2010/02/26 21:15:28 dak664 Exp

Definition in file hal.h.


Generated on Mon Apr 11 14:23:49 2011 for Contiki 2.5 by  doxygen 1.6.1