Skip to content

Commit

Permalink
kernel: cleanup debug APIs
Browse files Browse the repository at this point in the history
- `dbg_log` is a “NOT RECOMMENDED API”, convert the calling of this
  API to LOG_x and remove this API.

- `dbg_here`/`dbg_enter`/`dbg_exit`: no one use these APIs, remove
  them directly.

Signed-off-by: Chen Wang <[email protected]>
  • Loading branch information
unicornx authored and mysterywolf committed Dec 20, 2024
1 parent 6a7e797 commit 7c7ff6e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 83 deletions.
84 changes: 42 additions & 42 deletions bsp/nxp/imx/imxrt/libraries/drivers/drv_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void _enet_rx_callback(struct rt_imxrt_eth *eth)

void _enet_tx_callback(struct rt_imxrt_eth *eth)
{
dbg_log(DBG_LOG, "_enet_tx_callback\n");
LOG_D("_enet_tx_callback\n");
if (eth->tx_is_waiting == RT_TRUE)
{
eth->tx_is_waiting = RT_FALSE;
Expand Down Expand Up @@ -181,23 +181,23 @@ static void _enet_callback(ENET_Type *base,
break;

case kENET_ErrEvent:
dbg_log(DBG_LOG, "kENET_ErrEvent\n");
LOG_D("kENET_ErrEvent\n");
break;

case kENET_WakeUpEvent:
dbg_log(DBG_LOG, "kENET_WakeUpEvent\n");
LOG_D("kENET_WakeUpEvent\n");
break;

case kENET_TimeStampEvent:
dbg_log(DBG_LOG, "kENET_TimeStampEvent\n");
LOG_D("kENET_TimeStampEvent\n");
break;

case kENET_TimeStampAvailEvent:
dbg_log(DBG_LOG, "kENET_TimeStampAvailEvent \n");
LOG_D("kENET_TimeStampAvailEvent \n");
break;

default:
dbg_log(DBG_LOG, "unknow error\n");
LOG_D("unknow error\n");
break;
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ static void *_enet_rx_alloc(ENET_Type *base, void *userData, uint8_t ringId)
void *buffer = NULL;
int i;

// dbg_log(DBG_LOG, "get buff_wait sem in %d\r\n", __LINE__);
// LOG_D("get buff_wait sem in %d\r\n", __LINE__);
rt_sem_take(&imxrt_eth_device.buff_wait, RT_WAITING_FOREVER);

for (i = 0; i < ENET_RXBUFF_NUM; i++)
Expand All @@ -269,7 +269,7 @@ static void *_enet_rx_alloc(ENET_Type *base, void *userData, uint8_t ringId)
}

rt_sem_release(&imxrt_eth_device.buff_wait);
// dbg_log(DBG_LOG, "release buff_wait sem in %d\r\n", __LINE__);
// LOG_D("release buff_wait sem in %d\r\n", __LINE__);

return buffer;
}
Expand All @@ -282,15 +282,15 @@ static void _enet_rx_free(ENET_Type *base, void *buffer, void *userData, uint8_t
LOG_E("Freed buffer out of range\r\n");
}

// dbg_log(DBG_LOG, "get buff_wait sem in %d\r\n", __LINE__);
// LOG_D("get buff_wait sem in %d\r\n", __LINE__);
rt_sem_take(&imxrt_eth_device.buff_wait, RT_WAITING_FOREVER);
if (!(imxrt_eth_device.RxPbufs[idx].buffer_used))
{
LOG_E("_enet_rx_free: freeing unallocated buffer\r\n");
}
imxrt_eth_device.RxPbufs[idx].buffer_used = false;
rt_sem_release(&imxrt_eth_device.buff_wait);
// dbg_log(DBG_LOG, "release buff_wait sem in %d\r\n", __LINE__);
// LOG_D("release buff_wait sem in %d\r\n", __LINE__);
}

/**
Expand Down Expand Up @@ -356,13 +356,13 @@ static void _enet_config(void)
// /* Set SMI to get PHY link status. */
// sysClock = CLOCK_GetFreq(kCLOCK_IpgClk);
//
// dbg_log(DBG_LOG, "deinit\n");
// LOG_D("deinit\n");
// ENET_Deinit(imxrt_eth_device.enet_base);
// dbg_log(DBG_LOG, "init\n");
// LOG_D("init\n");
// ENET_Init(imxrt_eth_device.enet_base, &imxrt_eth_device.enet_handle, &config, &buffConfig[0], &imxrt_eth_device.dev_addr[0], sysClock);
//// dbg_log(DBG_LOG, "set call back\n");
//// LOG_D("set call back\n");
//// ENET_SetCallback(&imxrt_eth_device.enet_handle, _enet_callback, &imxrt_eth_device);
// dbg_log(DBG_LOG, "active read\n");
// LOG_D("active read\n");
// ENET_ActiveRead(imxrt_eth_device.enet_base);
//#else
int i;
Expand Down Expand Up @@ -423,13 +423,13 @@ static void _enet_config(void)
imxrt_eth_device.RxPbufs[i].buffer_used = false;
}

// dbg_log(DBG_LOG, "deinit\n");
// LOG_D("deinit\n");
// ENET_Deinit(imxrt_eth_device.enet_base);
dbg_log(DBG_LOG, "init\n");
LOG_D("init\n");
ENET_Init(imxrt_eth_device.enet_base, &imxrt_eth_device.enet_handle, &config, &buffConfig[0], &imxrt_eth_device.dev_addr[0], sysClock);
// dbg_log(DBG_LOG, "set call back\n");
// LOG_D("set call back\n");
// ENET_SetCallback(&imxrt_eth_device.enet_handle, _enet_callback, &imxrt_eth_device);
dbg_log(DBG_LOG, "active read\n");
LOG_D("active read\n");
ENET_ActiveRead(imxrt_eth_device.enet_base);
//#endif
}
Expand Down Expand Up @@ -474,41 +474,41 @@ static void packet_dump(const char *msg, const struct pbuf *p)
/* initialize the interface */
static rt_err_t rt_imxrt_eth_init(rt_device_t dev)
{
dbg_log(DBG_LOG, "rt_imxrt_eth_init...\n");
LOG_D("rt_imxrt_eth_init...\n");
_enet_config();

return RT_EOK;
}

static rt_err_t rt_imxrt_eth_open(rt_device_t dev, rt_uint16_t oflag)
{
dbg_log(DBG_LOG, "rt_imxrt_eth_open...\n");
LOG_D("rt_imxrt_eth_open...\n");
return RT_EOK;
}

static rt_err_t rt_imxrt_eth_close(rt_device_t dev)
{
dbg_log(DBG_LOG, "rt_imxrt_eth_close...\n");
LOG_D("rt_imxrt_eth_close...\n");
return RT_EOK;
}

static rt_ssize_t rt_imxrt_eth_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
dbg_log(DBG_LOG, "rt_imxrt_eth_read...\n");
LOG_D("rt_imxrt_eth_read...\n");
rt_set_errno(-RT_ENOSYS);
return 0;
}

static rt_ssize_t rt_imxrt_eth_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
dbg_log(DBG_LOG, "rt_imxrt_eth_write...\n");
LOG_D("rt_imxrt_eth_write...\n");
rt_set_errno(-RT_ENOSYS);
return 0;
}

static rt_err_t rt_imxrt_eth_control(rt_device_t dev, int cmd, void *args)
{
dbg_log(DBG_LOG, "rt_imxrt_eth_control...\n");
LOG_D("rt_imxrt_eth_control...\n");
switch (cmd)
{
case NIOCTL_GADDR:
Expand Down Expand Up @@ -807,7 +807,7 @@ rt_err_t rt_imxrt_eth_tx(rt_device_t dev, struct pbuf *p)
RT_ASSERT(p != NULL);
RT_ASSERT(enet_handle != RT_NULL);

dbg_log(DBG_LOG, "rt_imxrt_eth_tx: %d\n", p->len);
LOG_D("rt_imxrt_eth_tx: %d\n", p->len);

#ifdef ETH_TX_DUMP
packet_dump("send", p);
Expand Down Expand Up @@ -861,18 +861,18 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev)
}
else
{
dbg_log(DBG_LOG, " A frame read failed\n");
LOG_D(" A frame read failed\n");
pbuf_free(p);
}
}
else
{
dbg_log(DBG_LOG, " pbuf_alloc faild\n");
LOG_D(" pbuf_alloc faild\n");
}
}
else if (status == kStatus_ENET_RxFrameError)
{
dbg_log(DBG_WARNING, "ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n");
LOG_W("ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n");
/* Update the received buffer when error happened. */

/* Get the error information of the received g_frame. */
Expand Down Expand Up @@ -956,44 +956,44 @@ static void phy_monitor_thread_entry(void *parameter)

if (PHY_SPEED_10M == speed)
{
dbg_log(DBG_LOG, "10M\n");
LOG_D("10M\n");
}
else if (PHY_SPEED_100M == speed)
{
dbg_log(DBG_LOG, "100M\n");
LOG_D("100M\n");
}
else
{
dbg_log(DBG_LOG, "1000M\n");
LOG_D("1000M\n");
}

if (PHY_HALF_DUPLEX == duplex)
{
dbg_log(DBG_LOG, "half dumplex\n");
LOG_D("half dumplex\n");
}
else
{
dbg_log(DBG_LOG, "full dumplex\n");
LOG_D("full dumplex\n");
}

if ((imxrt_eth_device.speed != (enet_mii_speed_t)speed) || (imxrt_eth_device.duplex != (enet_mii_duplex_t)duplex))
{
imxrt_eth_device.speed = (enet_mii_speed_t)speed;
imxrt_eth_device.duplex = (enet_mii_duplex_t)duplex;

dbg_log(DBG_LOG, "link up, and update eth mode.\n");
LOG_D("link up, and update eth mode.\n");
rt_imxrt_eth_init((rt_device_t)&imxrt_eth_device);
}
else
{
dbg_log(DBG_LOG, "link up, eth not need re-config.\n");
LOG_D("link up, eth not need re-config.\n");
}
dbg_log(DBG_LOG, "link up.\n");
LOG_D("link up.\n");
eth_device_linkchange(&imxrt_eth_device.parent, RT_TRUE);
}
else
{
dbg_log(DBG_LOG, "link down.\n");
LOG_D("link down.\n");
eth_device_linkchange(&imxrt_eth_device.parent, RT_FALSE);
}
}
Expand Down Expand Up @@ -1050,24 +1050,24 @@ static int rt_hw_imxrt_eth_init(void)
imxrt_eth_device.parent.eth_rx = rt_imxrt_eth_rx;
imxrt_eth_device.parent.eth_tx = rt_imxrt_eth_tx;

dbg_log(DBG_LOG, "sem init: tx_wait\r\n");
LOG_D("sem init: tx_wait\r\n");
/* init tx semaphore */
rt_sem_init(&imxrt_eth_device.tx_wait, "tx_wait", 0, RT_IPC_FLAG_FIFO);

dbg_log(DBG_LOG, "sem init: buff_wait\r\n");
LOG_D("sem init: buff_wait\r\n");
/* init tx semaphore */
rt_sem_init(&imxrt_eth_device.buff_wait, "buff_wait", 1, RT_IPC_FLAG_FIFO);

/* register eth device */
dbg_log(DBG_LOG, "eth_device_init start\r\n");
LOG_D("eth_device_init start\r\n");
state = eth_device_init(&(imxrt_eth_device.parent), "e0");
if (RT_EOK == state)
{
dbg_log(DBG_LOG, "eth_device_init success\r\n");
LOG_D("eth_device_init success\r\n");
}
else
{
dbg_log(DBG_LOG, "eth_device_init faild: %d\r\n", state);
LOG_D("eth_device_init faild: %d\r\n", state);
}

