3#ifndef PRINTLINES_ALLOWED
4#define PRINTLINES_ALLOWED 0
7static const char *FNAME =
"kest_param_update.c";
9#ifdef KEST_USE_FREERTOS
10#define UPDATE_QUEUE_LENGTH 64
13static int n_waiting = 0;
14static int update_queue_head = 0;
15static int update_queue_tail = 0;
18static int n_updates = 0;
20#define UPDATE_RATE_HZ 500
21#define UPDATE_PERIOD_MS (1000.0f / (float)UPDATE_RATE_HZ)
23static const int update_period_ticks = (pdMS_TO_TICKS((
int)UPDATE_PERIOD_MS) == 0) ? 1 : pdMS_TO_TICKS((int)UPDATE_PERIOD_MS);
26QueueHandle_t update_rtos_queue;
28void remove_param_update(
int index)
30 for (
int i = index; i + 1 < n_updates; i++)
31 update_array[i] = update_array[i+1];
38 for (
int i = 0; i < n_updates; i++)
51 update_array[n_updates++] = up;
66 TickType_t last_wake = xTaskGetTickCount();
80 while ((update_queue_tail + 1) % UPDATE_QUEUE_LENGTH != update_queue_head && xQueueReceive(update_rtos_queue, ¤t, 0) == pdPASS)
85 for (
int i = 0; i < n_updates; i++)
88 if (update_array[i].
id.profile_id == current.
id.
profile_id
89 && update_array[i].id.effect_id == current.
id.
effect_id
101 for (
int j = update_queue_head; j != update_queue_tail; j = (j + 1) % UPDATE_QUEUE_LENGTH)
105 if (update_queue[j].
id.profile_id == current.
id.
profile_id
106 && update_queue[j].id.effect_id == current.
id.
effect_id
117 update_queue[update_queue_tail] = current;
118 update_queue_tail = (update_queue_tail + 1) % UPDATE_QUEUE_LENGTH;
124 update_array[n_updates++] = update_queue[update_queue_head];
125 update_queue_head = (update_queue_head + 1) % UPDATE_QUEUE_LENGTH;
132 for (
int i = 0; i < n_updates; i++)
134 current = update_array[i];
139 remove_param_update(i);
144 param = update_array[i].
p;
148 remove_param_update(i);
155 update_array[i].
send = (update_array[i].
t != NULL);
157 if (update_array[i].send)
159 for (
int j = 0; j < i && update_array[i].
send; j++)
161 if (update_array[j].t == update_array[i].t)
162 update_array[i].
send = 0;
165 if (!(update_array[i].send && update_array[i].t && xSemaphoreTake(update_array[i].t->mutex, 0) == pdTRUE))
166 update_array[i].
send = 0;
177 if (diff < -UPDATE_PERIOD_MS * param->max_velocity)
185 if (diff < -UPDATE_PERIOD_MS * param->max_velocity * param->
value)
195 update_array[i].
send = 0;
212 for (
int i = 0; i < n_updates; i++)
214 if (update_array[i].t && update_array[i].send)
216 if (
global_cxt.active_profile &&
global_cxt.active_profile->id == update_array[i].id.profile_id)
218 xSemaphoreGive(update_array[i].t->mutex);
222 for (
int i = 0; i < n_updates; i++)
224 if (!update_array[i].p)
226 remove_param_update(i);
231 if (update_array[i].p->value == update_array[i].target)
239 remove_param_update(i);
250 xTaskDelayUntil(&last_wake, update_period_ticks);
256 KEST_PRINTF(
"kest_parameter_trigger_update, param = %p, target = %f\n", param, target);
260 KEST_PRINTF(
"Parameter %s, ID %d.%d.%d. Current value: %f. Update target: %f. Max velocity: %f\n",
268 while (!queue_initd);
270 if (xQueueSend(update_rtos_queue, &up, pdMS_TO_TICKS(1)) != pdPASS)
278 KEST_PRINTF(
"kest_parameter_trigger_update, param = %p, target = %f\n", param, target);
282 param->
value = target;
int cxt_get_parameter_and_effect_by_id(kest_context *cxt, kest_parameter_id id, kest_parameter **pp, kest_effect **tp)
int kest_cxt_queue_save_state(kest_context *cxt)
#define CONTEXT_PROFILE_ID
int kest_effect_update_fpga_registers(kest_effect *effect)
#define ERR_CURRENTLY_EXHAUSTED
int kest_fpga_queue_input_gain_set(float gain_db)
int kest_fpga_queue_register_commit()
int kest_fpga_queue_output_gain_set(float gain_db)
int kest_parameter_trigger_update(kest_parameter *param, float target)
#define MAX_CONCURRENT_PARAM_UPDATES
void kest_param_update_task(void *arg)
#define PARAMETER_SCALE_LINEAR
#define PARAMETER_SCALE_LOGARITHMIC
int queue_representation_list_update(kest_representation_pll *reps)