drivers: i2c: move to new logger

Move to new logger subsystem.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2018-09-17 13:24:08 -05:00
parent 3da714193f
commit f7dac85d15
20 changed files with 155 additions and 148 deletions

View File

@ -34,18 +34,10 @@ config I2C_INIT_PRIORITY
help
I2C device driver initialization priority.
config SYS_LOG_I2C_LEVEL
int "I2C log level"
depends on SYS_LOG
default 0
help
Sets log level for I2C drivers.
Levels are:
- 0 OFF, do not write
- 1 ERROR, only write SYS_LOG_ERR
- 2 WARNING, write SYS_LOG_WRN in addition to previous level
- 3 INFO, write SYS_LOG_INF in addition to previous levels
- 4 DEBUG, write SYS_LOG_DBG in addition to previous levels
module = I2C
module-str = i2c
source "subsys/logging/Kconfig.template.log_config"
config I2C_0
bool "Enable I2C Port 0"

View File

@ -13,11 +13,7 @@ extern "C" {
#include <i2c.h>
#include <dt-bindings/i2c/i2c.h>
#ifndef SYS_LOG_LEVEL
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#endif
#include <logging/sys_log.h>
#include <logging/log.h>
static inline u32_t _i2c_map_dt_bitrate(u32_t bitrate)
{
@ -34,7 +30,7 @@ static inline u32_t _i2c_map_dt_bitrate(u32_t bitrate)
return I2C_SPEED_ULTRA << I2C_SPEED_SHIFT;
}
SYS_LOG_ERR("Invalid I2C bit rate value");
LOG_ERR("Invalid I2C bit rate value");
return 0;
}

View File

