diff options
-rw-r--r-- | openpcd/firmware/src/fifo.c | 17 | ||||
-rw-r--r-- | openpcd/firmware/src/fifo.h | 23 | ||||
-rw-r--r-- | openpcd/firmware/src/pio_irq.h | 4 | ||||
-rw-r--r-- | openpcd/firmware/src/rc632.c | 13 |
4 files changed, 37 insertions, 20 deletions
diff --git a/openpcd/firmware/src/fifo.c b/openpcd/firmware/src/fifo.c index 0c7ac6c..3772187 100644 --- a/openpcd/firmware/src/fifo.c +++ b/openpcd/firmware/src/fifo.c @@ -1,20 +1,9 @@ +/* Implementation of a virtual FIFO */ + +#include "fifo.h" #define FIFO_SIZE 1024 -/* virtual FIFO */ - -struct fifo { - u_int16_t size; /* actual FIFO size, can be smaller than 'data' */ - u_int16_t producer; /* index of producer */ - u_int16_t consumer; /* index of consumer */ - u_int16_t watermark; - u_int8_t irq; - u_int8_t irq_en; - u_int8_t status; - void (*callback)(struct fifo *fifo, u_int8_t event, void *data); - void *cb_data; - u_int8_t data[FIFO_SIZE]; -}; #define FIFO_IRQ_LO 0x01 #define FIFO_IRQ_HI 0x02 diff --git a/openpcd/firmware/src/fifo.h b/openpcd/firmware/src/fifo.h new file mode 100644 index 0000000..68430ee --- /dev/null +++ b/openpcd/firmware/src/fifo.h @@ -0,0 +1,23 @@ +#ifndef _FIFO_H +#define _FIFO_H + +struct fifo { + u_int16_t size; /* actual FIFO size, can be smaller than 'data' */ + u_int16_t producer; /* index of producer */ + u_int16_t consumer; /* index of consumer */ + u_int16_t watermark; + u_int8_t irq; + u_int8_t irq_en; + u_int8_t status; + void (*callback)(struct fifo *fifo, u_int8_t event, void *data); + void *cb_data; + u_int8_t data[FIFO_SIZE]; +}; + + +extern int fifo_init(struct fifo *fifo, u_int16_t size, void *cb_data); +extern u_int16_t fifo_data_get(struct fifo *fifo, u_int16_t len, u_int8_t *data); +extern u_int16_t fifo_data_put(struct fifo *fifo, u_int16_t len, u_int8_t *data); +extern int fifo_available(struct fifo *fifo); + +#endif diff --git a/openpcd/firmware/src/pio_irq.h b/openpcd/firmware/src/pio_irq.h index a71ed75..ecb1a2c 100644 --- a/openpcd/firmware/src/pio_irq.h +++ b/openpcd/firmware/src/pio_irq.h @@ -1,3 +1,5 @@ +#ifndef _PIO_IRQ_H +#define _PIO_IRQ_H typedef irq_handler_t (void)(u_int32_t pio); @@ -7,3 +9,5 @@ extern void pio_irq_enable(u_int32_t pio); extern void pio_irq_disable(u_int32_t pio); extern int pio_irq_register(u_int32_t pio, irq_handler_t func); extern void pio_irq_unregister(u_int32_t pio); + +#endif diff --git a/openpcd/firmware/src/rc632.c b/openpcd/firmware/src/rc632.c index 6c83182..422815d 100644 --- a/openpcd/firmware/src/rc632.c +++ b/openpcd/firmware/src/rc632.c @@ -3,6 +3,7 @@ * * */ +#include "fifo.h" #include "pio_irq.h" static void spi_irq(void) @@ -29,12 +30,12 @@ struct rc632 { /* RC632 access primitives */ -void rc632_write_reg(u_int8_t addr, u_int8_t data) +void rc632_reg_write(u_int8_t addr, u_int8_t data) { addr = (addr << 1) & 0x7e; } -void rc632_write_fifo(u_int8_t len, u_int8_t *data) +void rc632_fifo_write(u_int8_t len, u_int8_t *data) { if (len > sizeof(spi_outbuf)-1) len = sizeof(spi_outbuf)-1; @@ -47,12 +48,12 @@ void rc632_write_fifo(u_int8_t len, u_int8_t *data) return len; } -u_int8_t rc632_read_reg(u_int8_t addr) +u_int8_t rc632_reg_read(u_int8_t addr) { addr = (addr << 1) & 0x7e; } -u_int8_t rc632_read_fifo(u_int8_t max_len, u_int8_t *data) +u_int8_t rc632_fifo_read(u_int8_t max_len, u_int8_t *data) { u_int8_t fifo_length = rc632_reg_read(RC632_REG_FIFO_LENGTH); u_int8_t i; @@ -74,10 +75,10 @@ u_int8_t rc632_read_fifo(u_int8_t max_len, u_int8_t *data) static void rc632_irq(void) { /* CL RC632 has interrupted us */ - u_int8_t cause = rc632_read_reg(RC632_REG_INTERRUPT_RQ); + u_int8_t cause = rc632_reg_read(RC632_REG_INTERRUPT_RQ); /* ACK all interrupts */ - rc632_write_reg(RC632_REG_INTERRUPT_RQ, cause); + rc632_reg_write(RC632_REG_INTERRUPT_RQ, cause); if (cause & RC632_INT_LOALERT) { /* FIFO is getting low, refill from virtual FIFO */ |