在优先级 osPriorityIdle上创建两个任务。这两个任务只是不停地打印输出字符串,然它什么事情也不做。
第三个任务创建在优先级 osPriorityLow 上,高于另外两个任务的优先级。这个任务虽然也是打印输出字符串,但它是周期性的,所以调用了osDelayUntil(),在每两次打印之间处于阻塞态。
但最后的结果是一直打印任务3的内容,并没有出现两者交替打印的现象。
本人刚刚自学freertos ,不知问题出现在哪里,请懂freertos的大神指教一二。
/* definition and creation of myTask01 */
osThreadDef(myTask01, StartTask01, osPriorityIdle, 0, 128);
myTask01Handle = osThreadCreate(osThread(myTask01), NULL);
/* definition and creation of myTask02 */
osThreadDef(myTask02, StartTask02, osPriorityIdle, 0, 128);
myTask02Handle = osThreadCreate(osThread(myTask02), NULL);
/* definition and creation of myTask03 */
osThreadDef(myTask03, StartTask03, osPriorityLow, 0, 128);
myTask03Handle = osThreadCreate(osThread(myTask03), NULL);
/* USER CODE BEGIN Header_StartTask01 */
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Function implementing the myTask01 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask01 */
void StartTask01(void const * argument)
{
/* USER CODE BEGIN StartTask01 */
/* Infinite loop */
for(;;)
{
printf("task01 is runnning\r\n");
//osDelay(1);
}
/* USER CODE END StartTask01 */
}
/* USER CODE BEGIN Header_StartTask02 */
/**
* @brief Function implementing the myTask02 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask02 */
void StartTask02(void const * argument)
{
/* USER CODE BEGIN StartTask02 */
/* Infinite loop */
for(;;)
{
printf("task02 is runnning\r\n");
//osDelay(1);
}
/* USER CODE END StartTask02 */
}
/* USER CODE BEGIN Header_StartTask03 */
/**
* @brief Function implementing the myTask03 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask03 */
void StartTask03(void const * argument)
{
/* USER CODE BEGIN StartTask03 */
/* Infinite loop */
portTickType xLastWakeTime;
const portTickType xDelay5ms = pdMS_TO_TICKS(1000UL);
xLastWakeTime = xTaskGetTickCount();
for(;;)
{
printf("task03 is runnning\r\n");
osDelayUntil(&xLastWakeTime,xDelay5ms);
//osDelay(1);
}
/* USER CODE END StartTask03 */
}
|