queues.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #define LED_RED GPIO_NUM_2
  6. #define LED_GREEN GPIO_NUM_4
  7. QueueHandle_t xQueue;
  8. void getQueueValue(void *pvParameter)
  9. {
  10. int32_t value_to_recieve;
  11. BaseType_t xStatusRecieve;
  12. //const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
  13. gpio_num_t red_led = LED_RED ;
  14. //uint8_t led_value = 0;
  15. //gpio_reset_pin(red_led);
  16. gpio_set_direction(red_led, GPIO_MODE_OUTPUT);
  17. for(;;){
  18. //led_value = 1;
  19. gpio_set_level(red_led, 1);
  20. xStatusRecieve = xQueueReceive(xQueue, &value_to_recieve, 0);
  21. //printf("%d get value task \n",uxTaskGetStackHighWaterMark(NULL));
  22. //if(xStatusRecieve != pdPASS){
  23. // printf("cant get value \n");
  24. //}
  25. //else{
  26. //printf("value recieved is %d \n",value_to_recieve);
  27. //}
  28. //led_value = 0;
  29. gpio_set_level(red_led, 0);
  30. vTaskDelay(pdMS_TO_TICKS(200));
  31. }
  32. }
  33. void putQueueValue(void *pvParameters) {
  34. int32_t value_to_send = (int32_t ) pvParameters;
  35. //value_to_send = (int32_t) pvParameters ;
  36. BaseType_t xStatusSend;
  37. //TickType_t xTicksToWait = 1000;
  38. gpio_num_t green_led = LED_GREEN ;
  39. //uint8_t led_value = 0;
  40. //gpio_reset_pin(green_led);
  41. gpio_set_direction(green_led, GPIO_MODE_OUTPUT);
  42. for(;;){
  43. gpio_set_level(green_led, 1);
  44. xStatusSend = xQueueSendToBack(xQueue,&value_to_send,0);
  45. gpio_set_level(green_led, 0);
  46. vTaskDelay(pdMS_TO_TICKS(1000));
  47. }
  48. }
  49. extern "C" void app_main()
  50. //void app_main(void) //requires setup- and loop function
  51. {
  52. xQueue = xQueueCreate(1,sizeof(int32_t));
  53. if (xQueue != NULL){
  54. xTaskCreate(putQueueValue,"Sender",2048,(void*)100 , 1,NULL);
  55. xTaskCreate(getQueueValue,"Reciever",2048,NULL,1,NULL);
  56. }
  57. else{
  58. printf("not enough space");
  59. }
  60. }