/* This file has been prepared for Doxygen automatic documentation generation.*/ /*! \file ********************************************************************* * * \brief This file implements the HAL API for the AT86RF230 radio * transceiver. * * \defgroup hal_avr_api Hardware Abstraction Layer API Functions * This set of functions (Some defined as macros) is the API for the * Hardware Abstraction Layer. These functions gives complete access to * all of the low level functionality of the radio transceiver * (IO, SPI and ISR). * * \defgroup hal_avr_board Hardware Abstraction Layer Board Specific Configuration * This set of macros are provided so that the hal is easy to port to any * AVR device and board configuration. The porting is simply done by changing * the macros accordingly to the schematic and selected device. The clock * settings ensure that any of the supported clock frequencies are supported * seamlessly during compile time. * Default pin configuration (RCBs): * -# Chip Select: PB0 * -# SPI Clock Signal: PB1 * -# MOSI: PB2 * -# MISO: PB3 * -# SLP_TR: PB4 * -# RST: PB5 * -# CLKM: Not Used * -# IRQ: Timer1 Input Capture pin. Could also use pin change or external * interrupt. * * \par Application note: * AVR2001: AT86RF230 Software Programmer's Guide * * \par Documentation * For comprehensive code documentation, supported compilers, compiler * settings and supported devices see readme.html * * \author * Atmel Corporation: http://www.atmel.com \n * Support email: avr@atmel.com * * $Name$ * $Revision: 613 $ * $RCSfile$ * $Date: 2006-04-07 14:40:07 +0200 (fr, 07 apr 2006) $ \n * * 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. ******************************************************************************/ #ifndef HAL_AVR_H #define HAL_AVR_H /*============================ INCLUDE =======================================*/ #include #include /*============================ MACROS ========================================*/ /*! \brief Pin number that corresponds to the SLP_TR pin. * * \ingroup hal_avr_board */ #define SLP_TR ( 0x02 ) /*! \brief Data Direction Register that corresponds to the port where SLP_TR is * connected. * \ingroup hal_avr_board */ #define DDR_SLP_TR ( DDRB ) /*! \brief Port (Write Access) where SLP_TR is connected. * \ingroup hal_avr_board */ #define PORT_SLP_TR ( PORTB ) /*! \brief Pin (Read Access) where SLP_TR is connected. * \ingroup hal_avr_board */ #define PIN_SLP_TR ( PINB ) /*! \brief This macro pulls the SLP_TR pin high. * * \ingroup hal_avr_api */ #define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) ) /*! \brief This macro pulls the SLP_TR pin low. * * \ingroup hal_avr_api */ #define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) ) /*! \brief Read current state of the SLP_TR pin (High/Low). * * \retval 0 if the pin is low, 1 is the pin is high. * * \ingroup hal_avr_api */ #define hal_get_slptr( ) ( ( PIN_SLP_TR & ( 1 << SLP_TR ) ) >> SLP_TR ) /*! \brief Pin number that corresponds to the RST pin. * \ingroup hal_avr_board */ #define RST ( 0x01 ) /*! \brief Data Direction Register that corresponds to the port where RST is * connected. * \ingroup hal_avr_board */ #define DDR_RST ( DDRB ) /*! \brief Port (Write Access) where RST is connected. * \ingroup hal_avr_board */ #define PORT_RST ( PORTB ) /*! \brief Pin (Read Access) where RST is connected. * \ingroup hal_avr_board */ #define PIN_RST ( PINB ) /*! \brief This macro pulls the RST pin high. * * \ingroup hal_avr_api */ #define hal_set_rst_high( ) ( PORT_RST |= ( 1 << RST ) ) /*! \brief This macro pulls the RST pin low. * * \ingroup hal_avr_api */ #define hal_set_rst_low( ) ( PORT_RST &= ~( 1 << RST ) ) /*! \brief Read current state of the RST pin (High/Low). * * \retval 0 if the pin is low, 1 if the pin is high. * * \ingroup hal_avr_api */ #define hal_get_rst( ) ( ( PIN_RST & ( 1 << RST ) ) >> RST ) /*! \brief The slave select pin is PB0. * \ingroup hal_avr_board */ #define HAL_SS_PIN ( 0x04 ) /*! \brief The SPI module is located on PORTB. * \ingroup hal_avr_board */ #define HAL_PORT_SPI ( PORTB ) /*! \brief Data Direction Register for PORTB. * \ingroup hal_avr_board */ #define HAL_DDR_SPI ( DDRB ) /*! \brief Data Direction bit for SS. * \ingroup hal_avr_board */ #define HAL_DD_SS ( 0x04 ) /*! \brief Data Direction bit for SCK. * \ingroup hal_avr_board */ #define HAL_DD_SCK ( 0x07 ) /*! \brief Data Direction bit for MOSI. * \ingroup hal_avr_board */ #define HAL_DD_MOSI ( 0x05 ) /*! \brief Data Direction bit for MISO. * \ingroup hal_avr_board */ #define HAL_DD_MISO ( 0x06 ) #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. /*! \brief Macros defined for HAL_TIMER1. * * These macros are used to define the correct setupt of the AVR's Timer1, and * to ensure that the hal_get_system_time function returns the system time in * symbols (16 us ticks). * * \ingroup hal_avr_board */ #if ( F_CPU == 16000000UL ) #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS12 ) ) #define HAL_US_PER_SYMBOL ( 1 ) #define HAL_SYMBOL_MASK ( 0xFFFFffff ) #elif ( F_CPU == 8000000UL ) #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) | ( 1 << CS10 ) ) #define HAL_US_PER_SYMBOL ( 2 ) #define HAL_SYMBOL_MASK ( 0x7FFFffff ) #elif ( F_CPU == 4000000UL ) #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) | ( 1 << CS10 ) ) #define HAL_US_PER_SYMBOL ( 1 ) #define HAL_SYMBOL_MASK ( 0xFFFFffff ) #elif ( F_CPU == 1000000UL ) #define HAL_TCCR1B_CONFIG ( ( 1 << ICES1 ) | ( 1 << CS11 ) ) #define HAL_US_PER_SYMBOL ( 2 ) #define HAL_SYMBOL_MASK ( 0x7FFFffff ) #else #error "Clock speed not supported." #endif #define HAL_ENABLE_INPUT_CAPTURE_INTERRUPT( ) ( TIMSK1 |= ( 1 << ICIE1 ) ) #define HAL_DISABLE_INPUT_CAPTURE_INTERRUPT( ) ( TIMSK1 &= ~( 1 << ICIE1 ) ) #define HAL_ENABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 |= ( 1 << TOIE1 ) ) #define HAL_DISABLE_OVERFLOW_INTERRUPT( ) ( TIMSK1 &= ~( 1 << TOIE1 ) ) /*! \brief Enable the interrupt from the radio transceiver. * * \ingroup hal_avr_api */ #define hal_enable_trx_interrupt( ) ( HAL_ENABLE_INPUT_CAPTURE_INTERRUPT( ) ) /*! \brief Disable the interrupt from the radio transceiver. * * \retval 0 if the pin is low, 1 if the pin is high. * * \ingroup hal_avr_api */ #define hal_disable_trx_interrupt( ) ( HAL_DISABLE_INPUT_CAPTURE_INTERRUPT( ) ) /*============================ TYPDEFS =======================================*/ /*============================ PROTOTYPES ====================================*/ #endif /*EOF*/