MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / finsh_getchar

Function finsh_getchar

components/finsh/shell.c:157–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157int finsh_getchar(void)
158{
159#ifdef RT_USING_DEVICE
160 char ch = 0;
161#ifdef RT_USING_POSIX_STDIO
162 if(read(rt_posix_stdio_get_console(), &ch, 1) > 0)
163 {
164 return ch;
165 }
166 else
167 {
168 return -1; /* EOF */
169 }
170#else
171 rt_device_t device;
172
173 RT_ASSERT(shell != RT_NULL);
174
175 device = shell->device;
176 if (device == RT_NULL)
177 {
178 return -1; /* EOF */
179 }
180
181 while (rt_device_read(device, -1, &ch, 1) != 1)
182 {
183 rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
184 if (shell->device != device)
185 {
186 device = shell->device;
187 if (device == RT_NULL)
188 {
189 return -1;
190 }
191 }
192 }
193 return ch;
194#endif /* RT_USING_POSIX_STDIO */
195#else
196 extern signed char rt_hw_console_getchar(void);
197 return rt_hw_console_getchar();
198#endif /* RT_USING_DEVICE */
199}
200
201#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
202static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)

Callers 5

finsh_wait_authFunction · 0.85
finsh_thread_entryFunction · 0.85
ifFunction · 0.85
rt_serial_controlFunction · 0.85
rt_serial_controlFunction · 0.85

Calls 5

rt_device_readFunction · 0.85
rt_sem_takeFunction · 0.85
readFunction · 0.50
rt_hw_console_getcharFunction · 0.50

Tested by

no test coverage detected