[Device/I2C] Chang debug message print way to ulog

This commit is contained in:
a1012112796
2019-11-26 07:41:43 +08:00
parent 86e61ddfc3
commit ab981a32b5
7 changed files with 89 additions and 51 deletions

View File

@@ -10,11 +10,13 @@
#include <rtdevice.h>
#ifdef RT_I2C_BIT_DEBUG
#define bit_dbg(fmt, ...) rt_kprintf(fmt, ##__VA_ARGS__)
#define DBG_TAG "I2C"
#ifdef RT_I2C_BITOPS_DEBUG
#define DBG_LVL DBG_LOG
#else
#define bit_dbg(fmt, ...)
#define DBG_LVL DBG_INFO
#endif
#include <rtdbg.h>
#define SET_SDA(ops, val) ops->set_sda(ops->data, val)
#define SET_SCL(ops, val) ops->set_scl(ops->data, val)
@@ -54,11 +56,11 @@ static rt_err_t SCL_H(struct rt_i2c_bit_ops *ops)
return -RT_ETIMEOUT;
rt_thread_delay((ops->timeout + 1) >> 1);
}
#ifdef RT_I2C_BIT_DEBUG
#ifdef RT_I2C_BITOPS_DEBUG
if (rt_tick_get() != start)
{
bit_dbg("wait %ld tick for SCL line to go high\n",
rt_tick_get() - start);
LOG_D("wait %ld tick for SCL line to go high",
rt_tick_get() - start);
}
#endif
@@ -70,14 +72,14 @@ done:
static void i2c_start(struct rt_i2c_bit_ops *ops)
{
#ifdef RT_I2C_BIT_DEBUG
#ifdef RT_I2C_BITOPS_DEBUG
if (ops->get_scl && !GET_SCL(ops))
{
bit_dbg("I2C bus error, SCL line low\n");
LOG_E("I2C bus error, SCL line low");
}
if (ops->get_sda && !GET_SDA(ops))
{
bit_dbg("I2C bus error, SDA line low\n");
LOG_E("I2C bus error, SDA line low");
}
#endif
SDA_L(ops);
@@ -114,13 +116,13 @@ rt_inline rt_bool_t i2c_waitack(struct rt_i2c_bit_ops *ops)
if (SCL_H(ops) < 0)
{
bit_dbg("wait ack timeout\n");
LOG_W("wait ack timeout");
return -RT_ETIMEOUT;
}
ack = !GET_SDA(ops); /* ACK : SDA pin is pulled low */
bit_dbg("%s\n", ack ? "ACK" : "NACK");
LOG_D("%s", ack ? "ACK" : "NACK");
SCL_L(ops);
@@ -142,8 +144,8 @@ static rt_int32_t i2c_writeb(struct rt_i2c_bus_device *bus, rt_uint8_t data)
i2c_delay(ops);
if (SCL_H(ops) < 0)
{
bit_dbg("i2c_writeb: 0x%02x, "
"wait scl pin high timeout at bit %d\n",
LOG_D("i2c_writeb: 0x%02x, "
"wait scl pin high timeout at bit %d",
data, i);
return -RT_ETIMEOUT;
@@ -169,8 +171,8 @@ static rt_int32_t i2c_readb(struct rt_i2c_bus_device *bus)
if (SCL_H(ops) < 0)
{
bit_dbg("i2c_readb: wait scl pin high "
"timeout at bit %d\n", 7 - i);
LOG_D("i2c_readb: wait scl pin high "
"timeout at bit %d", 7 - i);
return -RT_ETIMEOUT;
}
@@ -205,13 +207,13 @@ static rt_size_t i2c_send_bytes(struct rt_i2c_bus_device *bus,
}
else if (ret == 0)
{
i2c_dbg("send bytes: NACK.\n");
LOG_D("send bytes: NACK.");
return 0;
}
else
{
i2c_dbg("send bytes: error %d\n", ret);
LOG_E("send bytes: error %d", ret);
return ret;
}
@@ -229,7 +231,7 @@ static rt_err_t i2c_send_ack_or_nack(struct rt_i2c_bus_device *bus, int ack)
i2c_delay(ops);
if (SCL_H(ops) < 0)
{
bit_dbg("ACK or NACK timeout\n");
LOG_E("ACK or NACK timeout.");
return -RT_ETIMEOUT;
}
@@ -263,7 +265,7 @@ static rt_size_t i2c_recv_bytes(struct rt_i2c_bus_device *bus,
ptr ++;
count --;
bit_dbg("recieve bytes: 0x%02x, %s\n",
LOG_D("recieve bytes: 0x%02x, %s",
val, (flags & RT_I2C_NO_READ_ACK) ?
"(No ACK/NACK)" : (count ? "ACK" : "NACK"));
@@ -291,10 +293,10 @@ static rt_int32_t i2c_send_address(struct rt_i2c_bus_device *bus,
ret = i2c_writeb(bus, addr);
if (ret == 1 || i == retries)
break;
bit_dbg("send stop condition\n");
LOG_D("send stop condition");
i2c_stop(ops);
i2c_delay2(ops);
bit_dbg("send start condition\n");
LOG_D("send start condition");
i2c_start(ops);
}
@@ -319,12 +321,12 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus,
addr1 = 0xf0 | ((msg->addr >> 7) & 0x06);
addr2 = msg->addr & 0xff;
bit_dbg("addr1: %d, addr2: %d\n", addr1, addr2);
LOG_D("addr1: %d, addr2: %d", addr1, addr2);
ret = i2c_send_address(bus, addr1, retries);
if ((ret != 1) && !ignore_nack)
{
bit_dbg("NACK: sending first addr\n");
LOG_W("NACK: sending first addr");
return -RT_EIO;
}
@@ -332,19 +334,19 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus,
ret = i2c_writeb(bus, addr2);
if ((ret != 1) && !ignore_nack)
{
bit_dbg("NACK: sending second addr\n");
LOG_W("NACK: sending second addr");
return -RT_EIO;
}
if (flags & RT_I2C_RD)
{
bit_dbg("send repeated start condition\n");
LOG_D("send repeated start condition");
i2c_restart(ops);
addr1 |= 0x01;
ret = i2c_send_address(bus, addr1, retries);
if ((ret != 1) && !ignore_nack)
{
bit_dbg("NACK: sending repeated addr\n");
LOG_E("NACK: sending repeated addr");
return -RT_EIO;
}
@@ -373,7 +375,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
rt_int32_t i, ret;
rt_uint16_t ignore_nack;
bit_dbg("send start condition\n");
LOG_D("send start condition");
i2c_start(ops);
for (i = 0; i < num; i++)
{
@@ -388,7 +390,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
ret = i2c_bit_send_address(bus, msg);
if ((ret != RT_EOK) && !ignore_nack)
{
bit_dbg("receive NACK from device addr 0x%02x msg %d\n",
LOG_D("receive NACK from device addr 0x%02x msg %d",
msgs[i].addr, i);
goto out;
}
@@ -397,7 +399,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
ret = i2c_recv_bytes(bus, msg);
if (ret >= 1)
bit_dbg("read %d byte%s\n", ret, ret == 1 ? "" : "s");
LOG_D("read %d byte%s", ret, ret == 1 ? "" : "s");
if (ret < msg->len)
{
if (ret >= 0)
@@ -409,7 +411,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
ret = i2c_send_bytes(bus, msg);
if (ret >= 1)
bit_dbg("write %d byte%s\n", ret, ret == 1 ? "" : "s");
LOG_D("write %d byte%s", ret, ret == 1 ? "" : "s");
if (ret < msg->len)
{
if (ret >= 0)
@@ -421,7 +423,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
ret = i;
out:
bit_dbg("send stop condition\n");
LOG_D("send stop condition");
i2c_stop(ops);
return ret;