Skip to content

Commit 48f5585

Browse files
committed
remove temporary variables:serial,rt_semphore,change RT_ASSERT()
1 parent 3a6d3c8 commit 48f5585

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

port/TinyFrame_port.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ static rt_err_t uart_input3(rt_device_t dev, rt_size_t size)
4646
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, uint32_t len)
4747
{
4848
TinyFramUserData *tfu = (TinyFramUserData *)tf->userdata;
49-
if (tfu->serial != RT_NULL)
50-
{
51-
rt_device_write(tfu->serial, 0, buff, len);
52-
}
53-
else
54-
{
55-
RT_ASSERT(0);
56-
}
49+
RT_ASSERT(tfu->serial != RT_NULL)
50+
51+
// for (int i = 0; i < len; i++)
52+
// {
53+
// rt_kprintf("%c", buff[i]);
54+
// }
55+
rt_device_write(tfu->serial, 0, buff, len);
5756
}
5857

5958
static void tf_thread_entry(void *parameter)
@@ -68,37 +67,38 @@ static void tf_thread_entry(void *parameter)
6867
{
6968
rt_sem_take(&tfu->rx_sem, RT_WAITING_FOREVER);
7069
}
70+
// rt_kprintf("%c", ch);
7171
TF_Accept(tf, &ch, 1);
7272
TF_Tick(tf);
7373
}
7474
}
7575

7676
static int _tf_uart_init(TinyFrame *tf, TinyFramUserData *tfu, char *uart_name, rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size))
7777
{
78-
rt_device_t serial = RT_NULL;
79-
static struct rt_semaphore *rx_sem = RT_NULL;
8078

79+
tf->userdata = tfu;
8180
/* init sem */
82-
rx_sem = &tfu->rx_sem;
81+
8382
char buf[PKG_TINYFRAME_UART_NAME_MAX_LEN + 6] = {0};
8483
char sem_name[] = "_rx_sem";
8584
memcpy(buf, uart_name, strlen(uart_name) + 1);
8685
strcat(buf, sem_name);
87-
rt_sem_init((rt_sem_t)&rx_sem, buf, 0, RT_IPC_FLAG_FIFO);
86+
rt_kprintf("sem name:%s\n", buf);
87+
rt_sem_init(&tfu->rx_sem, buf, 0, RT_IPC_FLAG_FIFO);
8888

8989
/* init uart */
90-
memcpy(tfu->uart_name, uart_name, strlen(uart_name) + 1);
90+
int uart_len = strlen(uart_name) + 1;
91+
92+
RT_ASSERT(uart_len < PKG_TINYFRAME_UART_NAME_MAX_LEN);
93+
memcpy(tfu->uart_name, uart_name, uart_len);
9194
tfu->serial = rt_device_find(tfu->uart_name);
92-
serial = tfu->serial;
93-
if (serial == RT_NULL)
94-
{
95-
RT_ASSERT(0);
96-
}
97-
rt_device_open(serial, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
9895

99-
rt_device_set_rx_indicate(serial, rx_ind);
96+
RT_ASSERT(tfu->serial != RT_NULL);
97+
98+
rt_device_open(tfu->serial, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
99+
100+
rt_device_set_rx_indicate(tfu->serial, rx_ind);
100101

101-
tf->userdata = tfu;
102102
/* creat thread */
103103
rt_thread_t thread = rt_thread_create("serial", tf_thread_entry, tf, 1024, 25, 10);
104104
if (thread != RT_NULL)

0 commit comments

Comments
 (0)