From 544c3f3025ae00b1500d94e5b616270601a0efc7 Mon Sep 17 00:00:00 2001 From: asterix Date: Thu, 8 Jul 2010 16:32:16 +0000 Subject: [PATCH] Add first implementation of i2c for lm3s. git-svn-id: https://src.develer.com/svnoss/bertos/branches/i2c@4013 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/i2c_lm3s.c | 165 ++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 bertos/cpu/cortex-m3/drv/i2c_lm3s.c diff --git a/bertos/cpu/cortex-m3/drv/i2c_lm3s.c b/bertos/cpu/cortex-m3/drv/i2c_lm3s.c new file mode 100644 index 00000000..27fed7c6 --- /dev/null +++ b/bertos/cpu/cortex-m3/drv/i2c_lm3s.c @@ -0,0 +1,165 @@ +/** + * \file + * + * + * \brief Driver for the LM3S I2C (implementation) + * + */ + +#include "cfg/cfg_i2c.h" + +#define LOG_LEVEL I2C_LOG_LEVEL +#define LOG_FORMAT I2C_LOG_FORMAT + +#include + +#include +#include // BV() +#include + +#include +#include +#include +#include + + +/** + * Send START condition on the bus. + * + * \return true on success, false otherwise. + */ +static bool i2c_builtin_start(void) +{ + + return false; +} + + +/** + * Send START condition and select slave for write. + * \c id is the device id comprehensive of address left shifted by 1. + * The LSB of \c id is ignored and reset to 0 for write operation. + * + * \return true on success, false otherwise. + */ +bool i2c_builtin_start_w(uint8_t id) +{ + /* + * Loop on the select write sequence: when the eeprom is busy + * writing previously sent data it will reply to the SLA_W + * control byte with a NACK. In this case, we must + * keep trying until the eeprom responds with an ACK. + */ + ticks_t start = timer_clock(); + while (i2c_builtin_start()) + { + else if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT)) + { + LOG_ERR("Timeout on TWI_MT_START\n"); + break; + } + } + + return false; +} + + +/** + * Send START condition and select slave for read. + * \c id is the device id comprehensive of address left shifted by 1. + * The LSB of \c id is ignored and set to 1 for read operation. + * + * \return true on success, false otherwise. + */ +bool i2c_builtin_start_r(uint8_t id) +{ + if (i2c_builtin_start()) + { + + } + + return false; +} + + +/** + * Send STOP condition. + */ +void i2c_builtin_stop(void) +{ + +} + + +/** + * Put a single byte in master transmitter mode + * to the selected slave device through the TWI bus. + * + * \return true on success, false on error. + */ +bool i2c_builtin_put(const uint8_t data) +{ + return true; +} + +/** + * Get 1 byte from slave in master transmitter mode + * to the selected slave device through the I2C bus. + * If \a ack is true issue a ACK after getting the byte, + * otherwise a NACK is issued. + * + * \return the byte read if ok, EOF on errors. + */ +int i2c_builtin_get(bool ack) +{ + + if (ack) + { + + } + else + { + + } + + /* avoid sign extension */ + return 0; +} + +MOD_DEFINE(i2c); + +/** + * Initialize I2C module. + */ +void i2c_builtin_init(void) +{ + MOD_INIT(i2c); +} -- 2.25.1