Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. /*** INCLUDES *******************************************************/
  2. #include "HardwareProfile.h"
  3.  
  4. /* FreeRTOS.org includes. */
  5. #include "FreeRTOS.h"
  6. #include "task.h"
  7. #include "croutine.h"
  8. #include "list.h"
  9. #include "semphr.h"
  10. #include "queue.h"
  11. #include "timers.h"
  12.  
  13.  
  14. /* Standard includes. */
  15. #include <stdio.h>
  16.  
  17. void vInitApp(void);
  18.  
  19. void button1Task( void *pvParameters );
  20. void button2Task( void *pvParameters );
  21. void LEDTask( void *pvParameters );
  22.  
  23. QueueHandle_t xQueue;
  24.  
  25. int main(void)
  26. {
  27.     vInitApp();
  28.    
  29.     xQueue = xQueueCreate( 5, sizeof( portBASE_TYPE ) );
  30.    
  31.     xTaskCreate( button1Task, "Button 1", 256, NULL, 2, NULL );
  32.     xTaskCreate( button2Task, "Button 2", 256, NULL, 2, NULL );
  33.     xTaskCreate( LEDTask, "LED 2", 256, NULL, 10, NULL );
  34.  
  35.     vTaskStartScheduler();
  36.  
  37.     for( ;; );
  38.  
  39.     return 0;
  40. }//end main
  41.  
  42. /********************************************************************
  43.  * Task 1
  44.  ********************************************************************/
  45. void button1Task( void *pvParameters )
  46. {
  47.     portBASE_TYPE xValueToSend = 0x5;
  48.  
  49.     for( ;; )
  50.     {
  51.         if(mGetButtonStatePB1()==1)
  52.         {
  53.             xQueueSend(xQueue,(void*)&xValueToSend, portMAX_DELAY );
  54.         }
  55.     }
  56. }
  57.  
  58. void button2Task( void *pvParameters )
  59. {
  60.     portBASE_TYPE xValueToSend = 0xA;
  61.  
  62.     for( ;; )
  63.     {
  64.         if(mGetButtonStatePB2()==1)
  65.             xQueueSend(xQueue,(void*)&xValueToSend, portMAX_DELAY );
  66.     }
  67. }
  68.  
  69. void LEDTask( void *pvParameters )
  70. {
  71.     portBASE_TYPE xReceivedValue;
  72.    
  73.     const TickType_t xFrequency = 2000/portTICK_RATE_MS;
  74.  
  75.     for( ;; )
  76.     {
  77.         if( xQueueReceive(xQueue, &(xReceivedValue), xFrequency ) == pdPASS )
  78.         {
  79.             mWriteLEDs(xReceivedValue);
  80.         }
  81.         else
  82.              mWriteLEDs(0);
  83.     }
  84. }
  85.  
  86.  
  87. void vApplicationIdleHook( void )
  88. {
  89. //    if(counter>10000)
  90. //        mToggleLED( 1 );// Toggle LED 1
  91. }
  92.  
  93. /**
  94.  *  @brief Initialise the hardware
  95.  *      - Init LED
  96.  *      - Init Buttons
  97.  **/
  98. void vInitApp(void)
  99. {
  100.     mInitLEDs(); /* Initialisation of LEDs */
  101.     mInitButtons(); /* Initialisation of Button */
  102. }
  103.  
  104. void __attribute__ ((__interrupt__, __auto_psv__)) _StackError(void)
  105. {
  106.     while(1){
  107.         Nop();
  108.     }
  109. }
  110. /*-----------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement