From b24866225a6301d3a663f874725e83c012dc25d3 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:36:00 +0100 Subject: digital/beacon: add bitcloud stack into common directory digital/zigbit --- .../HAL/avr/atmega1281/rcb230/include/halMacIsr.h | 77 ++++++++ .../HAL/avr/atmega1281/rcb230/include/halRfCtrl.h | 127 ++++++++++++ .../HAL/avr/atmega1281/rcb230/include/halRfPio.h | 43 +++++ .../HAL/avr/atmega1281/rcb230/include/halRfSpi.h | 80 ++++++++ .../HAL/avr/atmega1281/rcb230/src/halMacIsr.c | 152 +++++++++++++++ .../HAL/avr/atmega1281/rcb230/src/halRfCtrl.c | 214 +++++++++++++++++++++ .../HAL/avr/atmega1281/rcb230/src/halRfSpi.c | 90 +++++++++ .../HAL/avr/atmega1281/rcb230/src/halUid.c | 87 +++++++++ 8 files changed, 870 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halMacIsr.h create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfCtrl.h create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfPio.h create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfSpi.h create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halMacIsr.c create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfCtrl.c create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfSpi.c create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halUid.c (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230') diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halMacIsr.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halMacIsr.h new file mode 100644 index 00000000..127af1ee --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halMacIsr.h @@ -0,0 +1,77 @@ +/**************************************************************************//** + \file halMacIsr.h + + \brief Declaration mac timer interface. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 14/01/08 A. Mandychev - Created. + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +#ifndef _HALMACISR_H +#define _HALMACISR_H + +/****************************************************************************** + Includes section. +******************************************************************************/ +#include + +/****************************************************************************** + Types section. +******************************************************************************/ +typedef enum +{ + HAL_RTIMER_REPEAT_MODE = 0, + HAL_RTIMER_ONE_SHOT_MODE = 1, + HAL_RTIMER_STOPPED_MODE = 2, +} HAL_RTimerMode_t; + +typedef struct // Timer description. +{ + volatile HAL_RTimerMode_t mode; // Mode. + volatile uint16_t period; // Period of the timer. + volatile uint16_t nextEvent; // Counter of periods. +} RTimerDescr_t; + +/****************************************************************************** + External variables. +******************************************************************************/ +// Do not use it in other files. +extern RTimerDescr_t __rtimer; + +/****************************************************************************** + Prototypes section. +******************************************************************************/ +/****************************************************************************** + Initializes Rtimer and RF ext. interrupts. +******************************************************************************/ +void HAL_InitMacIsr(void); + +/****************************************************************************** + Starts RTimer. Function should be invoked in critical section. + Parameters: + source - source of invocation. + mode - RTimer mode. + period - RTimer period. +******************************************************************************/ +bool HAL_StartRtimer(HAL_RTimerMode_t mode, uint16_t period); + +/****************************************************************************** + Stops RTimer. Function should be invoked in critical section. +******************************************************************************/ +void HAL_StopRtimer(void); + +#endif /* _HALMACISR_H */ + +// eof halMacIsr.h diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfCtrl.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfCtrl.h new file mode 100644 index 00000000..7b6534d2 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfCtrl.h @@ -0,0 +1,127 @@ +/**************************************************************************//** + \file halRfCtrl.h + + \brief Types and constants declaration for IEEE802.15.4 PHY implementation. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 28/05/07 ALuzhetsky - Created. + 06/08/07 A. Mandychev, E. Ivanov - Modified. + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +#ifndef _HALRFCTRL_H +#define _HALRFCTRL_H + +/****************************************************************************** + Includes section. +******************************************************************************/ +#include + +/****************************************************************************** + Types section +******************************************************************************/ +typedef enum +{ + HAL_FREQ_NOCLK, + HAL_FREQ_1MHZ, + HAL_FREQ_2MHZ, + HAL_FREQ_4MHZ, + HAL_FREQ_8MHZ, + HAL_FREQ_16MHZ +} HalSysFreq_t; + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/****************************************************************************** + Delay in us +******************************************************************************/ +void HAL_Delay(uint8_t us); + +/****************************************************************************** + Clears the irq. +******************************************************************************/ +void HAL_ClearRfIrqFlag(void); + +/****************************************************************************** + Enables the irq. +******************************************************************************/ +void HAL_EnableRfIrq(void); + +/****************************************************************************** + Disables the irq. +******************************************************************************/ +uint8_t HAL_DisableRfIrq(void); + +/****************************************************************************** + Sets SLP_TR pin to 1. +******************************************************************************/ +void HAL_SetRfSlpTr(void); + +/****************************************************************************** + Clears SLP_TR pin to 0. +******************************************************************************/ +void HAL_ClearRfSlpTr(void); + +/****************************************************************************** + Makes SLP_TR pin as input. +******************************************************************************/ +void HAL_MakeInRfSlpTr(void); + +/****************************************************************************** + Makes SLP_TR pin as input. +******************************************************************************/ +void HAL_MakeOutRfSlpTr(void); + +/****************************************************************************** + Sets RST_TR pin to 1. +******************************************************************************/ +void HAL_SetRfRst(void); + +/****************************************************************************** + Clears RST_TR pin to 1. +******************************************************************************/ +void HAL_ClearRfRst(void); + +/****************************************************************************** + Init pins that controls RF chip. +******************************************************************************/ +void HAL_InitRfPins(void); + +/****************************************************************************** + Inits Atmega IRQ pin. +******************************************************************************/ +void HAL_InitRfIrq(void); + +/****************************************************************************** + Returns current frequency code. +******************************************************************************/ +HalSysFreq_t HAL_GetRfFreq(void); + +/**************************************************************************//** + \brief Wait for when radio will be waked up. + + \param none. + \return none. +******************************************************************************/ +void halWaitRadio(void); + +/**************************************************************************//** + \brief Enables RX TX indicator for radio if that is supported. +******************************************************************************/ +void HAL_EnableRxTxSwitcher(void); + +#endif /* _HALRFCTRL_H */ + +// eof halRfCtrl.h diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfPio.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfPio.h new file mode 100644 index 00000000..87ac6c88 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfPio.h @@ -0,0 +1,43 @@ +/**************************************************************************//** + \file halRfPio.h + + \brief AT86RF230 control pins declarations. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 29/05/07 A. Luzhetsky - Created + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +#ifndef _HALRFPIO_H +#define _HALRFPIO_H + +#include + +// Macros for the RF_SLP_TR pin manipulation. +HAL_ASSIGN_PIN(RF_SLP_TR, B, 4); +// Macros for the RF_RST pin manipulation. +HAL_ASSIGN_PIN(RF_RST, B, 5); +// Macros for the RF_IRQ pin manipulation. +HAL_ASSIGN_PIN(RF_IRQ, D, 4); +// Macros for the SPI_CS pin manipulation. +HAL_ASSIGN_PIN(SPI_CS, B, 0); +// Macros for the SPI_SCK pin manipulation. +HAL_ASSIGN_PIN(SPI_SCK, B, 1); +// Macros for the SPI_MOSI pin manipulation. +HAL_ASSIGN_PIN(SPI_MOSI, B, 2); +// Macros for the SPI_MISO pin manipulation. +HAL_ASSIGN_PIN(SPI_MISO, B, 3); +// Macros for the RF_TST pin manipulation. +HAL_ASSIGN_PIN(RF_TST, B, 6); +#endif /* _HALRFPIO_H */ diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfSpi.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfSpi.h new file mode 100644 index 00000000..663ae50b --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/include/halRfSpi.h @@ -0,0 +1,80 @@ +/***************************************************************************//** + \file halRfSpi.h + + \brief SPI interface routines header. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 29/05/07 A. Luzhetsky - Created + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +#ifndef _HALRFSPI_H +#define _HALRFSPI_H + +/****************************************************************************** + Includes section. +******************************************************************************/ +#include +#include +#include +#include + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/****************************************************************************** + Performs initialization of SPI interface. +******************************************************************************/ +void HAL_InitRfSpi(void); + +/****************************************************************************** + Writes/reads byte to/from SPI. + parameters: value - byte to write. + Returns: the byte which was read. +******************************************************************************/ +uint8_t HAL_WriteByteRfSpi(uint8_t value); + +/****************************************************************************** + Deselects a slave device. +******************************************************************************/ +void HAL_DeselectRfSpi(void); + +/****************************************************************************** + Selects a slave device. +******************************************************************************/ +void HAL_SelectRfSpi(void); + +/****************************************************************************** + Inline function (to use in critical sections) + Writes/reads byte to/from SPI. + parameters: value - byte to write. + Returns: the byte which was read. +******************************************************************************/ +INLINE uint8_t HAL_WriteByteInlineRfSpi(uint8_t value) +{ + ATOMIC_SECTION_ENTER + BEGIN_MEASURE + SPDR = value; // Write data. + asm("nop"); // This "nop" tunes up the "while" to reduce time for SPIF flag + // detecting. + while (!(SPSR&(1 << SPIF))); + END_MEASURE(HALATOM_WRITEBYTE_RFSPI_TIME_LIMIT) + ATOMIC_SECTION_LEAVE + return SPDR; +} + + +#endif /* _HALRFSPI_H */ + +//eof halRfSpi.h diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halMacIsr.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halMacIsr.c new file mode 100644 index 00000000..e622372d --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halMacIsr.c @@ -0,0 +1,152 @@ +/**************************************************************************//** + \file halMacIsr.c + + \brief mac interrupts implementation. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 14/01/08 A. Mandychev - Created. + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +/****************************************************************************** + Includes section. +******************************************************************************/ +#include +#include +#include +#include + +/****************************************************************************** + Define(s) section +******************************************************************************/ +#if defined(HAL_3d6864MHz) + #define HAL_RTIMER_INTERVAL_CALCULATE(period) (period >> 1) +#elif defined(HAL_4MHz) + #define HAL_RTIMER_INTERVAL_CALCULATE(period) (period >> 1) +#elif defined(HAL_7d3728MHz) + #define HAL_RTIMER_INTERVAL_CALCULATE(period) (period) +#elif defined(HAL_8MHz) + #define HAL_RTIMER_INTERVAL_CALCULATE(period) (period) +#endif + +/****************************************************************************** + Global variables section +******************************************************************************/ +RTimerDescr_t __rtimer; + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/****************************************************************************** + Initializes Rtimer. +******************************************************************************/ +void HAL_InitMacIsr(void); + +/****************************************************************************** + Redirect interrupt event depending on the TrxState. + Parameters: none. + Returns: none. +******************************************************************************/ +void phyDispatcheRTimerEvent(void); + +/****************************************************************************** + Redirect interrupt event depending on the TrxState. + Parameters: none. + Returns: none. +******************************************************************************/ +void phyDispatcheRfInterrupt(void); + +/****************************************************************************** + Implementations section +******************************************************************************/ +/****************************************************************************** + Initializes Rtimer. +******************************************************************************/ +void HAL_InitMacIsr(void) +{ + __rtimer.mode = HAL_RTIMER_STOPPED_MODE; + HAL_InitRfIrq(); +} + +/****************************************************************************** + Starts RTimer. Function should be invoked in critical section. + Parameters: + source - source of invocation. + mode - RTimer mode. + period - RTimer period. +******************************************************************************/ +bool HAL_StartRtimer(HAL_RTimerMode_t mode, uint16_t period) +{ + if (HAL_RTIMER_STOPPED_MODE != __rtimer.mode) + return false; + + __rtimer.period = HAL_RTIMER_INTERVAL_CALCULATE(period); + __rtimer.mode = mode; + __rtimer.nextEvent = TCNT4 + __rtimer.period; + if (__rtimer.nextEvent > TOP_TIMER_COUNTER_VALUE) + __rtimer.nextEvent -= TOP_TIMER_COUNTER_VALUE; + OCR4B = __rtimer.nextEvent; + // clear possible interrupt by setting logical one. + TIFR4 = (1 << OCF4B); + // enable interrupt + TIMSK4 |= (1 << OCIE4B); + return true; +} + +/****************************************************************************** + Stops RTimer. Function should be invoked in critical section. +******************************************************************************/ +void HAL_StopRtimer(void) +{ + // clear possible interrupt + TIFR4 &= ~(1 << OCF4B); + // disable interrupt + TIMSK4 &= ~(1 << OCIE4B); + __rtimer.mode = HAL_RTIMER_STOPPED_MODE; +} + +/****************************************************************************** + Output compare unit (channel B) interrupt handler. +******************************************************************************/ +ISR(TIMER4_COMPB_vect) +{ + BEGIN_MEASURE + if (HAL_RTIMER_ONE_SHOT_MODE == __rtimer.mode) + { + TIMSK4 &= ~(1 << OCIE4B); + __rtimer.mode = HAL_RTIMER_STOPPED_MODE; + } + else + { + __rtimer.nextEvent += __rtimer.period; + if (__rtimer.nextEvent > TOP_TIMER_COUNTER_VALUE) + __rtimer.nextEvent -= TOP_TIMER_COUNTER_VALUE; + OCR4B = __rtimer.nextEvent; + } + phyDispatcheRTimerEvent(); + END_MEASURE(HALISR_TIMER3_COMPA_TIME_LIMIT) +} + +/**************************************************************** + Interrupt service routine. + Do not move this ISR! It could be omitted in your project. +****************************************************************/ +ISR(TIMER1_CAPT_vect) +{ + BEGIN_MEASURE + phyDispatcheRfInterrupt(); + END_MEASURE(HALISR_PHYDISPATCH_RFINT_TIME_LIMIT) +} + +// eof halMacIsr.c diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfCtrl.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfCtrl.c new file mode 100644 index 00000000..ffbd38b5 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfCtrl.c @@ -0,0 +1,214 @@ +/**************************************************************************//** + \file halRfCtrl.c + + \brief mac pin interface implementation. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 28/05/07 ALuzhetsky - Created. + 06/08/07 A. Mandychev, E. Ivanov - Modified. + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +/****************************************************************************** + Includes section. +******************************************************************************/ +#include +#include +#include +#include +#include +#include + +/****************************************************************************** + Define(s) section +******************************************************************************/ +#define RF_REGISTER_READ_ACCESS_MODE 0x80 +#define RF_REGISTER_TRX_STATUS_ADDRESS 0x01 +#define RF_TRX_OFF_STATE 0x08 + +/****************************************************************************** + Prototypes section +******************************************************************************/ +#ifdef _HAL_RF_RX_TX_INDICATOR_ +/**************************************************************************//** +\brief Turn on pin 1 (DIG3) and pin 2 (DIG4) to indicate the transmit state of +the radio transceiver. +******************************************************************************/ +void phyRxTxSwitcherOn(void); + +#endif //_HAL_RF_RX_TX_INDICATOR_ + +/****************************************************************************** + Implementations section +******************************************************************************/ +/****************************************************************************** + Delay in us +******************************************************************************/ +void HAL_Delay(uint8_t us) +{ + __delay_us(us); +} + +/****************************************************************************** + Clears the irq. +******************************************************************************/ +void HAL_ClearRfIrqFlag(void) +{ + TIFR1 = 1 << ICF1; +} + +/****************************************************************************** + Enables the irq. +******************************************************************************/ +void HAL_EnableRfIrq(void) +{ + TIMSK1 |= 1 << ICIE1; +} + +/****************************************************************************** + Disables the irq. +******************************************************************************/ +uint8_t HAL_DisableRfIrq(void) +{ + uint8_t tmp; + + tmp = TIMSK1 & (1 << ICIE1); + TIMSK1 &= ~(1 << ICIE1); + return tmp; +} + +/****************************************************************************** + Sets SLP_TR pin to 1. +******************************************************************************/ +void HAL_SetRfSlpTr(void) +{ + GPIO_RF_SLP_TR_set(); +} + +/****************************************************************************** + Clears SLP_TR pin to 0. +******************************************************************************/ +void HAL_ClearRfSlpTr(void) +{ + GPIO_RF_SLP_TR_clr(); +} + +/****************************************************************************** + Makes SLP_TR pin as input. +******************************************************************************/ +void HAL_MakeInRfSlpTr(void) +{ + GPIO_RF_SLP_TR_make_in(); +} + +/****************************************************************************** + Makes SLP_TR pin as input. +******************************************************************************/ +void HAL_MakeOutRfSlpTr(void) +{ + GPIO_RF_SLP_TR_make_out(); +} + +/****************************************************************************** + Sets RST_TR pin to 1. +******************************************************************************/ +void HAL_SetRfRst(void) +{ + GPIO_RF_RST_set(); +} + +/****************************************************************************** + Clears RST_TR pin to 1. +******************************************************************************/ +void HAL_ClearRfRst(void) +{ + GPIO_RF_RST_clr(); +} + +/****************************************************************************** + Init pins that controls RF chip. +******************************************************************************/ +void HAL_InitRfPins(void) +{ + GPIO_RF_TST_make_out(); + GPIO_RF_TST_clr(); + + GPIO_RF_SLP_TR_clr(); + GPIO_RF_SLP_TR_make_out(); + + GPIO_RF_RST_set(); + GPIO_RF_RST_make_out(); + + GPIO_RF_IRQ_make_in(); +} + +/****************************************************************************** + Inits Atmega IRQ pin. +******************************************************************************/ +void HAL_InitRfIrq(void) +{ + OCR1A = 0; + TCCR1B = (1 << WGM12) | (1 << CS10); // CTC mode, clock source is not prescaled + TCCR1B |= (1 << ICNC1) | (1 << ICES1); // input noise canceler and rising edge are enabled +} + +/****************************************************************************** + Returns current frequency code. +******************************************************************************/ +HalSysFreq_t HAL_GetRfFreq(void) +{ +/* if (INTERNAL_RC == halGetClockSource()) + { + return HAL_FREQ_NOCLK; + } + else*/ + { + #if (F_CPU == 4000000ul) + return HAL_FREQ_4MHZ; + #endif + #if (F_CPU == 8000000ul) + return HAL_FREQ_8MHZ; + #endif + } +} + +/**************************************************************************//** + \brief Wait for when radio will be waked up. + + \param none. + \return none. +******************************************************************************/ +void halWaitRadio(void) +{ + uint8_t tempValue = 0; + + do { + HAL_SelectRfSpi(); + HAL_WriteByteRfSpi(RF_REGISTER_READ_ACCESS_MODE | RF_REGISTER_TRX_STATUS_ADDRESS); + tempValue = HAL_WriteByteRfSpi(tempValue); + HAL_DeselectRfSpi(); + } while(RF_TRX_OFF_STATE != tempValue); +} + +/**************************************************************************//** + \brief Enables RX TX indicator for radio if that is supported. +******************************************************************************/ +void HAL_EnableRxTxSwitcher(void) +{ + #ifdef _HAL_RF_RX_TX_INDICATOR_ + phyRxTxSwitcherOn(); + #endif //_HAL_RF_RX_TX_INDICATOR_ +} + +//eof halRfCtrl.c diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfSpi.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfSpi.c new file mode 100644 index 00000000..053ba68a --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halRfSpi.c @@ -0,0 +1,90 @@ +/**************************************************************************//** + \file halrfSpi.c + + \brief SPI interface routines. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 29/05/07 A. Luzhetsky - Created + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +#include +#include + +/****************************************************************************** + Implementations section +******************************************************************************/ +/****************************************************************************** + Performs initialization of SPI interface. +******************************************************************************/ +void HAL_InitRfSpi(void) +{ + GPIO_SPI_CS_set(); + GPIO_SPI_MISO_make_in(); + GPIO_SPI_MOSI_make_out(); + GPIO_SPI_SCK_make_out(); + GPIO_SPI_CS_make_out(); + SPCR = ((1 << SPE) | (1 << MSTR)); // SPI enable, master mode. + SPSR = (1 << SPI2X); // rate = fosc/2 +} + +/****************************************************************************** + Writes/reads byte to/from SPI. CPU clock critical function (4 MHz only). + parameters: value - byte to write. + Returns: the byte which was read. +******************************************************************************/ +uint8_t HAL_WriteByteRfSpi(uint8_t value) +{ + uint8_t tmp8; + + SPDR = value; // Write data. + asm("nop"); // 1 + asm("nop"); // 2 + asm("nop"); // 3 + asm("nop"); // 4 + asm("nop"); // 5 + asm("nop"); // 5 + asm("nop"); // 7 + asm("nop"); // 8 + asm("nop"); // 9 + asm("nop"); // 10 + asm("nop"); // 11 + asm("nop"); // 12 + asm("nop"); // 13 + asm("nop"); // 14 + asm("nop"); // 15 + asm("nop"); // 16 + asm("nop"); // 17 + tmp8 = SPSR; + (void)tmp8; + return SPDR; +} + +/****************************************************************************** + Deselects a slave device. +******************************************************************************/ +void HAL_DeselectRfSpi(void) +{ + GPIO_SPI_CS_set(); +} + +/****************************************************************************** + Selects a slave device. +******************************************************************************/ +void HAL_SelectRfSpi(void) +{ + GPIO_SPI_CS_clr(); +} + +// eof halrfSpi.c diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halUid.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halUid.c new file mode 100644 index 00000000..21976ce9 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halUid.c @@ -0,0 +1,87 @@ +/**************************************************************************//** + \file halUid.c + + \brief Implementation of UID interface. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 7/12/07 A. Khromykh - Created + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include +#include + +/****************************************************************************** + Types section +******************************************************************************/ +/** \brief uid type. */ +typedef union +{ + uint64_t uid; + uint8_t array[sizeof(uint64_t)]; +} HalUid_t; + +/****************************************************************************** + Global variables section +******************************************************************************/ +static HalUid_t halUid = {.uid = 0ull}; + +/****************************************************************************** + Implementations section +******************************************************************************/ +/****************************************************************************** + Reads uid from external spi eeprom at25010a. +******************************************************************************/ +void halReadUid(void) +{ + uint8_t command = 0x03; + uint8_t address = 0; + uint8_t itr; + + GPIO_RF_RST_make_out(); + GPIO_RF_RST_clr(); + GPIO_SPI_CS_clr(); + + HAL_WriteByteRfSpi(command); + HAL_WriteByteRfSpi(address); + for (itr=0; itr