iec10x_prio_queue.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "iec10x_prio_queue.h"
  2. #include "iec10x.h"
  3. #include "iec10x_conf.h"
  4. #include "iec10x_type.h"
  5. #include "includes.h"
  6. #include <stdio.h>
  7. extern PIEC10X_T IEC10X;
  8. extern Iec10x_PrioQueue_T Iec10x_PrioQueueArray[IEC10X_PRIO_MAX];
  9. #ifdef PRIO_QUEUE
  10. /*******************************************************************************
  11. * Function Name : HighestPrio
  12. * Description :
  13. * Input : None
  14. * Output : None
  15. * Return : RET_ERROR failure
  16. len sucess
  17. *******************************************************************************/
  18. iec_8u IEC10X_HighestPrio(void)
  19. {
  20. int i, prio;
  21. iec_8u flag = 0;
  22. prio = -1;
  23. // LOG("%s \r\n",__FUNCTION__);
  24. for (i = 0; i < IEC10X_PRIO_MAX; i++)
  25. {
  26. if (Iec10x_PrioQueueArray[i].ElementNum > 0 && !flag)
  27. {
  28. // return i;
  29. prio = i;
  30. flag = 1;
  31. LOG("<%s>Prio[%d],Num%d. \n", __FUNCTION__, i, Iec10x_PrioQueueArray[i].ElementNum);
  32. }
  33. LOG("[%d]%d.", i, Iec10x_PrioQueueArray[i].ElementNum);
  34. }
  35. LOG("out(%d)\r\n", prio);
  36. return prio;
  37. }
  38. void IEC10X_PrioInitQueue(Iec10x_PrioQueue_T *PrioQueue)
  39. {
  40. PrioQueue->Header = NULL;
  41. PrioQueue->Tail = NULL;
  42. PrioQueue->ElementNum = 0;
  43. }
  44. iec_8u IEC10X_PrioEnQueue(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *new_p)
  45. {
  46. new_p->Next = NULL;
  47. if (QueueHdr->Header == NULL)
  48. {
  49. QueueHdr->Header = new_p;
  50. QueueHdr->Tail = new_p;
  51. }
  52. else
  53. {
  54. QueueHdr->Tail->Next = new_p;
  55. QueueHdr->Tail = new_p;
  56. }
  57. QueueHdr->ElementNum++;
  58. LOG("%s ElementNum(%d) \r\n", __FUNCTION__, QueueHdr->ElementNum);
  59. return RET_SUCESS;
  60. }
  61. Iec10x_PrioNode_T *IEC10X_PrioDeQueue(Iec10x_PrioQueue_T *QueueHdr)
  62. {
  63. Iec10x_PrioNode_T *PrioNode_DeQ;
  64. if (QueueHdr->Header == NULL)
  65. {
  66. LOG("PrioDeQueue,error \r\n");
  67. return NULL;
  68. }
  69. PrioNode_DeQ = QueueHdr->Header;
  70. QueueHdr->Header = QueueHdr->Header->Next;
  71. if (QueueHdr->Header == NULL)
  72. {
  73. QueueHdr->Tail = NULL;
  74. }
  75. // LOG("PrioDeQueue(%d) \r\n",PrioNode_DeQ->Length);
  76. return PrioNode_DeQ;
  77. }
  78. Iec10x_PrioNode_T *IEC10X_PrioFindQueueHead(Iec10x_PrioQueue_T *QueueHdr)
  79. {
  80. Iec10x_PrioNode_T *PrioNode_DeQ;
  81. if (QueueHdr->Header == NULL)
  82. {
  83. // LOG("PrioDeQueue,error \r\n");
  84. return NULL;
  85. }
  86. PrioNode_DeQ = QueueHdr->Header;
  87. // LOG("PrioDeQueue(%d) \r\n",PrioNode_DeQ->Length);
  88. return PrioNode_DeQ;
  89. }
  90. void *IEC10X_PeekQueue(Iec10x_PrioQueue_T *QueueHdr)
  91. {
  92. if (QueueHdr->Header == NULL)
  93. {
  94. // LOG(" ");
  95. return NULL;
  96. }
  97. return QueueHdr->Header->value;
  98. }
  99. int IEC10X_Prio_IsEmptyQueue(Iec10x_PrioQueue_T *QueueHdr)
  100. {
  101. if (QueueHdr->Header == NULL)
  102. {
  103. return 1;
  104. }
  105. else
  106. {
  107. return 0;
  108. }
  109. }
  110. void IEC10X_Prio_ClearQueue(Iec10x_PrioQueue_T *QueueHdr)
  111. {
  112. Iec10x_PrioNode_T *p = QueueHdr->Header;
  113. while (p != NULL)
  114. {
  115. QueueHdr->Header = QueueHdr->Header->Next;
  116. IEC10X->Free(p);
  117. p = QueueHdr->Header;
  118. }
  119. QueueHdr->Tail = NULL;
  120. QueueHdr->ElementNum = 0;
  121. return;
  122. }
  123. #endif