Skip to content

Commit

Permalink
[task] added idle cycle task example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentrax committed Nov 11, 2018
1 parent aa54623 commit 55fc1a2
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Chapter04-Task/03-rtos-task-idle-cycle/03-rtos-task-idle-cycle.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// ====================================================
// ArduRTOS Copyright(C) 2018 Furkan Türkal
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
// and you are welcome to redistribute it under certain conditions; See
// file LICENSE, which is part of this source code package, for details.
// ====================================================

#include <Arduino_FreeRTOS.h>

static const char *pcTextForTask = "Task Ran!";

volatile uint32_t ulIdleCycleCount = 0ul;

void vTask(void *pvParamethers);

void setup() {
xTaskCreate(
vTask,
(const portCHAR *) "Task",
100,
(void *)pcTextForTask,
1,
NULL
);

vTaskStartScheduler();
}

void loop() {
// Must be empty to run Tasks correctly
}

void vApplicationIdleHook(void){
ulIdleCycleCount++;
}

void vTask(void *pvParameters){
(void) pvParameters;
const char *pcTaskName = "Task1 Ran!";

const TickType_t xDelay250MS = pdMS_TO_TICKS(250);

Serial.begin(9600);
Serial.println("Task[vTask]::Initialized!");

for(;;){
Serial.println(pcTaskName);
Serial.println(ulIdleCycleCount);
//vPrintStringAndNumber(pcTaskName, ulIdleCycleCount);
vTaskDelay(xDelay250MS);
}
}

void vTaskPeriodic(void *pvParameters){
(void) pvParameters;
const char *pcTaskName = "Task2 Ran!";

const TickType_t xDelay3ms = pdMS_TO_TICKS(1000);

TickType_t xLastWakeTime = xTaskGetTickCount();

Serial.begin(9600);
Serial.println("Task[vTaskPeriodic]::Initialized!");

for(;;){
vTaskDelayUntil(&xLastWakeTime, xDelay3ms);

Serial.print(xLastWakeTime);
Serial.println(pcTaskName);
}
}

0 comments on commit 55fc1a2

Please sign in to comment.