From 327806d9c3793f6e250c19df053686e200f1c559 Mon Sep 17 00:00:00 2001 From: asterix Date: Fri, 16 Sep 2011 12:34:31 +0000 Subject: [PATCH] Fix fuctions to configure lli dmac. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5056 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/dmac_sam3.c | 38 ++++++++++------------------ bertos/cpu/cortex-m3/drv/dmac_sam3.h | 13 +++++++++- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/bertos/cpu/cortex-m3/drv/dmac_sam3.c b/bertos/cpu/cortex-m3/drv/dmac_sam3.c index d0b8128c..621dc848 100644 --- a/bertos/cpu/cortex-m3/drv/dmac_sam3.c +++ b/bertos/cpu/cortex-m3/drv/dmac_sam3.c @@ -115,23 +115,22 @@ static Event data_ready; static Dmac dmac[DMAC_CHANNEL_CNT]; static uint8_t dmac_ch_enabled; -void dmac_setSourcesLLI(int ch, DmacDesc *lli, uint32_t src, uint32_t dst, uint32_t desc) +void dmac_configureDmacLLI(int ch, DmacDesc *lli, size_t transfer_size, uint32_t cfg, uint32_t ctrla, uint32_t ctrlb) { - ASSERT(lli); DMAC_CHDR = BV(ch); - lli->src_addr = src; - lli->dst_addr = dst; - lli->dsc_addr = desc; + *dmac_ch[ch].cfg = cfg | DMAC_CFG_FIFOCFG_ALAP_CFG | (0x1 << DMAC_CFG_AHB_PROT_SHIFT); + lli->ctrla = ctrla | (transfer_size & DMAC_CTRLA_BTSIZE_MASK); + lli->ctrlb = ctrlb;// & ~BV(DMAC_CTRLB_IEN); + *dmac_ch[ch].desc = (uint32_t)lli; } -void dmac_configureDmacLLI(int ch, DmacDesc *lli, size_t transfer_size, uint32_t cfg, uint32_t ctrla, uint32_t ctrlb) + +void dmac_configureDmaCfgLLI(int ch, DmacDesc *lli, uint32_t cfg) { DMAC_CHDR = BV(ch); *dmac_ch[ch].cfg = cfg | DMAC_CFG_FIFOCFG_ALAP_CFG | (0x1 << DMAC_CFG_AHB_PROT_SHIFT); - lli->ctrla = ctrla | (transfer_size & DMAC_CTRLA_BTSIZE_MASK); - lli->ctrlb = ctrlb & ~BV(DMAC_CTRLB_IEN); *dmac_ch[ch].desc = (uint32_t)lli; } @@ -207,27 +206,16 @@ int dmac_error(int ch) static DECLARE_ISR(dmac_irq) { uint32_t status = DMAC_EBCISR; - uint32_t irq_ch = (status & dmac_ch_enabled) & 0xFF; - //kprintf(" %08lx %08lx\n", status, irq_ch); + uint32_t irq_ch = (status & (((dmac_ch_enabled | + (dmac_ch_enabled << DMAC_EBCIDR_ERR0) >> DMAC_EBCIDR_ERR0) | + (dmac_ch_enabled << DMAC_EBCIDR_CBTC0) >> DMAC_EBCIDR_CBTC0) & 0xFF)); if (irq_ch) - for(int i = 0; i < 8; i++) + for(int i = 0; i < 6; i++) { if (BV(i) & irq_ch) if(dmac[i].handler) - dmac[i].handler(); + dmac[i].handler(status); } -/* - irq_ch = (status & (dmac_ch_enabled << DMAC_EBCIDR_CBTC0)) >> DMAC_EBCIDR_CBTC0; - //kprintf("c %08lx %08lx\n", status, irq_ch); - if (irq_ch) - for(int i = 0; i < 8; i++) - { - if (BV(i) & irq_ch) - if(dmac[i].handler) - dmac[i].handler(); - } -*/ - } bool dmac_enableCh(int ch, dmac_handler_t handler) @@ -238,7 +226,7 @@ bool dmac_enableCh(int ch, dmac_handler_t handler) if (handler) { dmac[ch].handler = handler; - DMAC_EBCIER |= (BV(ch) << DMAC_EBCIER_BTC0) | (BV(ch) << DMAC_EBCIDR_CBTC0); + DMAC_EBCIER |= (BV(ch) << DMAC_EBCIER_BTC0) | (BV(ch) << DMAC_EBCIDR_CBTC0) | (BV(ch) << DMAC_EBCIDR_ERR0); kprintf("Init dmac ch[%08lx]\n", DMAC_EBCIMR); } diff --git a/bertos/cpu/cortex-m3/drv/dmac_sam3.h b/bertos/cpu/cortex-m3/drv/dmac_sam3.h index 2fb192df..0f7a08ae 100644 --- a/bertos/cpu/cortex-m3/drv/dmac_sam3.h +++ b/bertos/cpu/cortex-m3/drv/dmac_sam3.h @@ -43,7 +43,7 @@ #include #include -typedef void (*dmac_handler_t)(void); +typedef void (*dmac_handler_t)(uint32_t status); /** * DMA Transfer Descriptor as well as Linked List Item @@ -67,6 +67,17 @@ typedef struct Dmac #define DMAC_ERR_CH_ALREDY_ON BV(0) +INLINE void dmac_setSourcesLLI(int ch, DmacDesc *lli, uint32_t src, uint32_t dst, uint32_t desc) +{ + ASSERT(lli); + DMAC_CHDR = BV(ch); + + lli->src_addr = src; + lli->dst_addr = dst; + lli->dsc_addr = desc; +} + +void dmac_configureDmaCfgLLI(int ch, DmacDesc *lli, uint32_t cfg); void dmac_setSourcesLLI(int ch, DmacDesc *lli, uint32_t src, uint32_t dst, uint32_t desc); void dmac_configureDmacLLI(int ch, DmacDesc *lli, size_t transfer_size, uint32_t cfg, uint32_t ctrla, uint32_t ctrlb); bool dmac_isLLIDone(int ch); -- 2.25.1