2424
2525#ifdef RT_USING_FINSH
2626
27+ #include <rtdevice.h>
2728#include "shell.h"
2829#include "msh.h"
2930
@@ -177,7 +178,8 @@ int finsh_getchar(void)
177178 {
178179 return -1 ; /* EOF */
179180 }
180-
181+ /* Temporarily retain the distinction */
182+ #ifndef RT_USING_SERIAL_V2
181183 while (rt_device_read (device , -1 , & ch , 1 ) != 1 )
182184 {
183185 rt_sem_take (& shell -> rx_sem , RT_WAITING_FOREVER );
@@ -190,6 +192,19 @@ int finsh_getchar(void)
190192 }
191193 }
192194 }
195+ #else
196+ while (rt_device_read (device , -1 , & ch , 1 ) != 1 )
197+ {
198+ if (shell -> device != device )
199+ {
200+ device = shell -> device ;
201+ if (device == RT_NULL )
202+ {
203+ return -1 ;
204+ }
205+ }
206+ }
207+ #endif
193208 return ch ;
194209#endif /* RT_USING_POSIX_STDIO */
195210#else
@@ -199,6 +214,7 @@ int finsh_getchar(void)
199214}
200215
201216#if !defined(RT_USING_POSIX_STDIO ) && defined(RT_USING_DEVICE )
217+ #ifndef RT_USING_SERIAL_V2
202218static rt_err_t finsh_rx_ind (rt_device_t dev , rt_size_t size )
203219{
204220 RT_ASSERT (shell != RT_NULL );
@@ -208,6 +224,7 @@ static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
208224
209225 return RT_EOK ;
210226}
227+ #endif
211228
212229/**
213230 * @ingroup group_finsh
@@ -231,8 +248,13 @@ void finsh_set_device(const char *device_name)
231248 /* check whether it's a same device */
232249 if (dev == shell -> device ) return ;
233250 /* open this device and set the new device in finsh shell */
251+ #ifndef RT_USING_SERIAL_V2
234252 if (rt_device_open (dev , RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
235253 RT_DEVICE_FLAG_STREAM ) == RT_EOK )
254+ #else
255+ if (rt_device_open (dev , RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | \
256+ RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_STREAM ) == RT_EOK )
257+ #endif
236258 {
237259 if (shell -> device != RT_NULL )
238260 {
@@ -246,7 +268,12 @@ void finsh_set_device(const char *device_name)
246268 shell -> line_curpos = shell -> line_position = 0 ;
247269
248270 shell -> device = dev ;
271+ #ifndef RT_USING_SERIAL_V2
249272 rt_device_set_rx_indicate (dev , finsh_rx_ind );
273+ #else
274+ rt_int32_t rx_timeout = RT_WAITING_FOREVER ;
275+ rt_device_control (dev , RT_SERIAL_CTRL_SET_RX_TIMEOUT , (void * )& rx_timeout );
276+ #endif
250277 }
251278}
252279
@@ -924,7 +951,10 @@ int finsh_system_init(void)
924951 FINSH_THREAD_PRIORITY , 10 );
925952#endif /* RT_USING_HEAP */
926953
954+ #ifndef RT_USING_SERIAL_V2
927955 rt_sem_init (& (shell -> rx_sem ), "shrx" , 0 , 0 );
956+ #endif
957+
928958 finsh_set_prompt_mode (1 );
929959
930960 if (tid != NULL && result == RT_EOK )
0 commit comments