Skip to content

Commit 04ee7b6

Browse files
committed
Fix smart serial_v2 bypass compile error issue
1 parent 88257a2 commit 04ee7b6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

components/drivers/include/drivers/dev_serial_v2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ struct rt_serial_device
333333

334334
struct rt_spinlock spinlock;
335335

336+
#ifdef RT_USING_SERIAL_BYPASS
337+
struct rt_serial_bypass* bypass;
338+
#endif
336339
struct rt_device_notify rx_notify;
337340
};
338341

components/drivers/include/rtdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ extern "C" {
152152
#include "drivers/dev_serial_v2.h"
153153
#else
154154
#include "drivers/dev_serial.h"
155+
#endif /* RT_USING_SERIAL_V2 */
155156
#ifdef RT_USING_SERIAL_BYPASS
156157
#include "drivers/serial_bypass.h"
157158
#endif /* RT_USING_SERIAL_BYPASS */
158-
#endif
159159
#endif /* RT_USING_SERIAL */
160160

161161
#ifdef RT_USING_I2C

components/drivers/serial/bypass.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)