抢占式调度
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for myTask02 */
osThreadId_t myTask03Handle;
const osThreadAttr_t myTask03_attributes = {
.name = "myTask03",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal1,
};
void StartDefaultTask(void *argument);
void StartTask03(void *argument);
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN StartDefaultTask */
/* Infinite loop */
for(;;)
{
printf("StartDefaultTask is running\r\n");
if(myTask03Handle == NULL)
myTask03Handle = osThreadNew(StartTask03, NULL, &myTask03_attributes);
printf("StartDefaultTask is end\r\n");
osDelay(1000);
}
/* USER CODE END StartDefaultTask */
}
void StartTask03(void *argument)
{
/* USER CODE BEGIN StartTask02 */
/* Infinite loop */
for(;;)
{
printf("StartTask03 is running\r\n");
osDelay(500);
}
/* USER CODE END StartTask02 */
}
时间片轮转
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for myTask02 */
osThreadId_t myTask02Handle;
uint32_t myTask02Buffer[ 64 ];
osStaticThreadDef_t myTask02ControlBlock;
const osThreadAttr_t myTask02_attributes = {
.name = "myTask02",
.cb_mem = &myTask02ControlBlock,
.cb_size = sizeof(myTask02ControlBlock),
.stack_mem = &myTask02Buffer[0],
.stack_size = sizeof(myTask02Buffer),
.priority = (osPriority_t) osPriorityNormal,
};
void StartDefaultTask(void *argument);
void StartTask02(void *argument);
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of myTask02 */
myTask02Handle = osThreadNew(StartTask02, NULL, &myTask02_attributes);
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN StartDefaultTask */
/* Infinite loop */
for(;;)
{
printf("StartDefaultTask is running\r\n");
for(int i=0;i<9000000;i++)
{
;
}
printf("StartDefaultTask is end\r\n");
osDelay(1000);
}
/* USER CODE END StartDefaultTask */
}
void StartTask02(void *argument)
{
/* USER CODE BEGIN StartTask02 */
/* Infinite loop */
for(;;)
{
printf("StartTask02 is running\r\n");
osDelay(1000);
}
/* USER CODE END StartTask02 */
}