]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Finished to implement rpp-test-suite basics, still without testing, expect plenty...
authorCarlos Miguel Jenkins Pérez <carlos@jenkins.co.cr>
Sun, 9 Jun 2013 14:26:08 +0000 (16:26 +0200)
committerCarlos Miguel Jenkins Pérez <carlos@jenkins.co.cr>
Sun, 9 Jun 2013 14:26:08 +0000 (16:26 +0200)
apps/rpp-test-suite/README.txt
apps/rpp-test-suite/include/test.h
apps/rpp-test-suite/src/ain.c
apps/rpp-test-suite/src/aout.c
apps/rpp-test-suite/src/din.c
apps/rpp-test-suite/src/hbr.c
apps/rpp-test-suite/src/lout.c
apps/rpp-test-suite/src/main.c
apps/rpp-test-suite/src/sdr.c

index 3725de3328ff0bf5b535e11e42003e457f1488f6..6f1873e296a16f0696645b36b6aa2a7310cdbf32 100644 (file)
@@ -1,12 +1,12 @@
-Module      Test implemented        Test description
+Module      Test implemented   Status         Test description
 
-AIN             YES                     Prints in SCI the values read on all AIN
+AIN             YES            DONE           Prints in SCI the values read on all AIN
 AOUT            YES                     Generates a Sinewave on all 4 AOUTs
 CAN             NO                      -
 DIN             YES                     Prints in SCI the values read on all DIN
 ETH             NO                      -
 FR              NO                      -
-HBR             YES                     PENDING! Use sinus function to control the H-Bridge
+HBR             YES                     Use sinus function to control the H-Bridge
 HOUT            NO                      -
 LIN             NO                      -
 LOUT            YES                     Output the value of a counter using all LOUT
index fe8b2ba18f2c81032a45792b1f9fe1a9f5be6cbc..6b7e5c8a6a33e70a4feccbfdaa85512142a98289 100644 (file)
@@ -12,6 +12,9 @@
 #ifndef __RPP_TEST_H
 #define __RPP_TEST_H
 
+#define TEST_TASK_PRIORITY   1
+#define TEST_TASK_TASK     512
+
 void wait_for_quit();
 void busy_infinite_loop();
 
index d0ec9464dc5fefb07793473a6f4c5f5bc288b8b3..7667792ae5f1ba20774b5633108408e207cbf294 100644 (file)
@@ -25,8 +25,6 @@
  */
 
 
-#include <string.h> // strncmp()
-
 #include "rpp/rpp.h"
 #include "test.h"
 
@@ -54,9 +52,13 @@ void ain_test_task(void *p)
         rpp_ain_update();
 
         // Print inputs
