PRIO_QUEUE_Iec10x.c 3.6 KB

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