From 1d9dc814c6ad1e9e4c06e9b212c116716985b14e Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Thu, 2 Apr 2009 13:49:08 +0400 Subject: [PATCH 1/3] Make RX fifo size configurable. To: address@hidden X-KMail-Transport: CodeSourcery X-KMail-Identity: 901867920 --- hw/sh_serial.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/sh_serial.c b/hw/sh_serial.c index 4957c41..cb7c9d1 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,7 +235,7 @@ 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) s->flags &= ~SH_SERIAL_FLAG_RDF; @@ -297,9 +296,9 @@ 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) { @@ -393,6 +392,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