X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Fser_dsp56k.c;h=ce865b996ad8c1943b07e568404b22645b0c9f59;hb=5f3952176a4e9a00ca8dd5ec4a6b994958f89e0a;hp=efdb2e2bcc0a899526736d6782266fde753f02d6;hpb=0c26c885fbf3ab9b731e4733eff7713d3980b1ea;p=bertos.git diff --git a/drv/ser_dsp56k.c b/drv/ser_dsp56k.c old mode 100755 new mode 100644 index efdb2e2b..ce865b99 --- a/drv/ser_dsp56k.c +++ b/drv/ser_dsp56k.c @@ -1,8 +1,8 @@ -/*! +/** * \file * * * \version $Id$ @@ -15,6 +15,27 @@ /*#* *#* $Log$ + *#* Revision 1.14 2006/07/19 12:56:26 bernie + *#* Convert to new Doxygen style. + *#* + *#* Revision 1.13 2005/11/04 16:20:02 bernie + *#* Fix reference to README.devlib in header. + *#* + *#* Revision 1.12 2005/04/11 19:10:27 bernie + *#* Include top-level headers from cfg/ subdir. + *#* + *#* Revision 1.11 2005/01/25 07:42:04 bernie + *#* Simplify. + *#* + *#* Revision 1.10 2005/01/14 00:48:33 aleph + *#* Rename callbacks; SerialHardwareVT.txSending: New callback. + *#* + *#* Revision 1.9 2004/12/08 09:42:55 bernie + *#* Add support for multiplexed serial ports. + *#* + *#* Revision 1.8 2004/10/26 09:00:49 bernie + *#* Don't access serial data register twice. + *#* *#* Revision 1.7 2004/10/19 08:57:15 bernie *#* Bugfixes for DSP56K serial driver from scfirm. *#* @@ -34,14 +55,18 @@ #include "ser.h" #include "ser_p.h" #include -#include +#include #include #include // GPIO E is shared with SPI (in DSP56807). Pins 0&1 are TXD0 and RXD0. To use // the serial, we need to disable the GPIO functions on them. -#define REG_GPIO_SERIAL REG_GPIO_E -#define REG_GPIO_SERIAL_MASK 0x3 +#define REG_GPIO_SERIAL_0 REG_GPIO_E +#define REG_GPIO_SERIAL_MASK_0 0x03 + +#define REG_GPIO_SERIAL_1 REG_GPIO_D +#define REG_GPIO_SERIAL_MASK_1 0xC0 + // Check flag consistency #if (SERRF_PARITYERROR != REG_SCI_SR_PF) || \ @@ -56,6 +81,15 @@ static unsigned char ser0_fifo_tx[CONFIG_SER0_FIFOSIZE_TX]; static unsigned char ser1_fifo_rx[CONFIG_SER1_FIFOSIZE_RX]; static unsigned char ser1_fifo_tx[CONFIG_SER1_FIFOSIZE_TX]; +#if CONFIG_SER_MULTI + #include + + #define MAX_MULTI_GROUPS 1 + + struct Semaphore multi_sems[MAX_MULTI_GROUPS]; +#endif + + struct SCI { struct SerialHardware hw; @@ -63,6 +97,8 @@ struct SCI volatile struct REG_SCI_STRUCT* regs; IRQ_VECTOR irq_tx; IRQ_VECTOR irq_rx; + int num_group; + int id; }; static inline void enable_tx_irq_bare(volatile struct REG_SCI_STRUCT* regs) @@ -88,25 +124,36 @@ static inline void disable_rx_irq_bare(volatile struct REG_SCI_STRUCT* regs) static inline void disable_tx_irq(struct SerialHardware* _hw) { struct SCI* hw = (struct SCI*)_hw; - volatile struct REG_SCI_STRUCT* regs = hw->regs; - disable_tx_irq_bare(regs); + disable_tx_irq_bare(hw->regs); +} + +static inline void disable_rx_irq(struct SerialHardware* _hw) +{ + struct SCI* hw = (struct SCI*)_hw; + + disable_rx_irq_bare(hw->regs); } static inline void enable_tx_irq(struct SerialHardware* _hw) { struct SCI* hw = (struct SCI*)_hw; - volatile struct REG_SCI_STRUCT* regs = hw->regs; - enable_tx_irq_bare(regs); + enable_tx_irq_bare(hw->regs); } static inline void enable_rx_irq(struct SerialHardware* _hw) { struct SCI* hw = (struct SCI*)_hw; - volatile struct REG_SCI_STRUCT* regs = hw->regs; - enable_rx_irq_bare(regs); + enable_rx_irq_bare(hw->regs); +} + +static inline bool tx_irq_enabled(struct SerialHardware* _hw) +{ + struct SCI* hw = (struct SCI*)_hw; + + return (hw->regs->CR & REG_SCI_CR_TEIE); } static void tx_isr(const struct SCI *hw) @@ -146,10 +193,10 @@ static void rx_isr(const struct SCI *hw) unsigned char data = regs->DR; if (fifo_isfull(&hw->serial->rxfifo)) - if (fifo_isfull(&hw->serial->rxfifo)) - hw->serial->status |= SERRF_RXFIFOOVERRUN; - else - fifo_push(&hw->serial->rxfifo, regs->DR); + hw->serial->status |= SERRF_RXFIFOOVERRUN; + else + fifo_push(&hw->serial->rxfifo, data); + } // Writing anything to the status register clear the error bits. regs->SR = 0; @@ -178,15 +225,22 @@ static void init(struct SerialHardware* _hw, struct Serial* ser) enable_rx_irq_bare(regs); // Disable GPIO pins for TX and RX lines - REG_GPIO_SERIAL->PER |= REG_GPIO_SERIAL_MASK; + // \todo this should be divided into serial 0 and 1 + REG_GPIO_SERIAL_0->PER |= REG_GPIO_SERIAL_MASK_0; + REG_GPIO_SERIAL_1->PER |= REG_GPIO_SERIAL_MASK_1; hw->serial = ser; } static void cleanup(struct SerialHardware* _hw) { - // TODO! - ASSERT(0); + struct SCI* hw = (struct SCI*)_hw; + + // Uninstall the ISRs + disable_rx_irq(_hw); + disable_tx_irq(_hw); + irq_uninstall(hw->irq_tx); + irq_uninstall(hw->irq_rx); } static void setbaudrate(struct SerialHardware* _hw, unsigned long rate) @@ -206,49 +260,121 @@ static void setparity(struct SerialHardware* _hw, int parity) } -static const struct SerialHardwareVT SCI_VT = +#if CONFIG_SER_MULTI + +static void multi_init(void) +{ + static bool flag = false; + int i; + + if (flag) + return; + + for (i = 0; i < MAX_MULTI_GROUPS; ++i) + sem_init(&multi_sems[i]); + flag = true; +} + +static void init_lock(struct SerialHardware* _hw, struct Serial *ser) +{ + struct SCI* hw = (struct SCI*)_hw; + + // Initialize the multi engine (if needed) + multi_init(); + + // Acquire the lock of the semaphore for this group + ASSERT(hw->num_group >= 0); + ASSERT(hw->num_group < MAX_MULTI_GROUPS); + sem_obtain(&multi_sems[hw->num_group]); + + // Do a hardware switch to the given serial + ser_hw_switch(hw->num_group, hw->id); + + init(_hw, ser); +} + +static void cleanup_unlock(struct SerialHardware* _hw) +{ + struct SCI* hw = (struct SCI*)_hw; + + cleanup(_hw); + + sem_release(&multi_sems[hw->num_group]); +} + +#endif /* CONFIG_SER_MULTI */ + + +static const struct SerialHardwareVT SCI_VT = { .init = init, .cleanup = cleanup, - .setbaudrate = setbaudrate, - .setparity = setparity, - .enabletxirq = enable_tx_irq, + .setBaudrate = setbaudrate, + .setParity = setparity, + .txStart = enable_tx_irq, + .txSending = tx_irq_enabled, }; -static struct SCI SCIDescs[2] = +#if CONFIG_SER_MULTI +static const struct SerialHardwareVT SCI_MULTI_VT = { - { - .hw = - { - .table = &SCI_VT, - .rxbuffer = ser0_fifo_rx, - .txbuffer = ser0_fifo_tx, - .rxbuffer_size = countof(ser0_fifo_rx), - .txbuffer_size = countof(ser0_fifo_tx), - }, - .regs = ®_SCI[0], - .irq_rx = IRQ_SCI0_RECEIVER_FULL, - .irq_tx = IRQ_SCI0_TRANSMITTER_READY, - }, - - { - .hw = - { - .table = &SCI_VT, - .rxbuffer = ser1_fifo_rx, - .txbuffer = ser1_fifo_tx, - .rxbuffer_size = countof(ser1_fifo_rx), - .txbuffer_size = countof(ser1_fifo_tx), - }, - .regs = ®_SCI[1], - .irq_rx = IRQ_SCI1_RECEIVER_FULL, - .irq_tx = IRQ_SCI1_TRANSMITTER_READY, - }, + .init = init_lock, + .cleanup = cleanup_unlock, + .setBaudrate = setbaudrate, + .setParity = setparity, + .txStart = enable_tx_irq, + .txSending = tx_irq_enabled, +}; +#endif /* CONFIG_SER_MULTI */ + +#define SCI_DESC_NORMAL(hwch) \ + { \ + .hw = \ + { \ + .table = &SCI_VT, \ + .rxbuffer = ser ## hwch ## _fifo_rx, \ + .txbuffer = ser ## hwch ## _fifo_tx, \ + .rxbuffer_size = countof(ser ## hwch ## _fifo_rx), \ + .txbuffer_size = countof(ser ## hwch ## _fifo_tx), \ + }, \ + .regs = ®_SCI[hwch], \ + .irq_rx = IRQ_SCI ## hwch ## _RECEIVER_FULL, \ + .irq_tx = IRQ_SCI ## hwch ## _TRANSMITTER_READY, \ + .num_group = -1, \ + .id = -1, \ + } \ + /**/ + +#if CONFIG_SER_MULTI +#define SCI_DESC_MULTI(hwch, group_, id_) \ + { \ + .hw = \ + { \ + .table = &SCI_MULTI_VT, \ + .rxbuffer = ser ## hwch ## _fifo_rx, \ + .txbuffer = ser ## hwch ## _fifo_tx, \ + .rxbuffer_size = countof(ser ## hwch ## _fifo_rx), \ + .txbuffer_size = countof(ser ## hwch ## _fifo_tx), \ + }, \ + .regs = ®_SCI[hwch], \ + .irq_rx = IRQ_SCI ## hwch ## _RECEIVER_FULL, \ + .irq_tx = IRQ_SCI ## hwch ## _TRANSMITTER_READY, \ + .num_group = group_, \ + .id = id_, \ + } \ + /**/ +#endif /* CONFIG_SER_MULTI */ + +// \todo Move this into hw.h, with a little preprocessor magic +static struct SCI SCIDescs[] = +{ + SCI_DESC_NORMAL(0), + SCI_DESC_MULTI(1, 0, 0), + SCI_DESC_MULTI(1, 0, 1), }; - struct SerialHardware* ser_hw_getdesc(int unit) { - ASSERT(unit < 2); + ASSERT(unit < countof(SCIDescs)); return &SCIDescs[unit].hw; }