add more files

This commit is contained in:
wmano
2025-08-30 23:48:55 +08:00
parent e26e47548f
commit 050eb19fc8
33 changed files with 820 additions and 479 deletions
+50 -22
View File
@@ -4,58 +4,68 @@
#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 = {
.name = THR_NAME_NORTH,
.tid = RT_NULL,
.name = THRED_NAME_NORTH,
.tty = RT_NULL,
.rx_len = 0,
};
static void chrg_north_entry (void *data)
static void chrg_north_thread_entry (void *data)
{
rt_err_t ret = RT_EOK;
struct chrg_north_t *pNOR = (struct chrg_north_t *)data;
if (RT_NULL == pNOR) {
if ((RT_NULL == pNOR)||(RT_NULL == pNOR->tty)) {
return ;
}
char *str = RT_NULL;
rt_uint8_t ch;
struct chrg_tty_t *pTTY = pNOR->tty;
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);
ret = rt_sem_take(&pTTY->sem_rx, RT_WAITING_FOREVER);
if (RT_EOK != ret) {
LOG_E("sem take failed. %d", ret);
continue;
}
//rt_thread_mdelay(1000);
rt_ringbuffer_getchar(pTTY->rb, &ch);
if (pNOR->rx_len < SIZE_BUF_UART) {
pNOR->rx_buf[pNOR->rx_len++] = ch;
rt_kprintf("%c", ch);
}
if (pNOR->rx_len >= 32) {
pNOR->rx_len = 0;
}
}
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->tty = &chrgtty[IDX_TTY_NORTH];
rt_memset(pNOR->rx_buf, 0, SIZE_BUF_UART);
ret = rt_mutex_init(&pNOR->lock, pNOR->name, RT_IPC_FLAG_FIFO);
if (ret != RT_EOK) {
LOG_E("init mutex '%s' failed.", pNOR->name);
return ret;
}
pNOR->tid = rt_thread_create(pNOR->name, chrg_north_entry, pNOR,
4096, RT_MAIN_THREAD_PRIORITY, 10);
pNOR->tid = rt_thread_create(pNOR->name, chrg_north_thread_entry, pNOR, 4096,
RT_MAIN_THREAD_PRIORITY, 20);
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;
LOG_E("create thread '%s' failed.", pNOR->name);
}
return 0;
@@ -65,3 +75,21 @@ static int chrg_north_init (void)
INIT_APP_EXPORT(chrg_north_init);
static int north_send(rt_uint8_t argc, char **argv)
{
rt_ssize_t ret = 0;
struct chrg_north_t *pNOR = &chrgnor;
struct chrg_tty_t *pTTY = pNOR->tty;
if (RT_NULL != pTTY->dev) {
ret = rt_device_write(pTTY->dev, 0, "1234567890abcdef", 16);
}
return ret;
}
MSH_CMD_EXPORT(north_send, north send test);