-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
162 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <stdint.h> | ||
|
||
// 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 <stdint.h> | ||
|
||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <math.h> | ||
#include <stdint.h> | ||
|
||
// 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 <math.h> | ||
#include <stdint.h> | ||
|
||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |