代码:
- #include "at32l021_board.h"
- #include "at32l021_clock.h"
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
- #include "semphr.h"
- #include "stdio.h"
- /** @addtogroup UTILITIES_examples
- * @{
- */
- int cnt=0;
- QueueHandle_t Key_Queue;
- #define KEYMSG_Q_NUM 1
- /** @addtogroup FreeRTOS_demo
- * @{
- */
- //unsigned char const mainSENDER_1=30;
- //unsigned char const mainSENDER_2=50;
- button_type at32_button_press(void);
- void task1(void *pvParameters)
- {
- //uint8_t key;
- BaseType_t err;
- button_type key=0;
- while(1)
- {
- cnt++;
-
- err=xQueueOverwrite(Key_Queue,&cnt);
- //err=xQueueSend(Key_Queue,&key,10);
- if(err!=pdTRUE)
- {
- printf("Queue Send Failed!\r\n");
- }
- else
- {
- printf("Queue Send Succeed!\r\n");
- }
- //LED0_TOGGLE(); /* LED0闪烁 */
- vTaskDelay(1000); /* 延时1000ticks */
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] task2
- * @param pvParameters : 传入参数(未用到)
- * @retval 无
- */
- void Keyprocess_task(void *pvParameters)
- {
- uint8_t key;
- BaseType_t err;
- while(1)
- {
- /* 更新数值 */
- //printf("task3正在运行!!!\r\n"); /* 打印数值 */
-
- if(Key_Queue!=NULL)
- {
- err=xQueueReceive(Key_Queue,&key,portMAX_DELAY);
- if(err==pdTRUE)
- {
- printf("cnt value=%d\r\n",cnt);
- }
- }
- // else
- // {
- //
- // vTaskDelay(1000); /* 延时1000ticks */
- // }
- }
- }
- /**
- * @brief main function.
- * @param none
- * @retval none
- */
- int main(void)
- {
- system_clock_config();
- delay_init();
- /* init led2 and led3 */
- at32_led_init(LED2);
- at32_led_init(LED3);
- at32_button_init();
- /* init usart1 */
- uart_print_init(115200);
-
- Key_Queue=xQueueCreate(KEYMSG_Q_NUM,sizeof(uint8_t));
-
- /* create led2 task */
- xTaskCreate(task1,
- "vTask1",
- 512,
- (void *)30,
-
- 3,
- NULL);
-
- xTaskCreate(Keyprocess_task,
- "vTask2",
- 128,
- NULL,
- 3,
- NULL);
- /* start scheduler */
- vTaskStartScheduler();
-
- }
运行效果图:
|