Merge pull request #86 from grissiom/serial-rb-size

serial: use RT_SERIAL_RB_BUFSZ to define the size of ring buffer.
This commit is contained in:
Bernard Xiong 2013-05-11 23:18:18 -07:00
commit f1e34eef11
2 changed files with 15 additions and 11 deletions

View File

@ -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;
};

View File

@ -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 <rthw.h>
@ -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;