Blink cycling, stack sizes
This commit is contained in:
parent
08da189293
commit
c1ccfacaf0
3 changed files with 55 additions and 18 deletions
15
main/main.c
15
main/main.c
|
@ -7,15 +7,16 @@ extern QueueHandle_t blink_rate_q;
|
|||
|
||||
void app_main(void) {
|
||||
TaskHandle_t task_handle_blink;
|
||||
TaskHandle_t task_handle_blink_cycle;
|
||||
|
||||
blink_rate_q = xQueueCreate(10, sizeof(BlinkCmd_t));
|
||||
|
||||
xTaskCreate(task_blink, "task_blink", 1024, NULL, 0, &task_handle_blink);
|
||||
// Static here, since main exits, this becomes a dead pointer almost instantly
|
||||
static BlinkCmd_t initial_command = {.variant = BLINK_STATE, .state = 1};
|
||||
|
||||
BlinkCmd_t br = {
|
||||
.variant = BLINK_STATE,
|
||||
.state = true,
|
||||
};
|
||||
if (xTaskCreate(task_blink, "task_blink", 1 << 11, (void *)&initial_command, 0, &task_handle_blink) != pdPASS)
|
||||
printf("Error creating task: task_blink");
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
xQueueSend(blink_rate_q, &br, pdMS_TO_TICKS(200));
|
||||
if (xTaskCreate(task_blink_cycle, "task_blink_cycle", 1 << 11, NULL, 0, &task_handle_blink_cycle) != pdPASS)
|
||||
printf("Error creating task: task_blink_cycle");
|
||||
}
|
||||
|
|
|
@ -5,30 +5,30 @@
|
|||
#include <esp_rom_gpio.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "tasks.h"
|
||||
|
||||
QueueHandle_t blink_rate_q;
|
||||
|
||||
void blink_cmd_print(const BlinkCmd_t *cmd) {
|
||||
printf("BlinkCmd {\n");
|
||||
void blink_cmd_print(const BlinkCmd_t *cmd) {
|
||||
printf("BlinkCmd { ");
|
||||
|
||||
switch (cmd->variant) {
|
||||
case BLINK_RATE:
|
||||
printf(" variant: BLINK_RATE,\n");
|
||||
printf(" rate: %lu\n", cmd->rate);
|
||||
printf("variant: BLINK_RATE, ");
|
||||
printf("rate: %" PRIu32, cmd->rate);
|
||||
break;
|
||||
case BLINK_STATE:
|
||||
printf(" variant: BLINK_STATE,\n");
|
||||
printf(" state: %s\n", cmd->state ? "ON" : "OFF");
|
||||
printf("variant: BLINK_STATE, ");
|
||||
printf("state: %s", cmd->state ? "ON" : "OFF");
|
||||
break;
|
||||
default:
|
||||
printf(" variant: UNKNOWN (%d)\n", cmd->variant);
|
||||
printf("variant: UNKNOWN (%d)", cmd->variant);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("}\n");
|
||||
printf(" }\n");
|
||||
}
|
||||
|
||||
void task_blink(void *pvParams) {
|
||||
|
@ -40,12 +40,12 @@ void task_blink(void *pvParams) {
|
|||
// Set this to some initial value
|
||||
BlinkCmd_t command = {
|
||||
.variant = BLINK_RATE,
|
||||
.rate = 1000,
|
||||
.rate = 800,
|
||||
};
|
||||
|
||||
if (pvParams != NULL) {
|
||||
command = *(BlinkCmd_t *)pvParams;
|
||||
printf("Got initial configuration for leds:\n");
|
||||
printf("Got initial configuration for leds: ");
|
||||
blink_cmd_print(&command);
|
||||
}
|
||||
|
||||
|
@ -66,3 +66,38 @@ void task_blink(void *pvParams) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void task_blink_cycle(void *pvParams) {
|
||||
BlinkCmd_t cmd = {
|
||||
.variant = BLINK_RATE,
|
||||
.rate = 1000,
|
||||
};
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
|
||||
if (xQueueSend(blink_rate_q, &cmd, pdMS_TO_TICKS(200)) != pdPASS) {
|
||||
printf("Error sending blink command...");
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
|
||||
cmd.rate = 50;
|
||||
if (xQueueSend(blink_rate_q, &cmd, pdMS_TO_TICKS(200)) != pdPASS) {
|
||||
printf("Error sending blink command...");
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
|
||||
cmd.rate = 500;
|
||||
if (xQueueSend(blink_rate_q, &cmd, pdMS_TO_TICKS(200)) != pdPASS) {
|
||||
printf("Error sending blink command...");
|
||||
}
|
||||
|
||||
cmd.variant = BLINK_STATE;
|
||||
cmd.state = 1;
|
||||
if (xQueueSend(blink_rate_q, &cmd, pdMS_TO_TICKS(200)) != pdPASS) {
|
||||
printf("Error sending blink command...");
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ typedef struct {
|
|||
} BlinkCmd_t;
|
||||
|
||||
void task_blink(void *pvParams);
|
||||
void task_blink_cycle(void *pvParams);
|
||||
|
||||
/* End: task_blink.c */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue