X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Fcortex-m3%2Fdrv%2Fdmac_sam3.c;h=e97066860e792f27b7a6f0d882f0ea3a0a075ca0;hb=a535d0ea510fe25b0d27690272bfbed9b3187500;hp=d0b8128c0bc6e2b3c02953a113811a7e9e208c5f;hpb=442fdad4adb197550693c24747493799ae293aea;p=bertos.git diff --git a/bertos/cpu/cortex-m3/drv/dmac_sam3.c b/bertos/cpu/cortex-m3/drv/dmac_sam3.c index d0b8128c..e9706686 100644 --- a/bertos/cpu/cortex-m3/drv/dmac_sam3.c +++ b/bertos/cpu/cortex-m3/drv/dmac_sam3.c @@ -56,7 +56,7 @@ struct DmacCh reg32_t *ctrlb; }; -#define DMAC_CHANNEL_CNT 5 +#define DMAC_CHANNEL_CNT 6 struct DmacCh dmac_ch[] = { { @@ -109,29 +109,17 @@ struct DmacCh dmac_ch[] = }, }; - /* We use event to signal the end of conversion */ -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) -{ - ASSERT(lli); - DMAC_CHDR = BV(ch); - - lli->src_addr = src; - lli->dst_addr = dst; - lli->dsc_addr = desc; -} - -void dmac_configureDmacLLI(int ch, DmacDesc *lli, size_t transfer_size, uint32_t cfg, uint32_t ctrla, uint32_t ctrlb) +void dmac_setLLITransfer(int ch, DmacDesc *lli, uint32_t cfg) { DMAC_CHDR = BV(ch); + reg32_t reg = DMAC_EBCISR; + (void)reg; *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; } @@ -161,40 +149,14 @@ int dmac_start(int ch) return -1; } DMAC_CHER = BV(ch); + dmac_ch_enabled |= BV(ch); return 0; } -int dmac_stop(int ch) +void dmac_stop(int ch) { DMAC_CHDR = BV(ch); - return 0; -} - -bool dmac_isLLIDone(int ch) -{ - return (DMAC_EBCIMR |= (BV(ch) << DMAC_EBCISR_CBTC0)); -} - -bool dmac_waitLLIDone(int ch) -{ - while(!(DMAC_EBCIMR |= (BV(ch) << DMAC_EBCISR_CBTC0))) - cpu_relax(); - - DMAC_CHDR = BV(ch); - return true; -} - -bool dmac_isDone(int ch) -{ - //event_wait(&data_ready); - return (*dmac_ch[ch].ctrla & BV(31));//(DMAC_CHSR |= (BV(dmac->ch) << DMAC_CHSR_EMPT0)); -} - -bool dmac_waitDone(int ch) -{ - event_wait(&data_ready); - DMAC_CHDR = BV(ch); - return true; + dmac_ch_enabled &= ~BV(ch); } int dmac_error(int ch) @@ -207,27 +169,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 +189,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); }