summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h
diff options
context:
space:
mode:
authorFlorent Duchon2012-12-26 17:36:00 +0100
committerFlorent Duchon2013-02-13 21:21:12 +0100
commitb24866225a6301d3a663f874725e83c012dc25d3 (patch)
treeca527a2aab9abcdfbaf244c53ca63f0c531892b0 /digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h
parent2ba279f4eb2f23fa08a7c13465d16ae6ba5d0f96 (diff)
digital/beacon: add bitcloud stack into common directory digital/zigbit
Diffstat (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h')
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h180
1 files changed, 180 insertions, 0 deletions
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h
new file mode 100644
index 00000000..59ab72c8
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halSpi.h
@@ -0,0 +1,180 @@
+/*****************************************************************************//**
+\file halSpi.h
+
+\brief Declarations of USART SPI mode.
+
+\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/06/07 E. Ivanov - Created
+**********************************************************************************/
+/******************************************************************************
+ * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. *
+ * EXPERT USERS SHOULD PROCEED WITH CAUTION. *
+ ******************************************************************************/
+#ifndef _HALSPI_H
+#define _HALSPI_H
+
+/******************************************************************************
+ Includes section
+******************************************************************************/
+#include <usart.h>
+
+/******************************************************************************
+ Define(s) section
+******************************************************************************/
+#define SPI_CHANNEL_0 USART_CHANNEL_0 // USART0 AtMega1281/2561 start addresss
+#define SPI_CHANNEL_1 USART_CHANNEL_1 // USART1 AtMega1281/2561 start addresss
+
+/******************************************************************************
+ Types section
+******************************************************************************/
+// spi channel
+typedef UsartChannel_t SpiChannel_t;
+
+// types of the clock mode
+typedef enum
+{
+ // leading edge sample RX bit (rising), trailing edge setup TX bit (falling).
+ SPI_CLOCK_MODE0,
+ // leading edge setup TX bit (rising), trailing edge sample RX bit (falling).
+ SPI_CLOCK_MODE1,
+ // leading edge sample RX bit (falling), trailing edge setup TX bit (rising).
+ SPI_CLOCK_MODE2,
+ // leading edge setup TX bit (falling), trailing edge sample RX bit (rising).
+ SPI_CLOCK_MODE3
+} SpiClockMode_t;
+
+// clock rate
+typedef enum
+{
+ SPI_CLOCK_RATE_62 = ((F_CPU / (2 * 62500ul)) - 1),
+ SPI_CLOCK_RATE_125 = ((F_CPU / (2 * 125000ul)) - 1),
+ SPI_CLOCK_RATE_250 = ((F_CPU / (2 * 250000ul)) - 1),
+ SPI_CLOCK_RATE_500 = ((F_CPU / (2 * 500000ul)) - 1),
+ SPI_CLOCK_RATE_1000 = ((F_CPU / (2 * 1000000ul)) - 1),
+ SPI_CLOCK_RATE_2000 = ((F_CPU / (2 * 2000000ul)) - 1)
+} SpiBaudRate_t;
+
+// Data order
+typedef enum
+{
+ SPI_DATA_MSB_FIRST, // data with MSB first
+ SPI_DATA_LSB_FIRST // data with LSB first
+} SpiDataOrder_t;
+
+/******************************************************************************
+ Prototypes section
+******************************************************************************/
+/******************************************************************************
+Disables USART channel.
+Parameters:
+ tty - spi channel.
+******************************************************************************/
+void halClearUsartSpi(SpiChannel_t tty);
+
+/******************************************************************************
+Write a length bytes to the SPI.
+Parameters:
+ tty - spi channel
+ buffer - pointer to application data buffer;
+ length - number bytes for transfer;
+Returns:
+ number of written bytes
+******************************************************************************/
+uint16_t halSyncUsartSpiWriteData(SpiChannel_t tty, uint8_t *buffer, uint16_t length);
+
+/******************************************************************************
+Write & read a length bytes to & from the SPI.
+Parameters:
+ tty - spi channel
+ buffer - pointer to application data buffer;
+ length - number bytes for transfer;
+Returns:
+ number of written & read bytes
+******************************************************************************/
+uint16_t halSyncUsartSpiReadData(SpiChannel_t tty, uint8_t *buffer, uint16_t length);
+
+/******************************************************************************
+ Inline static functions section
+******************************************************************************/
+/******************************************************************************
+Enables data register empty interrupt.
+Parameters:
+ tty - spi channel.
+Returns:
+ none.
+******************************************************************************/
+INLINE void halEnableUsartSpiDremInterrupt(SpiChannel_t tty)
+{
+ UCSRnB(tty) |= (1 << UDRIE0);
+}
+
+/******************************************************************************
+Disables data register empty interrupt.
+Parameters:
+ tty - spi channel.
+Returns:
+ none.
+******************************************************************************/
+INLINE void halDisableUsartSpiDremInterrupt(SpiChannel_t tty)
+{
+ UCSRnB(tty) &= ~(1 << UDRIE0);
+}
+
+/******************************************************************************
+Enables transmit complete interrupt.
+Parameters:
+ tty - spi channel.
+Returns:
+ none.
+******************************************************************************/
+INLINE void halEnableUsartSpiTxcInterrupt(SpiChannel_t tty)
+{
+ UCSRnB(tty) |= (1 << TXCIE0);
+}
+
+/******************************************************************************
+Disables transmit complete interrupt.
+Parameters:
+ tty - spi channel.
+Returns:
+ none.
+******************************************************************************/
+INLINE void halDisableUsartSpiTxcInterrupt(SpiChannel_t tty)
+{
+ UCSRnB(tty) &= ~(1 << TXCIE0);
+}
+
+/*****************************************************************************
+Enables receive complete interrupt.
+Parameters:
+ tty - spi channel.
+Returns:
+ none.
+******************************************************************************/
+INLINE void halEnableUsartSpiRxcInterrupt(SpiChannel_t tty)
+{
+ UCSRnB(tty) |= (1 << RXCIE0);
+}
+
+/*****************************************************************************
+Disables receive complete interrupt.
+Parameters:
+ tty - spi channel.
+Returns:
+ none.
+******************************************************************************/
+INLINE void halDisableUsartSpiRxcInterrupt(SpiChannel_t tty)
+{
+ UCSRnB(tty) &= ~(1 << RXCIE0);
+}
+#endif
+//eof halSpi.h
+