projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add -fomit-frame-pointer when we are not in debug mode.
[bertos.git]
/
bertos
/
cpu
/
avr
/
drv
/
i2c_avr.c
diff --git
a/bertos/cpu/avr/drv/i2c_avr.c
b/bertos/cpu/avr/drv/i2c_avr.c
index fe3a4eb18aa32358f6096cc4362930e198440915..7425240305cebea0ea6ca383111c88305934b758 100644
(file)
--- a/
bertos/cpu/avr/drv/i2c_avr.c
+++ b/
bertos/cpu/avr/drv/i2c_avr.c
@@
-38,9
+38,15
@@
* \author Bernie Innocenti <bernie@codewiz.org>
*/
* \author Bernie Innocenti <bernie@codewiz.org>
*/
-#include
"hw/hw_cpu.h" /* CLOCK
_FREQ */
+#include
<hw/hw_cpufreq.h> /* CPU
_FREQ */
#include "cfg/cfg_i2c.h"
#include "cfg/cfg_i2c.h"
+
+#define LOG_LEVEL I2C_LOG_LEVEL
+#define LOG_FORMAT I2C_LOG_FORMAT
+
+#include <cfg/log.h>
+
#include <cfg/debug.h>
#include <cfg/macros.h> // BV()
#include <cfg/module.h>
#include <cfg/debug.h>
#include <cfg/macros.h> // BV()
#include <cfg/module.h>
@@
-61,7
+67,7
@@
*
* \return true on success, false otherwise.
*/
*
* \return true on success, false otherwise.
*/
-static bool i2c_start(void)
+static bool i2c_
builtin_
start(void)
{
TWCR = BV(TWINT) | BV(TWSTA) | BV(TWEN);
WAIT_TWI_READY;
{
TWCR = BV(TWINT) | BV(TWSTA) | BV(TWEN);
WAIT_TWI_READY;
@@
-69,7
+75,7
@@
static bool i2c_start(void)
if (TW_STATUS == TW_START || TW_STATUS == TW_REP_START)
return true;
if (TW_STATUS == TW_START || TW_STATUS == TW_REP_START)
return true;
-
kprintf
("!TW_(REP)START: %x\n", TWSR);
+
LOG_ERR
("!TW_(REP)START: %x\n", TWSR);
return false;
}
return false;
}
@@
-81,7
+87,7
@@
static bool i2c_start(void)
*
* \return true on success, false otherwise.
*/
*
* \return true on success, false otherwise.
*/
-bool i2c_start_w(uint8_t id)
+bool i2c_
builtin_
start_w(uint8_t id)
{
/*
* Loop on the select write sequence: when the eeprom is busy
{
/*
* Loop on the select write sequence: when the eeprom is busy
@@
-90,9
+96,9
@@
bool i2c_start_w(uint8_t id)
* keep trying until the eeprom responds with an ACK.
*/
ticks_t start = timer_clock();
* keep trying until the eeprom responds with an ACK.
*/
ticks_t start = timer_clock();
- while (i2c_start())
+ while (i2c_
builtin_
start())
{
{
- TWDR = id & ~
READ_
BIT;
+ TWDR = id & ~
I2C_READ
BIT;
TWCR = BV(TWINT) | BV(TWEN);
WAIT_TWI_READY;
TWCR = BV(TWINT) | BV(TWEN);
WAIT_TWI_READY;
@@
-100,12
+106,12
@@
bool i2c_start_w(uint8_t id)
return true;
else if (TW_STATUS != TW_MT_SLA_NACK)
{
return true;
else if (TW_STATUS != TW_MT_SLA_NACK)
{
-
kprintf
("!TW_MT_SLA_(N)ACK: %x\n", TWSR);
+
LOG_ERR
("!TW_MT_SLA_(N)ACK: %x\n", TWSR);
break;
}
else if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT))
{
break;
}
else if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT))
{
-
kprintf
("Timeout on TWI_MT_START\n");
+
LOG_ERR
("Timeout on TWI_MT_START\n");
break;
}
}
break;
}
}
@@
-121,18
+127,18
@@
bool i2c_start_w(uint8_t id)
*
* \return true on success, false otherwise.
*/
*
* \return true on success, false otherwise.
*/
-bool i2c_start_r(uint8_t id)
+bool i2c_
builtin_
start_r(uint8_t id)
{
{
- if (i2c_start())
+ if (i2c_
builtin_
start())
{
{
- TWDR = id |
READ_
BIT;
+ TWDR = id |
I2C_READ
BIT;
TWCR = BV(TWINT) | BV(TWEN);
WAIT_TWI_READY;
if (TW_STATUS == TW_MR_SLA_ACK)
return true;
TWCR = BV(TWINT) | BV(TWEN);
WAIT_TWI_READY;
if (TW_STATUS == TW_MR_SLA_ACK)
return true;
-
kprintf
("!TW_MR_SLA_ACK: %x\n", TWSR);
+
LOG_ERR
("!TW_MR_SLA_ACK: %x\n", TWSR);
}
return false;
}
return false;
@@
-142,7
+148,7
@@
bool i2c_start_r(uint8_t id)
/**
* Send STOP condition.
*/
/**
* Send STOP condition.
*/
-void i2c_stop(void)
+void i2c_
builtin_
stop(void)
{
TWCR = BV(TWINT) | BV(TWEN) | BV(TWSTO);
}
{
TWCR = BV(TWINT) | BV(TWEN) | BV(TWSTO);
}
@@
-154,14
+160,14
@@
void i2c_stop(void)
*
* \return true on success, false on error.
*/
*
* \return true on success, false on error.
*/
-bool i2c_put(const uint8_t data)
+bool i2c_
builtin_
put(const uint8_t data)
{
TWDR = data;
TWCR = BV(TWINT) | BV(TWEN);
WAIT_TWI_READY;
if (TW_STATUS != TW_MT_DATA_ACK)
{
{
TWDR = data;
TWCR = BV(TWINT) | BV(TWEN);
WAIT_TWI_READY;
if (TW_STATUS != TW_MT_DATA_ACK)
{
-
kprintf
("!TW_MT_DATA_ACK: %x\n", TWSR);
+
LOG_ERR
("!TW_MT_DATA_ACK: %x\n", TWSR);
return false;
}
return true;
return false;
}
return true;
@@
-175,7
+181,7
@@
bool i2c_put(const uint8_t data)
*
* \return the byte read if ok, EOF on errors.
*/
*
* \return the byte read if ok, EOF on errors.
*/
-int i2c_get(bool ack)
+int i2c_
builtin_
get(bool ack)
{
TWCR = BV(TWINT) | BV(TWEN) | (ack ? BV(TWEA) : 0);
WAIT_TWI_READY;
{
TWCR = BV(TWINT) | BV(TWEN) | (ack ? BV(TWEA) : 0);
WAIT_TWI_READY;
@@
-184,7
+190,7
@@
int i2c_get(bool ack)
{
if (TW_STATUS != TW_MR_DATA_ACK)
{
{
if (TW_STATUS != TW_MR_DATA_ACK)
{
-
kprintf
("!TW_MR_DATA_ACK: %x\n", TWSR);
+
LOG_ERR
("!TW_MR_DATA_ACK: %x\n", TWSR);
return EOF;
}
}
return EOF;
}
}
@@
-192,7
+198,7
@@
int i2c_get(bool ack)
{
if (TW_STATUS != TW_MR_DATA_NACK)
{
{
if (TW_STATUS != TW_MR_DATA_NACK)
{
-
kprintf
("!TW_MR_DATA_NACK: %x\n", TWSR);
+
LOG_ERR
("!TW_MR_DATA_NACK: %x\n", TWSR);
return EOF;
}
}
return EOF;
}
}
@@
-206,7
+212,7
@@
MOD_DEFINE(i2c);
/**
* Initialize TWI module.
*/
/**
* Initialize TWI module.
*/
-void i2c_init(void)
+void i2c_
builtin_
init(void)
{
ATOMIC(
/*
{
ATOMIC(
/*
@@
-231,7
+237,7
@@
void i2c_init(void)
/*
* Set speed:
/*
* Set speed:
- * F = C
LOCK
_FREQ / (16 + 2*TWBR * 4^TWPS)
+ * F = C
PU
_FREQ / (16 + 2*TWBR * 4^TWPS)
*/
#ifndef CONFIG_I2C_FREQ
#warning Using default value of 300000L for CONFIG_I2C_FREQ
*/
#ifndef CONFIG_I2C_FREQ
#warning Using default value of 300000L for CONFIG_I2C_FREQ
@@
-239,7
+245,7
@@
void i2c_init(void)
#endif
#define TWI_PRESC 1 /* 4 ^ TWPS */
#endif
#define TWI_PRESC 1 /* 4 ^ TWPS */
- TWBR = (C
LOCK
_FREQ / (2 * CONFIG_I2C_FREQ * TWI_PRESC)) - (8 / TWI_PRESC);
+ TWBR = (C
PU
_FREQ / (2 * CONFIG_I2C_FREQ * TWI_PRESC)) - (8 / TWI_PRESC);
TWSR = 0;
TWCR = BV(TWEN);
);
TWSR = 0;
TWCR = BV(TWEN);
);