2424
2525#ifdef RT_USING_FINSH
2626
27+ #include <rtdef.h>
28+ #include <rtdevice.h>
2729#include "shell.h"
2830#include "msh.h"
2931
@@ -177,7 +179,8 @@ int finsh_getchar(void)
177179 {
178180 return -1 ; /* EOF */
179181 }
180-
182+ /* Temporarily retain the distinction */
183+ #ifndef RT_USING_SERIAL_V2
181184 while (rt_device_read (device , -1 , & ch , 1 ) != 1 )
182185 {
183186 rt_sem_take (& shell -> rx_sem , RT_WAITING_FOREVER );
@@ -190,6 +193,19 @@ int finsh_getchar(void)
190193 }
191194 }
192195 }
196+ #else
197+ while (rt_device_read (device , -1 , & ch , 1 ) != 1 )
198+ {
199+ if (shell -> device != device )
200+ {
201+ device = shell -> device ;
202+ if (device == RT_NULL )
203+ {
204+ return -1 ;
205+ }
206+ }
207+ }
208+ #endif
193209 return ch ;
194210#endif /* RT_USING_POSIX_STDIO */
195211#else
@@ -199,6 +215,7 @@ int finsh_getchar(void)
199215}
200216
201217#if !defined(RT_USING_POSIX_STDIO ) && defined(RT_USING_DEVICE )
218+ #ifndef RT_USING_SERIAL_V2
202219static rt_err_t finsh_rx_ind (rt_device_t dev , rt_size_t size )
203220{
204221 RT_ASSERT (shell != RT_NULL );
@@ -208,6 +225,7 @@ static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
208225
209226 return RT_EOK ;
210227}
228+ #endif
211229
212230/**
213231 * @ingroup group_finsh
@@ -231,8 +249,13 @@ void finsh_set_device(const char *device_name)
231249 /* check whether it's a same device */
232250 if (dev == shell -> device ) return ;
233251 /* open this device and set the new device in finsh shell */
252+ #ifndef RT_USING_SERIAL_V2
234253 if (rt_device_open (dev , RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
235254 RT_DEVICE_FLAG_STREAM ) == RT_EOK )
255+ #else
256+ if (rt_device_open (dev , RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | \
257+ RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_STREAM ) == RT_EOK )
258+ #endif
236259 {
237260 if (shell -> device != RT_NULL )
238261 {
@@ -246,7 +269,12 @@ void finsh_set_device(const char *device_name)
246269 shell -> line_curpos = shell -> line_position = 0 ;
247270
248271 shell -> device = dev ;
272+ #ifndef RT_USING_SERIAL_V2
249273 rt_device_set_rx_indicate (dev , finsh_rx_ind );
274+ #else
275+ rt_int32_t rx_timeout = RT_WAITING_FOREVER ;
276+ rt_device_control (dev , RT_SERIAL_CTRL_SET_RX_TIMEOUT , (void * )& rx_timeout );
277+ #endif
250278 }
251279}
252280
@@ -924,7 +952,10 @@ int finsh_system_init(void)
924952 FINSH_THREAD_PRIORITY , 10 );
925953#endif /* RT_USING_HEAP */
926954
955+ #ifndef RT_USING_SERIAL_V2
927956 rt_sem_init (& (shell -> rx_sem ), "shrx" , 0 , 0 );
957+ #endif
958+
928959 finsh_set_prompt_mode (1 );
929960
930961 if (tid != NULL && result == RT_EOK )
0 commit comments