Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stm32f4xx.h"                  // Device header
  2. #include "FreeRTOS.h"                   // ARM.FreeRTOS::RTOS:Core
  3. #include "FreeRTOSConfig.h"             // ARM.FreeRTOS::RTOS:Config
  4. #include "Task.h"
  5. #include "queue.h"
  6. #include "semphr.h"
  7.  
  8.  
  9. SemaphoreHandle_t Semaphore = NULL;
  10. TickType_t WakeTime1 = NULL;
  11. TickType_t WakeTime2 = NULL;
  12. TaskHandle_t BlinkTaskHandle = NULL;
  13. TaskHandle_t SOSTaskHandle = NULL;
  14.  
  15. void vBlinkTask(void* pvParams)
  16. {
  17.     TickType_t WakeTime1 = xTaskGetTickCount();
  18.     while(1)
  19.     {
  20.         if(Semaphore != NULL)
  21.         {
  22.             if((xSemaphoreTake(Semaphore,10) == pdTRUE) || (xSemaphoreGetMutexHolder(Semaphore) == BlinkTaskHandle))
  23.             {
  24.                 for(char i=0; i<4; i++)
  25.                 {
  26.                     GPIOA->ODR |= GPIO_ODR_ODR_5;
  27.                     vTaskDelay(pdMS_TO_TICKS(500));
  28.                     GPIOA->ODR &= ~GPIO_ODR_ODR_5;
  29.                     vTaskDelay(pdMS_TO_TICKS(500));
  30.                 }
  31.                 xSemaphoreGive(Semaphore);
  32.                 vTaskDelayUntil(&WakeTime1, pdMS_TO_TICKS(8000));
  33.             }
  34.             else taskYIELD();
  35.         }
  36.     }
  37. }
  38.  
  39. void vSOSTask(void* pvParams)
  40. {
  41.     TickType_t WakeTime2 = xTaskGetTickCount();
  42.     while(1)
  43.     {
  44.         if(Semaphore != NULL)
  45.         {
  46.             if((xSemaphoreTake(Semaphore,10) == pdTRUE) || ( xSemaphoreGetMutexHolder(Semaphore) == SOSTaskHandle))
  47.             {
  48.                 for( char i=0; i<3; i++ )
  49.                 {
  50.                     GPIOA->ODR |= GPIO_ODR_ODR_6;
  51.                     vTaskDelay(pdMS_TO_TICKS(150));
  52.                     GPIOA->ODR &= ~GPIO_ODR_ODR_6;
  53.                     vTaskDelay(pdMS_TO_TICKS(150));
  54.                 }
  55.                 for( char i=0; i<3; i++ )
  56.                 {
  57.                     GPIOA->ODR |= GPIO_ODR_ODR_6;
  58.                     vTaskDelay(pdMS_TO_TICKS(400));
  59.                     GPIOA->ODR &= ~GPIO_ODR_ODR_6;
  60.                     vTaskDelay(pdMS_TO_TICKS(400));
  61.                 }
  62.                 for( char i=0; i<3; i++ )
  63.                 {
  64.                     GPIOA->ODR |= GPIO_ODR_ODR_6;
  65.                     vTaskDelay(pdMS_TO_TICKS(150));
  66.                     GPIOA->ODR &= ~GPIO_ODR_ODR_6;
  67.                     vTaskDelay(pdMS_TO_TICKS(150));
  68.                 }
  69.                 xSemaphoreGive(Semaphore);
  70.                 vTaskDelayUntil(&WakeTime2, pdMS_TO_TICKS(8000));
  71.             }
  72.             else taskYIELD();
  73.         }
  74.     }
  75. }
  76.  
  77. int main(void)
  78. {
  79.     RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
  80.     GPIOA->MODER |= GPIO_MODER_MODER5_0 | GPIO_MODER_MODER6_0;
  81.     xTaskCreate(vBlinkTask, "BlinkingDiode", configMINIMAL_STACK_SIZE, NULL, 1, &BlinkTaskHandle);
  82.     xTaskCreate(vSOSTask, "SOSDiode", configMINIMAL_STACK_SIZE, NULL, 1, &SOSTaskHandle);
  83.     Semaphore = xSemaphoreCreateMutex();
  84.     vTaskStartScheduler();
  85.     while(1)
  86.     {
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement