# $Id$
# ATmega128RFA1 Template for generating the headerfile.
# License see in the HEADER section of this file
#
REGISTER
0x00 - - - - - - - - - -
0x01 TRX_STATUS CCA_DONE CCA_STATUS - TRX_STATUS[4] TRX_STATUS[3] TRX_STATUS[2] TRX_STATUS[1] TRX_STATUS[0] 44,68,97
0x02 TRX_STATE TRAC_STATUS[1] TRAC_STATUS[0] TRAC_STATUS[0] TRX_CMD[4] TRX_CMD[3] TRX_CMD[2] TRX_CMD[1] TRX_CMD[0] 33,44,68
0x03 TRX_CTRL_0 PAD_IO[1] PAD_IO[0] PAD_IO[1] PAD_IO_CLKM[0] CLKM_SHA_SEL CLKM_CTRL[2] CLKM_CTRL[1] CLKM_CTRL[0] 8,118,
0x04 TRX_CTRL_1 PA_EXT_EN IRQ_2_EXT_EN TX_AUTO_CRC_ON RX_BL_CTRL SPI_CMD_MODE[1] SPI_CMD_MODE[0] IRQ_MASK_MODE IRQ_POLARITY 24,30,148
0x05 PHY_TX_PWR PA_BUF_LT[1] PA_BUF_LT[0] PA_LT[1] PA_LT[0] TX_PWR[3] TX_PWR[2] TX_PWR[1] TX_PWR[0] 105
0x06 PHY_RSSI RX_CRC_VALID RND_VALUE[1] RND_VALUE[0] RSSI[4] RSSI[3] RSSI[2] RSSI[1] RSSI[0] 90,136
0x07 PHY_ED_LEVEL ED_LEVEL[7] ED_LEVEL[6] ED_LEVEL[5] ED_LEVEL[4] ED_LEVEL[3] ED_LEVEL[2] ED_LEVEL[1] ED_LEVEL[0] 93
0x08 PHY_CC_CCA CCA_REQUEST CCA_MODE[1] CCA_MODE[0] CHANNEL[4] CHANNEL[3] CHANNEL[2] CHANNEL[1] CHANNEL[0] 97
0x09 CCA_THRES - - - - CCA_ED_THRES[3] CCA_ED_THRES[2] CCA_ED_THRES[1] CCA_ED_THRES[0] 97
0x0A RX_CTRL - - - - PDT_THRES[3] PDT_THRES[2] PDT_THRES[1] PDT_THRES[0] 140
0x0B SFD_VALUE SFD_VALUE[7] SFD_VALUE[6] SFD_VALUE[5] SFD_VALUE[4] SFD_VALUE[3] SFD_VALUE[2] SFD_VALUE[1] SFD_VALUE[0] 155
0x0C TRX_CTRL_2 RX_SAFE_MODE - - - - - OQPSK_DATA_RATE[1] OQPSK_DATA_RATE[0] 154
0x0D ANT_DIV ANT_SEL - - - ANT_DIV_EN ANT_EXT_SW_EN ANT_CTRL[1] ANT_CTRL[0] 143
0x0E IRQ_MASK MASK_BAT_LOW MASK_TRX_UR MASK_AMI MASK_CCA_ED_READY MASK_TRX_END MASK_TRX_START MASK_PLL_UNLOCK MASK_PLL_LOCK 30
0x0F IRQ_STATUS BAT_LOW TRX_UR AMI CCA_ED_READY RX_END RX_START PLL_UNLOCK PLL_LOCK 30
0x10 VREG_CTRL AVREG_EXT AVDD_OK - - DVREG_EXT DVDD_OK - - 111
0x11 BATMON - - BATMON_OK BATMON_HR BATMON_VTH[3] BATMON_VTH[2] BATMON_VTH[1] BATMON_VTH[0] 113
0x12 XOSC_CTRL XTAL_MODE[3] XTAL_MODE[2] XTAL_MODE[1] XTAL_MODE[0] XTAL_TRIM[3] XTAL_TRIM[2] XTAL_TRIM[1] XTAL_TRIM[0] 116
0x13 - - - - - - - - -
0x14 - - - - - - - - -
0x15 RX_SYN RX_PDT_DIS - - - RX_PDT_LEVEL[3] RX_PDT_LEVEL[2] RX_PDT_LEVEL[1] RX_PDT_LEVEL[0] 103
0x16 - - - - - - - - -
0x17 XAH_CTRL_1 - - AACK_FLTR_RES_FT AACK_UPLD_RES_FT - AACK_ACK_TIME AACK_PROM_MODE - 68,140
0x18 FTN_CTRL FTN_START - - - - - - - 125
0x19 - - - - - - - - -
0x1A PLL_CF PLL_CF_START - - - - - - - 122
0x1B PLL_DCU PLL_DCU_START - - - - - - - 122
0x1C PART_NUM PART_NUM[7] PART_NUM[6] PART_NUM[5] PART_NUM[4] PART_NUM[3] PART_NUM[2] PART_NUM[1] PART_NUM[0] 25
0x1D VERSION_NUM VERSION_NUM[7] VERSION_NUM[6] VERSION_NUM[5] VERSION_NUM[4] VERSION_NUM[3] VERSION_NUM[2] VERSION_NUM[1] VERSION_NUM[0] 25
0x1E MAN_ID_0 MAN_ID_0[7] MAN_ID_0[6] MAN_ID_0[5] MAN_ID_0[4] MAN_ID_0[3] MAN_ID_0[2] MAN_ID_0[1] MAN_ID_0[0] 25
0x1F MAN_ID_1 MAN_ID_1[7] MAN_ID_1[6] MAN_ID_1[5] MAN_ID_1[4] MAN_ID_1[3] MAN_ID_1[2] MAN_ID_1[1] MAN_ID_1[0] 25
0x20 SHORT_ADDR_0 SHORT_ADDR_0[7] SHORT_ADDR_0[6] SHORT_ADDR_0[5] SHORT_ADDR_0[4] SHORT_ADDR_0[3] SHORT_ADDR_0[2] SHORT_ADDR_0[1] SHORT_ADDR_0[0] 76
0x21 SHORT_ADDR_1 SHORT_ADDR_1[7] SHORT_ADDR_1[6] SHORT_ADDR_1[5] SHORT_ADDR_1[4] SHORT_ADDR_1[3] SHORT_ADDR_1[2] SHORT_ADDR_1[1] SHORT_ADDR_1[0] 76
0x22 PAN_ID_0 PAN_ID_0[7] PAN_ID_0[6] PAN_ID_0[5] PAN_ID_0[4] PAN_ID_0[3] PAN_ID_0[2] PAN_ID_0[1] PAN_ID_0[0] 76
0x23 PAN_ID_1 PAN_ID_1[7] PAN_ID_1[6] PAN_ID_1[5] PAN_ID_1[4] PAN_ID_1[3] PAN_ID_1[2] PAN_ID_1[1] PAN_ID_1[0] 76
0x24 IEEE_ADDR_0 IEEE_ADDR_0[7] IEEE_ADDR_0[6] IEEE_ADDR_0[5] IEEE_ADDR_0[4] IEEE_ADDR_0[3] IEEE_ADDR_0[2] IEEE_ADDR_0[1] IEEE_ADDR_0[0] 76
0x25 IEEE_ADDR_1 IEEE_ADDR_1[7] IEEE_ADDR_1[6] IEEE_ADDR_1[5] IEEE_ADDR_1[4] IEEE_ADDR_1[3] IEEE_ADDR_1[2] IEEE_ADDR_1[1] IEEE_ADDR_1[0] 76
0x26 IEEE_ADDR_2 IEEE_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0] 68
0x2E CSMA_SEED_1 AACK_FVN_MODE[1] AACK_FVN_MODE[0] AACK_SET_PD AACK_DIS_ACK AACK_I_AM_COORD CSMA_SEED_1[2] CSMA_SEED_1[1] CSMA_SEED_1[0] 68
0x2F CSMA_BE MAX_BE[3] MAX_BE[2] MAX_BE[1] MAX_BE[0] MIN_BE[3] MIN_BE[2] MIN_BE[1] MIN_BE[0] 68
CONST

