diff --git a/src/FreeRTOSConfig.h b/src/FreeRTOSConfig.h index 59f6099..8b596d7 100644 --- a/src/FreeRTOSConfig.h +++ b/src/FreeRTOSConfig.h @@ -46,7 +46,7 @@ #define configUSE_PREEMPTION 1 -#define configUSE_IDLE_HOOK 1 +#define configUSE_IDLE_HOOK 1 // 0 = loop() is a dedicated task | 1 = loop() is the FreeRTOS idle hook function TODO #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( ( unsigned long ) F_CPU ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) @@ -159,6 +159,9 @@ to all Cortex-M ports, and do not rely on any particular library functions. */ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* Run Arduino Loop function as dedicated stack */ +extern void runLoopAsTask(uint16_t stack, uint16_t priority); + /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ #define vPortSVCHandler SVC_Handler diff --git a/src/heap_4bis.c b/src/heap_4bis.c index c6d3354..319f66b 100644 --- a/src/heap_4bis.c +++ b/src/heap_4bis.c @@ -435,7 +435,9 @@ uint8_t *puc; } // non standard contributed feature that can be enabled +#ifndef ENABLE_CALLOC_REALLOC #define ENABLE_CALLOC_REALLOC 0 +#endif #if ENABLE_CALLOC_REALLOC diff --git a/src/idle_hook.c b/src/idle_hook.c index 1d1c725..ab5c23e 100644 --- a/src/idle_hook.c +++ b/src/idle_hook.c @@ -1,12 +1,33 @@ #include #include +//Arduino loop as task +#include "task.h" +uint8_t loopAsTask = 0; +TaskHandle_t loopHandle; // this is referring to the loop function of your arduino project extern void loop(void); void __attribute__((weak)) vApplicationIdleHook( void ) { - loop(); //will use your projects loop function as the rtos idle loop + if (!loopAsTask) + { + loop(); //will use your projects loop function as the rtos idle loop + } +} + +void loopTask(void *pvParameters) +{ + while(1) + { + loop(); + } +} + +void runLoopAsTask(uint16_t stack, uint16_t priority) +{ + loopAsTask = 1; + xTaskCreate(loopTask, "loop", stack, ( void * ) NULL, ( (UBaseType_t)priority | portPRIVILEGE_BIT ) , &loopHandle); }