stm32f103 중freertos의tasks 기본 사용 사례 및 메모
기본 실례
freetos는 stm32에서 사용하고 구덩이를 밟았습니다. 일이 끝나면 잊어버리고 뒤에 있는 사람에게 참고가 되었으면 합니다.먼저 실제적인 예를 하나 제시합시다.
void task_create(void)
{
    xTaskCreate(vButtonCheckTask,"Button",configMINIMAL_STACK_SIZE,NULL,configMAX_PRIORITIES-1,NULL);
    xTaskCreate(vButtonLEDsTask,"ButtonLeds",configMINIMAL_STACK_SIZE,NULL,configMAX_PRIORITIES-1,NULL);
}
  static void vButtonCheckTask( void *pvParameters )
{
  //for debounce
  static uint8_t count;
  portTickType xLastWakeTime;
  const portTickType xFrequency = 20;
  const portTickType yDelay = 20 / portTICK_RATE_MS;
  xLastWakeTime=xTaskGetTickCount();
  //create semaphores for each button
  vSemaphoreCreateBinary(xButtonWakeupSemaphore);
  vSemaphoreCreateBinary(xButtonUser1Semaphore);
  vSemaphoreCreateBinary(xButtonUser2Semaphore);
//check if semaphores were created successfully
  if((xButtonWakeupSemaphore!=NULL)&&(xButtonUser1Semaphore!=NULL)&&(xButtonUser2Semaphore!=NULL))
  {
    //successfully created
    //resets initial semaphores to 0
    xSemaphoreTake(xButtonWakeupSemaphore, (portTickType)0);
    xSemaphoreTake(xButtonUser1Semaphore, (portTickType)0);
    xSemaphoreTake(xButtonUser2Semaphore, (portTickType)0);
  }  else {
      //send error of failure
  }
  for (;;)
    {
      if (ButtonRead(BWAKEUPPORT, BWAKEUP)==pdTRUE)
        {
          vTaskDelay(yDelay);
          if(ButtonRead(BWAKEUPPORT, BWAKEUP)==pdTRUE)
          {
              while(ButtonRead(BWAKEUPPORT, BWAKEUP)==pdTRUE);
              xSemaphoreGive(xButtonWakeupSemaphore);
              //LEDToggle(1);
              usart1_puts(" key1 pressed \r
");
              //printf(" led 1 on\r
");
          }
        }
      if (ButtonRead(BUSER1PORT, BUSER1)==pdTRUE)
        {
          vTaskDelay(yDelay);
          if(ButtonRead(BUSER1PORT, BUSER1)==pdTRUE)
          {
              while(ButtonRead(BUSER1PORT, BUSER1)==pdTRUE);
              //LEDToggle(1);
              //printf(" use1 presssed
\r");
              usart1_puts("key2 presssed
\r");
              xSemaphoreGive(xButtonUser1Semaphore);
          }
        }
      if (ButtonRead(BUSER2PORT, BUSER2)==pdTRUE)
        {
          vTaskDelay(yDelay);
          if(ButtonRead(BUSER2PORT, BUSER2)==pdTRUE)
          {
              while(ButtonRead(BUSER2PORT, BUSER2)==pdTRUE);
              usart1_puts("key3 presssed 
\r");
              //xSemaphoreGive(xButtonUser2Semaphore);
          }
        }
    }
}
void vButtonLEDsTask( void *pvParameters )
{
  const portTickType xDelay = 50 / portTICK_RATE_MS;
  for( ;; )
  {
      if((xButtonWakeupSemaphore!=NULL)&&(xButtonUser1Semaphore!=NULL)&&(xButtonUser2Semaphore!=NULL))
      {
         if (xSemaphoreTake(xButtonWakeupSemaphore, (portTickType)10)==pdTRUE)
             {
               //LEDOn(1);
               usart1_puts("led1 on 
\r");
               LEDToggle(1);
               //give semaphore back
               //xSemaphoreGive(xButtonWakeupSemaphore);
             }
         if (xSemaphoreTake(xButtonUser1Semaphore, (portTickType)10)==pdTRUE)
             {
               usart1_puts("led2 on 
\r");
               LEDToggle(2);
               //LEDOn(2);
               //xSemaphoreGive(xButtonUser1Semaphore);
             }
         if (xSemaphoreTake(xButtonUser2Semaphore, (portTickType)10)==pdTRUE)
             {
               usart1_puts("led3 on 
\r");
               //LEDToggle(3);
               //LEDOn(2);
               //xSemaphoreGive(xButtonUser2Semaphore);
             }
      }
    //usart1_puts("task running 
\r");
    vTaskDelay(xDelay);
    //vTaskDelayUntil(&xLastWakeTime,xFrequency);
  }
}
  중요 비망
freetos의task와 그 안의 함수는 가능한 한 한 한 파일에 있습니다.일부 stm32 플랫폼에서 리셋 함수와task가 한 파일에 없으면 약간의 이상이 발생할 수 있습니다.
freetos의task의 리셋 함수는 가능한 정적 함수를 사용합니다.
freetos의task의 순환 중 vTaskDelay(xDelay)를 잃어버리면 안 된다.그렇지 않으면 계속 순환하고 스케줄이 잡히지 않는 상황이 나타날 수 있다. 특히 당신의task 우선순위가 비교적 높을 때다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.