Files
chrg/apps/chrg/applications/thread/chrg_north.c
T
2025-08-28 23:32:26 +08:00

68 lines
1.2 KiB
C

#include <rtthread.h>
#include "chrg_north.h"
#define LOG_TAG "chrg.nor"
#define DBG_ENABLE
#define DBG_SECTION_NAME LOG_TAG
#define DBG_LEVEL DBG_LOG
#define DBG_COLOR
#include <rtdbg.h>
struct chrg_north_t chrgnor = {
.tid = RT_NULL,
.name = THRED_NAME_NORTH,
};
static void chrg_north_entry (void *data)
{
struct chrg_north_t *pNOR = (struct chrg_north_t *)data;
if (RT_NULL == pNOR) {
return ;
}
char *str = RT_NULL;
while (1) {
if (rt_mb_recv(&pNOR->mb, (rt_uint32_t *)&str, RT_WAITING_FOREVER) == RT_EOK) {
rt_kprintf("%s recv %s\r\n", pNOR->name, str);
}
//rt_thread_mdelay(1000);
}
rt_mb_detach(&pNOR->mb);
}
static int chrg_north_init (void)
{
rt_err_t ret;
struct chrg_north_t *pNOR = &chrgnor;
ret = rt_mb_init(&pNOR->mb, "mb_nor", &pNOR->mb_pool[0],
sizeof(pNOR->mb_pool)/4, RT_IPC_FLAG_FIFO);
if (RT_NULL != ret) {
LOG_E("mb init failed.");
return RT_ENOMEM;
}
pNOR->tid = rt_thread_create(pNOR->name, chrg_north_entry, pNOR,
4096, RT_MAIN_THREAD_PRIORITY, 10);
if (RT_NULL != pNOR->tid) {
rt_thread_startup(pNOR->tid);
LOG_I("start thread '%s'.", pNOR->name);
} else {
LOG_E("start thread '%s' failed.", pNOR->name);
return -RT_ERROR;
}
return 0;
}
INIT_APP_EXPORT(chrg_north_init);