Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/heap_4bis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 22 additions & 1 deletion src/idle_hook.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@

#include <FreeRTOS.h>
#include <Arduino.h>
//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);
}