On 19/09/15 10:29, Brady O'Brien wrote:
> 
> Are you developing under codec2-dev from the SVN repository? I could add
> a dacN_fifo_free to stm32f4_dac.c and push it up for you, if you're not
> already moving on it.

I'm not directly working from SVN, but rather a `git svn clone`
check-out of it so that I can commit my changes.  In any case, you were
right, it was trivial to add.
-- 
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
  ...it's backed up on a tape somewhere.
>From 97698ae33bbbc59aa050ccbc93c263da982cebec Mon Sep 17 00:00:00 2001
From: Stuart Longland <[email protected]>
Date: Sat, 19 Sep 2015 10:28:55 +1000
Subject: [PATCH 5/6] fifo: Add fifo_free function, const correctness.

Add a new function for the FIFO routines that returns the free space in
a FIFO.

The code was actually nicked out of fifo_write, just made into its own
function so that other code can make use of it.
---
 src/codec2_fifo.h | 11 ++++++++++-
 src/fifo.c        | 17 +++++++++--------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/codec2_fifo.h b/src/codec2_fifo.h
index dc93e15..383254f 100644
--- a/src/codec2_fifo.h
+++ b/src/codec2_fifo.h
@@ -42,7 +42,16 @@ struct FIFO *fifo_create(int nshort);
 void fifo_destroy(struct FIFO *fifo);
 int fifo_write(struct FIFO *fifo, short data[], int n);
 int fifo_read(struct FIFO *fifo, short data[], int n);
-int fifo_used(struct FIFO *fifo);
+
+/*!
+ * Return the number of bytes stored in the FIFO.
+ */
+int fifo_used(const struct FIFO * const fifo);
+
+/*!
+ * Return the space available in the FIFO.
+ */
+int fifo_free(const struct FIFO * const fifo);
 
 #ifdef __cplusplus
 }
diff --git a/src/fifo.c b/src/fifo.c
index 566d77a..d562a6a 100644
--- a/src/fifo.c
+++ b/src/fifo.c
@@ -64,19 +64,13 @@ void fifo_destroy(struct FIFO *fifo) {
 
 int fifo_write(struct FIFO *fifo, short data[], int n) {
     int            i;
-    int            fifo_free;
     short         *pdata;
     short         *pin = fifo->pin;
 
     assert(fifo != NULL);
     assert(data != NULL);
 
-    // available storage is one less than nshort as prd == pwr
-    // is reserved for empty rather than full
-
-    fifo_free = fifo->nshort - fifo_used(fifo) - 1;
-
-    if (n > fifo_free) {
+    if (n > fifo_free(fifo)) {
 	return -1;
     }
     else {
@@ -125,7 +119,7 @@ int fifo_read(struct FIFO *fifo, short data[], int n)
     return 0;
 }
 
-int fifo_used(struct FIFO *fifo)
+int fifo_used(const struct FIFO * const fifo)
 {
     short         *pin = fifo->pin;
     short         *pout = fifo->pout;
@@ -140,3 +134,10 @@ int fifo_used(struct FIFO *fifo)
     return used;
 }
 
+int fifo_free(const struct FIFO * const fifo)
+{
+    // available storage is one less than nshort as prd == pwr
+    // is reserved for empty rather than full
+
+    return fifo->nshort - fifo_used(fifo) - 1;
+}
-- 
2.4.6

>From d19c5929e3c1a89e74b8c9a85eb4ad789384922c Mon Sep 17 00:00:00 2001
From: Stuart Longland <[email protected]>
Date: Sat, 19 Sep 2015 10:30:24 +1000
Subject: [PATCH 6/6] stm32f4_dac: Add dac[12]_free.

Returns the number of samples available in the buffer.
---
 stm32/inc/stm32f4_dac.h | 2 ++
 stm32/src/stm32f4_dac.c | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/stm32/inc/stm32f4_dac.h b/stm32/inc/stm32f4_dac.h
index d0b8259..aa30415 100644
--- a/stm32/inc/stm32f4_dac.h
+++ b/stm32/inc/stm32f4_dac.h
@@ -32,6 +32,8 @@
 
 void dac_open(int fifo_sz);
 int dac1_write(short buf[], int n); /* DAC1 pin PA4 */
+int dac1_free();
 int dac2_write(short buf[], int n); /* DAC2 pin PA5 */
+int dac2_free();
 
 #endif
diff --git a/stm32/src/stm32f4_dac.c b/stm32/src/stm32f4_dac.c
index d160454..f78004d 100644
--- a/stm32/src/stm32f4_dac.c
+++ b/stm32/src/stm32f4_dac.c
@@ -111,6 +111,14 @@ int dac2_write(short buf[], int n) {
     return fifo_write(dac2_fifo, buf, n);
 }
 
+int dac1_free() {
+    return fifo_free(dac1_fifo);
+}
+
+int dac2_free() {
+    return fifo_free(dac2_fifo);
+}
+
 static void tim6_config(void)
 {
   TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
-- 
2.4.6

------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freetel-codec2

Reply via email to