Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.21 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.             xQueueSend(xQueue,(void*)&xValueToSend, portMAX_DELAY );
  53.     }
  54. }
  55.  
  56. void button2Task( void *pvParameters )
  57. {
  58.     portBASE_TYPE xValueToSend = 0xA;
  59.  
  60.     for( ;; )
  61.     {
  62.         if(mGetButtonStatePB2()==1)
  63.             xQueueSend(xQueue,(void*)&xValueToSend, portMAX_DELAY );
  64.     }
  65. }
  66.  
  67. void LEDTask( void *pvParameters )
  68. {
  69.     portBASE_TYPE xReceivedValue;
  70.  
  71.     for( ;; )
  72.     {
  73.         if( xQueueReceive(xQueue, &(xReceivedValue), ( 1000 / portTICK_RATE_MS ) ) == pdPASS )
  74.         {
  75.             mWriteLEDs(xReceivedValue);
  76.         }
  77.         else
  78.              mWriteLEDs(0);
  79.     }
  80. }
  81.  
  82.  
  83. void vApplicationIdleHook( void )
  84. {
  85. //    if(counter>10000)
  86. //        mToggleLED( 1 );// Toggle LED 1
  87. }
  88.  
  89. /**
  90.  *  @brief Initialise the hardware
  91.  *      - Init LED
  92.  *      - Init Buttons
  93.  **/
  94. void vInitApp(void)
  95. {
  96.     mInitLEDs(); /* Initialisation of LEDs */
  97.     mInitButtons(); /* Initialisation of Button */
  98. }
  99.  
  100. void __attribute__ ((__interrupt__, __auto_psv__)) _StackError(void)
  101. {
  102.     while(1){
  103.         Nop();
  104.     }
  105. }
  106. /*-----------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement