gl_task.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef __GL_TASK_H__
  2. #define __GL_TASK_H__
  3. #include "gl_types.h"
  4. /******************************************************************************/
  5. /*!
  6. * @brief To create a task.
  7. *
  8. * @param szName String identifier for the task. Limit to 16 characters. Used wherever supported.
  9. * @param pEntryPoint Function address from which the task starts executing.
  10. * @param pTaskArg parameter passed to entry function.
  11. * @param dPriority Task priority ranging from 0-31, with 0 being the lowest priority (see restrictions).
  12. * @param dStackSize Task stack size in bytes.
  13. * @param fTaskRun If DTV_TRUE, the task is scheduled for execution immediately. If DTV_FALSE, the task is suspended upon creation, and GL_TaskActivateResume() has to be explicitly invoked to start the task.
  14. * @param pTaskId Task object identifier returned by the API (on success)
  15. *
  16. * @return @a GL_SUCCESS on success
  17. * @return @a GL_FAILURE on failure
  18. *
  19. * @note Cannot be used from ISR/DSR. It supports only 32 priority levels.
  20. *******************************************************************************/
  21. GL_Status_t GL_TaskCreate(char *szName, void (*pEntryPoint)(void *pArg),
  22. void *pTaskArg, GL_UINT32 dPriority, GL_UINT32 dStackSize, GL_BOOL fTaskRun, GL_Task_t *pTaskId);
  23. /******************************************************************************/
  24. /*!
  25. * @brief To self-delete a task.
  26. *
  27. * @return @a GL_SUCCESS if task is successfully deleted.
  28. * @return @a GL_FAILURE if the task was not created by GSL.
  29. *
  30. * @note Cannot be used from ISR/DSR. It supports only 32 priority levels. Use @a GL_TaskPoolSelfDelete is the task is created by taskpool.
  31. *******************************************************************************/
  32. GL_Status_t GL_TaskSelfDelete(void);
  33. /******************************************************************************/
  34. /*!
  35. * @brief To activate a task that was immediately suspended upon creation (by setting fTaskRun=DTV_FALSE).
  36. * @param taskId Task object identifier
  37. *
  38. * @return @a GL_SUCCESS on success
  39. * @return @a GL_FAILURE on failure
  40. *
  41. * @note None
  42. *******************************************************************************/
  43. GL_Status_t GL_TaskActivate(GL_Task_t taskId);
  44. /******************************************************************************/
  45. /*!
  46. * @brief To suspend a task, not remember task status in Task_t
  47. * @param taskId Task object identifier
  48. *
  49. * @return @a GL_SUCCESS on success
  50. * @return @a GL_FAILURE on failure
  51. *
  52. * @note None
  53. *******************************************************************************/
  54. GL_Status_t GL_TaskSuspend(GL_Task_t taskId);
  55. /******************************************************************************/
  56. /*!
  57. * @brief To put a task to sleep for a finite period of time.
  58. *
  59. * @param sdTimeout timeout period to suspend task. Measured in milliseconds. Set to any value between 1-2147483647 for finite wait.
  60. *
  61. * @return @a GL_SUCCESS on success
  62. * @return @a GL_FAILURE on failure
  63. *
  64. * @note Cannot be used from ISR/DSR.
  65. *******************************************************************************/
  66. GL_Status_t GL_TaskSleep(GL_UINT32 sdTimeout);
  67. /******************************************************************************/
  68. /*!
  69. * @brief Used to yield processor time to other tasks of same priority, i.e., if any other task of same priority is ready to run, the other tasks will run before the current task gets a chance to run again. If no other task of same priority is ready, the current task will continue running. Please note that this API only affects scheduling among tasks of same priority. By default, a higher priority task will automatically preempt a lower priority task.
  70. *
  71. * @return @a GL_SUCCESS on success
  72. * @return @a GL_FAILURE on failure
  73. *
  74. * @note Cannot be used from ISR/DSR.
  75. *******************************************************************************/
  76. GL_Status_t GL_TaskYield(void);
  77. /******************************************************************************/
  78. /*!
  79. * @brief To change a task's priority.
  80. *
  81. * @param taskId Task object identifier
  82. * @param dNewPriority Changes the tasks priority to specified value.
  83. *
  84. * @return @a GL_SUCCESS on success
  85. * @return @a GL_FAILURE on failure
  86. *
  87. * @note Cannot be used from ISR/DSR.
  88. *******************************************************************************/
  89. GL_Status_t GL_TaskSetPriority(GL_Task_t taskId, GL_UINT32 dNewPriority);
  90. /******************************************************************************/
  91. /*!
  92. * @brief To query a tasks priority.
  93. *
  94. * @param taskId Task object identifier
  95. * @param pdPriority Returns with the task priority
  96. *
  97. * @return @a GL_SUCCESS on success
  98. * @return @a GL_FAILURE on failure
  99. *
  100. * @note Cannot be used from ISR/DSR.
  101. *******************************************************************************/
  102. GL_Status_t GL_TaskGetPriority(GL_Task_t taskId, GL_UINT32 *pdPriority);
  103. /******************************************************************************/
  104. /*!
  105. * @brief Used to lock the scheduler and prevents the current task from being preempted by any other task, irrespective of priority. However, interrupts are enabled and an ISR can preempt the task. This API is used in conjunction with GL_TaskGlobalUnlock() to protect critical code in a task.
  106. *
  107. * @return @a GL_SUCCESS on success
  108. * @return @a GL_FAILURE on failure
  109. *
  110. * @note Cannot be used from ISR/DSR.
  111. *******************************************************************************/
  112. GL_Status_t GL_TaskGlobalLock(void);
  113. /******************************************************************************/
  114. /*!
  115. * @brief Used to unlock the scheduler and enable normal task preemption. This API is used in conjuction with GL_TaskGlobalLock() to protect critical code in a task. This call does not affect enabling/disabling of interrupts in any way.
  116. *
  117. * @return @a GL_SUCCESS on success
  118. * @return @a GL_FAILURE on failure
  119. *
  120. * @note Cannot be used from ISR/DSR.
  121. *******************************************************************************/
  122. GL_Status_t GL_TaskGlobalUnlock(void);
  123. /******************************************************************************/
  124. /*!
  125. * @brief To get the current task's gsl handle.
  126. *
  127. * @return the current task's gsl handle
  128. *
  129. * @note Cannot be used from ISR/DSR. Use @a GL_TaskPoolCurTask is the task is created by taskpool.
  130. *
  131. *******************************************************************************/
  132. GL_Task_t GL_CurrentTask(void);
  133. /******************************************************************************/
  134. /*!
  135. * @brief To get the current task's handle of OS.
  136. *
  137. * @return the current task's handle of OS
  138. *
  139. * @note Cannot be used from ISR/DSR.
  140. *******************************************************************************/
  141. GL_UINT32 GL_CurrentTaskDebug(void);
  142. /******************************************************************************/
  143. /*!
  144. * @brief To destroy a GL_Task_t, for some specical usage. GL_TaskSelfDelete would be safer.
  145. *
  146. * @param taskId Task object identifier
  147. *
  148. * @return @a GL_SUCCESS on success
  149. * @return @a GL_FAILURE on failure
  150. *
  151. * @note Cannot be used from ISR/DSR.
  152. *******************************************************************************/
  153. GL_Status_t GL_TaskDestroyOne(GL_Task_t taskId);
  154. char *GL_TaskName(GL_Task_t taskId);
  155. #endif // __GL_TASK_H__