📄 os_task.c
字号:
/*$PAGE*/
#if OS_TASK_DEL_EN > 0
INT8U OSTaskDelReq (INT8U prio)
{
INT8U stat;
OS_TCB *ptcb;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
cpu_sr = 0; /* Prevent compiler warning */
#endif
#if OS_ARG_CHK_EN > 0
if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task */
return (OS_TASK_DEL_IDLE);
}
if (prio >= OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
return (OS_PRIO_INVALID);
}
}
#endif
if (prio == OS_PRIO_SELF) { /* See if a task is requesting to ... */
OS_ENTER_CRITICAL(); /* ... this task to delete itself */
stat = OSTCBCur->OSTCBDelReq; /* Return request status to caller */
OS_EXIT_CRITICAL();
return (stat);
}
OS_ENTER_CRITICAL();
ptcb = OSTCBPrioTbl[prio];
if (ptcb == (OS_TCB *)0) { /* Task to delete must exist */
OS_EXIT_CRITICAL();
return (OS_TASK_NOT_EXIST); /* Task must already be deleted */
}
if (ptcb == (OS_TCB *)1) { /* Must NOT be assigned to a Mutex */
OS_EXIT_CRITICAL();
return (OS_TASK_DEL_ERR);
}
ptcb->OSTCBDelReq = OS_TASK_DEL_REQ; /* Set flag indicating task to be DEL. */
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* GET THE NAME OF A TASK
*
* Description: This function is called to obtain the name of a task.
*
* Arguments : prio is the priority of the task that you want to obtain the name from.
*
* pname is a pointer to an ASCII string that will receive the name of the task. The
* string must be able to hold at least OS_TASK_NAME_SIZE characters.
*
* err is a pointer to an error code that can contain one of the following values:
*
* OS_NO_ERR if the requested task is resumed
* OS_TASK_NOT_EXIST if the task has not been created or is assigned to a Mutex
* OS_PRIO_INVALID if you specified an invalid priority:
* A higher value than the idle task or not OS_PRIO_SELF.
* OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
*
* Returns : The length of the string or 0 if the task does not exist.
*********************************************************************************************************
*/
#if OS_TASK_NAME_SIZE > 1
INT8U OSTaskNameGet (INT8U prio, char *pname, INT8U *err)
{
OS_TCB *ptcb;
INT8U len;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
cpu_sr = 0; /* Prevent compiler warning */
#endif
#if OS_ARG_CHK_EN > 0
if (prio > OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
*err = OS_PRIO_INVALID; /* No */
return (0);
}
}
if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
*err = OS_ERR_PNAME_NULL; /* Yes */
return (0);
}
#endif
OS_ENTER_CRITICAL();
if (prio == OS_PRIO_SELF) { /* See if caller desires it's own name */
prio = OSTCBCur->OSTCBPrio;
}
ptcb = OSTCBPrioTbl[prio];
if (ptcb == (OS_TCB *)0) { /* Does task exist? */
OS_EXIT_CRITICAL(); /* No */
*err = OS_TASK_NOT_EXIST;
return (0);
}
if (ptcb == (OS_TCB *)1) { /* Task assigned to a Mutex? */
OS_EXIT_CRITICAL(); /* Yes */
*err = OS_TASK_NOT_EXIST;
return (0);
}
len = OS_StrCopy(pname, ptcb->OSTCBTaskName); /* Yes, copy name from TCB */
OS_EXIT_CRITICAL();
*err = OS_NO_ERR;
return (len);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* ASSIGN A NAME TO A TASK
*
* Description: This function is used to set the name of a task.
*
* Arguments : prio is the priority of the task that you want the assign a name to.
*
* pname is a pointer to an ASCII string that contains the name of the task. The ASCII
* string must be NUL terminated.
*
* err is a pointer to an error code that can contain one of the following values:
*
* OS_NO_ERR if the requested task is resumed
* OS_TASK_NOT_EXIST if the task has not been created or is assigned to a Mutex
* OS_ERR_TASK_NAME_TOO_LONG if the name you are giving to the task exceeds the
* storage capacity of a task name as specified by
* OS_TASK_NAME_SIZE.
* OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
* OS_PRIO_INVALID if you specified an invalid priority:
* A higher value than the idle task or not OS_PRIO_SELF.
*
* Returns : None
*********************************************************************************************************
*/
#if OS_TASK_NAME_SIZE > 1
void OSTaskNameSet (INT8U prio, char *pname, INT8U *err)
{
INT8U len;
OS_TCB *ptcb;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
cpu_sr = 0; /* Prevent compiler warning */
#endif
#if OS_ARG_CHK_EN > 0
if (prio > OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
*err = OS_PRIO_INVALID; /* No */
return;
}
}
if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
*err = OS_ERR_PNAME_NULL; /* Yes */
return;
}
#endif
OS_ENTER_CRITICAL();
if (prio == OS_PRIO_SELF) { /* See if caller desires to set it's own name */
prio = OSTCBCur->OSTCBPrio;
}
ptcb = OSTCBPrioTbl[prio];
if (ptcb == (OS_TCB *)0) { /* Does task exist? */
OS_EXIT_CRITICAL(); /* No */
*err = OS_TASK_NOT_EXIST;
return;
}
if (ptcb == (OS_TCB *)1) { /* Task assigned to a Mutex? */
OS_EXIT_CRITICAL(); /* Yes */
*err = OS_TASK_NOT_EXIST;
return;
}
len = OS_StrLen(pname); /* Yes, Can we fit the string in the TCB? */
if (len > (OS_TASK_NAME_SIZE - 1)) { /* No */
OS_EXIT_CRITICAL();
*err = OS_ERR_TASK_NAME_TOO_LONG;
return;
}
(void)OS_StrCopy(ptcb->OSTCBTaskName, pname); /* Yes, copy to TCB */
OS_EXIT_CRITICAL();
*err = OS_NO_ERR;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* RESUME A SUSPENDED TASK
*
* Description: This function is called to resume a previously suspended task. This is the only call that
* will remove an explicit task suspension.
*
* Arguments : prio is the priority of the task to resume.
*
* Returns : OS_NO_ERR if the requested task is resumed
* OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
* (i.e. >= OS_LOWEST_PRIO)
* OS_TASK_RESUME_PRIO if the task to resume does not exist
* OS_TASK_NOT_EXIST if the task is assigned to a Mutex PIP
* OS_TASK_NOT_SUSPENDED if the task to resume has not been suspended
*********************************************************************************************************
*/
#if OS_TASK_SUSPEND_EN > 0
INT8U OSTaskResume (INT8U prio)
{
OS_TCB *ptcb;
#if OS_CRITICAL_METHOD == 3 /* Storage for CPU status register */
OS_CPU_SR cpu_sr;
cpu_sr = 0; /* Prevent compiler warning */
#endif
#if OS_ARG_CHK_EN > 0
if (prio >= OS_LOWEST_PRIO) { /* Make sure task priority is valid */
return (OS_PRIO_INVALID);
}
#endif
OS_ENTER_CRITICAL();
ptcb = OSTCBPrioTbl[prio];
if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
OS_EXIT_CRITICAL();
return (OS_TASK_RESUME_PRIO);
}
if (ptcb == (OS_TCB *)1) { /* See if assigned to Mutex */
OS_EXIT_CRITICAL();
return (OS_TASK_NOT_EXIST);
}
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* Task must be suspended */
ptcb->OSTCBStat &= ~OS_STAT_SUSPEND; /* Remove suspension */
if (ptcb->OSTCBStat == OS_STAT_RDY) { /* See if task is now ready */
if (ptcb->OSTCBDly == 0) {
OSRdyGrp |= ptcb->OSTCBBitY; /* Yes, Make task ready to run */
OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
OS_EXIT_CRITICAL();
OS_Sched();
} else {
OS_EXIT_CRITICAL();
}
} else { /* Must be pending on event */
OS_EXIT_CRITICAL();
}
return (OS_NO_ERR);
}
OS_EXIT_CRITICAL();
return (OS_TASK_NOT_SUSPENDED);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -