训练营PLSR题目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

158 rivejä
6.0 KiB

  1. /*
  2. ************************************************************************************************************************
  3. * uC/OS-III
  4. * The Real-Time Kernel
  5. *
  6. * (c) Copyright 2009-2014; 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.04.04
  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 find our product's user manual, API reference, release notes and
  30. * more information at https://doc.micrium.com.
  31. * You can contact us at www.micrium.com.
  32. ************************************************************************************************************************
  33. */
  34. #define MICRIUM_SOURCE
  35. #include "os.h"
  36. #ifdef VSC_INCLUDE_SOURCE_FILE_NAMES
  37. const CPU_CHAR *os_prio__c = "$Id: $";
  38. #endif
  39. CPU_DATA OSPrioTbl[OS_PRIO_TBL_SIZE]; /* Declare the array local to this file to allow for ... */
  40. /* ... optimization. In other words, this allows the ... */
  41. /* ... table to be located in fast memory */
  42. /*
  43. ************************************************************************************************************************
  44. * INITIALIZE THE PRIORITY LIST
  45. *
  46. * Description: This function is called by uC/OS-III to initialize the list of ready priorities.
  47. *
  48. * Arguments : none
  49. *
  50. * Returns : none
  51. *
  52. * Note : This function is INTERNAL to uC/OS-III and your application should not call it.
  53. ************************************************************************************************************************
  54. */
  55. void OS_PrioInit (void)
  56. {
  57. CPU_DATA i;
  58. /* Clear the bitmap table ... no task is ready */
  59. for (i = 0u; i < OS_PRIO_TBL_SIZE; i++) {
  60. OSPrioTbl[i] = (CPU_DATA)0;
  61. }
  62. }
  63. /*
  64. ************************************************************************************************************************
  65. * GET HIGHEST PRIORITY TASK WAITING
  66. *
  67. * Description: This function is called by other uC/OS-III services to determine the highest priority task
  68. * waiting on the event.
  69. *
  70. * Arguments : none
  71. *
  72. * Returns : The priority of the Highest Priority Task (HPT) waiting for the event
  73. *
  74. * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
  75. ************************************************************************************************************************
  76. */
  77. OS_PRIO OS_PrioGetHighest (void)
  78. {
  79. CPU_DATA *p_tbl;
  80. OS_PRIO prio;
  81. prio = (OS_PRIO)0;
  82. p_tbl = &OSPrioTbl[0];
  83. while (*p_tbl == (CPU_DATA)0) { /* Search the bitmap table for the highest priority */
  84. prio += DEF_INT_CPU_NBR_BITS; /* Compute the step of each CPU_DATA entry */
  85. p_tbl++;
  86. }
  87. prio += (OS_PRIO)CPU_CntLeadZeros(*p_tbl); /* Find the position of the first bit set at the entry */
  88. return (prio);
  89. }
  90. /*
  91. ************************************************************************************************************************
  92. * INSERT PRIORITY
  93. *
  94. * Description: This function is called to insert a priority in the priority table.
  95. *
  96. * Arguments : prio is the priority to insert
  97. *
  98. * Returns : none
  99. *
  100. * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
  101. ************************************************************************************************************************
  102. */
  103. void OS_PrioInsert (OS_PRIO prio)
  104. {
  105. CPU_DATA bit;
  106. CPU_DATA bit_nbr;
  107. OS_PRIO ix;
  108. ix = prio / DEF_INT_CPU_NBR_BITS;
  109. bit_nbr = (CPU_DATA)prio & (DEF_INT_CPU_NBR_BITS - 1u);
  110. bit = 1u;
  111. bit <<= (DEF_INT_CPU_NBR_BITS - 1u) - bit_nbr;
  112. OSPrioTbl[ix] |= bit;
  113. }
  114. /*
  115. ************************************************************************************************************************
  116. * REMOVE PRIORITY
  117. *
  118. * Description: This function is called to remove a priority in the priority table.
  119. *
  120. * Arguments : prio is the priority to remove
  121. *
  122. * Returns : none
  123. *
  124. * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
  125. ************************************************************************************************************************
  126. */
  127. void OS_PrioRemove (OS_PRIO prio)
  128. {
  129. CPU_DATA bit;
  130. CPU_DATA bit_nbr;
  131. OS_PRIO ix;
  132. ix = prio / DEF_INT_CPU_NBR_BITS;
  133. bit_nbr = (CPU_DATA)prio & (DEF_INT_CPU_NBR_BITS - 1u);
  134. bit = 1u;
  135. bit <<= (DEF_INT_CPU_NBR_BITS - 1u) - bit_nbr;
  136. OSPrioTbl[ix] &= ~bit;
  137. }