Skip to content

Commit c5595bd

Browse files
committed
[componnents][finsh] 适配serial_v2提高效率,减少内存占用
1 parent dce06ba commit c5595bd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

components/finsh/shell.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include "shell.h"
2828
#include "msh.h"
2929

30+
#include <rtthread.h>
31+
#include <rtdevice.h>
32+
3033
#ifdef DFS_USING_POSIX
3134
#include <unistd.h>
3235
#include <fcntl.h>
@@ -177,7 +180,8 @@ int finsh_getchar(void)
177180
{
178181
return -1; /* EOF */
179182
}
180-
183+
/* Temporarily retain the distinction */
184+
#ifndef RT_USING_SERIAL_V2
181185
while (rt_device_read(device, -1, &ch, 1) != 1)
182186
{
183187
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
@@ -190,6 +194,19 @@ int finsh_getchar(void)
190194
}
191195
}
192196
}
197+
#else
198+
while (rt_device_read(device, -1, &ch, 1) != 1)
199+
{
200+
if (shell->device != device)
201+
{
202+
device = shell->device;
203+
if (device == RT_NULL)
204+
{
205+
return -1;
206+
}
207+
}
208+
}
209+
#endif
193210
return ch;
194211
#endif /* RT_USING_POSIX_STDIO */
195212
#else
@@ -199,6 +216,7 @@ int finsh_getchar(void)
199216
}
200217

201218
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
219+
#ifndef RT_USING_SERIAL_V2
202220
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
203221
{
204222
RT_ASSERT(shell != RT_NULL);
@@ -208,6 +226,7 @@ static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
208226

209227
return RT_EOK;
210228
}
229+
#endif
211230

212231
/**
213232
* @ingroup group_finsh
@@ -231,8 +250,13 @@ void finsh_set_device(const char *device_name)
231250
/* check whether it's a same device */
232251
if (dev == shell->device) return;
233252
/* open this device and set the new device in finsh shell */
253+
#ifndef RT_USING_SERIAL_V2
234254
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
235255
RT_DEVICE_FLAG_STREAM) == RT_EOK)
256+
#else
257+
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | \
258+
RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_STREAM) == RT_EOK)
259+
#endif
236260
{
237261
if (shell->device != RT_NULL)
238262
{
@@ -246,7 +270,12 @@ void finsh_set_device(const char *device_name)
246270
shell->line_curpos = shell->line_position = 0;
247271

248272
shell->device = dev;
273+
#ifndef RT_USING_SERIAL_V2
249274
rt_device_set_rx_indicate(dev, finsh_rx_ind);
275+
#else
276+
rt_int32_t rx_timeout = RT_WAITING_FOREVER;
277+
rt_device_control(dev, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
278+
#endif
250279
}
251280
}
252281

@@ -924,7 +953,10 @@ int finsh_system_init(void)
924953
FINSH_THREAD_PRIORITY, 10);
925954
#endif /* RT_USING_HEAP */
926955

956+
#ifndef RT_USING_SERIAL_V2
927957
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
958+
#endif
959+
928960
finsh_set_prompt_mode(1);
929961

930962
if (tid != NULL && result == RT_EOK)

components/finsh/shell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ enum input_stat
6060
};
6161
struct finsh_shell
6262
{
63+
#ifndef RT_USING_SERIAL_V2
6364
struct rt_semaphore rx_sem;
65+
#endif
6466

6567
enum input_stat stat;
6668

0 commit comments

Comments
 (0)