add parse threads

This commit is contained in:
wmano
2025-10-25 23:44:23 +08:00
parent d52c94b866
commit 604fe4688c
38 changed files with 1597 additions and 956 deletions
+14 -39
View File
@@ -25,9 +25,7 @@ rt_uint16_t usSRegHoldBuf[S_REG_HOLDING_NREGS];
struct chrg_comm_t chrgcomm = {
.name = THR_NAME_COMM,
.devname = DEV_NAME_COMM,
.tid = RT_NULL,
.tty = RT_NULL,
.rx_len = 0,
.tx_len = 0,
@@ -663,16 +661,23 @@ static int chrg_comm_parse_msg (struct chrg_comm_t *pCOMM)
return ret;
}
static void chrg_comm_thread_entry (void *data)
void chrg_comm_thread_entry (void *data)
{
struct chrg_comm_t *pCOMM = (struct chrg_comm_t *)data;
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
if ((RT_NULL == pCOMM)||(RT_NULL == pCOMM->tty)) {
if (RT_NULL == pTHR) {
return ;
}
int len = 0;
struct chrg_tty_t *pTTY = pCOMM->tty;
struct chrg_tty_t *pTTY = RT_NULL;
struct chrg_comm_t *pCOMM = &chrgcomm;
pTTY = chrg_tty_create(pCOMM->devname, BAUD_RATE_115200, 0, 8, 1);
if (RT_NULL == pTTY) {
LOG_E("tty can't create.");
return ;
}
chrg_tty_set_recv_tmo(pTTY, 8);
if (chrg_tty_connect(pTTY) != RT_EOK) {
@@ -681,8 +686,10 @@ static void chrg_comm_thread_entry (void *data)
}
chrg_tty_mode_set(pTTY, 0);
pCOMM->tty = pTTY;
while (1) {
memset(pCOMM->rx_buf, 0, sizeof(pCOMM->rx_buf));
rt_memset(pCOMM->rx_buf, 0, sizeof(pCOMM->rx_buf));
len = chrg_tty_recv(pTTY, pCOMM->rx_buf, sizeof(pCOMM->rx_buf));
if (len <= 0) {
rt_thread_mdelay(1);
@@ -696,39 +703,7 @@ static void chrg_comm_thread_entry (void *data)
}
static int chrg_comm_init (void)
{
rt_err_t ret = RT_EOK;
struct chrg_comm_t *pCOMM = &chrgcomm;
pCOMM->tty = chrg_tty_create(pCOMM->devname, 115200, 0, 8, 1);
if (RT_NULL == pCOMM->tty) {
LOG_E("tty can't create.");
return -1;
}
rt_memset(pCOMM->rx_buf, 0, SIZE_BUF_TTY);
ret = rt_mutex_init(&pCOMM->lock, pCOMM->name, RT_IPC_FLAG_FIFO);
if (ret != RT_EOK) {
LOG_E("init mutex '%s' failed.", pCOMM->name);
return ret;
}
pCOMM->tid = rt_thread_create(pCOMM->name, chrg_comm_thread_entry, pCOMM, 4096,
RT_MAIN_THREAD_PRIORITY, 20);
if (RT_NULL != pCOMM->tid) {
rt_thread_startup(pCOMM->tid);
} else {
LOG_E("create thread '%s' failed.", pCOMM->name);
}
return 0;
}
INIT_APP_EXPORT(chrg_comm_init);