PAD_IO_CLKM CLKM_2mA 0
PAD_IO_CLKM CLKM_4mA 1
PAD_IO_CLKM CLKM_6mA 2
PAD_IO_CLKM CLKM_8mA 3

CLKM_CTRL CLKM_no_clock 0
CLKM_CTRL CLKM_1MHz 1
CLKM_CTRL CLKM_2MHz 2
CLKM_CTRL CLKM_4MHz 3
CLKM_CTRL CLKM_8MHz 4
CLKM_CTRL CLKM_16MHz 5

PART_NUM RFA1_PART_NUM 0x83

VERSION_NUM RFA1_VERSION_NUM_NONE 0
VERSION_NUM RFA1_VERSION_NUM_A 2
VERSION_NUM RFA1_VERSION_NUM_B 2
VERSION_NUM RFA1_VERSION_NUM_C 3
VERSION_NUM RFA1_VERSION_NUM_D 4

HEADER
/* Copyright (c) 2009 Axel Wachtler
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
   * 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.
   * Neither the name of the authors nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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. */

/* $Id$ */
/**
 * @file
 * @brief ATmega128RFA1 2.4GHz IEEE 802.15.4-2006-Transceiver.
 */
#ifndef ATMEGA_128RFA1_H
#define ATMEGA_128RFA1_H (1)

