Small example for xIFO

Dependencies:   xIFO mbed

Files at this revision

API Documentation at this revision

Comitter:
jeroen3
Date:
Mon Oct 28 19:10:54 2013 +0000
Child:
1:f8ee57bf1292
Commit message:
Initial example

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
xIFO.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 28 19:10:54 2013 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+// Create a buffer (note that this is a C module, not an object)
+xifo_t buffer;
+// Allocate memory for buffer
+xifo_pool_t buffer_memory[16]; 
+
+int main() {
+    uint32_t data, succes;
+
+    // Initialise the created buffer
+    xifo_init(&buffer, 128, (uint32_t *)&buffer_memory); 
+    
+    // Erase buffer contents
+    xifo_clear(&buffer);
+
+    // Write some data
+    succes = xifo_write(&buffer, 0x1); 
+    succes = xifo_write(&buffer, 0x2); 
+    succes = xifo_write(&buffer, 0x3);
+    succes = xifo_write(&buffer, 0x4); 
+    succes = xifo_write(&buffer, 0x5); 
+    // Are we full yet?
+    if( xifo_get_free(&buffer) > 0 )
+    {
+        succes = xifo_write(&buffer, 0x6); 
+    }
+            
+    /* Read from the buffer, read-only! */
+    // Read the least recent element        : 0x1
+    data = xifo_read_lr(&buffer, 0);  
+    
+    // Read the 2nd least recent element    : 0x2
+    data = xifo_read_lr(&buffer, 1);
+    
+    // Read the most recent element         : 0x6
+    data = xifo_read_mr(&buffer, 0);
+    
+    // Read the 2nd most recent element     : 0x5
+    data = xifo_read_mr(&buffer, 1);
+    
+    /* Pop from the buffer, removes elements */
+    // Remove the least recent element      : 0x1
+    data = xifo_pop_lr(&buffer);
+    
+    // Remove the most recent element       : 0x6
+    data = xifo_pop_mr(&buffer);
+    
+    /* Done 
+     * Buffer should have this: 0x2, 0x3, 0x4, 0x5
+     */
+        
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xIFO.lib	Mon Oct 28 19:10:54 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/jeroen3/code/xIFO/#a04dc0c57d20