Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.8 KB

RTOS-Basics.md

File metadata and controls

56 lines (37 loc) · 1.8 KB

RTOS basics

RTOS Installation

To set up a new project with RTOS built-in, follow this guide

If you have an existing project and want to switch to add RTOS:

First click on the project and open the SDK manager. (FYI this is how you can access most information you select on project setup.)

Next, check the FreeRTOS box under Operating System tab. Also check "import other files". Click ok and apply.

freeRTOS usage

Include relevant headers.

#include "FreeRTOS.h"
#include "task.h"

Define a function that contains what your task does. Make sure you use the correct delay and other timer-related functions.

/* simple task */
static void MyTask(void *pv) {
    //Do stuff
   	vTaskDelay(pdMS_TO_TICKS(1000)); //1000ms delay
    
}

In the main loop, create task (allocate memory) and start task scheduler.

if (xTaskCreate(  /* create task */
        MyTask,  /* pointer to the task */
        "App", /* task name for kernel awareness debugging */
        200/sizeof(StackType_t), /* task stack size */
        (void*)NULL, /* optional task startup argument */
        tskIDLE_PRIORITY+2,  /* initial priority */
        (TaskHandle_t*)NULL /* optional task handle to create */
      ) != pdPASS) {
       for(;;){} /* error! probably out of memory */
}

vTaskStartScheduler(); //start running tasks

Read more at the freeRTOS API documentation here. A very good and easy to read guide on general usage can be found here.