From b9fe11870745ce18bb8637d55db9f8e7f4e7a03b Mon Sep 17 00:00:00 2001 From: Ryan Srichai Date: Fri, 2 Aug 2024 12:50:23 -0500 Subject: [PATCH] permissions on blink --- .../src/usr/blink/task_blink.c | 184 +++++++++--------- .../src/usr/blink/task_vsi.c | 110 +++++------ .../src/usr/blink/task_vsi.h | 30 +-- 3 files changed, 162 insertions(+), 162 deletions(-) diff --git a/sdk/freertos_app_cpu0/src/usr/blink/task_blink.c b/sdk/freertos_app_cpu0/src/usr/blink/task_blink.c index 2a84c892..1293eba4 100644 --- a/sdk/freertos_app_cpu0/src/usr/blink/task_blink.c +++ b/sdk/freertos_app_cpu0/src/usr/blink/task_blink.c @@ -1,92 +1,92 @@ -#ifdef APP_BLINK - -/* FreeRTOS includes */ -#include "FreeRTOS.h" -#include "task.h" -/* other includes */ -#include "usr/blink/task_blink.h" -#include "drv/led.h" -#include "sys/defines.h" -#include - -// Hold LED animation state -static uint8_t led_pos = 0; -static uint8_t led_color_idx = 0; -#define NUM_LED_COLORS (7) -static led_color_t led_colors[NUM_LED_COLORS] = { - LED_COLOR_RED, // - LED_COLOR_GREEN, // - LED_COLOR_BLUE, // - LED_COLOR_YELLOW, // - LED_COLOR_CYAN, // - LED_COLOR_MAGENTA, // - LED_COLOR_WHITE, // -}; - -// Scheduler TCB which holds task "context" -static TaskHandle_t tcb; -static uint8_t taskExists = 0; // extra data to ensure tasks don't get duplicated or double free'd - -int task_blink_init(void) -{ - if (taskExists) { - return FAILURE; - } - // Fill TCB with parameters - xTaskCreate(task_blink, (const char *) "blink", configMINIMAL_STACK_SIZE, - NULL, tskIDLE_PRIORITY, &tcb); - taskExists = 1; - return SUCCESS; -} - -int task_blink_deinit(void) -{ - if (taskExists == 0) { - return FAILURE; - } - // Turn off all LEDs - for (uint8_t i = 0; i < NUM_LEDS; i++) { - led_set_color(i, LED_COLOR_BLACK); - } - - // Reset state - led_pos = 0; - led_color_idx = 0; - - // Unregister task with scheduler - vTaskDelete(tcb); - taskExists = 0; - return SUCCESS; -} - -void task_blink(void *arg) -{ - for (;;) { - vTaskDelay(TASK_BLINK_INTERVAL_TICKS); - for (uint8_t i = 0; i < NUM_LEDS; i++) { - led_set_color(i, led_pos == i ? led_colors[led_color_idx] : LED_COLOR_BLACK); - } - - if (++led_pos == NUM_LEDS) { - led_pos = 0; - - if (++led_color_idx >= NUM_LED_COLORS) { - led_color_idx = 0; - } - } - } -} - -void task_blink_stats_print(void) -{ - char statsBuffer[configSTATS_BUFFER_MAX_LENGTH]; - vTaskGetRunTimeStats(statsBuffer); - xil_printf("%s\n", statsBuffer); -} - -void task_blink_stats_reset(void) -{ - /* currently does nothing */ -} - -#endif // APP_BLINK +#ifdef APP_BLINK + +/* FreeRTOS includes */ +#include "FreeRTOS.h" +#include "task.h" +/* other includes */ +#include "usr/blink/task_blink.h" +#include "drv/led.h" +#include "sys/defines.h" +#include + +// Hold LED animation state +static uint8_t led_pos = 0; +static uint8_t led_color_idx = 0; +#define NUM_LED_COLORS (7) +static led_color_t led_colors[NUM_LED_COLORS] = { + LED_COLOR_RED, // + LED_COLOR_GREEN, // + LED_COLOR_BLUE, // + LED_COLOR_YELLOW, // + LED_COLOR_CYAN, // + LED_COLOR_MAGENTA, // + LED_COLOR_WHITE, // +}; + +// Scheduler TCB which holds task "context" +static TaskHandle_t tcb; +static uint8_t taskExists = 0; // extra data to ensure tasks don't get duplicated or double free'd + +int task_blink_init(void) +{ + if (taskExists) { + return FAILURE; + } + // Fill TCB with parameters + xTaskCreate(task_blink, (const char *) "blink", configMINIMAL_STACK_SIZE, + NULL, tskIDLE_PRIORITY, &tcb); + taskExists = 1; + return SUCCESS; +} + +int task_blink_deinit(void) +{ + if (taskExists == 0) { + return FAILURE; + } + // Turn off all LEDs + for (uint8_t i = 0; i < NUM_LEDS; i++) { + led_set_color(i, LED_COLOR_BLACK); + } + + // Reset state + led_pos = 0; + led_color_idx = 0; + + // Unregister task with scheduler + vTaskDelete(tcb); + taskExists = 0; + return SUCCESS; +} + +void task_blink(void *arg) +{ + for (;;) { + vTaskDelay(TASK_BLINK_INTERVAL_TICKS); + for (uint8_t i = 0; i < NUM_LEDS; i++) { + led_set_color(i, led_pos == i ? led_colors[led_color_idx] : LED_COLOR_BLACK); + } + + if (++led_pos == NUM_LEDS) { + led_pos = 0; + + if (++led_color_idx >= NUM_LED_COLORS) { + led_color_idx = 0; + } + } + } +} + +void task_blink_stats_print(void) +{ + char statsBuffer[configSTATS_BUFFER_MAX_LENGTH]; + vTaskGetRunTimeStats(statsBuffer); + xil_printf("%s\n", statsBuffer); +} + +void task_blink_stats_reset(void) +{ + /* currently does nothing */ +} + +#endif // APP_BLINK diff --git a/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.c b/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.c index e6e7bbe7..6e8c0d9a 100644 --- a/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.c +++ b/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.c @@ -1,55 +1,55 @@ -#ifdef APP_BLINK -/* FreeRTOS includes */ -#include "FreeRTOS.h" -#include "task.h" -/* other includes */ -#include "usr/blink/task_vsi.h" -#include "drv/led.h" -#include "sys/defines.h" -#include -#include - -// Scheduler TCB which holds task "context" -static TaskHandle_t tcb; - -// Example logging variables for testing -int LOG_task_vsi_runs = 0; -double LOG_vsi_a = 0; -float LOG_vsi_b = 0; -int LOG_vsi_c = 0; - -static double Ts = 1.0 / 10000.0; // [sec] -static double theta = 0.0; // [rad] -static double omega = 10.0; // [rad/s] -static double Do = 0.75; // [--] - -void task_vsi_init(void) -{ - // Fill TCB with parameters - xTaskCreate(task_vsi, (const char *) "vsi", configMINIMAL_STACK_SIZE, - NULL, tskIDLE_PRIORITY, &tcb); -} - -void task_vsi(void *arg) -{ - for (;;) { - vTaskDelay(TASK_VSI_INTERVAL_TICKS); - LOG_task_vsi_runs += 1; - - // Update theta - theta += (Ts * omega); - theta = fmod(theta, 2.0 * M_PI); // Wrap to 2*pi - - // Calculate desired duty ratios - double vsi_a = Do * cos(theta); - double vsi_b = Do * cos(theta + 2.0 * M_PI / 3.0); - double vsi_c = Do * cos(theta + 4.0 * M_PI / 3.0); - - // Update logging variables - LOG_vsi_a = (double) (10e3 * vsi_a); - LOG_vsi_b = (float) (10e3 * vsi_b); - LOG_vsi_c = (int) (10e3 * vsi_c); - } -} - -#endif // APP_BLINK +#ifdef APP_BLINK +/* FreeRTOS includes */ +#include "FreeRTOS.h" +#include "task.h" +/* other includes */ +#include "usr/blink/task_vsi.h" +#include "drv/led.h" +#include "sys/defines.h" +#include +#include + +// Scheduler TCB which holds task "context" +static TaskHandle_t tcb; + +// Example logging variables for testing +int LOG_task_vsi_runs = 0; +double LOG_vsi_a = 0; +float LOG_vsi_b = 0; +int LOG_vsi_c = 0; + +static double Ts = 1.0 / 10000.0; // [sec] +static double theta = 0.0; // [rad] +static double omega = 10.0; // [rad/s] +static double Do = 0.75; // [--] + +void task_vsi_init(void) +{ + // Fill TCB with parameters + xTaskCreate(task_vsi, (const char *) "vsi", configMINIMAL_STACK_SIZE, + NULL, tskIDLE_PRIORITY, &tcb); +} + +void task_vsi(void *arg) +{ + for (;;) { + vTaskDelay(TASK_VSI_INTERVAL_TICKS); + LOG_task_vsi_runs += 1; + + // Update theta + theta += (Ts * omega); + theta = fmod(theta, 2.0 * M_PI); // Wrap to 2*pi + + // Calculate desired duty ratios + double vsi_a = Do * cos(theta); + double vsi_b = Do * cos(theta + 2.0 * M_PI / 3.0); + double vsi_c = Do * cos(theta + 4.0 * M_PI / 3.0); + + // Update logging variables + LOG_vsi_a = (double) (10e3 * vsi_a); + LOG_vsi_b = (float) (10e3 * vsi_b); + LOG_vsi_c = (int) (10e3 * vsi_c); + } +} + +#endif // APP_BLINK diff --git a/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.h b/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.h index eeaf396f..c401d6f4 100644 --- a/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.h +++ b/sdk/freertos_app_cpu0/src/usr/blink/task_vsi.h @@ -1,15 +1,15 @@ -#ifndef TASK_VSI_H -#define TASK_VSI_H - -/* FreeRTOS includes */ -#include "FreeRTOS.h" -#include "task.h" - -#define TASK_VSI_UPDATES_PER_SEC (10000) -#define TASK_VSI_INTERVAL_TICKS (pdMS_TO_TICKS(1000.0 / TASK_VSI_UPDATES_PER_SEC)) - -void task_vsi_init(void); - -void task_vsi(void *arg); - -#endif // TASK_VSI_H +#ifndef TASK_VSI_H +#define TASK_VSI_H + +/* FreeRTOS includes */ +#include "FreeRTOS.h" +#include "task.h" + +#define TASK_VSI_UPDATES_PER_SEC (10000) +#define TASK_VSI_INTERVAL_TICKS (pdMS_TO_TICKS(1000.0 / TASK_VSI_UPDATES_PER_SEC)) + +void task_vsi_init(void); + +void task_vsi(void *arg); + +#endif // TASK_VSI_H