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 --- .../Components/HAL/avr/atmega1281/common/src/i2c.c | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/i2c.c') 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 +#include +#include +#include +/****************************************************************************** + 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 + -- cgit v1.2.3