代码:
#include "at32l021_board.h"
#include "at32l021_clock.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/** @addtogroup UTILITIES_examples
* @{
*/
QueueHandle_t xBinarySemaphore;
/** @addtogroup FreeRTOS_demo
* @{
*/
static void vPeriodicTassk(void *pvParamters)
{
button_type key;
while(1)
{
key=at32_button_press();
if(key==0)
{
if(xBinarySemaphore!=NULL)
{
xSemaphoreGive(xBinarySemaphore);
}
//LED0_TOGGLE();
//vTaskDelay(10);
}/* 延时1000ticks */
}
}
static void vHandlerTask(void *pvParamters)
{
for(;;)
{
xSemaphoreTake(xBinarySemaphore,portMAX_DELAY);
//printf("Handler task - Processing event.\r\n");
if(xBinarySemaphore!=NULL)
{
at32_led_toggle(LED2);
}
//vTaskDelay(500);
}
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] main function.
* @param none
* @retval none
*/
int main(void)
{
system_clock_config();
at32_board_init();
/* init led2 and led3 */
at32_led_init(LED2);
at32_led_init(LED3);
/* init usart1 */
uart_print_init(115200);
/* enter critical */
taskENTER_CRITICAL();
vSemaphoreCreateBinary(xBinarySemaphore);
/* create led2 task */
xTaskCreate((TaskFunction_t )vPeriodicTassk,
(const char* )"vTask1",
(uint16_t )128,
(void* )NULL,
(UBaseType_t )1,
(TaskHandle_t* )NULL);
/* create led3 task */
xTaskCreate((TaskFunction_t )vHandlerTask,
(const char* )"vTask2",
(uint16_t )128,
(void* )NULL,
(UBaseType_t )2,
(TaskHandle_t* )NULL) ;
/* exit critical */
taskEXIT_CRITICAL();
/* start scheduler */
vTaskStartScheduler();
}
效果图
|