eth_device_linkchange(&imxrt_eth_device.parent, RT_FALSE);
Expand Down
4 changes: 2 additions & 2 deletions components/lwp/arch/x86/i386/lwp_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int arch_expand_user_stack(void *addr)
else /* map failed, send signal SIGSEGV */
{
#ifdef RT_USING_SIGNALS
dbg_log(DBG_ERROR, "[fault] thread %s mapped addr %p failed!\n", rt_thread_self()->parent.name, addr);
LOG_E("[fault] thread %s mapped addr %p failed!\n", rt_thread_self()->parent.name, addr);
lwp_thread_kill(rt_thread_self(), SIGSEGV);
ret = 1; /* return 1, will return back to intr, then check exit */
#endif
Expand All @@ -57,7 +57,7 @@ int arch_expand_user_stack(void *addr)
else /* not stack, send signal SIGSEGV */
{
#ifdef RT_USING_SIGNALS
dbg_log(DBG_ERROR, "[fault] thread %s access unmapped addr %p!\n", rt_thread_self()->parent.name, addr);
LOG_E("[fault] thread %s access unmapped addr %p!\n", rt_thread_self()->parent.name, addr);
lwp_thread_kill(rt_thread_self(), SIGSEGV);
ret = 1; /* return 1, will return back to intr, then check exit */
#endif
Expand Down
2 changes: 1 addition & 1 deletion components/lwp/lwp.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)

if (lwp == RT_NULL)
{
dbg_log(DBG_ERROR, "lwp struct out of memory!\n");
LOG_E("lwp struct out of memory!\n");
return -ENOMEM;
}
LOG_D("lwp malloc : %p, size: %d!", lwp, sizeof(struct rt_lwp));
Expand Down
4 changes: 2 additions & 2 deletions components/lwp/lwp_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ sysret_t sys_unlink(const char *pathname)
sysret_t sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
int ret = 0;
dbg_log(DBG_LOG, "sys_nanosleep\n");
LOG_D("sys_nanosleep\n");
if (!lwp_user_accessable((void *)rqtp, sizeof *rqtp))
return -EFAULT;

Expand Down Expand Up @@ -4759,7 +4759,7 @@ sysret_t sys_clock_gettime(clockid_t clk, struct timespec *ts)
sysret_t sys_clock_nanosleep(clockid_t clk, int flags, const struct timespec *rqtp, struct timespec *rmtp)
{
int ret = 0;
dbg_log(DBG_LOG, "sys_nanosleep\n");
LOG_D("sys_nanosleep\n");
if (!lwp_user_accessable((void *)rqtp, sizeof *rqtp))
return -EFAULT;

Expand Down
6 changes: 0 additions & 6 deletions components/utilities/ulog/ulog_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ extern "C" {
#undef DBG_WARNING
#undef DBG_INFO
#undef DBG_LOG
#undef dbg_log
#define DBG_ERROR LOG_LVL_ERROR
#define DBG_WARNING LOG_LVL_WARNING
#define DBG_INFO LOG_LVL_INFO
#define DBG_LOG LOG_LVL_DBG
#define dbg_log(level, ...) \
if ((level) <= LOG_LVL) \
{ \
ulog_output(level, LOG_TAG, RT_FALSE, __VA_ARGS__);\
}

#if !defined(LOG_TAG)
/* compatible for rtdbg */
Expand Down
30 changes: 0 additions & 30 deletions include/rtdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,6 @@ extern "C" {
rt_kprintf("\n")
#endif /* DBG_COLOR */

/*
* static debug routine
* NOTE: This is a NOT RECOMMENDED API. Please using LOG_X API.
* It will be DISCARDED later. Because it will take up more resources.
*/
#define dbg_log(level, fmt, ...) \
if ((level) <= DBG_LEVEL) \
{ \
switch(level) \
{ \
case DBG_ERROR: _DBG_LOG_HDR("E", 31); break; \
case DBG_WARNING: _DBG_LOG_HDR("W", 33); break; \
case DBG_INFO: _DBG_LOG_HDR("I", 32); break; \
case DBG_LOG: _DBG_LOG_HDR("D", 0); break; \
default: break; \
} \
rt_kprintf(fmt, ##__VA_ARGS__); \
_DBG_COLOR(0); \
}

#define dbg_here \
if ((DBG_LEVEL) <= DBG_LOG){ \
rt_kprintf(DBG_SECTION_NAME " Here %s:%d\n", \
__FUNCTION__, __LINE__); \
}

#define dbg_log_line(lvl, color_n, fmt, ...) \
do \
{ \
Expand All @@ -151,10 +125,6 @@ extern "C" {
#define dbg_raw(...) rt_kprintf(__VA_ARGS__);

#else
#define dbg_log(level, fmt, ...)
#define dbg_here
#define dbg_enter
#define dbg_exit
#define dbg_log_line(lvl, color_n, fmt, ...)
#define dbg_raw(...)
#endif /* DBG_ENABLE */
Expand Down

0 comments on commit 7c7ff6e

Please sign in to comment.