From: asterix Date: Wed, 23 Mar 2011 18:55:56 +0000 (+0000) Subject: Add write function for dac. X-Git-Tag: 2.7.0~161 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=465ded5c829816372a7f70f864c0477d5943c3fd;p=bertos.git Add write function for dac. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4805 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/cortex-m3/drv/dac_sam3.c b/bertos/cpu/cortex-m3/drv/dac_sam3.c index e4e7e9a9..98e4fa88 100644 --- a/bertos/cpu/cortex-m3/drv/dac_sam3.c +++ b/bertos/cpu/cortex-m3/drv/dac_sam3.c @@ -47,10 +47,33 @@ #include #include + +#include + #include -int dac_write(int ch, buf, len) +#include + +int dac_write(int ch, void *buf, size_t len) { + ASSERT(ch <= 1); + + DACC_MR |= (ch << DACC_USER_SEL_SHIFT) & DACC_USER_SEL_MASK; + DACC_CHER |= BV(ch); + + kprintf("mr: %08lx\n", DACC_MR); + + if (len <= sizeof(uint32_t)) + { + memcpy((void *)DACC_CDR, buf, len); + } + else + { + DACC_TPR = (uint32_t)buf ; + DACC_TCR = len ; + DACC_PTCR |= BV(DACC_PTCR_TXTEN); + } + return 0; } @@ -64,12 +87,7 @@ void dac_init(void) /* Refresh period */ DACC_MR |= (16 << DACC_REFRESH_SHIFT) & DACC_REFRESH_MASK; - /* Select channel */ - DACC_MR |= (DACC_CH1 << DACC_USER_SEL_SHIFT) & DACC_USER_SEL_MASK; /* Start up */ DACC_MR |= (DACC_MR_STARTUP_0 << DACC_STARTUP_SHIFT) & DACC_STARTUP_MASK; - kprintf("mr: %08lx\n", DACC_MR); - /* Register and enable irq for adc. */ - sysirq_setHandler(INT_DACC, dac); }