[AT32L021] 【AT-START-L021测评】+FREERTOS二值信号量

[复制链接]
1085|0
 楼主| 比神乐 发表于 2024-12-9 10:59 | 显示全部楼层 |阅读模式
代码:
  1. #include "at32l021_board.h"
  2. #include "at32l021_clock.h"
  3. #include "FreeRTOS.h"
  4. #include "task.h"
  5. #include "semphr.h"
  6. /** @addtogroup UTILITIES_examples
  7.   * @{
  8.   */
  9. QueueHandle_t xBinarySemaphore;
  10. /** @addtogroup FreeRTOS_demo
  11.   * @{
  12.   */
  13. static void vPeriodicTassk(void *pvParamters)
  14. {
  15.         button_type key;
  16.     while(1)
  17.     {        
  18.                                 key=at32_button_press();
  19.                         if(key==0)
  20.                         {
  21.                                         if(xBinarySemaphore!=NULL)
  22.                                         {
  23.                                                 xSemaphoreGive(xBinarySemaphore);
  24.                                         }
  25.                                 
  26.         
  27.                                 //LED0_TOGGLE();
  28.         //vTaskDelay(10);
  29.                                 }/* 延时1000ticks */
  30.     }
  31. }
  32. static void vHandlerTask(void *pvParamters)
  33. {
  34.         for(;;)
  35.         {
  36.                 xSemaphoreTake(xBinarySemaphore,portMAX_DELAY);
  37.                 //printf("Handler task - Processing event.\r\n");
  38.                 if(xBinarySemaphore!=NULL)
  39.                 {
  40.                         at32_led_toggle(LED2);
  41.                 }
  42.                 //vTaskDelay(500);
  43.         }
  44. }
  45. /**
  46.   * [url=home.php?mod=space&uid=247401]@brief[/url]  main function.
  47.   * @param  none
  48.   * @retval none
  49.   */
  50. int main(void)
  51. {
  52.   system_clock_config();
  53.         at32_board_init();
  54.   /* init led2 and led3 */
  55.   at32_led_init(LED2);
  56.   at32_led_init(LED3);

  57.   /* init usart1 */
  58.   uart_print_init(115200);
  59.         
  60.   /* enter critical */
  61.   taskENTER_CRITICAL();
  62.         vSemaphoreCreateBinary(xBinarySemaphore);
  63.   /* create led2 task */
  64.   xTaskCreate((TaskFunction_t )vPeriodicTassk,
  65.                  (const char*    )"vTask1",
  66.                  (uint16_t       )128,
  67.                  (void*          )NULL,
  68.                  (UBaseType_t    )1,
  69.                  (TaskHandle_t*  )NULL);
  70.   
  71.   /* create led3 task */
  72.   xTaskCreate((TaskFunction_t )vHandlerTask,
  73.                  (const char*    )"vTask2",
  74.                  (uint16_t       )128,
  75.                  (void*          )NULL,
  76.                  (UBaseType_t    )2,
  77.                  (TaskHandle_t*  )NULL) ;
  78.   

  79.   /* exit critical */
  80.   taskEXIT_CRITICAL();

  81.   /* start scheduler */
  82.   vTaskStartScheduler();
  83. }

效果图
5.jpg 6.jpg
您需要登录后才可以回帖 登录 | 注册

本版积分规则

470

主题

3537

帖子

7

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