-        rpp_sci_printf(
-                // Terminal needs to be at least 59 chars long
-                (const char*)"%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d\r\n",
+        // Terminal needs to be at least 59 chars long
+        rpp_sci_printf((const char*)
+                "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+                "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+            );
+        rpp_sci_printf((const char*)
+                "%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d",
                 rpp_ain_get(1),
                 rpp_ain_get(2),
                 rpp_ain_get(3),
@@ -82,18 +84,25 @@ void test_ain(void)
     xTaskHandle test_task_handle;
 
     if(xTaskCreate(ain_test_task, (const signed char*)"ain_test_task",
-                   512, NULL, 1, &test_task_handle) != pdPASS) {
+                   TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
+                   &test_task_handle) != pdPASS) {
 
-        rpp_sci_printf(
-                (const char*)"ERROR: Problem spawning the test task. "
+        rpp_sci_printf((const char*)
+                "ERROR: Problem spawning the test task. "
                 "Error code: %d\r\n", task_created
             );
         wait_for_quit();
-    } else {
-        wait_for_quit();
-        vTaskDelete(test_task_handle);
+        return;
+
     }
 
+    wait_for_quit();
+    vTaskDelete(test_task_handle);
+
+    // Reset module
+    // - Not required
+
+    return;
 }
 
 
index d65b0602f50d68307ef1f93775705d3bd4a7af48..c8936163b7c97f2d6154c3c2de0aa11ac6c2e34e 100644 (file)
@@ -1,33 +1,68 @@
-#include <math.h>
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : aout.c
+ * Abstract:
+ *     RPP test suite - module for testing AOUT.
+ *
+ * References:
+ *     test.h
+ */
+
+
+#include <math.h> // sin()
+
 #include "rpp/rpp.h"
+#include "test.h"
 
-#define PIN                 1
 #define SINE_FREQ_HZ       10
 #define SAMPLE_RATE_HZ   1000
 // Which means 100 samples per period
 
+
 /**
- * FreeRTOS Task that create a sinusoid wave using analog RPP outputs.
+ * FreeRTOS Task that generates a sinewave on all analog outputs.
+ *
+ * Waves on analog outputs are shifted by pi/2 each.
  */
-void sinusoid(void* p)
+void aout_test_task(void* p)
 {
-    rpp_sci_printf(
-            (const char*)"Sinus wave on pin %d at %d Hz:\r\n",
-            PIN, SINE_FREQ_HZ
+    rpp_sci_printf((const char*)
+            "Analog Output Test at %d Hz:\r\n", SINE_FREQ_HZ
+        );
+    rpp_sci_printf((const char*)
+            "================================\r\n"
         );
-    rpp_sci_printf(
-            (const char*)"================================\r\n");
 
     // Calculate wait time in OS ticks
-    static const portTickType freq_ticks = SAMPLE_RATE_HZ / configTICK_RATE_HZ;
+    static const portTickType freq_ticks = configTICK_RATE_HZ / SAMPLE_RATE_HZ;
     portTickType last_wake_time = xTaskGetTickCount();
 
-    // Configure pin
-    rpp_aout_setup(PIN, TRUE);
+    // Configure pins
+    int pin;
+    for(pin = 1; pin <= 4; pin++) {
+        rpp_aout_setup(pin, TRUE);
+    }
     rpp_aout_update();
 
     // Constant trigonometric variables
-    const double two_pi = 2.0 * (4.0 * atan(1.0)); // Just 2pi
+    const double two_pi  = 2.0 * (4.0 * atan(1.0)); // Just 2pi
+    const double half_pi = 0.5 * (4.0 * atan(1.0)); // Just pi/2
     /*
      * A little bit of math:
      * In this example we want to generate a 10Hz sinusoid wave with a sampling
@@ -49,20 +84,23 @@ void sinusoid(void* p)
             // Wait until next step
             vTaskDelayUntil(&last_wake_time, freq_ticks);
 
-            // Calculate sine sample
-            sinus = sin(i * step);
+            for(pin = 1; pin <= 4; pin++) {
+
+                // Calculate sine sample
+                sinus = sin(i * step + (pin - 1) * half_pi);
 
-            // Map wave from [-1.0, 1.0] to [0, 4095]
-            val = (uint32_t)(((sinus + 1.0) / 2.0) * 4095.0);
+                // Map wave from [-1.0, 1.0] to [0, 4095]
+                val = (uint32_t)(((sinus + 1.0) / 2.0) * 4095.0);
 
-            // Output value
-            rpp_aout_set(PIN, val);
+                // Output value
+                rpp_aout_set(pin, val);
+            }
 
             // Update outputs
             rpp_aout_update();
         }
 
-        rpp_sci_printf(
+        rpp_sci_printf((const char*)
                 "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                 "Samples: %d", samples
             );
@@ -72,20 +110,34 @@ void sinusoid(void* p)
 
 
 /**
- * Application main function
- *
- * This function is called after startup.
+ * AOUT Test entry point.
  */
-void main(void)
+void test_aout(void)
 {
-    // Initialize library
-    rpp_init();
+    xTaskHandle test_task_handle;
 
-    // Spawn tasks
-    xTaskCreate(sinusoid, (const signed char*)"sinusoid", 512, NULL, 1, NULL);
+    if(xTaskCreate(aout_test_task, (const signed char*)"aout_test_task",
+                   TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
+                   &test_task_handle) != pdPASS) {
 
-    // Start Scheduler
-    vTaskStartScheduler();
-}
+        rpp_sci_printf((const char*)
+                "ERROR: Problem spawning the test task. "
+                "Error code: %d\r\n", task_created
+            );
+        wait_for_quit();
+        return;
+    }
+
+    wait_for_quit();
+    vTaskDelete(test_task_handle);
+
+    // Reset module
+    int p;
+    for(p = 1; p <= 4; p++) {
+        rpp_aout_set(pin, 0);
+    }
+    rpp_aout_update();
 
+    return;
+}
 
index 2beb988ea1ee73fca722c92973a8276ec018916d..aba79758fe4e44e20f2a2b93277f620e728a43f6 100644 (file)
@@ -1,13 +1,42 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : din.c
+ * Abstract:
+ *     RPP test suite - module for testing DIN.
+ *
+ * References:
+ *     test.h
+ */
+
+
 #include "rpp/rpp.h"
+#include "test.h"
 
 #define FREQ_MILLIS     1000
 
+
 /**
  * FreeRTOS Task that read digital inputs and prints them on the SCI.
  */
-void din_sci(void *p)
+void din_test_task(void *p)
 {
-    rpp_sci_printf((const char*)"Digital inputs [1-16]:\r\n");
+    rpp_sci_printf((const char*)"Digital Inputs Test [1-16]:\r\n");
     rpp_sci_printf((const char*)"================================\r\n");
 
     // Calculate wait time in OS ticks
@@ -29,8 +58,14 @@ void din_sci(void *p)
         // Update inputs
         rpp_din_update();
 
-        rpp_sci_printf(
-                (const char*)"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\r\n",
+        // Print inputs
+        // Terminal needs to be at least 31 chars long
+        rpp_sci_printf((const char*)
+                "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+            );
+
+        rpp_sci_printf((const char*)
+                "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
                 rpp_din_get( 1, FALSE),
                 rpp_din_get( 2, FALSE),
                 rpp_din_get( 3, FALSE),
@@ -53,20 +88,31 @@ void din_sci(void *p)
 
 
 /**
- * Application main function
- *
- * This function is called after startup.
+ * DIN Test entry point.
  */
-void main(void)
+void test_din(void)
 {
-    // Initialize library
-    rpp_init();
+    xTaskHandle test_task_handle;
+
+    if(xTaskCreate(din_test_task, (const signed char*)"din_test_task",
+                   TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
+                   &test_task_handle) != pdPASS) {
+
+        rpp_sci_printf((const char*)
+                "ERROR: Problem spawning the test task. "
+                "Error code: %d\r\n", task_created
+            );
+        wait_for_quit();
+        return;
+    }
+
+    wait_for_quit();
+    vTaskDelete(test_task_handle);
 
-    // Spawn tasks
-    xTaskCreate(din_sci, (const signed char*)"din_sci", 512, NULL, 1, NULL);
+    // Reset module
+    // - Not required
 
-    // Start Scheduler
-    vTaskStartScheduler();
+    return;
 }
 
 
index d65b0602f50d68307ef1f93775705d3bd4a7af48..25bdbf839c50b83be9a2a37f95d48410fb4f459d 100644 (file)
@@ -1,46 +1,74 @@
-#include <math.h>
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : aout.c
+ * Abstract:
+ *     RPP test suite - module for testing AOUT.
+ *
+ * References:
+ *     test.h
+ */
+
+
+#include <math.h> // sin()
+
 #include "rpp/rpp.h"
+#include "test.h"
 
-#define PIN                 1
-#define SINE_FREQ_HZ       10
-#define SAMPLE_RATE_HZ   1000
-// Which means 100 samples per period
+#define SINE_FREQ_HZ     0.05
+#define SAMPLE_RATE_HZ     20
+// Which means 1% increment of duty cycle per sample
 
 /**
- * FreeRTOS Task that create a sinusoid wave using analog RPP outputs.
+ * FreeRTOS Task that controls the H-Bridge following a sine wave.
  */
-void sinusoid(void* p)
+void hbr_test_task(void* p)
 {
-    rpp_sci_printf(
-            (const char*)"Sinus wave on pin %d at %d Hz:\r\n",
-            PIN, SINE_FREQ_HZ
+    rpp_sci_printf((const char*)
+            "H-Bridge Test at %1.2f Hz:\r\n", SINE_FREQ_HZ
+        );
+    rpp_sci_printf((const char*)
+            "================================\r\n"
         );
-    rpp_sci_printf(
-            (const char*)"================================\r\n");
 
     // Calculate wait time in OS ticks
-    static const portTickType freq_ticks = SAMPLE_RATE_HZ / configTICK_RATE_HZ;
+    static const portTickType freq_ticks = configTICK_RATE_HZ / SAMPLE_RATE_HZ;
     portTickType last_wake_time = xTaskGetTickCount();
 
-    // Configure pin
-    rpp_aout_setup(PIN, TRUE);
-    rpp_aout_update();
+    // Configure H-Bridge at default frequency
+    if(rpp_hbr_enable(-1) != SUCCESS) {
+        rpp_sci_printf((const char*)
+                "ERROR: H-Bridge could not be started.\r\n"
+            );
+        vTaskSuspend(NULL);
+    }
 
     // Constant trigonometric variables
     const double two_pi = 2.0 * (4.0 * atan(1.0)); // Just 2pi
     /*
      * A little bit of math:
-     * In this example we want to generate a 10Hz sinusoid wave with a sampling
-     * rate of 1000Hz. Sinus period is defined over 2pi, 10Hz means 10 periods
-     * per second, at 1000Hz sampling rate means 100 samples per period. It
-     * means that in 100 samples we should go from range [0, 2pi]. Here, we
-     * calculate the step.
+     * In this example we want to generate a 0.05Hz (one period each 20s)
+     * sinusoid wave with a sampling rate of 20Hz so duty cycle increments or
+     * decrements 1% per sample.
      */
     const double step = (two_pi * SINE_FREQ_HZ) / SAMPLE_RATE_HZ;
 
     uint64_t samples = 1;
-    double sinus = 0.0;
-    uint32_t val = 0;
     int i = 0;
     while(TRUE) {
 
@@ -49,17 +77,8 @@ void sinusoid(void* p)
             // Wait until next step
             vTaskDelayUntil(&last_wake_time, freq_ticks);
 
-            // Calculate sine sample
-            sinus = sin(i * step);
-
-            // Map wave from [-1.0, 1.0] to [0, 4095]
-            val = (uint32_t)(((sinus + 1.0) / 2.0) * 4095.0);
-
-            // Output value
-            rpp_aout_set(PIN, val);
-
-            // Update outputs
-            rpp_aout_update();
+            // Update H-Bridge
+            rpp_hbr_control(sin(i * step));
         }
 
         rpp_sci_printf(
@@ -72,20 +91,34 @@ void sinusoid(void* p)
 
 
 /**
- * Application main function
- *
- * This function is called after startup.
+ * HBR Test entry point.
  */
-void main(void)
+void test_hbr(void)
 {
-    // Initialize library
-    rpp_init();
+    xTaskHandle test_task_handle;
 
-    // Spawn tasks
-    xTaskCreate(sinusoid, (const signed char*)"sinusoid", 512, NULL, 1, NULL);
+    if(xTaskCreate(hbr_test_task, (const signed char*)"hbr_test_task",
+                   TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
+                   &test_task_handle) != pdPASS) {
 
-    // Start Scheduler
-    vTaskStartScheduler();
-}
+        rpp_sci_printf((const char*)
+                "ERROR: Problem spawning the test task. "
+                "Error code: %d\r\n", task_created
+            );
+        wait_for_quit();
+        return;
+    }
+
+    wait_for_quit();
+    vTaskDelete(test_task_handle);
+
+    // Reset module
+    if(rpp_hbr_disable() != SUCCESS) {
+        rpp_sci_printf((const char*)
+            "ERROR: Could not stop H-Bridge module.\r\n"
+        );
+    }
 
+    return;
+}
 
index 2ec04ad9288dc2e2f40b524362b7ce4f44a449ce..c85386269d402e8e4c8a97193710ffa84ec97df8 100644 (file)
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : lout.c
+ * Abstract:
+ *     RPP test suite - module for testing LOUT.
+ *
+ * References:
+ *     test.h
+ */
+
+
 #include "rpp/rpp.h"
 
 #define FREQ_MILLIS     1000
-#define LED_PIN         1
+
 
 /**
- * FreeRTOS Task that toggle an LED.
+ * FreeRTOS Task that outputs a counter to all the digital outputs.
  */
-void blink_led(void *p)
+void lout_test_task(void *p)
 {
-    rpp_sci_printf(
-            (const char*)"LED blink on pin %d at %d Hz:\r\n",
-            LED_PIN, configCPU_CLOCK_HZ
+    rpp_sci_printf((const char*)
+            "Digital Output Test:\r\n"
+        );
+    rpp_sci_printf((const char*)
+            "================================\r\n"
         );
-    rpp_sci_printf(
-            (const char*)"================================\r\n");
 
     // Calculate wait time in OS ticks
     static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
     portTickType last_wake_time = xTaskGetTickCount();
 
-    boolean_t is_high = TRUE;
+    uint8_t c = 0;
+    uint8_t p = 0;
     while(TRUE) {
 
         // Wait until next step
         vTaskDelayUntil(&last_wake_time, freq_ticks);
 
-        // Toggle LED
-        if(is_high) {
-            rpp_lout_set(LED_PIN, HIGH);
-        } else {
-            rpp_lout_set(LED_PIN, LOW);
+        // Output counter
+        for(p = 1; p <= 8; p++) {
+            if(is_bit_set(counter, p - 1)) {
+                rpp_lout_set(p, HIGH);
+            } else {
+                rpp_lout_set(p, LOW);
+            }
         }
         rpp_lout_update();
 
-        is_high = !is_high;
+        rpp_sci_printf((const char*)
+                "\b\b\b\b\b\b\b\b\b\b\b\b"
+                "Counter: %d", c
+            );
+
+        c++;
     }
 }
 
 
 /**
- * Application main function
- *
- * This function is called after startup.
+ * LOUT Test entry point.
  */
-void main(void)
+void test_lout(void)
 {
-    // Initialize library
-    rpp_init();
+    xTaskHandle test_task_handle;
+
+    if(xTaskCreate(lout_test_task, (const signed char*)"lout_test_task",
+                   TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
+                   &test_task_handle) != pdPASS) {
 
-    // Spawn tasks
-    xTaskCreate(blink_led, (const signed char*)"blink_led", 512, NULL, 1, NULL);
+        rpp_sci_printf((const char*)
+                "ERROR: Problem spawning the test task. "
+                "Error code: %d\r\n", task_created
+            );
+        wait_for_quit();
+        return;
+    }
+
+    wait_for_quit();
+    vTaskDelete(test_task_handle);
+
+    // Reset module
+    int p;
+    for(p = 1; p <= 8; p++) {
+        rpp_lout_set(pin, LOW);
+    }
+    rpp_lout_update();
 
-    // Start Scheduler
-    vTaskStartScheduler();
+    return;
 }
 
index 96bcace3c8578fb22df7d96c35dc62896ba2caad..217175c00b2800277720cbb1f350db5d20181920 100644 (file)
@@ -215,17 +215,20 @@ void main(void)
     // Initialize library
     rpp_init();
 
+    // Speed up the SCI
+    //rpp_sci_setup(115200);
+
     // Spawn tasks
     portBASE_TYPE task_created =
         xTaskCreate(test_cmdproc,
                 (const signed char*)"test_cmdproc",
-                512, NULL, 1, NULL
+                512, NULL, 0, NULL
             );
 
     if(task_created != pdPASS) {
-        rpp_sci_printf(
-                (const char*)"ERROR: Problem allocating memory for command "
-                "processor to start. Error code: %d\r\n", task_created
+        rpp_sci_printf((const char*)
+                "ERROR: Problem allocating memory for command processor to "
+                "start. Error code: %d\r\n", task_created
             );
         busy_infinite_loop();
     }
@@ -234,9 +237,8 @@ void main(void)
     vTaskStartScheduler();
 
     // Catch memory problems
-    rpp_sci_printf(
-            (const char*)"ERROR: Problem allocating memory for scheduler "
-            "to start.\r\n"
+    rpp_sci_printf((const char*)
+            "ERROR: Problem allocating memory for scheduler to start.\r\n"
         );
     busy_infinite_loop();
 }
@@ -247,8 +249,8 @@ void main(void)
  */
 void vApplicationMallocFailedHook(void)
 {
-    rpp_sci_printf(
-            (const char*)"ERROR: manual memory allocation failed.\r\n"
+    rpp_sci_printf((const char*)
+            "ERROR: manual memory allocation failed.\r\n"
         );
 }
 
@@ -259,9 +261,8 @@ void vApplicationMallocFailedHook(void)
 void vApplicationStackOverflowHook(xTaskHandle xTask,
                                    signed portCHAR *pcTaskName)
 {
-    rpp_sci_printf(
-            (const char*)"ERROR: Stack overflow : \"%s\".\r\n",
-            pcTaskName
+    rpp_sci_printf((const char*)
+            "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName
         );
 }
 
index df768d2a301ec918d633f7638bad5ad791afabdf..ac0bfd19ace20f7dff0a9c2955c18a169d5852e6 100644 (file)
@@ -1,12 +1,42 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : sdr.c
+ * Abstract:
+ *     RPP test suite - module for testing SDR.
+ *
+ * References:
+ *     test.h
+ */
+
+
+#include <stdlib.h> // rand()
+
 #include "rpp/rpp.h"
-#include <stdlib.h>
+#include "test.h"
+
+#define FREQ_MILLIS     1000
 
-#define FREQ_MILLIS     3000
 
 /**
  * FreeRTOS Task that send some noise to the log from time to time.
  */
-void log_noise(void *p)
+void sdr_test_task(void *p)
 {
     // Calculate wait time in OS ticks
     static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
@@ -30,42 +60,54 @@ void log_noise(void *p)
     }
 }
 
+extern xSemaphoreHandle rpp_sdr_cmdproc_semaphore;
 
 /**
- * Application main function
- *
- * This function is called after startup.
+ * SDR Test entry point.
  */
-int main(void)
+void test_sdr(void)
 {
-    // Initialize library
-    rpp_init();
-
-    // Initialize log
-    rpp_sdr_setup(TRUE);
-
-    // Spawn tasks
-    xTaskCreate(log_noise, (const signed char*)"log_noise", 512, NULL, 1, NULL);
+    xTaskHandle test_task_handle;
+
+    // Spawn noise task first, and later enable logging. Depending on the time
+    // required the first logs might not be registeres, but that's ok, is better
+    // to check if logging could be enabled after data is being sent that enable
+    // command processor (which output messages to the SCI), and that inmediatly
+    // after the noise task could not be created, forcing to close the just
+    // opened command processor.
+    if(xTaskCreate(sdr_test_task, (const signed char*)"sdr_test_task",
+                   TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
+                   &test_task_handle) != pdPASS) {
+
+        rpp_sci_printf((const char*)
+                "ERROR: Problem spawning the test task. "
+                "Error code: %d\r\n", task_created
+            );
 
-    // Start Scheduler
-    vTaskStartScheduler();
+        wait_for_quit();
+        return;
+    }
 
-    return 0;
-}
+    if(rpp_sdr_setup(TRUE) != SUCCESS) {
+        vTaskDelete(test_task_handle);
+        rpp_sci_printf((const char*)
+                "ERROR: Problem enabling the logging module. "
+            );
+        wait_for_quit();
+        return;
+    }
 
+    // Wait for the SDR included command processor to finish
+    xSemaphoreTake(rpp_sdr_cmdproc_semaphore, portMAX_DELAY);
+    vTaskDelete(test_task_handle);
 
-/**
- * FreeRTOS malloc() failed hook.
- */
-void vApplicationMallocFailedHook(void) {
-    rpp_sci_printf((const char*)"<malloc() failed>\r\n");
-}
+    // Reset module
+    if(rpp_sdr_setup(FALSE) != SUCCESS) {
+        rpp_sci_printf((const char*)
+            "ERROR: Could not stop logging module.\r\n"
+        );
+    }
 
-/**
- * FreeRTOS stack overflow hook.
- */
-void vApplicationStackOverflowHook(xTaskHandle xTask,
-                                   signed portCHAR *pcTaskName) {
-    rpp_sci_printf((const char*)"<stack overflow : \"%s\">\r\n", pcTaskName);
+    return;
 }