Skip to content

Instantly share code, notes, and snippets.

@martinribelotta
Created February 16, 2018 22:14
Show Gist options
  • Save martinribelotta/25873f0edc2f7acfe2f18ca471a06f37 to your computer and use it in GitHub Desktop.
Save martinribelotta/25873f0edc2f7acfe2f18ca471a06f37 to your computer and use it in GitHub Desktop.
Static freeRTOS task creation macros
#include "staticTaskFreeRTOS.h"
TASK_DECL(task, configMINIMAL_STACK_SIZE) {
while(1) {
// DO anything
taskYIELD();
}
}
int main(void)
{
TASK_CREATE(task, tskIDLE_PRIORITY+1);
vTaskStartScheduler();
return 0;
}
#ifndef __STATIC_TASK_FREERTOS_H__
#define __STATIC_TASK_FREERTOS_H__
#include <FreeRTOS.h>
#include <task.h>
#define TASK_TCB(name) __##name##_tcb
#define TASK_STACK(name) __##name##_stack
#define TASK_STACK_SIZE(name) (sizeof(TASK_STACK(name))/sizeof(*TASK_STACK(name)))
#define TASK_DECL(name, stack_size) \
StackType_t TASK_STACK(name)[stack_size]; \
StaticTask_t TASK_TCB(name); \
void name( void* taskParmPtr )
#define TASK_CREATE(name, priority) do { \
xTaskCreateStatic(name, #name, TASK_STACK_SIZE(name), NULL, \
priority, TASK_STACK(name), &TASK_TCB(name)); \
} while(0)
#endif /* __STATIC_TASK_FREERTOS_H__ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment