#include "rpp/rpp.h"
#include "test.h"
+#define FREQ_MILLIS 1000
+
+
+// Task control
+static boolean_t stop_tasks = FALSE;
+static uint8_t tasks_running = 0;
+
/**
- * Test the MOUT module.
+ * FreeRTOS Task that toggle the MOUT outputs, then reads the diagnostics and
+ * compare.
*/
-void test_mout()
+void mout_test_task(void* par)
{
rpp_sci_printf((const char*)
- "MOUT test is unimplemented. Press any key to continue...\r\n"
+ "Power Output Test:\r\n"
+ );
+ rpp_sci_printf((const char*)
+ "===========================================================\r\n"
+ );
+ rpp_sci_printf((const char*)
+ "1 2 3 4 5 6\r\n"
+ // 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD
+ // 1: OK 1: OK 1: OK 1: OK 1: OK 1: OK
);
+
+ // Calculate wait time in OS ticks
+ static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
+ portTickType last_wake_time = xTaskGetTickCount();
+
+ uint8_t i;
+ uint8_t pin;
+ boolean_t state = FALSE;
+ while(!stop_tasks) {
+
+ // Toggle state
+ for(pin = 1; pin <= 6; pin++) {
+ rpp_mout_set(pin, state);
+ }
+ state = !state;
+
+ 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"
+ );
+
+ for(pin = 1; pin <= 6; pin++) {
+ rpp_sci_printf((const char*)
+ "%d: ", rpp_mout_get(pin)
+ );
+ }
+
+ for(i = 0; i < 10; i++) {
+
+ // Wait until next step
+ if(!stop_tasks) {
+ vTaskDelayUntil(&last_wake_time, freq_ticks);
+ } else {
+ break;
+ }
+
+ 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"
+ );
+
+ for(pin = 1; pin <= 6; pin++) {
+ rpp_sci_printf((const char*)
+ "%d:%s ", rpp_mout_get(pin),
+ (rpp_mout_get(pin) == rpp_mout_diag(pin)) ? " OK" : "BAD"
+ );
+ }
+
+ }
+ }
+
+ // Delete myself
+ tasks_running--;
+ vTaskDelete(NULL);
+}
+
+
+/**
+ * MOUT Test entry point.
+ */
+void test_mout()
+{
+ /// Configure module
+ // - Not needed
+
+
+ /// Spawn tasks
+ xTaskHandle test_task_handle;
+
+ portBASE_TYPE task_created = xTaskCreate(mout_test_task,
+ (const signed char*)"mout_test_task",
+ TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
+ &test_task_handle
+ );
+
+ if(task_created != pdPASS) {
+
+ rpp_sci_printf((const char*)
+ "ERROR: Problem spawning the test task. "
+ "Error code: %d\r\n", (uint32_t)task_created
+ );
+ wait_for_quit();
+ return;
+ }
+ tasks_running++;
+
+
+ // Wait for user exit
wait_for_quit();
+ stop_tasks = TRUE;
+ while(tasks_running > 0) {
+ taskYIELD();
+ }
+ stop_tasks = FALSE;
+
+
+ /// Reset module configuration
+ uint8_t pin;
+ for(pin = 1; pin <= 6; pin++) {
+ rpp_mout_set(pin, LOW);
+ }
+
+
+ rpp_sci_printf((const char*)"\r\n");
+
+ return;
}
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
+ // required the first logs might not be registered, 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