/* === Includes ============================================================== */
#include <stdint.h>
/* === Externals ============================================================= */

/* === Types ================================================================= */

typedef uint8_t trx_ramaddr_t;
typedef uint8_t trx_regval_t;
typedef uint8_t trx_regaddr_t;

/* === Macros ================================================================ */

FOOTER
/** name string of the radio */
#define RADIO_NAME "ATmega128RFA1"
/** contents of the RG_PART_NUM register */
#define RADIO_PART_NUM (RFA1_PART_NUM)
/** contents of the RG_VERSION_NUM register */
#if RADIO_TYPE == RADIO_ATMEGA128RFA1_A
# define RADIO_VERSION_NUM (RFA1_VERSION_NUM_A)
#elif RADIO_TYPE == RADIO_ATMEGA128RFA1_B
# define RADIO_VERSION_NUM (RFA1_VERSION_NUM_B)
#elif RADIO_TYPE == RADIO_ATMEGA128RFA1_C
# define RADIO_VERSION_NUM (RFA1_VERSION_NUM_C)
#elif RADIO_TYPE == RADIO_ATMEGA128RFA1_D
# define RADIO_VERSION_NUM (RFA1_VERSION_NUM_D)
#endif


/** Start of the transceiver register block. */
#define TRX_REGISTER_BASEADDR (0x140)
/** Start of the AES register block. */
#define AES_REGISTER_BASEADDR (0x13c)


#define TRX_IF_RFA1    (1)     /* interfaces to RFA1 rather than SPI */

#define TRX_CMD_RADDR_MASK   (0x3f)

/** duration while reset=low is asserted */
#define TRX_RESET_TIME_US    (6)

/** duration transceiver reaches TRX_OFF for the first time */
#define TRX_INIT_TIME_US     (510)

/** maximum duration, which PLL needs to lock */
#define TRX_PLL_LOCK_TIME_US     (180)


/** duration of a CCA measurement */
#define TRX_CCA_TIME_US     (140)

/** Mask for PLL lock interrupt */
#define TRX_IRQ_PLL_LOCK   _BV(0)

/** Mask for PLL unlock interrupt */
#define TRX_IRQ_PLL_UNLOCK _BV(1)

/** Mask for RX Start interrupt */
#define TRX_IRQ_RX_START   _BV(2)

/** Mask for RX end interrupt */
#define TRX_IRQ_RX_END     _BV(3)

/** Mask for CCA_ED interrupt */
#define TRX_IRQ_CCA_ED     _BV(4)

/** Mask for AMI interrupt */
#define TRX_IRQ_AMI        _BV(5)

/** Mask for TX end interrupt */
#define TRX_IRQ_TX_END     _BV(6)

/** lowest supported channel number */
#define TRX_MIN_CHANNEL (11)

/** highest supported channel number */
#define TRX_MAX_CHANNEL (26)

/** number of channels */
#define TRX_NB_CHANNELS (16)

/**
 * @brief Mask for supported channels of this radio.
 * The AT86RF230 supports channels 11 ... 26 of IEEE 802.15.4
 */
#define TRX_SUPPORTED_CHANNELS  (0x7fff800UL)

#define TRX_SUPPORTS_BAND_2400 (1)
/**
 * @brief Mask for supported channel pages (a.k.a. modulation schemes) of this radio.
 * The AT86RF230 supports channel page ???? OQPSK_250
 */
#define TRX_SUPPORTED_PAGES     (42)

/** Rate code for OQPSK250, xx kchip/s, yy kbit/s */
#define TRX_OQPSK250  (0)

/** Rate code for OQPSK500, xx kchip/s, yy kbit/s */
#define TRX_OQPSK500  (1)

/** Rate code for OQPSK1000, xx kchip/s, yy kbit/s */
#define TRX_OQPSK1000 (2)
/** Rate code for OQPSK2000, xx kchip/s, yy kbit/s */
#define TRX_OQPSK2000 (3)
/** undefined data rate */
#define TRX_NONE      (255)

#ifdef __cplusplus
extern "C" {
#endif

extern volatile uint8_t SHADOW_IRQ_MASK;
static inline void disable_all_trx_irqs(void)
{
    SHADOW_IRQ_MASK = IRQ_MASK;
    IRQ_MASK = 0;
}

static inline void enable_all_trx_irqs(void)
{
    IRQ_MASK= SHADOW_IRQ_MASK;
}

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* ifndef ATMEGA_128RFA1_H */
