实现多个任务利用同一个函数,传进不同的任务参数,打印不同的任务内容。多个人用同一个电脑干不同工作,美工用电脑干美工,程序员用电脑敲代码
#include "stm32f10x.h" // Device header
#include "freertos.h"
#include "task.h"
#include "usart.h"
TaskHandle_t myTaskHandler1;
TaskHandle_t myTaskHandler2;
TaskHandle_t myTaskHandler3;
TaskHandle_t startTaskHandler;
void myPrintf(void* arg){
char* str=arg;
while(1){
taskENTER_CRITICAL();
printf("%s\n",str);
taskEXIT_CRITICAL();
vTaskDelay(500);
}
}
void startTask(void* arg){
taskENTER_CRITICAL();
printf("start running\n");
taskEXIT_CRITICAL();
xTaskCreate(myPrintf, "myTask", 128, "myTask1", 2, &myTaskHandler1);
xTaskCreate(myPrintf, "myTask", 128, "myTask2", 2, &myTaskHandler2);
xTaskCreate(myPrintf, "myTask", 128, "myTask3", 2, &myTaskHandler3);
vTaskDelete(NULL);
}
int main(void){
USART_Config();
xTaskCreate(startTask,"startTask",128,NULL,2,&startTaskHandler);
vTaskStartScheduler();
while(1)
{
}
}
StaticTask_t IdleTaskTCB;
StackType_t IdleTaskStack[configMINIMAL_STACK_SIZE];
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize )
{
*ppxIdleTaskTCBBuffer = &IdleTaskTCB;
*ppxIdleTaskStackBuffer = IdleTaskStack;
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
现象: