Skip to content

Commit

Permalink
tested and validated signal injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Known4225 committed Nov 18, 2024
1 parent 06b5e2d commit e14f096
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
7 changes: 7 additions & 0 deletions sdk/freertos_app_cpu0/src/usr/vsiApp/cmd/cmd_vsiApp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static command_help_t cmd_help[] = {
{ "deinit", "Stop task" },
{ "amplitude <value>", "set the analog wave to a specific amplitude" },
{ "frequency <value>", "set the analog wave to a specific frequency" },
{ "clear", "clear signal injections" },
{ "stats print", "Print stats to screen" },
{ "stats reset", "Reset the task timing stats" }
};
Expand Down Expand Up @@ -55,6 +56,12 @@ int cmd_vsiApp(int argc, char **argv)
}
return CMD_SUCCESS;
}
if (argc == 2 && strcmp("clear", argv[1]) == 0) {
if (task_vsiApp_clear_inj() != SUCCESS) {
return CMD_FAILURE;
}
return CMD_SUCCESS;
}

if (argc == 2 && strcmp("init", argv[1]) == 0) {
if (task_vsiApp_init() != SUCCESS) {
Expand Down
34 changes: 28 additions & 6 deletions sdk/freertos_app_cpu0/src/usr/vsiApp/task_vsiApp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "drv/amds.h"
#include "sys/defines.h"
#include "sys/log.h"
#include "sys/injection.h"
#include "sys/util.h"
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
Expand All @@ -21,28 +23,35 @@
static TaskHandle_t tcb;
static uint8_t taskExists = 0; // extra data to ensure tasks don't get duplicated or double free'd


static double Ts = 1.0 / 10000.0; // [sec]
static double theta = 0.0; // [rad]
static double omega = 10.0 * 2 * PI; // [rad/s]
static double Do = 0.3; // [--]

/* trying this out */
#include "xil_io.h"
#define PWM_MUX_ADDR_LOGGING (0x43C40000)
/* injection */
static inj_ctx_t inj_ctx_ctrl[3] = {0};

int task_vsiApp_init(void)
{
if (taskExists) {
return FAILURE;
}

/* PWM */
if (pwm_enable_hw(true) != SUCCESS) {
return FAILURE;
}
if (pwm_enable() != SUCCESS) {
return FAILURE;
}
/* Initialize signal injection points */
injection_ctx_init(&inj_ctx_ctrl[0], "amp*");
injection_ctx_init(&inj_ctx_ctrl[1], "theta*");
injection_ctx_init(&inj_ctx_ctrl[2], "omega_m*");

/* Register all signal injection points */
for (int i = 0; i < ARRAY_SIZE(inj_ctx_ctrl); i++) {
injection_ctx_register(&inj_ctx_ctrl[i]);
}

// Fill TCB with parameters
taskExists = 1;
Expand Down Expand Up @@ -78,6 +87,11 @@ void task_vsiApp(void *arg)
float amds_current_a = 0.0;
for (;;) {
vTaskDelay(TASK_VSIAPP_INTERVAL_TICKS);
// Perform signal injections
injection_inj(&Do, &inj_ctx_ctrl[0], Ts);
injection_inj(&theta, &inj_ctx_ctrl[1], Ts);
injection_inj(&omega, &inj_ctx_ctrl[2], Ts);

// Update theta
theta += (Ts * omega);
theta = fmod(theta, 2.0 * M_PI); // Wrap to 2*pi
Expand Down Expand Up @@ -131,7 +145,7 @@ void task_vsiApp(void *arg)
// sample value for each channel
}

log_callback(&current_a, LOG_FLOAT, "current_a");
log_callback(&Do, LOG_DOUBLE, "current_a");
log_callback(&current_b, LOG_FLOAT, "current_b");
log_callback(&current_c, LOG_FLOAT, "current_c");
log_callback(&voltage_a, LOG_FLOAT, "voltage_a");
Expand Down Expand Up @@ -167,4 +181,12 @@ void task_vsiApp_stats_reset(void) {
/* does nothing */
}

int task_vsiApp_clear_inj(void) {
// Clear all injection points
for (int i = 0; i < ARRAY_SIZE(inj_ctx_ctrl); i++) {
injection_ctx_clear(&inj_ctx_ctrl[i]);
}
return SUCCESS;
}

#endif // APP_BLINK
1 change: 1 addition & 0 deletions sdk/freertos_app_cpu0/src/usr/vsiApp/task_vsiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void task_vsiApp(void *arg);

int task_vsiApp_amplitude(double amplitude);
int task_vsiApp_frequency(double frequency);
int task_vsiApp_clear_inj(void);

void task_vsiApp_stats_print(void);
void task_vsiApp_stats_reset(void);
Expand Down
11 changes: 5 additions & 6 deletions sdk/shared/sys/injection.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,19 @@ void injection_ramp(inj_ctx_t *ctx, inj_op_e op, double valueMin, double valueMa
typedef enum sm_states_list_e { LISTING = 1, REMOVE_TASK } sm_states_list_e;

typedef struct sm_ctx_list_t {
sm_states_list_e state;
TaskHandle_t tcb;

sm_states_list_e state;
inj_ctx_t *curr;
TaskHandle_t tcb;
} sm_ctx_list_t;

static sm_ctx_list_t ctx_list;

#define TASK_SM_LIST_UPDATES_PER_SEC (10000)
#define TASK_SM_LIST_INTERVAL_TICKS (pdMS_TO_TICKS(1000.0 / TASK_SM_LIST_UPDATES_PER_SEC))

void state_machine_list_callback(void *arg)
{
sm_ctx_list_t *ctx = (sm_ctx_list_t *) arg;
sm_ctx_list_t *ctx = &ctx_list;
for (;;) {
vTaskDelay(TASK_SM_LIST_INTERVAL_TICKS);
switch (ctx->state) {
Expand All @@ -440,8 +441,6 @@ void state_machine_list_callback(void *arg)
}
}

static sm_ctx_list_t ctx_list;

void injection_list(void)
{
if (inj_ctxs == NULL) {
Expand Down

0 comments on commit e14f096

Please sign in to comment.