From c9335797806ab006bca95b3749dfcb4ff0c1772c Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Thu, 2 Apr 2009 13:49:08 +0400 Subject: [PATCH 1/6] Make RX fifo size configurable. Signed-off-by: Vladimir Prus --- hw/sh_serial.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/sh_serial.c b/hw/sh_serial.c index 4957c41..7fefaa6 100644 --- a/hw/sh_serial.c +++ b/hw/sh_serial.c @@ -37,8 +37,6 @@ #define SH_SERIAL_FLAG_BRK (1 << 3) #define SH_SERIAL_FLAG_DR (1 << 4) -#define SH_RX_FIFO_LENGTH (16) - typedef struct { uint8_t smr; uint8_t brr; @@ -48,10 +46,11 @@ typedef struct { uint16_t fcr; uint8_t sptr; - uint8_t rx_fifo[SH_RX_FIFO_LENGTH]; /* frdr / rdr */ + uint8_t *rx_fifo; /* frdr / rdr */ uint8_t rx_cnt; uint8_t rx_tail; uint8_t rx_head; + int rx_capacity; int freq; int feat; @@ -69,7 +68,7 @@ typedef struct { static void sh_serial_clear_fifo(sh_serial_state * s) { - memset(s->rx_fifo, 0, SH_RX_FIFO_LENGTH); + memset(s->rx_fifo, 0, s->rx_capacity); s->rx_cnt = 0; s->rx_head = 0; s->rx_tail = 0; @@ -236,10 +235,12 @@ static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs) if (s->rx_cnt > 0) { ret = s->rx_fifo[s->rx_tail++]; s->rx_cnt--; - if (s->rx_tail == SH_RX_FIFO_LENGTH) + if (s->rx_tail == s->rx_capacity) { s->rx_tail = 0; - if (s->rx_cnt < s->rtrg) + } + if (s->rx_cnt < s->rtrg) { s->flags &= ~SH_SERIAL_FLAG_RDF; + } } break; #if 0 @@ -297,10 +298,11 @@ static int sh_serial_can_receive(sh_serial_state *s) static void sh_serial_receive_byte(sh_serial_state *s, int ch) { if (s->feat & SH_SERIAL_FEAT_SCIF) { - if (s->rx_cnt < SH_RX_FIFO_LENGTH) { + if (s->rx_cnt < s->rx_capacity) { s->rx_fifo[s->rx_head++] = ch; - if (s->rx_head == SH_RX_FIFO_LENGTH) + if (s->rx_head == s->rx_capacity) { s->rx_head = 0; + } s->rx_cnt++; if (s->rx_cnt >= s->rtrg) { s->flags |= SH_SERIAL_FLAG_RDF; @@ -393,6 +395,8 @@ void sh_serial_init (target_phys_addr_t base, int feat, s->dr = 0xff; } + s->rx_capacity = 16; + s->rx_fifo = (uint8_t *)malloc(s->rx_capacity); sh_serial_clear_fifo(s); s_io_memory = cpu_register_io_memory(0, sh_serial_readfn, -- 1.6.2.1