Article Index

 

Page 416

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"

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

void app_main(void)
{
    gpio_reset_pin(2);
    gpio_set_direction(2, GPIO_MODE_OUTPUT);

    TaskHandle_t th1;
    xTaskCreatePinnedToCore(task1, "task1", 2048,
                            NULL, 0, &th1, 1);
    TaskHandle_t th2;
    xTaskCreatePinnedToCore(task2, "task2", 2048,
                            NULL, 0, &th2, 1);
}

 

Page 422

#include <stdio.h>
#include "freertos/FreeRTOS.h"
uint64_t flag1 = 0;
uint64_t flag2 = 0;

void task1(void *arg)
{
    for (;;)
    {
        flag1 = 0xFFFFFFFFFFFFFFFF;
        flag2 = 0xFFFFFFFFFFFFFFFF;
        if (flag1 != flag2)
        {
            printf("task 1 %llX   %llX\n", flag1, flag2);
            fflush(stdout);
        }
    }
}
void task2(void *arg)
{
    for (;;)
    {
        flag1 = 0x0;
        flag2 = 0x0;
        if (flag1 != flag2)
        {
            printf("task 2 %llX   %llX\n", flag1, flag1);
            fflush(stdout);
        }
    }
}
void app_main(void)
{
    TaskHandle_t th1;
    xTaskCreatePinnedToCore(task1, "task1", 4048, NULL, 0, &th1, 1);
    TaskHandle_t th2;
    xTaskCreatePinnedToCore(task2, "task2", 4048, NULL, 0, &th2, 0);
}

 

 Path  424

#include <stdio.h>
#include "freertos/FreeRTOS.h"
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 app_main(void)
{
    TaskHandle_t th1;
    xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 0, &th1, 1);
    TaskHandle_t th2;
    xTaskCreatePinnedToCore(task2, "task2", 2048, NULL, 0, &th2, 0);
    vTaskDelay(4000 / portTICK_PERIOD_MS);
    printf("%llX\n", count);
}

 

Path 426

#include <stdio.h>
#include "freertos/FreeRTOS.h"
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 app_main(void)
{
    TaskHandle_t th1;
    xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 0, &th1, 1);
    TaskHandle_t th2;
    xTaskCreatePinnedToCore(task2, "task2", 2048, NULL, 0, &th2, 0);
    vTaskDelay(4000 / portTICK_PERIOD_MS);
    printf("%llX\n", count);
}

 

Page 428

#include <stdio.h>
#include "freertos/FreeRTOS.h"
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);
        printf("%llX %d\n", data, uxQueueSpacesAvailable(q));
    }
}

void app_main(void)
{
    q = xQueueCreate(100, sizeof(int64_t));

    TaskHandle_t th1;
    xTaskCreatePinnedToCore(task1, "task1", 2048, NULL, 0, &th1, 1);
    TaskHandle_t th2;
    xTaskCreatePinnedToCore(task2, "task2", 4048, NULL, 0, &th2, 0);
}