代码:
#include "at32l021_board.h"
#include "at32l021_clock.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
/** @addtogroup UTILITIES_examples
* @{
*/
QueueHandle_t CountSemaphore;
//unsigned char flag=0;
/** @addtogroup FreeRTOS_demo
* @{
*/
button_type key=1;
//extern QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
//const UBaseType_t uxInitialCount );
static void vPeriodicTassk(void *pvParamters)
{
unsigned int i;
UBaseType_t err;
while(1)
{
key=at32_adatin_state();
if(key==0)
{
for(i=0;i<3000;i++)
{
key=at32_adatin_state();
if(key==0)
{
while(1)
{
key=at32_adatin_state();
if(key==1)
break;
}
if(CountSemaphore!=NULL)
{
err=xSemaphoreGive(CountSemaphore);
if(err==pdFALSE)
{
printf("Sem Rele Failed!\r\n");
//flag=0;
}
else
{
printf("Sem Role Succeed!\r\n");
//flag=1;
}
}
}
}
//LED0_TOGGLE();
//vTaskDelay(10);
}/* 延时1000ticks */
}
}
static void vHandlerTask(void *pvParamters)
{
unsigned int i;
UBaseType_t semavalue=0;
while(1)
{
if(CountSemaphore!=NULL)
{
//if(flag==1)
//{
// flag=0;
xSemaphoreTake(CountSemaphore,portMAX_DELAY);
semavalue=uxSemaphoreGetCount(CountSemaphore);
printf("semavalue value=%d\r\n",(int)semavalue);
//}
}
//else
//{
// for(i=0;i<1000;i++);
//}
//printf("Task2 Running!\r\n");
//vTaskDelay(1000);
for(i=0;i<60000;i++);
}
}
/**
* [url=home.php?mod=space&uid=159083]@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();
CountSemaphore=xSemaphoreCreateCounting(10,10);
if(CountSemaphore==NULL)
{
printf("create CountSemaphore failed!\r\n");
}
/* create led2 task */
xTaskCreate((TaskFunction_t )vPeriodicTassk,
(const char* )"vTask1",
(uint16_t )128,
(void* )NULL,
(UBaseType_t )2,
(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();
}
/**
* @}
*/
/**
* @}
*/
这个程序,一运行就收到信号量
到零后,按下按键,发送成功,可是收不到信号量。
请问高手,这个程序有什么问题?谢谢
|