代码:
- #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;
- SemaphoreHandle_t MutexSemaphore;
- /** @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)
- {
- static uint32_t times;
- while(1)
- {
- xSemaphoreTake(MutexSemaphore,portMAX_DELAY);
- printf("low task Running!\r\n");
- for(times=0;times<2000000;times++)
- {
- delay_us(2);
- //taskYIELD();
- }
- xSemaphoreGive(MutexSemaphore);
- vTaskDelay(1000); /* 延时1000ticks */
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] task2
- * @param pvParameters : 传入参数(未用到)
- * @retval 无
- */
- void Keyprocess_task(void *pvParameters)
- {
- while(1)
- {
-
- printf("middle task Running!\r\n");
- vTaskDelay(1000);
-
- }
- }
- void task3(void *pvParameters)
- {
-
- while(1)
- {
- printf("high task Pend Sem!\r\n");
- xSemaphoreTake(MutexSemaphore,portMAX_DELAY);
- printf("high task Running!\r\n");
- xSemaphoreGive(MutexSemaphore);
- vTaskDelay(1000);
-
- }
- }
- /**
- * @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);
-
- MutexSemaphore=xSemaphoreCreateMutex();
- if(MutexSemaphore==NULL)
- {
- printf("Sema Create Failed!\r\n");
- }
-
- /* create led2 task */
- xTaskCreate(task1,
- "vTask1",
- 128,
- (void *)30,
-
- 2,
- NULL);
-
- xTaskCreate(Keyprocess_task,
- "vTask2",
- 128,
- NULL,
- 3,
- NULL);
- xTaskCreate(task3,
- "vTask3",
- 128,
- NULL,
- 4,
- NULL);
- /* start scheduler */
- vTaskStartScheduler();
-
- }
运行效果图:
|