]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Added printf() implementation on top of SCI and test app.
authorCarlos Miguel Jenkins Pérez <carlos@jenkins.co.cr>
Wed, 29 May 2013 18:34:02 +0000 (20:34 +0200)
committerCarlos Miguel Jenkins Pérez <carlos@jenkins.co.cr>
Wed, 29 May 2013 18:34:02 +0000 (20:34 +0200)
rpp/include/rpp/sci.h
rpp/include/rpp/sdc.h
rpp/include/rpp/sdr.h
rpp/src/rpp/sci.c
test/din-sci/include/.gitignore [new file with mode: 0644]
test/din-sci/src/main.c [new file with mode: 0644]

index 14ca19790363822344550db52a98f30fe55f22a7..d2502ee59699ee943f0e99be2f9b317cfcdd25a0 100644 (file)
  * Call this method before using this module.
  *
  * @return SUCCESS if initialization successful.
- *          FAILURE is module already initialized.
+ *         FAILURE is module already initialized.
  */
 int8_t rpp_sci_init();
 
 
+/**
+ * C's printf using RPP SCI module.
+ * Implementation uses vsnprintf() from stdio.h using a fixed 128 bytes buffer.
+ *
+ * @param[in] format    C string that contains a format string that follows the
+ *                      same specifications as format in printf (see stdio.h's
+ *                      printf for details).
+ * @param[in] ...       (additional arguments) Depending on the format string,
+ *                      the function may expect a sequence of additional
+ *                      arguments, each containing a value to be used to replace
+ *                      a format specifier in the format string (or a pointer to
+ *                      a storage location).
+ *                      There should be at least as many of these arguments as
+ *                      the number of values specified in the format specifiers.
+ *                      Additional arguments are ignored by the function.
+ *
+ * @return The number of characters that would have been written if the buffer
+ *         had been sufficiently large, not counting the terminating null
+ *         character. If an encoding error occurs, a negative number is
+ *         returned. Notice that only when this returned value is non-negative
+ *         and less than the buffer size, the string has been completely
+ *         written.
+ */
+int rpp_sci_printf(const char *format, ...);
+
+
 #endif /* __RPP_SCI_H */
 
index a6b1fae2bef23c4663737d5b12fe3ce79e97f078..9c3ccb5d5117be09ad8772e89b3ea12f6fecf60d 100644 (file)
@@ -17,7 +17,7 @@
  * Call this method before using this module.
  *
  * @return SUCCESS if initialization successful.
- *          FAILURE is module already initialized.
+ *         FAILURE is module already initialized.
  */
 int8_t rpp_sdc_init();
 
index 29b551a4025449b3e2903731c6162cb7e9a21d8f..dce365ae87c6479a137f21957596824ed857087f 100644 (file)
@@ -17,7 +17,7 @@
  * Call this method before using this module.
  *
  * @return SUCCESS if initialization successful.
- *          FAILURE is module already initialized.
+ *         FAILURE is module already initialized.
  */
 int8_t rpp_sdr_init();
 
index e365d2283181eb2e73a9cab2c8e09fa4c00a1e84..f216938904e3001aa8fdf291a25ddcb2e89837fd 100644 (file)
@@ -29,6 +29,7 @@
 #include "rpp/rpp.h"
 
 #if rppCONFIG_INCLUDE_SCI == 1
+#include <stdio.h>
 
 static boolean_t initialized = FALSE;
 
@@ -43,6 +44,25 @@ int8_t rpp_sci_init()
    return SUCCESS;
 }
 
+int rpp_sci_printf(const char *format, ...)
+{
+   char str[128];
+   int length = -1;
+
+   va_list argList;
+   va_start(argList, format);
+
+   length = vsnprintf(str, sizeof(str), format, argList);
+
+   va_end(argList);
+
+   if(length > 0) {
+      sciSend(sciREG1, (unsigned)length, (unsigned char*)str);
+   }
+
+   return length;
+}
+
 
 #endif /* rppCONFIG_INCLUDE_SCI */
 
diff --git a/test/din-sci/include/.gitignore b/test/din-sci/include/.gitignore
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/din-sci/src/main.c b/test/din-sci/src/main.c
new file mode 100644 (file)
index 0000000..b26efa1
--- /dev/null
@@ -0,0 +1,46 @@
+#include "rpp/rpp.h"
+
+
+/**
+ * FreeRTOS Task that read digital inputs and prints them on the SCI.
+ */
+void din_sci(void *p) {
+
+    // Calculate wait time in OS ticks
+    static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
+    portTickType last_wake_time = xTaskGetTickCount();
+
+    int pin;
+    while(TRUE) {
+
+        // Wait until next step
+        vTaskDelayUntil(&last_wake_time, freq_ticks);
+
+        // Update inputs
+        rpp_din_update();
+
+        // Read and print inputs
+        for(pin = 1; pin < 16; pin++) {
+            rpp_sci_printf((const char*)"%d ", rpp_din_get(pin, FALSE));
+        }
+        rpp_sci_printf((const char*)"%d\n", rpp_din_get(16, FALSE));
+    }
+}
+
+
+/**
+ * Application main function
+ *
+ * This function is called after startup.
+ */
+void main(void)
+{
+    // Initialize library
+    rpp_init();
+
+    // Spawn tasks
+    xTaskCreate(din_sci, (signed char*) "din_sci", 256, NULL, 1, NULL);
+
+    // Start Scheduler
+    vTaskStartScheduler();
+}