From 8e9e7f3e7c14f9a34124c4a173d14734b4bf2faf Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 12 May 2013 14:03:11 +0800 Subject: [PATCH] serial: use RT_SERIAL_RB_BUFSZ to define the size of ring buffer. --- components/drivers/include/drivers/serial.h | 14 ++++++++------ components/drivers/serial/serial.c | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/components/drivers/include/drivers/serial.h b/components/drivers/include/drivers/serial.h index b10dbe57d6..edf05cfa1d 100644 --- a/components/drivers/include/drivers/serial.h +++ b/components/drivers/include/drivers/serial.h @@ -10,7 +10,9 @@ * Change Logs: * Date Author Notes * 2012-05-15 lgnq first version. - * 2012-05-28 bernard chage interfaces + * 2012-05-28 bernard change interfaces + * 2013-02-20 bernard use RT_SERIAL_RB_BUFSZ to define + * the size of ring buffer. */ #ifndef __SERIAL_H__ @@ -43,9 +45,9 @@ #define NRZ_NORMAL 0 /* Non Return to Zero : normal mode */ #define NRZ_INVERTED 1 /* Non Return to Zero : inverted mode */ -#define UART_RX_BUFFER_SIZE 64 -#define UART_TX_BUFFER_SIZE 64 -#define SERIAL_RBUFFER_SIZE 64 +#ifndef RT_SERIAL_RB_BUFSZ +#define RT_SERIAL_RB_BUFSZ 64 +#endif #define RT_DEVICE_CTRL_CONFIG 0x03 /* configure device */ #define RT_DEVICE_CTRL_SET_INT 0x10 /* enable receive irq */ @@ -59,7 +61,7 @@ #define RT_SERIAL_ERR_FRAMING 0x02 #define RT_SERIAL_ERR_PARITY 0x03 -#define RT_SERIAL_TX_DATAQUEUE_SIZE 40 +#define RT_SERIAL_TX_DATAQUEUE_SIZE 2048 #define RT_SERIAL_TX_DATAQUEUE_LWM 30 /* Default config for serial_configure structure */ @@ -76,7 +78,7 @@ struct serial_ringbuffer { - rt_uint8_t buffer[SERIAL_RBUFFER_SIZE]; + rt_uint8_t buffer[RT_SERIAL_RB_BUFSZ]; rt_uint16_t put_index, get_index; }; diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index f73325a440..d202dcc565 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -13,6 +13,8 @@ * 2012-05-15 lgnq modified according bernard's implementation. * 2012-05-28 bernard code cleanup * 2012-11-23 bernard fix compiler warning. + * 2013-02-20 bernard use RT_SERIAL_RB_BUFSZ to define + * the size of ring buffer. */ #include @@ -35,12 +37,12 @@ rt_inline void serial_ringbuffer_putc(struct serial_ringbuffer *rbuffer, level = rt_hw_interrupt_disable(); rbuffer->buffer[rbuffer->put_index] = ch; - rbuffer->put_index = (rbuffer->put_index + 1) & (SERIAL_RBUFFER_SIZE - 1); + rbuffer->put_index = (rbuffer->put_index + 1) & (RT_SERIAL_RB_BUFSZ - 1); /* if the next position is read index, discard this 'read char' */ if (rbuffer->put_index == rbuffer->get_index) { - rbuffer->get_index = (rbuffer->get_index + 1) & (SERIAL_RBUFFER_SIZE - 1); + rbuffer->get_index = (rbuffer->get_index + 1) & (RT_SERIAL_RB_BUFSZ - 1); } /* enable interrupt */ @@ -56,7 +58,7 @@ rt_inline int serial_ringbuffer_putchar(struct serial_ringbuffer *rbuffer, /* disable interrupt */ level = rt_hw_interrupt_disable(); - next_index = (rbuffer->put_index + 1) & (SERIAL_RBUFFER_SIZE - 1); + next_index = (rbuffer->put_index + 1) & (RT_SERIAL_RB_BUFSZ - 1); if (next_index != rbuffer->get_index) { rbuffer->buffer[rbuffer->put_index] = ch; @@ -87,7 +89,7 @@ rt_inline int serial_ringbuffer_getc(struct serial_ringbuffer *rbuffer) if (rbuffer->get_index != rbuffer->put_index) { ch = rbuffer->buffer[rbuffer->get_index]; - rbuffer->get_index = (rbuffer->get_index + 1) & (SERIAL_RBUFFER_SIZE - 1); + rbuffer->get_index = (rbuffer->get_index + 1) & (RT_SERIAL_RB_BUFSZ - 1); } /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -101,7 +103,7 @@ rt_inline rt_uint32_t serial_ringbuffer_size(struct serial_ringbuffer *rbuffer) rt_base_t level; level = rt_hw_interrupt_disable(); - size = (rbuffer->put_index - rbuffer->get_index) & (SERIAL_RBUFFER_SIZE - 1); + size = (rbuffer->put_index - rbuffer->get_index) & (RT_SERIAL_RB_BUFSZ - 1); rt_hw_interrupt_enable(level); return size;