@ -35,8 +35,9 @@
#include <misc/util.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_atmel_sam3)
#define TWI_IRQ_PDC \
(TWI_SR_ENDRX | TWI_SR_ENDTX | TWI_SR_RXBUFF | TWI_SR_TXBUFE)
@ -587,7 +588,7 @@ static int __deprecated i2c_sam3_init(struct device *dev)
if (i2c_sam3_runtime_configure(dev, dev_data->dev_config)
!= 0) {
SYS_LOG_DBG("I2C: Cannot set default configuration 0x%x",
LOG_DBG("I2C: Cannot set default configuration 0x%x",
dev_data->dev_config);
return -EINVAL;
}

View File

@ -10,7 +10,6 @@
#include <errno.h>
#include <i2c.h>
#include <soc.h>
#include "i2c-priv.h"
/* Driverlib includes */
#include <inc/hw_memmap.h>
@ -19,6 +18,12 @@
#include <driverlib/rom_map.h>
#include <driverlib/i2c.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_cc32xx)
#include "i2c-priv.h"
#define I2C_MASTER_CMD_BURST_RECEIVE_START_NACK I2C_MASTER_CMD_BURST_SEND_START
#define I2C_MASTER_CMD_BURST_RECEIVE_STOP \
I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP
@ -269,7 +274,7 @@ static void i2c_cc32xx_isr(void *arg)
/* Clear interrupt source to avoid additional interrupts */
MAP_I2CMasterIntClearEx(base, int_status);
SYS_LOG_DBG("primed state: %d; err_status: 0x%x; int_status: 0x%x",
LOG_DBG("primed state: %d; err_status: 0x%x; int_status: 0x%x",
data->state, err_status, int_status);
/* Handle errors: */

View File

@ -32,12 +32,12 @@
#include "i2c_dw.h"
#include "i2c_dw_registers.h"
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_dw);
#include "i2c-priv.h"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
static inline void _i2c_dw_data_ask(struct device *dev)
{
struct i2c_dw_dev_config * const dw = dev->driver_data;
@ -221,7 +221,7 @@ static void i2c_dw_isr(void *arg)
* - Receive data is available (rx_avail)
*/
SYS_LOG_DBG("I2C: interrupt received");
LOG_DBG("I2C: interrupt received");
/* Check if we are configured as a master device */
if (regs->ic_con.bits.master_mode) {
@ -299,7 +299,7 @@ static int _i2c_dw_setup(struct device *dev, u16_t slave_address)
* Make sure to set both the master_mode and slave_disable_bit
* to both 0 or both 1
*/
SYS_LOG_DBG("I2C: host configured as Master Device");
LOG_DBG("I2C: host configured as Master Device");
ic_con.bits.master_mode = 1;
ic_con.bits.slave_disable = 1;
} else {
@ -310,7 +310,7 @@ static int _i2c_dw_setup(struct device *dev, u16_t slave_address)
/* Set addressing mode - (initialization = 7 bit) */
if (I2C_ADDR_10_BITS & dw->app_config) {
SYS_LOG_DBG("I2C: using 10-bit address");
LOG_DBG("I2C: using 10-bit address");
ic_con.bits.addr_master_10bit = 1;
ic_con.bits.addr_slave_10bit = 1;
}
@ -318,7 +318,7 @@ static int _i2c_dw_setup(struct device *dev, u16_t slave_address)
/* Setup the clock frequency and speed mode */
switch (I2C_SPEED_GET(dw->app_config)) {
case I2C_SPEED_STANDARD:
SYS_LOG_DBG("I2C: speed set to STANDARD");
LOG_DBG("I2C: speed set to STANDARD");
regs->ic_ss_scl_lcnt = dw->lcnt;
regs->ic_ss_scl_hcnt = dw->hcnt;
ic_con.bits.speed = I2C_DW_SPEED_STANDARD;
@ -327,7 +327,7 @@ static int _i2c_dw_setup(struct device *dev, u16_t slave_address)
case I2C_SPEED_FAST:
/* fall through */
case I2C_SPEED_FAST_PLUS:
SYS_LOG_DBG("I2C: speed set to FAST or FAST_PLUS");
LOG_DBG("I2C: speed set to FAST or FAST_PLUS");
regs->ic_fs_scl_lcnt = dw->lcnt;
regs->ic_fs_scl_hcnt = dw->hcnt;
ic_con.bits.speed = I2C_DW_SPEED_FAST;
@ -338,19 +338,19 @@ static int _i2c_dw_setup(struct device *dev, u16_t slave_address)
return -EINVAL;
}
SYS_LOG_DBG("I2C: speed set to HIGH");
LOG_DBG("I2C: speed set to HIGH");
regs->ic_hs_scl_lcnt = dw->lcnt;
regs->ic_hs_scl_hcnt = dw->hcnt;
ic_con.bits.speed = I2C_DW_SPEED_HIGH;
break;
default:
SYS_LOG_DBG("I2C: invalid speed requested");
LOG_DBG("I2C: invalid speed requested");
return -EINVAL;
}
SYS_LOG_DBG("I2C: lcnt = %d", dw->lcnt);
SYS_LOG_DBG("I2C: hcnt = %d", dw->hcnt);
LOG_DBG("I2C: lcnt = %d", dw->lcnt);
LOG_DBG("I2C: hcnt = %d", dw->hcnt);
/* Set the IC_CON register */
regs->ic_con = ic_con;
@ -629,7 +629,7 @@ static inline int i2c_dw_pci_setup(struct device *dev)
pci_bus_scan_init();
if (!pci_bus_scan(&dw->pci_dev)) {
SYS_LOG_DBG("Could not find device");
LOG_DBG("Could not find device");
return 0;
}
@ -664,7 +664,7 @@ static int i2c_dw_initialize(struct device *dev)
/* verify that we have a valid DesignWare register first */
if (regs->ic_comp_type != I2C_DW_MAGIC_KEY) {
dev->driver_api = NULL;
SYS_LOG_DBG("I2C: DesignWare magic key not found, check base "
LOG_DBG("I2C: DesignWare magic key not found, check base "
"address. Stopping initialization");
return -EIO;
}
@ -675,10 +675,10 @@ static int i2c_dw_initialize(struct device *dev)
* can move provide support for it
*/
if (regs->ic_con.bits.speed == I2C_DW_SPEED_HIGH) {
SYS_LOG_DBG("I2C: high speed supported");
LOG_DBG("I2C: high speed supported");
dw->support_hs_mode = true;
} else {
SYS_LOG_DBG("I2C: high speed NOT supported");
LOG_DBG("I2C: high speed NOT supported");
dw->support_hs_mode = false;
}
@ -687,7 +687,7 @@ static int i2c_dw_initialize(struct device *dev)
dw->app_config = I2C_MODE_MASTER | _i2c_map_dt_bitrate(rom->bitrate);
if (i2c_dw_runtime_configure(dev, dw->app_config) != 0) {
SYS_LOG_DBG("I2C: Cannot set default configuration");
LOG_DBG("I2C: Cannot set default configuration");
return -EIO;
}

View File

@ -12,11 +12,13 @@
#include <board.h>
#include <errno.h>
#include <i2c.h>
#include "i2c-priv.h"
#include "i2c_ll_stm32.h"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_ll_stm32);
#include "i2c-priv.h"
int i2c_stm32_runtime_configure(struct device *dev, u32_t config)
{
@ -202,7 +204,7 @@ static int i2c_stm32_init(struct device *dev)
ret = i2c_stm32_runtime_configure(dev, I2C_MODE_MASTER | bitrate_cfg);
if (ret < 0) {
SYS_LOG_ERR("i2c: failure initializing");
LOG_ERR("i2c: failure initializing");
return ret;
}

View File

@ -17,8 +17,9 @@
#include <i2c.h>
#include "i2c_ll_stm32.h"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_ll_stm32_v1);
#define I2C_REQUEST_WRITE 0x00
#define I2C_REQUEST_READ 0x01
@ -242,10 +243,10 @@ s32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg,
if (data->current.is_nack || data->current.is_err) {
if (data->current.is_nack)
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
if (data->current.is_err)
SYS_LOG_DBG("%s: ERR %d", __func__,
LOG_DBG("%s: ERR %d", __func__,
data->current.is_err);
data->current.is_nack = 0;
@ -287,7 +288,7 @@ s32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg,
LL_I2C_DisableIT_BUF(i2c);
if (data->current.is_err) {
SYS_LOG_DBG("%s: ERR %d", __func__, data->current.is_err);
LOG_DBG("%s: ERR %d", __func__, data->current.is_err);
data->current.is_err = 0;
ret = -EIO;
}
@ -338,7 +339,7 @@ s32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg,
if (LL_I2C_IsActiveFlag_AF(i2c)) {
LL_I2C_ClearFlag_AF(i2c);
LL_I2C_GenerateStopCondition(i2c);
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
return -EIO;
}
@ -354,7 +355,7 @@ s32_t stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg,
if (LL_I2C_IsActiveFlag_AF(i2c)) {
LL_I2C_ClearFlag_AF(i2c);
LL_I2C_GenerateStopCondition(i2c);
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
return -EIO;
}
@ -424,7 +425,7 @@ s32_t stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg,
if (LL_I2C_IsActiveFlag_AF(i2c)) {
LL_I2C_ClearFlag_AF(i2c);
LL_I2C_GenerateStopCondition(i2c);
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
return -EIO;
}

View File

@ -15,11 +15,13 @@
#include <board.h>
#include <errno.h>
#include <i2c.h>
#include "i2c-priv.h"
#include "i2c_ll_stm32.h"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_ll_stm32_v2);
#include "i2c-priv.h"
static inline void msg_init(struct device *dev, struct i2c_msg *msg,
u8_t *next_msg_flags, u16_t slave,
@ -197,7 +199,7 @@ int i2c_stm32_slave_register(struct device *dev,
ret = i2c_stm32_runtime_configure(dev, bitrate_cfg);
if (ret < 0) {
SYS_LOG_ERR("i2c: failure initializing");
LOG_ERR("i2c: failure initializing");
return ret;
}
@ -211,7 +213,7 @@ int i2c_stm32_slave_register(struct device *dev,
data->slave_attached = true;
SYS_LOG_DBG("i2c: slave registered");
LOG_DBG("i2c: slave registered");
LL_I2C_EnableIT_ADDR(i2c);
@ -244,7 +246,7 @@ int i2c_stm32_slave_unregister(struct device *dev,
LL_I2C_Disable(i2c);
SYS_LOG_DBG("i2c: slave unregistered");
LOG_DBG("i2c: slave unregistered");
return 0;
}
@ -396,18 +398,18 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg,
return 0;
error:
if (data->current.is_arlo) {
SYS_LOG_DBG("%s: ARLO %d", __func__,
LOG_DBG("%s: ARLO %d", __func__,
data->current.is_arlo);
data->current.is_arlo = 0;
}
if (data->current.is_nack) {
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
data->current.is_nack = 0;
}
if (data->current.is_err) {
SYS_LOG_DBG("%s: ERR %d", __func__,
LOG_DBG("%s: ERR %d", __func__,
data->current.is_err);
data->current.is_err = 0;
}
@ -445,18 +447,18 @@ int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg,
return 0;
error:
if (data->current.is_arlo) {
SYS_LOG_DBG("%s: ARLO %d", __func__,
LOG_DBG("%s: ARLO %d", __func__,
data->current.is_arlo);
data->current.is_arlo = 0;
}
if (data->current.is_nack) {
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
data->current.is_nack = 0;
}
if (data->current.is_err) {
SYS_LOG_DBG("%s: ERR %d", __func__,
LOG_DBG("%s: ERR %d", __func__,
data->current.is_err);
data->current.is_err = 0;
}
@ -517,7 +519,7 @@ int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg,
return 0;
error:
LL_I2C_ClearFlag_NACK(i2c);
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
return -EIO;
}
@ -601,7 +603,7 @@ int stm32_i2c_configure_timing(struct device *dev, u32_t clock)
} while (presc < 16);
if (presc >= 16) {
SYS_LOG_DBG("I2C:failed to find prescaler value");
LOG_DBG("I2C:failed to find prescaler value");
return -EINVAL;
}

View File

@ -11,8 +11,9 @@
#include <altera_common.h>
#include "altera_avalon_i2c.h"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_nios2);
#define NIOS2_I2C_TIMEOUT_USEC 1000
@ -32,19 +33,19 @@ static int i2c_nios2_configure(struct device *dev, u32_t dev_config)
k_sem_take(&config->sem_lock, K_FOREVER);
if (!(I2C_MODE_MASTER & dev_config)) {
SYS_LOG_ERR("i2c config mode error\n");
LOG_ERR("i2c config mode error\n");
rc = -EINVAL;
goto i2c_cfg_err;
}
if (I2C_ADDR_10_BITS & dev_config) {
SYS_LOG_ERR("i2c config addresing error\n");
LOG_ERR("i2c config addresing error\n");
rc = -EINVAL;
goto i2c_cfg_err;
}
if (I2C_SPEED_GET(dev_config) != I2C_SPEED_STANDARD) {
SYS_LOG_ERR("i2c config speed error\n");
LOG_ERR("i2c config speed error\n");
rc = -EINVAL;
goto i2c_cfg_err;
}
@ -106,7 +107,7 @@ static int i2c_nios2_transfer(struct device *dev, struct i2c_msg *msgs,
* start successfully e.g., if the bus was busy
*/
if (status != ALT_AVALON_I2C_SUCCESS) {
SYS_LOG_ERR("i2c transfer error %lu\n", status);
LOG_ERR("i2c transfer error %lu\n", status);
rc = -EIO;
goto i2c_transfer_err;
}
@ -123,7 +124,7 @@ static int i2c_nios2_transfer(struct device *dev, struct i2c_msg *msgs,
}
if (timeout <= 0) {
SYS_LOG_ERR("i2c busy or timeout error %lu\n", status);
LOG_ERR("i2c busy or timeout error %lu\n", status);
rc = -EIO;
goto i2c_transfer_err;
}
@ -180,7 +181,7 @@ static int i2c_nios2_init(struct device *dev)
I2C_MODE_MASTER |
I2C_SPEED_SET(I2C_SPEED_STANDARD));
if (rc) {
SYS_LOG_ERR("i2c configure failed %d\n", rc);
LOG_ERR("i2c configure failed %d\n", rc);
return rc;
}

View File

@ -8,9 +8,9 @@
#include <i2c.h>
#include <nrfx_twi.h>
#define SYS_LOG_DOMAIN "i2c_nrfx_twi"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_nrfx_twi);
struct i2c_nrfx_twi_data {
struct k_sem sync;
@ -59,7 +59,7 @@ static int i2c_nrfx_twi_transfer(struct device *dev, struct i2c_msg *msgs,
k_sem_take(&(get_dev_data(dev)->sync), K_FOREVER);
res = get_dev_data(dev)->res;
if (res != NRFX_SUCCESS) {
SYS_LOG_ERR("Error %d occurred for message %d", res, i);
LOG_ERR("Error %d occurred for message %d", res, i);
return -EIO;
}
}
@ -106,7 +106,7 @@ static int i2c_nrfx_twi_configure(struct device *dev, u32_t dev_config)
nrf_twi_frequency_set(inst->p_twi, NRF_TWI_FREQ_400K);
break;
default:
SYS_LOG_ERR("unsupported speed");
LOG_ERR("unsupported speed");
return -EINVAL;
}
@ -123,7 +123,7 @@ static int init_twi(struct device *dev, const nrfx_twi_config_t *config)
nrfx_err_t result = nrfx_twi_init(&get_dev_config(dev)->twi, config,
event_handler, dev);
if (result != NRFX_SUCCESS) {
SYS_LOG_ERR("Failed to initialize device: %s",
LOG_ERR("Failed to initialize device: %s",
dev->config->name);
return -EBUSY;
}

View File

@ -8,9 +8,10 @@
#include <i2c.h>
#include <nrfx_twim.h>
#define SYS_LOG_DOMAIN "i2c_nrfx_twim"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_DOMAIN "i2c_nrfx_twim"
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_nrfx_twim);
struct i2c_nrfx_twim_data {
struct k_sem sync;
@ -59,7 +60,7 @@ static int i2c_nrfx_twim_transfer(struct device *dev, struct i2c_msg *msgs,
k_sem_take(&(get_dev_data(dev)->sync), K_FOREVER);
res = get_dev_data(dev)->res;
if (res != NRFX_SUCCESS) {
SYS_LOG_ERR("Error %d occurred for message %d", res, i);
LOG_ERR("Error %d occurred for message %d", res, i);
return -EIO;
}
}
@ -106,7 +107,7 @@ static int i2c_nrfx_twim_configure(struct device *dev, u32_t dev_config)
nrf_twim_frequency_set(inst->p_twim, NRF_TWIM_FREQ_400K);
break;
default:
SYS_LOG_ERR("unsupported speed");
LOG_ERR("unsupported speed");
return -EINVAL;
}
@ -123,7 +124,7 @@ static int init_twim(struct device *dev, const nrfx_twim_config_t *config)
nrfx_err_t result = nrfx_twim_init(&get_dev_config(dev)->twim, config,
event_handler, dev);
if (result != NRFX_SUCCESS) {
SYS_LOG_ERR("Failed to initialize device: %s",
LOG_ERR("Failed to initialize device: %s",
dev->config->name);
return -EBUSY;
}

View File

@ -20,11 +20,12 @@
#include <init.h>
#include <soc.h>
#include <i2c.h>
#include "i2c-priv.h"
#define SYS_LOG_DOMAIN "dev/i2c_sam_twi"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_sam_twi)
#include "i2c-priv.h"
/** I2C bus speed [Hz] in Standard Mode */
#define BUS_SPEED_STANDARD_HZ 100000U
@ -90,7 +91,7 @@ static int i2c_clk_set(Twi *const twi, u32_t speed)
}
if (ck_div > CKDIV_MAX) {
SYS_LOG_ERR("Failed to configure I2C clock");
LOG_ERR("Failed to configure I2C clock");
return -EIO;
}
@ -109,13 +110,13 @@ static int i2c_sam_twi_configure(struct device *dev, u32_t config)
int ret;
if (!(config & I2C_MODE_MASTER)) {
SYS_LOG_ERR("Master Mode is not enabled");
LOG_ERR("Master Mode is not enabled");
return -EIO;
}
if (config & I2C_ADDR_10_BITS) {
SYS_LOG_ERR("I2C 10-bit addressing is currently not supported");
SYS_LOG_ERR("Please submit a patch");
LOG_ERR("I2C 10-bit addressing is currently not supported");
LOG_ERR("Please submit a patch");
return -EIO;
}
@ -128,7 +129,7 @@ static int i2c_sam_twi_configure(struct device *dev, u32_t config)
bitrate = BUS_SPEED_FAST_HZ;
break;
default:
SYS_LOG_ERR("Unsupported I2C speed value");
LOG_ERR("Unsupported I2C speed value");
return -EIO;
}
@ -318,14 +319,14 @@ static int i2c_sam_twi_initialize(struct device *dev)
ret = i2c_sam_twi_configure(dev, I2C_MODE_MASTER | bitrate_cfg);
if (ret < 0) {
SYS_LOG_ERR("Failed to initialize %s device", DEV_NAME(dev));
LOG_ERR("Failed to initialize %s device", DEV_NAME(dev));
return ret;
}
/* Enable module's IRQ */
irq_enable(dev_cfg->irq_id);
SYS_LOG_INF("Device %s initialized", DEV_NAME(dev));
LOG_INF("Device %s initialized", DEV_NAME(dev));
return 0;
}

View File

@ -10,9 +10,6 @@
* Only I2C Master Mode with 7 bit addressing is currently supported.
*/
#define SYS_LOG_DOMAIN "dev/i2c_sam_twihs"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#include <errno.h>
#include <misc/__assert.h>
@ -21,6 +18,11 @@
#include <init.h>
#include <soc.h>
#include <i2c.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_sam_twihs)
#include "i2c-priv.h"
/** I2C bus speed [Hz] in Standard Mode */
@ -89,7 +91,7 @@ static int i2c_clk_set(Twihs *const twihs, u32_t speed)
}
if (ck_div > CKDIV_MAX) {
SYS_LOG_ERR("Failed to configure I2C clock");
LOG_ERR("Failed to configure I2C clock");
return -EIO;
}
@ -108,13 +110,13 @@ static int i2c_sam_twihs_configure(struct device *dev, u32_t config)
int ret;
if (!(config & I2C_MODE_MASTER)) {
SYS_LOG_ERR("Master Mode is not enabled");
LOG_ERR("Master Mode is not enabled");
return -EIO;
}
if (config & I2C_ADDR_10_BITS) {
SYS_LOG_ERR("I2C 10-bit addressing is currently not supported");
SYS_LOG_ERR("Please submit a patch");
LOG_ERR("I2C 10-bit addressing is currently not supported");
LOG_ERR("Please submit a patch");
return -EIO;
}
@ -127,7 +129,7 @@ static int i2c_sam_twihs_configure(struct device *dev, u32_t config)
bitrate = BUS_SPEED_FAST_HZ;
break;
default:
SYS_LOG_ERR("Unsupported I2C speed value");
LOG_ERR("Unsupported I2C speed value");
return -EIO;
}
@ -304,14 +306,14 @@ static int i2c_sam_twihs_initialize(struct device *dev)
ret = i2c_sam_twihs_configure(dev, I2C_MODE_MASTER | bitrate_cfg);
if (ret < 0) {
SYS_LOG_ERR("Failed to initialize %s device", DEV_NAME(dev));
LOG_ERR("Failed to initialize %s device", DEV_NAME(dev));
return ret;
}
/* Enable module's IRQ */
irq_enable(dev_cfg->irq_id);
SYS_LOG_INF("Device %s initialized", DEV_NAME(dev));
LOG_INF("Device %s initialized", DEV_NAME(dev));
return 0;
}

View File

@ -22,18 +22,18 @@ config I2C_SLAVE_INIT_PRIORITY
help
I2C Slave device driver initialization priority.
config SYS_LOG_I2C_SLAVE_LEVEL
config LOG_I2C_SLAVE_LEVEL
int "I2C Slave log level"
depends on SYS_LOG
depends on LOG
default 0
help
Sets log level for I2C drivers.
Levels are:
- 0 OFF, do not write
- 1 ERROR, only write SYS_LOG_ERR
- 2 WARNING, write SYS_LOG_WRN in addition to previous level
- 3 INFO, write SYS_LOG_INF in addition to previous levels
- 4 DEBUG, write SYS_LOG_DBG in addition to previous levels
- 1 ERROR, only write LOG_ERR
- 2 WARNING, write LOG_WRN in addition to previous level
- 3 INFO, write LOG_INF in addition to previous levels
- 4 DEBUG, write LOG_DBG in addition to previous levels
source "drivers/i2c/slave/Kconfig.eeprom"

View File

@ -11,8 +11,9 @@
#include <string.h>
#include <drivers/i2c/slave/eeprom.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_SLAVE_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_slave)
struct i2c_eeprom_slave_data {
struct device *i2c_controller;
@ -71,7 +72,7 @@ static int eeprom_slave_write_requested(struct i2c_slave_config *config)
struct i2c_eeprom_slave_data,
config);
SYS_LOG_DBG("eeprom: write req");
LOG_DBG("eeprom: write req");
data->first_write = true;
@ -87,7 +88,7 @@ static int eeprom_slave_read_requested(struct i2c_slave_config *config,
*val = data->buffer[data->buffer_idx];
SYS_LOG_DBG("eeprom: read req, val=0x%x", *val);
LOG_DBG("eeprom: read req, val=0x%x", *val);
/* Increment will be done in the read_processed callback */
@ -101,7 +102,7 @@ static int eeprom_slave_write_received(struct i2c_slave_config *config,
struct i2c_eeprom_slave_data,
config);
SYS_LOG_DBG("eeprom: write done, val=0x%x", val);
LOG_DBG("eeprom: write done, val=0x%x", val);
/* In case EEPROM wants to be R/O, return !0 here could trigger
* a NACK to the I2C controller, support depends on the
@ -132,7 +133,7 @@ static int eeprom_slave_read_processed(struct i2c_slave_config *config,
*val = data->buffer[data->buffer_idx];
SYS_LOG_DBG("eeprom: read done, val=0x%x", *val);
LOG_DBG("eeprom: read done, val=0x%x", *val);
/* Increment will be done in the next read_processed callback
* In case of STOP, the byte won't be taken in account
@ -147,7 +148,7 @@ static int eeprom_slave_stop(struct i2c_slave_config *config)
struct i2c_eeprom_slave_data,
config);
SYS_LOG_DBG("eeprom: stop");
LOG_DBG("eeprom: stop");
data->first_write = true;
@ -189,7 +190,7 @@ static int i2c_eeprom_slave_init(struct device *dev)
data->i2c_controller =
device_get_binding(cfg->controller_dev_name);
if (!data->i2c_controller) {
SYS_LOG_ERR("i2c controller not found: %s",
LOG_ERR("i2c controller not found: %s",
cfg->controller_dev_name);
return -EINVAL;
}

View File

@ -6,7 +6,7 @@ CONFIG_SENSOR=y
CONFIG_SYS_LOG=y
CONFIG_SYS_LOG_SENSOR_LEVEL=1
CONFIG_SYS_LOG_I2C_LEVEL=1
CONFIG_I2C_LOG_LEVEL_INF=y
CONFIG_APDS9960=y
CONFIG_APDS9960_TRIGGER_GLOBAL_THREAD=n

View File

@ -12,8 +12,9 @@
#include <errno.h>
#include <i2c.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_I2C_LEVEL
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_DECLARE(main);
#define DEV_DATA(dev) ((struct i2c_virtual_data * const)(dev)->driver_data)
@ -113,7 +114,7 @@ static int i2c_virtual_msg_write(struct device *dev, struct i2c_msg *msg,
return 0;
error:
SYS_LOG_DBG("%s: NACK", __func__);
LOG_DBG("%s: NACK", __func__);
return -EIO;
}

View File

@ -1,5 +1,5 @@
CONFIG_SYS_LOG=y
CONFIG_SYS_LOG_I2C_LEVEL=4
CONFIG_LOG=y
CONFIG_I2C_LOG_LEVEL_DBG=y
CONFIG_BOOT_BANNER=y
CONFIG_ZTEST=y
CONFIG_I2C=y

View File

@ -1,5 +1,5 @@
CONFIG_SYS_LOG=y
CONFIG_SYS_LOG_I2C_LEVEL=4
CONFIG_LOG=y
CONFIG_I2C_LOG_LEVEL_DBG=y
CONFIG_BOOT_BANNER=y
CONFIG_ZTEST=y
CONFIG_I2C=y

View File

@ -7,8 +7,9 @@
#include <errno.h>
#include <string.h>
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
#include <logging/sys_log.h>
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(main);
#include <zephyr.h>
#include <device.h>
@ -46,7 +47,7 @@ static void run_full_read(struct device *i2c, u8_t addr, u8_t *comp_buffer)
{
int ret;
SYS_LOG_INF("Start full read. Master: %s, address: 0x%x",
LOG_INF("Start full read. Master: %s, address: 0x%x",
i2c->config->name, addr);
/* Read EEPROM from I2C Master requests, then compare */
@ -59,9 +60,9 @@ static void run_full_read(struct device *i2c, u8_t addr, u8_t *comp_buffer)
buffer_print_i2c);
to_display_format(comp_buffer, TEST_DATA_SIZE,
buffer_print_eeprom);
SYS_LOG_ERR("Buffer contents are different: %s",
LOG_ERR("Buffer contents are different: %s",
buffer_print_i2c);
SYS_LOG_ERR(" vs: %s",
LOG_ERR(" vs: %s",
buffer_print_eeprom);
ztest_test_fail();
@ -73,7 +74,7 @@ static void run_partial_read(struct device *i2c, u8_t addr, u8_t *comp_buffer,
{
int ret;
SYS_LOG_INF("Start partial read. Master: %s, address: 0x%x, off=%d",
LOG_INF("Start partial read. Master: %s, address: 0x%x, off=%d",
i2c->config->name, addr, offset);
ret = i2c_burst_read(i2c, addr,
@ -85,9 +86,9 @@ static void run_partial_read(struct device *i2c, u8_t addr, u8_t *comp_buffer,
buffer_print_i2c);
to_display_format(&comp_buffer[offset], TEST_DATA_SIZE-offset,
buffer_print_eeprom);
SYS_LOG_ERR("Buffer contents are different: %s",
LOG_ERR("Buffer contents are different: %s",
buffer_print_i2c);
SYS_LOG_ERR(" vs: %s",
LOG_ERR(" vs: %s",
buffer_print_eeprom);
ztest_test_fail();
@ -98,7 +99,7 @@ static void run_program_read(struct device *i2c, u8_t addr, unsigned int offset)
{
int ret, i;
SYS_LOG_INF("Start program. Master: %s, address: 0x%x, off=%d",
LOG_INF("Start program. Master: %s, address: 0x%x, off=%d",
i2c->config->name, addr, offset);
for (i = 0 ; i < TEST_DATA_SIZE-offset ; ++i) {
@ -120,7 +121,7 @@ static void run_program_read(struct device *i2c, u8_t addr, unsigned int offset)
if (i2c_buffer[i] != i) {
to_display_format(i2c_buffer, TEST_DATA_SIZE-offset,
buffer_print_i2c);
SYS_LOG_ERR("Invalid Buffer content: %s",
LOG_ERR("Invalid Buffer content: %s",
buffer_print_i2c);
ztest_test_fail();
@ -141,7 +142,7 @@ void test_eeprom_slave(void)
zassert_not_null(i2c_0, "I2C device %s not found",
EEPROM_SLAVE_0_BUS_NAME);
SYS_LOG_INF("Found I2C Master device %s",
LOG_INF("Found I2C Master device %s",
EEPROM_SLAVE_0_BUS_NAME);
i2c_1 = device_get_binding(
@ -149,20 +150,20 @@ void test_eeprom_slave(void)
zassert_not_null(i2c_1, "I2C device %s not found",
EEPROM_SLAVE_1_BUS_NAME);
SYS_LOG_INF("Found I2C Master device %s",
LOG_INF("Found I2C Master device %s",
EEPROM_SLAVE_1_BUS_NAME);
eeprom_0 = device_get_binding(EEPROM_SLAVE_0_LABEL);
zassert_not_null(eeprom_0, "EEPROM device %s not found",
EEPROM_SLAVE_0_LABEL);
SYS_LOG_INF("Found EEPROM device %s", EEPROM_SLAVE_0_LABEL);
LOG_INF("Found EEPROM device %s", EEPROM_SLAVE_0_LABEL);
eeprom_1 = device_get_binding(EEPROM_SLAVE_1_LABEL);
zassert_not_null(eeprom_1, "EEPROM device %s not found",
EEPROM_SLAVE_1_LABEL);
SYS_LOG_INF("Found EEPROM device %s", EEPROM_SLAVE_1_LABEL);
LOG_INF("Found EEPROM device %s", EEPROM_SLAVE_1_LABEL);
/* Program dummy bytes */
ret = eeprom_slave_program(eeprom_0, eeprom_0_data, TEST_DATA_SIZE);
@ -178,13 +179,13 @@ void test_eeprom_slave(void)
zassert_equal(ret, 0, "Failed to register EEPROM %s",
EEPROM_SLAVE_0_LABEL);
SYS_LOG_INF("EEPROM %s Attached !", EEPROM_SLAVE_0_LABEL);
LOG_INF("EEPROM %s Attached !", EEPROM_SLAVE_0_LABEL);
ret = i2c_slave_driver_register(eeprom_1);
zassert_equal(ret, 0, "Failed to register EEPROM %s",
EEPROM_SLAVE_1_LABEL);
SYS_LOG_INF("EEPROM %s Attached !", EEPROM_SLAVE_1_LABEL);
LOG_INF("EEPROM %s Attached !", EEPROM_SLAVE_1_LABEL);
/* Run Tests without bus access conflicts */
run_full_read(i2c_0, EEPROM_SLAVE_1_BASE_ADDRESS, eeprom_1_data);
@ -210,21 +211,21 @@ void test_eeprom_slave(void)
offset);
}
SYS_LOG_INF("Success !");
LOG_INF("Success !");
/* Detach EEPROM */
ret = i2c_slave_driver_unregister(eeprom_0);
zassert_equal(ret, 0, "Failed to unregister EEPROM %s",
EEPROM_SLAVE_0_LABEL);
SYS_LOG_INF("EEPROM %s Detached !",
LOG_INF("EEPROM %s Detached !",
EEPROM_SLAVE_0_LABEL);
ret = i2c_slave_driver_unregister(eeprom_1);
zassert_equal(ret, 0, "Failed to unregister EEPROM %s",
EEPROM_SLAVE_1_LABEL);
SYS_LOG_INF("EEPROM %s Detached !",
LOG_INF("EEPROM %s Detached !",
EEPROM_SLAVE_1_LABEL);
}