cs101_queue.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * cs101_queue.h
  3. *
  4. * Copyright 2017 MZ Automation GmbH
  5. *
  6. * This file is part of lib60870-C
  7. *
  8. * lib60870-C is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * lib60870-C is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with lib60870-C. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * See COPYING file for the complete license text.
  22. */
  23. #ifndef SRC_INC_INTERNAL_CS101_QUEUE_H_
  24. #define SRC_INC_INTERNAL_CS101_QUEUE_H_
  25. #include "lib60870_config.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #if ((CONFIG_USE_THREADS == 1) || (CONFIG_USE_SEMAPHORES == 1))
  30. //#include "hal_thread.h"
  31. #endif
  32. #ifdef CONFIG_SLAVE_MESSAGE_QUEUE_SIZE
  33. #define CS101_MAX_QUEUE_SIZE CONFIG_SLAVE_MESSAGE_QUEUE_SIZE
  34. #else
  35. #define CS101_MAX_QUEUE_SIZE 10
  36. #endif
  37. typedef struct sCS101_QueueElement* CS101_QueueElement;
  38. #include "iec_include.h"
  39. struct sCS101_QueueElement {
  40. uint8_t size;
  41. uint8_t buffer[256];
  42. };
  43. #include "platform_mutex.h"
  44. typedef struct sCS101_Queue* CS101_Queue;
  45. struct sCS101_Queue {
  46. int size;
  47. int entryCounter;
  48. int lastMsgIndex;
  49. int firstMsgIndex;
  50. struct sBufferFrame encodeFrame;
  51. #if (CS101_MAX_QUEUE_SIZE == -1)
  52. struct sCS101_QueueElement* elements;
  53. #else
  54. struct sCS101_QueueElement elements[CS101_MAX_QUEUE_SIZE];
  55. #endif
  56. #if (CONFIG_USE_SEMAPHORES == 1)
  57. platform_mutex_t* queueLock;
  58. #endif
  59. };
  60. void
  61. CS101_Queue_initialize(CS101_Queue self, int maxQueueSize);
  62. void
  63. CS101_Queue_dispose(CS101_Queue self);
  64. void
  65. CS101_Queue_lock(CS101_Queue self);
  66. void
  67. CS101_Queue_unlock(CS101_Queue self);
  68. void
  69. CS101_Queue_enqueue(CS101_Queue self, CS101_ASDU asdu);
  70. /*
  71. * NOTE: Locking has to be done by caller!
  72. */
  73. Frame
  74. CS101_Queue_dequeue(CS101_Queue self, Frame resultStorage);
  75. bool
  76. CS101_Queue_isFull(CS101_Queue self);
  77. bool
  78. CS101_Queue_isEmpty(CS101_Queue self);
  79. void
  80. CS101_Queue_flush(CS101_Queue self);
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif /* SRC_INC_INTERNAL_CS101_QUEUE_H_ */