FreeRTOS

FreeRTOS

void vTaskCode( void * pvParameters )
{
    /* Grab Parameter */
    uint32_t c = (uint32_t)(pvParameters);
    /* Define Constants Here */
    const uint32_t COUNT_INCREMENT = 20;
    /* Define Local Variables */
    uint32_t counter = 0;
    /* Initialization Code */
    initTIMER();
    /* Code Loop */
    while(1)
    {
        /* Insert Loop Code */
    }
    /* Only necessary if above loop has a condition */
    xTaskDelete(NULL);
}

int main(int argc, char const *argv[])
{
    //// You may need to change this value.
    const uint32_t STACK_SIZE = 128;
    xReturned = xTaskCreate(
                    vTaskCode,       /* Function that implements the task. */
                    "NAME",          /* Text name for the task. */
                    STACK_SIZE,      /* Stack size in words, not bytes. */
                    ( void * ) 1,    /* Parameter passed into the task. */
                    tskIDLE_PRIORITY,/* Priority at which the task is created. */
                    &xHandle );      /* Used to pass out the created task's handle. */

    /* Start Scheduler */
    vTaskStartScheduler();

    return 0;
}

C++ Scheduler Task

/**
 * Add this on top of main()
 * Read "scheduler.task" for more documentation
 * Read "examples.cpp" for more examples.
 */
class myTask : public scheduler_task
{
public:
	myTask (uint8_t priority) : scheduler_task("mytask", 512 * 8, priority)
	{
	}

	/* this function will be called in a loop by FreeRTOS */
	bool run(void *p)
	{
		puts("Hello");
		vTaskDelay(1000);
		return true; /* Returning false will suspend the task */
	}
};

int main(void)
{
	// ...
	/* Add your new task here */
	scheduler_add_task(new myTask(PRIORITY_LOW));
	// ...
	scheduler_start(false);
	// ...
}

Revision #2
Created 10 months ago by Khalil Estell
Updated 10 months ago by Khalil Estell