summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit
diff options
context:
space:
mode:
Diffstat (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit')
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halAtmelUid.h68
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halMacIsr.h77
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfCtrl.h142
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfPio.h41
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfSpi.h79
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halAtmelUid.c248
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halMacIsr.c152
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfCtrl.c281
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfSpi.c87
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halUid.c72
10 files changed, 1247 insertions, 0 deletions
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halAtmelUid.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halAtmelUid.h
new file mode 100644
index 00000000..d3931966
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halAtmelUid.h
@@ -0,0 +1,68 @@
+/**************************************************************************//**
+ \file halAtmelUid.h
+
+ \brief The header file describes the UID interface for Atmel MeshBean.
+
+ \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:
+ 10/12/10 A. Malkin - Created
+ ******************************************************************************/
+/******************************************************************************
+ * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. *
+ * EXPERT USERS SHOULD PROCEED WITH CAUTION. *
+ ******************************************************************************/
+
+#ifndef _HALATMELUID_H
+#define _HALATMELUID_H
+
+/******************************************************************************
+ Includes section
+******************************************************************************/
+#include <types.h>
+#include <gpio.h>
+
+/******************************************************************************
+ Definitions section
+******************************************************************************/
+#define SINGLE_WIRE_SUCCESS_STATUS 0
+#define SINGLE_WIRE_ERROR_STATUS -1
+
+/******************************************************************************
+ Types section
+******************************************************************************/
+/** \brief uid type. */
+typedef union
+{
+ uint64_t uid;
+ uint8_t array[sizeof(uint64_t)];
+} HalUid_t;
+
+/******************************************************************************
+ Inline static functions prototypes section.
+******************************************************************************/
+HAL_ASSIGN_PIN(SINGLE_WIRE, G, 5); // Macros for the Single-wire pin actions.
+
+/******************************************************************************
+ Prototypes section
+******************************************************************************/
+/**************************************************************************//**
+\brief Reads Atmel MeshBean UID from ATTiny13A
+
+\param[in] uidBuffer - memory for unique ID.
+
+\return
+ SINGLE_WIRE_SUCCESS_STATUS - if UID read successfully;
+ SINGLE_WIRE_ERROR_STATUS - if error occured during UID read.
+******************************************************************************/
+int halReadAtmelMeshbeanUid(uint8_t *uidBuffer);
+
+#endif /* _HALATMELUID_H */
+
+// eof halAtmelUid.h
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halMacIsr.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halMacIsr.h
new file mode 100644
index 00000000..127af1ee
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/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 <halAppClock.h>
+
+/******************************************************************************
+ 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/zigBit/include/halRfCtrl.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfCtrl.h
new file mode 100644
index 00000000..846b101c
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfCtrl.h
@@ -0,0 +1,142 @@
+/**************************************************************************//**
+ \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.h>
+
+/******************************************************************************
+ 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);
+
+/**************************************************************************//**
+ \brief Enables Antenna diversity option for radio if that is supported.
+******************************************************************************/
+void HAL_InitAntennaDiversity(void);
+
+/**************************************************************************//**
+ \brief Enables Antenna diversity in RX mode for radio if that is supported.
+******************************************************************************/
+void HAL_EnableRxAntennaDiversity(void);
+
+/**************************************************************************//**
+ \brief Enables Antenna diversity in TX mode for radio if that is supported.
+******************************************************************************/
+void HAL_EnableTxAntennaDiversity(void);
+
+#endif /* _HALRFCTRL_H */
+
+// eof halRfCtrl.h
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfPio.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfPio.h
new file mode 100644
index 00000000..05f3f296
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfPio.h
@@ -0,0 +1,41 @@
+/**************************************************************************//**
+ \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 <gpio.h>
+
+// 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, A, 7);
+// Macros for the RF_IRQ pin manipulation.
+HAL_ASSIGN_PIN(RF_IRQ, E, 5);
+// 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);
+#endif /* _HALRFPIO_H */
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfSpi.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfSpi.h
new file mode 100644
index 00000000..fe3328a6
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/include/halRfSpi.h
@@ -0,0 +1,79 @@
+/***************************************************************************//**
+ \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 <types.h>
+#include <atomic.h>
+#include <halDbg.h>
+#include <halDiagnostic.h>
+
+/******************************************************************************
+ 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/zigBit/src/halAtmelUid.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halAtmelUid.c
new file mode 100644
index 00000000..9c80dcbe
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halAtmelUid.c
@@ -0,0 +1,248 @@
+/**************************************************************************//**
+ \file halAtmelUid.c
+
+ \brief The header file describes the UID interface for Atmel MeshBean.
+
+ \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:
+ 10/12/10 A. Malkin - Created
+ ******************************************************************************/
+/******************************************************************************
+ * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. *
+ * EXPERT USERS SHOULD PROCEED WITH CAUTION. *
+ ******************************************************************************/
+
+/******************************************************************************
+ Includes section
+******************************************************************************/
+#include <halAtmelUid.h>
+#include <halW1.h>
+
+/******************************************************************************
+ Define(s) section
+******************************************************************************/
+#define UID_LEN 0x08 // size of UID (bytes)
+
+#define SINGLE_WIRE_ZERO_BIT 0x00 // logical level zero
+#define SINGLE_WIRE_ONE_BIT 0x01 // logical level one
+
+#define BIT_DURATION 208 // bit duration - 208 us
+#define BIT_DURATION_HALF BIT_DURATION/2
+#define MAX_START_BIT_WAITING 10 // waiting time(in bit) of Start bit
+
+// Commands for Single-wire UART (Atmel MeshBean)
+#define CMD_SYNCH 0xAA // Synchronization
+#define CMD_READ_MAC64_0 0x60 // Read 64-bit MAC address
+#define NUM_OF_MAC64 0x00 // Number of MAC64 slot
+/******************************************************************************
+ Prototypes section
+******************************************************************************/
+static void halWriteSingleWireBit(uint8_t value);
+static void halWriteSingleWire(uint8_t value);
+static int halWaitSingleWireStartBit(void);
+static uint8_t halReadSingleWireBit(void);
+static int halReadSingleWire(uint8_t *data);
+
+/******************************************************************************
+ Global variables section
+******************************************************************************/
+
+/******************************************************************************
+ Implementations section
+******************************************************************************/
+/***************************************************************************//**
+\brief Writes bit to the bus
+
+\param[in]
+ value - byte to write. The bit is placed to position of LSB.
+*******************************************************************************/
+static void halWriteSingleWireBit(uint8_t value)
+{
+ if (value)
+ GPIO_SINGLE_WIRE_set();
+ else
+ GPIO_SINGLE_WIRE_clr();
+
+ __delay_us(BIT_DURATION);
+}
+
+/***************************************************************************//**
+\brief Writes byte to the bus
+
+\param[in]
+ value - byte to write.
+*******************************************************************************/
+static void halWriteSingleWire(uint8_t value)
+{
+ uint8_t i;
+
+ // write Start bit
+ halWriteSingleWireBit(SINGLE_WIRE_ZERO_BIT);
+
+ // write Data
+ for (i = 0; i < UID_LEN; i++)
+ {
+ halWriteSingleWireBit(value & 0x01);
+ value >>= 1;
+ }
+
+ // add 2 Stop bits
+ halWriteSingleWireBit(SINGLE_WIRE_ONE_BIT);
+ halWriteSingleWireBit(SINGLE_WIRE_ONE_BIT);
+}
+
+/***************************************************************************//**
+\brief Wait for Start bit from the bus.
+
+\return
+ SINGLE_WIRE_SUCCESS_STATUS - if Start bit has been found successfully; \n
+ SINGLE_WIRE_ERROR_STATUS - if Start bit has been not found.
+*******************************************************************************/
+static int halWaitSingleWireStartBit(void)
+{
+ uint16_t i;
+
+ for (i = BIT_DURATION * MAX_START_BIT_WAITING; i > 0; i--)
+ {
+ if (!GPIO_SINGLE_WIRE_read())
+ return SINGLE_WIRE_SUCCESS_STATUS;
+ __delay_us(1);
+ }
+
+ return SINGLE_WIRE_ERROR_STATUS;
+}
+
+/***************************************************************************//**
+\brief Reads bit from the bus.
+
+\return
+ Read bit is placed to position of last significant bit.
+*******************************************************************************/
+static uint8_t halReadSingleWireBit(void)
+{
+ uint8_t result;
+
+ // read pin level in half of bit period
+ if (GPIO_SINGLE_WIRE_read())
+ result = SINGLE_WIRE_ONE_BIT;
+ else
+ result = SINGLE_WIRE_ZERO_BIT;
+
+ // wait for bit period before next bit reading
+ __delay_us(BIT_DURATION);
+
+ return result;
+}
+
+/***************************************************************************//**
+\brief Reads byte from the Atmel Single-wire bus.
+
+\param[in]
+ data - byte read from the bus.
+
+\return
+ SINGLE_WIRE_SUCCESS_STATUS - if byte read without error;
+ SINGLE_WIRE_ERROR_STATUS - if there are some errors during byte read.
+*******************************************************************************/
+static int halReadSingleWire(uint8_t *data)
+{
+ uint8_t reg = 0;
+ uint8_t bit;
+ uint8_t i;
+ int result;
+
+ // wait for Start bit of response
+ result = halWaitSingleWireStartBit();
+
+ if (result)
+ return SINGLE_WIRE_ERROR_STATUS;
+
+ // wait for half of bit period before reading Start bit
+ __delay_us(BIT_DURATION_HALF);
+
+ // read Start bit
+ bit = halReadSingleWireBit();
+ if (SINGLE_WIRE_ZERO_BIT != bit)
+ return SINGLE_WIRE_ERROR_STATUS;
+
+ // read byte
+ for (i = 0; i < UID_LEN; i++)
+ {
+ if (SINGLE_WIRE_ONE_BIT == halReadSingleWireBit())
+ reg |= (1 << i);
+ }
+
+ // read and check 1'st Stop bit
+ bit = halReadSingleWireBit();
+ if (SINGLE_WIRE_ONE_BIT != bit)
+ return SINGLE_WIRE_ERROR_STATUS;
+
+ // wait for bit period after reading
+ __delay_us(BIT_DURATION_HALF);
+
+ *data = reg;
+
+ return SINGLE_WIRE_SUCCESS_STATUS;
+}
+
+/**************************************************************************//**
+\brief Reads Atmel MeshBean UID from ATTiny13A
+
+\param[in] uidBuffer - memory for unique ID.
+
+\return
+ SINGLE_WIRE_SUCCESS_STATUS - if UID read successfully;
+ SINGLE_WIRE_ERROR_STATUS - if error occured during UID read.
+******************************************************************************/
+int halReadAtmelMeshbeanUid(uint8_t *uidBuffer)
+{
+ uint8_t i;
+ uint8_t reg = 0;
+
+ // port sets as output.
+ GPIO_SINGLE_WIRE_make_out();
+
+ // send synchronization byte
+ halWriteSingleWire(CMD_SYNCH);
+
+ // write command
+ halWriteSingleWire(CMD_READ_MAC64_0);
+
+ // write UID location
+ halWriteSingleWire(NUM_OF_MAC64);
+
+ // Tri-state (external pullup)
+ GPIO_SINGLE_WIRE_make_in();
+
+ // wait for synchronization
+ if (halReadSingleWire(&reg))
+ return SINGLE_WIRE_ERROR_STATUS;
+
+ if (CMD_SYNCH != reg)
+ return SINGLE_WIRE_ERROR_STATUS;
+
+ // wait for response with same command ID
+ if (halReadSingleWire(&reg))
+ return SINGLE_WIRE_ERROR_STATUS;
+
+ if (CMD_READ_MAC64_0 == reg)
+ {
+ // wait for 8 bytes of UID
+ for (i = UID_LEN; i > 0; i--)
+ {
+ // fill array in reversionary order
+ if (halReadSingleWire(uidBuffer + i - 1))
+ return SINGLE_WIRE_ERROR_STATUS;
+ }
+ }
+ return SINGLE_WIRE_SUCCESS_STATUS;
+}
+
+// eof halAtmelUid.c
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halMacIsr.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halMacIsr.c
new file mode 100644
index 00000000..7f349660
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/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 <halMacIsr.h>
+#include <halRfCtrl.h>
+#include <atomic.h>
+#include <halDiagnostic.h>
+
+/******************************************************************************
+ 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(INT5_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/zigBit/src/halRfCtrl.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfCtrl.c
new file mode 100644
index 00000000..8e3232a7
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfCtrl.c
@@ -0,0 +1,281 @@
+/**************************************************************************//**
+ \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 <halClkCtrl.h>
+#include <halW1.h>
+#include <halRfPio.h>
+#include <halRfCtrl.h>
+#include <halRfSpi.h>
+#include <halClkCtrl.h>
+//#include <phyRxTxIndicator.h>
+
+/******************************************************************************
+ 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_
+
+#ifdef _HAL_ANT_DIVERSITY_
+/**************************************************************************//**
+\brief Enable antenna diversity feature.
+******************************************************************************/
+void phyAntennaDiversityInit(void);
+
+/**************************************************************************//**
+\brief Enable antenna diversity in the receive state of the radio transceiver.
+******************************************************************************/
+void phyRxAntennaDiversity(void);
+
+/**************************************************************************//**
+\brief Enable antenna diversity in the transmit state of the radio transceiver.
+******************************************************************************/
+void phyTxAntennaDiversity(void);
+
+#endif //_HAL_ANT_DIVERSITY_
+
+/******************************************************************************
+ Implementations section
+******************************************************************************/
+/******************************************************************************
+ Delay in us
+******************************************************************************/
+void HAL_Delay(uint8_t us)
+{
+ __delay_us(us);
+}
+
+/******************************************************************************
+ Clears the irq.
+******************************************************************************/
+void HAL_ClearRfIrqFlag(void)
+{
+ EIFR = 1 << INTF5;
+}
+
+/******************************************************************************
+ Enables the irq.
+******************************************************************************/
+void HAL_EnableRfIrq(void)
+{
+ EIMSK |= 1 << INT5;
+}
+
+/******************************************************************************
+ Disables the irq.
+******************************************************************************/
+uint8_t HAL_DisableRfIrq(void)
+{
+ uint8_t tmp;
+
+ tmp = EIMSK & (1 << INT5);
+ EIMSK &= ~(1 << INT5);
+ 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_SLP_TR_clr();
+ GPIO_RF_SLP_TR_make_out();
+
+ GPIO_RF_RST_set();
+ GPIO_RF_RST_make_out();
+
+ GPIO_RF_IRQ_make_in();
+
+ #ifdef _HAL_USE_AMPLIFIER_
+ // enable power amplifier
+ // make port C pin 1 as output
+ GPIO_POW_AMPLF_SLP_make_out();
+ // set one on pin
+ GPIO_POW_AMPLF_SLP_set();
+ #endif
+}
+
+/******************************************************************************
+ Inits Atmega IRQ pin.
+******************************************************************************/
+void HAL_InitRfIrq(void)
+{
+ EICRB |= (1 << ISC51) | (1 << ISC50); // rising edge
+}
+
+/******************************************************************************
+ 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 Checks if amplifier is used.
+
+\return true - is used, \n
+ false - is not used.
+******************************************************************************/
+bool HAL_IsAmplifierUsed(void)
+{
+ #ifdef _HAL_USE_AMPLIFIER_
+ return true;
+ #else
+ return false;
+ #endif
+}
+
+/**************************************************************************//**
+ \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_
+}
+
+/**************************************************************************//**
+ \brief Enables Antenna diversity option for radio if that is supported.
+******************************************************************************/
+void HAL_InitAntennaDiversity(void)
+{
+ #ifdef _HAL_ANT_DIVERSITY_
+ phyAntennaDiversityInit();
+ #endif //_HAL_ANT_DIVERSITY_
+}
+
+/**************************************************************************//**
+ \brief Enables Antenna diversity in RX mode for radio if that is supported.
+******************************************************************************/
+void HAL_EnableRxAntennaDiversity(void)
+{
+ #ifdef _HAL_ANT_DIVERSITY_
+ phyRxAntennaDiversity();
+ #endif //_HAL_ANT_DIVERSITY_
+}
+
+/**************************************************************************//**
+ \brief Enables Antenna diversity in TX mode for radio if that is supported.
+******************************************************************************/
+void HAL_EnableTxAntennaDiversity(void)
+{
+ #ifdef _HAL_ANT_DIVERSITY_
+ phyTxAntennaDiversity();
+ #endif //_HAL_ANT_DIVERSITY_
+}
+
+//eof halRfCtrl.c
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfSpi.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfSpi.c
new file mode 100644
index 00000000..6edb9d7a
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halRfSpi.c
@@ -0,0 +1,87 @@
+/**************************************************************************//**
+ \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 <halRfSpi.h>
+#include <halRfPio.h>
+
+/******************************************************************************
+ 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/zigBit/src/halUid.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halUid.c
new file mode 100644
index 00000000..4f135528
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/zigBit/src/halUid.c
@@ -0,0 +1,72 @@
+/**************************************************************************//**
+ \file uid.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 <w1.h>
+#include <uid.h>
+#include <halAtmelUid.h>
+
+/******************************************************************************
+ Global variables section
+******************************************************************************/
+static HalUid_t halUid = {.uid = 0ull};
+
+/******************************************************************************
+ Implementations section
+******************************************************************************/
+/******************************************************************************
+ Reads uid from ds2411 (meshnetics meshbean) or ATTiny13A (atmel meshbean).
+******************************************************************************/
+void halReadUid(void)
+{
+#ifdef _HAL_TINY_UID_
+ // Atmel Single-Wire Software UART UID
+ halReadAtmelMeshbeanUid(halUid.array);
+#else
+ // 1-Wire UID
+ if (W1_SUCCESS_STATUS == HAL_SearchW1Device(W1_ANY_FAMILY, halUid.array, 1, NULL))
+ {
+ *(halUid.array + 7) = *(halUid.array + 0);
+ halUid.uid >>= 8;
+ }
+#endif
+}
+
+/******************************************************************************
+ UID discovery.
+ Parameters:
+ id - UID buffer pointer.
+ Returns:
+ 0 - if unique ID has been found without error;
+ -1 - if there are some errors during UID discovery.
+******************************************************************************/
+int HAL_ReadUid(uint64_t *id)
+{
+ if (!id)
+ return -1;
+
+ *id = halUid.uid;
+ return 0;
+}
+
+// eof uid.c