* 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 */
* 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();
* 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();
#include "rpp/rpp.h"
#if rppCONFIG_INCLUDE_SCI == 1
+#include <stdio.h>
static boolean_t initialized = FALSE;
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 */
--- /dev/null
+#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();
+}