[AT32L021] 【AT-START-L021测评】任务函数

[复制链接]
1447|0
 楼主| 比神乐 发表于 2024-12-4 23:38 | 显示全部楼层 |阅读模式
代码:
  1. #include "at32l021_board.h"
  2. #include "at32l021_clock.h"
  3. #include "FreeRTOS.h"
  4. #include "task.h"

  5. /** @addtogroup UTILITIES_examples
  6.   * @{
  7.   */
  8. static const char *pcTextForTask1="Task 1 is running\r\n";
  9. static const char *pcTextForTask2="Task 2 is running\r\n";

  10. /** @addtogroup FreeRTOS_demo
  11.   * @{
  12.   */
  13. /* led2 task function */
  14. void vTaskFunction(void *pvParameters)
  15. {
  16.         char *pcTaskName;
  17.         pcTaskName=(char * )pvParameters;
  18.   while(1)
  19.   {
  20.                 printf("%s\r\n",pcTaskName);
  21.     vTaskDelay(1000);
  22.   }
  23. }



  24. //void vTask1(void *pvParameters);
  25. //void vTask2(void *pvParameters);
  26. /**
  27.   * [url=home.php?mod=space&uid=247401]@brief[/url]  main function.
  28.   * @param  none
  29.   * @retval none
  30.   */
  31. int main(void)
  32. {
  33.   system_clock_config();

  34.   /* init led2 and led3 */
  35.   at32_led_init(LED2);
  36.   at32_led_init(LED3);

  37.   /* init usart1 */
  38.   uart_print_init(115200);

  39.   /* enter critical */
  40.   taskENTER_CRITICAL();

  41.   /* create led2 task */
  42.   xTaskCreate((TaskFunction_t )vTaskFunction,
  43.                  (const char*    )"vTask1",
  44.                  (uint16_t       )512,
  45.                  (void*          )pcTextForTask1,
  46.                  (UBaseType_t    )1,
  47.                  (TaskHandle_t*  )NULL);
  48.   
  49.   /* create led3 task */
  50.   xTaskCreate((TaskFunction_t )vTaskFunction,
  51.                  (const char*    )"vTask2",
  52.                  (uint16_t       )512,
  53.                  (void*          )pcTextForTask2,
  54.                  (UBaseType_t    )2,
  55.                  (TaskHandle_t*  )NULL) ;
  56.   

  57.   /* exit critical */
  58.   taskEXIT_CRITICAL();

  59.   /* start scheduler */
  60.   vTaskStartScheduler();
  61. }

运行效果:
5.jpg
您需要登录后才可以回帖 登录 | 注册

本版积分规则

470

主题

3537

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部