@@ -41,7 +41,11 @@ rt_err_t rt_serial_bypass_init(struct rt_serial_device* serial)
4141{
4242 serial -> bypass = rt_malloc (sizeof (struct rt_serial_bypass ));
4343 rt_memset (serial -> bypass , 0 , sizeof (struct rt_serial_bypass ));
44+ #ifdef RT_USING_SERIAL_V2
45+ serial -> bypass -> pipe = rt_ringbuffer_create (serial -> config .rx_bufsz );
46+ #else
4447 serial -> bypass -> pipe = rt_ringbuffer_create (serial -> config .bufsz );
48+ #endif
4549 serial -> bypass -> mutex = rt_mutex_create ("serial_bypass" , RT_IPC_FLAG_FIFO );
4650
4751 return RT_EOK ;
@@ -140,6 +144,22 @@ static inline rt_err_t _bypass_getchar_form_serial_fifo(struct rt_serial_device*
140144 level = rt_spin_lock_irqsave (& (serial -> spinlock ));
141145
142146 /* there's no data: */
147+ #ifdef RT_USING_SERIAL_V2
148+ rt_size_t ringbuf_date_stat ;
149+ ringbuf_date_stat = rt_ringbuffer_data_len (& rx_fifo -> rb );
150+ if (!ringbuf_date_stat )
151+ {
152+ /* no data, enable interrupt and break out */
153+ rt_spin_unlock_irqrestore (& (serial -> spinlock ), level );
154+ return - RT_EEMPTY ;
155+ }
156+ if (!rt_ringbuffer_getchar (& rx_fifo -> rb , (rt_uint8_t * )ch ))
157+ {
158+ /* Failed to read data */
159+ rt_spin_unlock_irqrestore (& (serial -> spinlock ), level );
160+ return - RT_EOK ;
161+ }
162+ #else
143163 if ((rx_fifo -> get_index == rx_fifo -> put_index ) && (rx_fifo -> is_full == RT_FALSE ))
144164 {
145165 /* no data, enable interrupt and break out */
@@ -156,7 +176,7 @@ static inline rt_err_t _bypass_getchar_form_serial_fifo(struct rt_serial_device*
156176 {
157177 rx_fifo -> is_full = RT_FALSE ;
158178 }
159-
179+ #endif
160180 /* enable interrupt */
161181 rt_spin_unlock_irqrestore (& (serial -> spinlock ), level );
162182
0 commit comments