From: asterix Date: Mon, 28 Mar 2011 10:25:37 +0000 (+0000) Subject: Add sam3x dac private funcion to use hight level api. X-Git-Tag: 2.7.0~150 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=577a9116e32fac33614a21b15d8d1443c3ac420b;p=bertos.git Add sam3x dac private funcion to use hight level api. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4816 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 98e4fa88..072bc647 100644 --- a/bertos/cpu/cortex-m3/drv/dac_sam3.c +++ b/bertos/cpu/cortex-m3/drv/dac_sam3.c @@ -54,31 +54,59 @@ #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); +static int sam3x_dac_write(DacContext *ctx, unsigned channel, uint16_t sample) +{ + ASSERT(channel <= 1); + + DACC_MR |= (channel << DACC_USER_SEL_SHIFT) & DACC_USER_SEL_MASK; + DACC_CHER |= BV(channel); - 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); - } + DACC_CDR = sample ; return 0; } -void dac_init(void) +static void sam3x_dac_setCh(struct DacContext *ctx, uint32_t mask) +{ +} + +static void sam3x_dac_setSampleRate(struct DacContext *ctx, uint32_t rate) +{ +} + +static void sam3x_dac_conversion(struct DacContext *ctx, void *buf, size_t len) +{ + DACC_TPR = (uint32_t)buf ; + DACC_TCR = len; + DACC_PTCR |= BV(DACC_PTCR_TXTEN); +} + +static bool sam3x_dac_isFinished(struct DacContext *ctx) { +} + +static void sam3x_dac_start(struct DacContext *ctx, void *buf, size_t len, size_t slicelen) +{ +} + +static void sam3x_dac_stop(struct DacContext *ctx) +{ +} + + +void dac_init(struct DacContext *ctx) +{ + ctx->write = sam3x_dac_write; + ctx->setCh = sam3x_dac_setCh; + ctx->setSampleRate = sam3x_dac_setSampleRate; + ctx->conversion = sam3x_dac_conversion; + ctx->isFinished = sam3x_dac_isFinished; + ctx->start = sam3x_dac_start; + ctx->stop = sam3x_dac_stop; + + /* Clock ADC peripheral */ pmc_periphEnable(DACC_ID); diff --git a/bertos/drv/dac.h b/bertos/drv/dac.h index eacab989..eee8e0ad 100644 --- a/bertos/drv/dac.h +++ b/bertos/drv/dac.h @@ -62,7 +62,6 @@ typedef void (*SetSamplingRate_t) (struct DacContext *ctx, uint32_t rate); typedef void (*DmaConversionBufFunc_t) (struct DacContext *ctx, void *buf, size_t len); typedef bool (*DmaConversionIsFinished_t) (struct DacContext *ctx); typedef void (*DmaStartStreamingFunc_t) (struct DacContext *ctx, void *buf, size_t len, size_t slicelen); -typedef void *(*DmaWaitConversionFunc_t) (struct DacContext *ctx); typedef void (*DmaStopFunc_t) (struct DacContext *ctx); typedef struct DacContext @@ -73,7 +72,6 @@ typedef struct DacContext DmaConversionBufFunc_t conversion; DmaConversionIsFinished_t isFinished; DmaStartStreamingFunc_t start; - DmaWaitConversionFunc_t wait; DmaStopFunc_t stop; size_t slicelen; @@ -129,12 +127,6 @@ INLINE void dac_dmaStartStreaming(struct DacContext *ctx, void *buf, size_t len, ctx->start(ctx, buf, len, slicelen); } -INLINE void *dac_dmaWaitConversion(struct DacContext *ctx) -{ - ASSERT(ctx->wait); - return ctx->wait(ctx); -} - INLINE void dac_dmaStop(struct DacContext *ctx) { ASSERT(ctx->stop); @@ -143,7 +135,7 @@ INLINE void dac_dmaStop(struct DacContext *ctx) #define dac_bits() DAC_BITS -void dac_init(void); +void dac_init(struct DacContext *ctx); /** \} */ //defgroup dac #endif /* DRV_DAC_H */