Article Index

 

Page 340

void task1(void* arg) {
  for (;;) {
    digitalWrite(2, 1);
  }
}
void task2(void* arg) {
  for (;;) {
    digitalWrite(2, 0);
  }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  pinMode(2, OUTPUT);
 
  vTaskSuspendAll();
  TaskHandle_t th1;
  xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 1, &th1, 1);
  TaskHandle_t th2;
  xTaskCreatePinnedToCore(task2, "task2", 2048, NULL, 1, &th2, 1);
  xTaskResumeAll();
}

void loop() {
}

Page 344

uint64_t flag1 = 0;
uint64_t flag2 = 0;

void task1(void* arg) {
    for (;;) {
        flag1 = 0xFFFFFFFFFFFFFFFF;
        flag2 = 0xFFFFFFFFFFFFFFFF;
        if (flag1 != flag2) {
             Serial.printf("task 1 %llX   %llX\n", flag1, flag2);
        }
    }
}
void task2(void* arg) {
    for (;;) {
        flag1 = 0x0;
        flag2 = 0x0;
        if (flag1 != flag2) {
             Serial.printf("task 2 %llX   %llX\n", flag1, flag1);
       
        }
    }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  vTaskSuspendAll();
  TaskHandle_t th1;
  xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 1, &th1, 1);
  TaskHandle_t th2;
  xTaskCreatePinnedToCore(task2, "task2", 2048, NULL, 1, &th2, 1);
  xTaskResumeAll();
}

void loop() {
}

Page 347

int64_t count = 0;

void task1(void* arg) {
    for (int i = 0;i < 0xFFFFF; i++) {
          count = count + 1;        
    }
    for (;;) {
    }
}
void task2(void* arg) {
    for (int i = 0;i < 0xFFFFF; i++) {
          count = count + 1;
    }
    for (;;) {
    }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  vTaskSuspendAll();
  TaskHandle_t th1;
  xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 1, &th1, 1);
  TaskHandle_t th2;
  xTaskCreatePinnedToCore(task2, "task2", 2048, NULL, 0, &th2, 0);
  xTaskResumeAll();
  delay(4000);
  Serial.printf("%llX\n", count);
}

void loop() {
}

 

Page 349


int64_t count = 0;
static portMUX_TYPE my_spinlock = portMUX_INITIALIZER_UNLOCKED;
void task1(void* arg) {
    for (int i = 0;i < 0xFFFFF; i++) {
          taskENTER_CRITICAL(&my_spinlock);
          count = count + 1;
          taskEXIT_CRITICAL(&my_spinlock);        
    }
    for (;;) {
    }
}
void task2(void* arg) {
    for (int i = 0;i < 0xFFFFF; i++) {
          taskENTER_CRITICAL(&my_spinlock);
          count = count + 1;
          taskEXIT_CRITICAL(&my_spinlock);    
    }
    for (;;) {
    }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  vTaskSuspendAll();
  TaskHandle_t th1;
  xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 1, &th1, 1);
  TaskHandle_t th2;
  xTaskCreatePinnedToCore(task2, "task2", 2048, NULL, 0, &th2, 0);
  xTaskResumeAll();
  delay(4000);
  Serial.printf("%llX\n", count);
}

void loop() {
}

Page

QueueHandle_t q;
int64_t count = 0;

void task1(void* arg) {
    for (;;) {
        xQueueSendToBack(q, &count, 2);
        count++;
        vTaskDelay(1);
    }
}
void task2(void* arg) {
    int64_t data;
    for (;;) {
        xQueueReceive(q, &data, 20);
        Serial.printf("%llX %d\n", data,uxQueueSpacesAvailable(q));
    }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  q = xQueueCreate(100, sizeof(int64_t));
  vTaskSuspendAll();
  TaskHandle_t th1;
  xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 1, &th1, 1);
  TaskHandle_t th2;
  xTaskCreatePinnedToCore(task2, "task2", 4048, NULL, 1, &th2, 1);
  xTaskResumeAll();
 }
void loop() {
}

 

Page 354

Not supported on NANO ESP32

#include "esp_task_wdt.h"

esp_task_wdt_user_handle_t uhandle;
void setup() {
  Serial.begin(9600);
  Serial.println();
  esp_task_wdt_add_user("TestWD", &uhandle);
}

void loop() {
  esp_task_wdt_reset_user(uhandle);
  delay(10);
}