From 03597d9162a2fcbdd32e4d187b07a021c221d613 Mon Sep 17 00:00:00 2001 From: Andrew Clink Date: Mon, 20 Mar 2017 12:56:17 -0700 Subject: [PATCH] Make FreeRTOS hooks weak; Add example --- core/app_main.c | 4 +- examples/tick_idle_hooks/FreeRTOSConfig.h | 10 ++++ examples/tick_idle_hooks/Makefile | 3 ++ examples/tick_idle_hooks/hooks_example.c | 56 +++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 examples/tick_idle_hooks/FreeRTOSConfig.h create mode 100644 examples/tick_idle_hooks/Makefile create mode 100644 examples/tick_idle_hooks/hooks_example.c diff --git a/core/app_main.c b/core/app_main.c index 05ad952..e56b0ab 100644 --- a/core/app_main.c +++ b/core/app_main.c @@ -236,12 +236,12 @@ void IRAM vApplicationStackOverflowHook(TaskHandle_t task, char *task_name) { } // .text+0x3d8 -void IRAM vApplicationIdleHook(void) { +void __attribute__((weak)) IRAM vApplicationIdleHook(void) { printf("idle %u\n", WDEV.SYS_TIME); } // .text+0x404 -void IRAM vApplicationTickHook(void) { +void __attribute__((weak)) IRAM vApplicationTickHook(void) { printf("tick %u\n", WDEV.SYS_TIME); } diff --git a/examples/tick_idle_hooks/FreeRTOSConfig.h b/examples/tick_idle_hooks/FreeRTOSConfig.h new file mode 100644 index 0000000..e21d827 --- /dev/null +++ b/examples/tick_idle_hooks/FreeRTOSConfig.h @@ -0,0 +1,10 @@ +/** + + Configuration overrides for FreeRTOS. + +**/ + +#define configUSE_IDLE_HOOK 1 +#define configUSE_TICK_HOOK 1 + +#include_next "FreeRTOSConfig.h" \ No newline at end of file diff --git a/examples/tick_idle_hooks/Makefile b/examples/tick_idle_hooks/Makefile new file mode 100644 index 0000000..717b163 --- /dev/null +++ b/examples/tick_idle_hooks/Makefile @@ -0,0 +1,3 @@ +# Simple makefile for simple example +PROGRAM=simple +include ../../common.mk diff --git a/examples/tick_idle_hooks/hooks_example.c b/examples/tick_idle_hooks/hooks_example.c new file mode 100644 index 0000000..8b9fa49 --- /dev/null +++ b/examples/tick_idle_hooks/hooks_example.c @@ -0,0 +1,56 @@ +/* Very basic example that just demonstrates we can run at all! + */ +#include "espressif/esp_common.h" +#include "esp/uart.h" +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + +void vApplicationIdleHook(void) +{ + // Go to sleep; either deeply (waiting for an event to wake) + // or light, allowing FreeRTOS ticks to wake + sdk_wifi_set_sleep_type(WIFI_SLEEP_MODEM); +} + +void vApplicationTickHook(void) +{ + // Called every tick +} + +void task1(void *pvParameters) +{ + QueueHandle_t *queue = (QueueHandle_t *)pvParameters; + printf("Hello from task1!\r\n"); + uint32_t count = 0; + while(1) { + vTaskDelay(100); + xQueueSend(*queue, &count, 0); + count++; + } +} + +void task2(void *pvParameters) +{ + printf("Hello from task 2!\r\n"); + QueueHandle_t *queue = (QueueHandle_t *)pvParameters; + while(1) { + uint32_t count; + if(xQueueReceive(*queue, &count, 1000)) { + printf("Got %u\n", count); + } else { + printf("No msg :(\n"); + } + } +} + +static QueueHandle_t mainqueue; + +void user_init(void) +{ + uart_set_baud(0, 115200); + printf("SDK version:%s\n", sdk_system_get_sdk_version()); + mainqueue = xQueueCreate(10, sizeof(uint32_t)); + xTaskCreate(task1, "tsk1", 256, &mainqueue, 2, NULL); + xTaskCreate(task2, "tsk2", 256, &mainqueue, 2, NULL); +}