Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.84 KB | None | 0 0
  1. #include "HardwareProfile.h"
  2.  
  3. #include "FreeRTOS.h"
  4. #include "task.h"
  5. #include "croutine.h"
  6. #include "list.h"
  7. #include "semphr.h"
  8. #include "queue.h"
  9. #include "timers.h"
  10. #include <stdio.h>
  11.  
  12. void vInitApp(void);
  13.  
  14. void vTask1( void *pvParameters );
  15. void vTask2( void *pvParameters );
  16. void vTask3( void *pvParameters );
  17. void vTask4( void *pvParameters );
  18.  
  19. xSemaphoreHandle LED1_binSemaphore=NULL;
  20. xSemaphoreHandle LED2_binSemaphore=NULL;
  21. xSemaphoreHandle LED3_binSemaphore=NULL;
  22. xSemaphoreHandle LED4_binSemaphore=NULL;
  23.  
  24. int main(void)
  25. {
  26.     vInitApp();
  27.  
  28.     vSemaphoreCreateBinary( LED1_binSemaphore );
  29.     vSemaphoreCreateBinary( LED2_binSemaphore );
  30.     vSemaphoreCreateBinary( LED3_binSemaphore );
  31.     vSemaphoreCreateBinary( LED4_binSemaphore );
  32.    
  33.     if(LED1_binSemaphore == NULL || LED2_binSemaphore == NULL ||
  34.        LED3_binSemaphore == NULL || LED4_binSemaphore == NULL )
  35.     {
  36.         while(1);   //in case of semaphore creation error
  37.     }
  38.  
  39.     xSemaphoreGive(LED1_binSemaphore);
  40.     xSemaphoreTake(LED2_binSemaphore,portMAX_DELAY);
  41.     xSemaphoreTake(LED3_binSemaphore,portMAX_DELAY);
  42.     xSemaphoreTake(LED4_binSemaphore,portMAX_DELAY);
  43.    
  44.     xTaskCreate( vTask1, "Task LED1", 256, NULL, 1, NULL );
  45.     xTaskCreate( vTask2, "Task LED2", 256, NULL, 1, NULL );
  46.     xTaskCreate( vTask3, "Task LED3", 256, NULL, 1, NULL );
  47.     xTaskCreate( vTask4, "Task LED4", 256, NULL, 1, NULL );
  48.  
  49.     vTaskStartScheduler();
  50.  
  51.     for( ;; );
  52.  
  53.     return 0;
  54. }
  55.  
  56. void vTask1(void *pvParameters)
  57. {
  58.     while(1)
  59.         if(xSemaphoreTake(LED1_binSemaphore,portMAX_DELAY))
  60.         {
  61.             mTurnOnLED(0);
  62.             vTaskDelay(250/portTICK_RATE_MS);
  63.             mTurnOffLED(0);
  64.             xSemaphoreGive(LED2_binSemaphore);
  65.         }
  66. }
  67.  
  68. void vTask2( void *pvParameters )
  69. {
  70.     while(1)
  71.         if(xSemaphoreTake(LED2_binSemaphore,portMAX_DELAY))
  72.         {
  73.             mTurnOnLED(1);
  74.             vTaskDelay(250/portTICK_RATE_MS);
  75.             mTurnOffLED(1);
  76.             xSemaphoreGive(LED3_binSemaphore);
  77.         }
  78. }
  79.  
  80. void vTask3( void *pvParameters )
  81. {
  82.     while(1)
  83.         if(xSemaphoreTake(LED3_binSemaphore,portMAX_DELAY))
  84.         {
  85.             mTurnOnLED(2);
  86.             vTaskDelay(250/portTICK_RATE_MS);
  87.             mTurnOffLED(2);
  88.             xSemaphoreGive(LED4_binSemaphore);
  89.         }
  90. }
  91.  
  92. void vTask4( void *pvParameters )
  93. {
  94.     while(1)
  95.         if(xSemaphoreTake(LED4_binSemaphore,portMAX_DELAY))
  96.         {
  97.             mTurnOnLED(3);
  98.             vTaskDelay(250/portTICK_RATE_MS);
  99.             mTurnOffLED(3);
  100.             xSemaphoreGive(LED1_binSemaphore);
  101.         }
  102. }
  103.  
  104. void vInitApp(void) {
  105.     mInitLEDs(); /* Initialisation of LEDs */
  106.     mInitButtons(); /* Initialisation of Button */
  107. }
  108.  
  109. void __attribute__ ((__interrupt__, __auto_psv__)) _StackError(void)
  110. {
  111.     while(1){
  112.         Nop();
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement