tty use mq

This commit is contained in:
wmano
2025-09-03 22:00:08 +08:00
parent 5409d3a614
commit 7b764c34b9
14 changed files with 117 additions and 71 deletions
+29 -11
View File
@@ -3,6 +3,8 @@
#include "chrg_north.h"
#include "chrg_utils.h"
#define LOG_TAG "chrg.nor"
#define DBG_LEVEL DBG_LOG
#include <rtdbg.h>
@@ -29,32 +31,48 @@ int chrg_north_send (rt_uint8_t *data, rt_size_t length)
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)||(RT_NULL == pNOR->tty)) {
return ;
}
rt_uint8_t ch;
rt_uint8_t crc8 = 0;
rt_size_t len_mq = 0, len_get = 0, len_msg = 0;
struct chrg_tty_t *pTTY = pNOR->tty;
struct mq_msg_t *pMQ = &pTTY->msg_mq;
while (1) {
ret = rt_sem_take(&pTTY->sem_rx, RT_WAITING_FOREVER);
if (RT_EOK != ret) {
LOG_E("sem take failed. %d", ret);
rt_memset(pMQ, 0, sizeof(struct mq_msg_t));
len_mq = rt_mq_recv(pTTY->mq, pMQ, sizeof(struct mq_msg_t), RT_WAITING_FOREVER);
if (len_mq <= 0) {
continue;
}
rt_ringbuffer_getchar(pTTY->rb, &ch);
if (pNOR->rx_len < SIZE_BUF_UART) {
pNOR->rx_buf[pNOR->rx_len++] = ch;
rt_kprintf("%c", ch);
len_get = rt_device_read(pMQ->dev, 0, &pNOR->rx_buf[0], 1);
if (1 != len_get) {
continue;
}
if (pNOR->rx_len >= 32) {
pNOR->rx_len = 0;
pNOR->rx_len = 1;
len_msg = rt_device_read(pMQ->dev, 0, &pNOR->rx_buf[1], len_get-1);
if (len_msg <= 0) {
continue;
}
pNOR->rx_len += len_msg;
if (len_msg == len_get-1) {
crc8 = calc_crc8(pNOR->rx_buf, len_msg);
if (crc8 == pNOR->rx_buf[len_msg]) {
pNOR->rx_len = 0;
}
}
}
}