summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c')
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c
new file mode 100644
index 00000000..f118194e
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c
@@ -0,0 +1,90 @@
+/**************************************************************************//**
+ \file i2c.c
+
+ \brief Provides the functionality of TWI.
+
+ \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:
+ 5/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 <i2c.h>
+#include <halTaskManager.h>
+#include <halDbg.h>
+#include <halDiagnostic.h>
+/******************************************************************************
+ Implementations section
+******************************************************************************/
+/******************************************************************************
+Inits TWI module. Setup teh speed of TWI.
+Parameters:
+ i2cMode - the speed of TWI.
+Returns:
+ none.
+******************************************************************************/
+void halInitI2c(HAL_i2cMode_t *i2cMode)
+{
+ TWCR = 0x00;
+ TWSR = HAL_I2C_PRESCALER; // prescaler
+ // Set bit rate
+ TWBR = i2cMode->clockrate;
+}
+
+/******************************************************************************
+Interrupt handler.
+******************************************************************************/
+ISR(TWI_vect)
+{
+ BEGIN_MEASURE
+ switch (TWSR & 0xF8)
+ {
+ case TWS_START:
+ case TWS_RSTART:
+ halSendStartDoneI2c();
+ break;
+
+ case TWS_MT_SLA_ACK:
+ case TWS_MT_DATA_ACK:
+ halWriteDoneI2c();
+ break;
+
+ case TWS_BUSERROR:
+ case TWS_MT_SLA_NACK:
+ case TWS_MT_DATA_NACK:
+ case TWS_MR_SLA_NACK:
+ halI2cBusReset();
+ break;
+
+ case TWS_MR_SLA_ACK:
+ halMasterReadWriteAddressAckI2c();
+ break;
+
+ case TWS_MR_DATA_ACK:
+ halReadDoneI2c(halReadByteI2c());
+ break;
+
+ case TWS_MR_DATA_NACK:
+ halReadLastByteDoneI2c(halReadByteI2c());
+ break;
+
+ default:
+ break;
+ }
+ END_MEASURE(HALISR_TWI_TIME_LIMIT)
+}
+// eof i2c.c
+