代码:
#include <stdio.h>
#include “sdkconfig.h”
#include “freertos/FreeRTOS.h”
#include “freertos/task.h”
#include “freertos/semphr.h”
#include “esp_system.h”
#include “esp_spi_flash.h”
/互斥体测试/
SemaphoreHandle_t xmutex;
//void printf_my(char name[],char *arg1) {
void printf_my(char name[],void *arg1,int *counter) {
xSemaphoreTake(xmutex, portMAX_DELAY);
printf(“%s%s”,name,(char *)arg1);
printf(“\n”);
vTaskDelay(100);
printf(“hello\n”);
vTaskDelay(100);
printf(“world!\n”);
vTaskDelay(100);
printf(“%d”,*counter);
vTaskDelay(100);
printf(“\n”);
vTaskDelay(100);
xSemaphoreGive(xmutex);
}
void task1()
{
char name1[] = {“task”};
char * number = {“1 say:”};
int counter = 0;
while (1)
{
//printf_my(name1,number);
counter++;
printf_my(name1,(void *)number,&counter);
}
}
void task2()
{
char name2[] = {“task”};
char * number = {“2 say:”};
int counter = 0;
while (1)
{
//printf_my(name2,(void *)number);
counter++;
printf_my(name2,(void *)number,&counter);
}
}
void test23()
{
xmutex = xSemaphoreCreateMutex()
TaskHandle_t task1Handle = NULL;
TaskHandle_t task2Handle = NULL;
xTaskCreate(task1, "task1", 1024, NULL, 10, &task1Handle);
xTaskCreate(task2, "task2", 1024, NULL, 10, &task2Handle);
}
void app_main(void)
{
printf(“----test 23----\n”);
test23();
}