From 7fb37d56c0cba9a49efb9632ed5a739452ea71e4 Mon Sep 17 00:00:00 2001
From: asterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Date: Thu, 15 Sep 2011 14:36:10 +0000
Subject: [PATCH] Fix streaming implementation, now it could be halt only
 calling the stop function.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5051 38d2e660-2303-0410-9eaa-f027e97ec537
---
 bertos/cpu/cortex-m3/drv/dac_sam3.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/bertos/cpu/cortex-m3/drv/dac_sam3.c b/bertos/cpu/cortex-m3/drv/dac_sam3.c
index f4090468..0516fdec 100644
--- a/bertos/cpu/cortex-m3/drv/dac_sam3.c
+++ b/bertos/cpu/cortex-m3/drv/dac_sam3.c
@@ -276,14 +276,16 @@ static void sam3x_dac_start(struct Dac *dac, void *_buf, size_t len, size_t slic
 	while (1)
 	{
 		event_wait(&buff_emtpy);
+		if (dac->hw->end)
+			break;
+
+		remaing_size -= chunk_size;
+		next_idx += chunk_size;
+
 		if (remaing_size <= 0)
 		{
-			DAC_TC_CCR = BV(TC_CCR_CLKDIS);
-			dac->hw->end = true;
+			remaing_size = len;
 			next_idx = 0;
-			chunk_size = 0;
-			remaing_size = 0;
-			break;
 		}
 
 		dac->ctx.callback(dac, &sample_buff[next_idx], chunk_size);
@@ -293,10 +295,16 @@ static void sam3x_dac_start(struct Dac *dac, void *_buf, size_t len, size_t slic
 static void sam3x_dac_stop(struct Dac *dac)
 {
 	dac->hw->end = false;
+	next_idx = 0;
+	remaing_size = 0;
+	chunk_size = 0;
+
 	/* Disable the irq, timer and channel */
 	DACC_IDR = BV(DACC_ENDTX);
 	DACC_PTCR |= BV(DACC_PTCR_TXTDIS);
 	DAC_TC_CCR = BV(TC_CCR_CLKDIS);
+
+	event_do(&buff_emtpy);
 }
 
 
-- 
2.34.1