os_prio.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ************************************************************************************************************************
  3. * uC/OS-III
  4. * The Real-Time Kernel
  5. *
  6. * (c) Copyright 2009-2011; Micrium, Inc.; Weston, FL
  7. * All rights reserved. Protected by international copyright laws.
  8. *
  9. * PRIORITY MANAGEMENT
  10. *
  11. * File : OS_PRIO.C
  12. * By : JJL
  13. * Version : V3.02.00
  14. *
  15. * LICENSING TERMS:
  16. * ---------------
  17. * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or
  18. * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/
  19. * product then, you need to contact Micrium to properly license uC/OS-III for its use in your
  20. * application/product. We provide ALL the source code for your convenience and to help you
  21. * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use
  22. * it commercially without paying a licensing fee.
  23. *
  24. * Knowledge of the source code may NOT be used to develop a similar product.
  25. *
  26. * Please help us continue to provide the embedded community with the finest software available.
  27. * Your honesty is greatly appreciated.
  28. *
  29. * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036.
  30. ************************************************************************************************************************
  31. */
  32. #include <os.h>
  33. #ifdef VSC_INCLUDE_SOURCE_FILE_NAMES
  34. const CPU_CHAR *os_prio__c = "$Id: $";
  35. #endif
  36. CPU_DATA OSPrioTbl[OS_PRIO_TBL_SIZE]; /* Declare the array local to this file to allow for ... */
  37. /* ... optimization. In other words, this allows the ... */
  38. /* ... table to be located in fast memory */
  39. /*
  40. ************************************************************************************************************************
  41. * INITIALIZE THE PRIORITY LIST
  42. *
  43. * Description: This function is called by uC/OS-III to initialize the list of ready priorities.
  44. *
  45. * Arguments : none
  46. *
  47. * Returns : none
  48. *
  49. * Note : This function is INTERNAL to uC/OS-III and your application should not call it.
  50. ************************************************************************************************************************
  51. */
  52. void OS_PrioInit (void)
  53. {
  54. CPU_DATA i;
  55. /* Clear the bitmap table ... no task is ready */
  56. for (i = 0u; i < OS_PRIO_TBL_SIZE; i++) {
  57. OSPrioTbl[i] = (CPU_DATA)0;
  58. }
  59. }
  60. /*
  61. ************************************************************************************************************************
  62. * GET HIGHEST PRIORITY TASK WAITING
  63. *
  64. * Description: This function is called by other uC/OS-III services to determine the highest priority task
  65. * waiting on the event.
  66. *
  67. * Arguments : none
  68. *
  69. * Returns : The priority of the Highest Priority Task (HPT) waiting for the event
  70. *
  71. * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
  72. ************************************************************************************************************************
  73. */
  74. OS_PRIO OS_PrioGetHighest (void)
  75. {
  76. CPU_DATA *p_tbl;
  77. OS_PRIO prio;
  78. prio = (OS_PRIO)0;
  79. p_tbl = &OSPrioTbl[0];
  80. while (*p_tbl == (CPU_DATA)0) { /* Search the bitmap table for the highest priority */
  81. prio += DEF_INT_CPU_NBR_BITS; /* Compute the step of each CPU_DATA entry */
  82. p_tbl++;
  83. }
  84. prio += (OS_PRIO)CPU_CntLeadZeros(*p_tbl); /* Find the position of the first bit set at the entry */
  85. return (prio);
  86. }
  87. /*
  88. ************************************************************************************************************************
  89. * INSERT PRIORITY
  90. *
  91. * Description: This function is called to insert a priority in the priority table.
  92. *
  93. * Arguments : prio is the priority to insert
  94. *
  95. * Returns : none
  96. *
  97. * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
  98. ************************************************************************************************************************
  99. */
  100. void OS_PrioInsert (OS_PRIO prio)
  101. {
  102. CPU_DATA bit;
  103. CPU_DATA bit_nbr;
  104. OS_PRIO ix;
  105. ix = prio / DEF_INT_CPU_NBR_BITS;
  106. bit_nbr = (CPU_DATA)prio & (DEF_INT_CPU_NBR_BITS - 1u);
  107. bit = 1u;
  108. bit <<= (DEF_INT_CPU_NBR_BITS - 1u) - bit_nbr;
  109. OSPrioTbl[ix] |= bit;
  110. }
  111. /*
  112. ************************************************************************************************************************
  113. * REMOVE PRIORITY
  114. *
  115. * Description: This function is called to remove a priority in the priority table.
  116. *
  117. * Arguments : prio is the priority to remove
  118. *
  119. * Returns : none
  120. *
  121. * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
  122. ************************************************************************************************************************
  123. */
  124. void OS_PrioRemove (OS_PRIO prio)
  125. {
  126. CPU_DATA bit;
  127. CPU_DATA bit_nbr;
  128. OS_PRIO ix;
  129. ix = prio / DEF_INT_CPU_NBR_BITS;
  130. bit_nbr = (CPU_DATA)prio & (DEF_INT_CPU_NBR_BITS - 1u);
  131. bit = 1u;
  132. bit <<= (DEF_INT_CPU_NBR_BITS - 1u) - bit_nbr;
  133. OSPrioTbl[ix] &= ~bit;
  134. }