📄 os_task.c
字号:
*
*
* p_err is a pointer to a variable that will hold the error code associated
* with the outcome of this call. Errors can be:
*
* OS_ERR_NONE The call was successful and the message was sent
* OS_ERR_Q_MAX If the queue is full
* OS_ERR_MSG_POOL_EMPTY If there are no more OS_MSGs available from the pool
*
* Returns : none
************************************************************************************************************************
*/
#if OS_CFG_TASK_Q_EN > 0u
void OSTaskQPost (OS_TCB *p_tcb,
void *p_void,
OS_MSG_SIZE msg_size,
OS_OPT opt,
OS_ERR *p_err)
{
CPU_TS ts;
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
#if OS_CFG_ARG_CHK_EN > 0u /* ---------------- VALIDATE ARGUMENTS ------------------ */
switch (opt) { /* User must supply a valid option */
case OS_OPT_POST_FIFO:
case OS_OPT_POST_LIFO:
case OS_OPT_POST_FIFO | OS_OPT_POST_NO_SCHED:
case OS_OPT_POST_LIFO | OS_OPT_POST_NO_SCHED:
break;
default:
*p_err = OS_ERR_OPT_INVALID;
return;
}
#endif
ts = OS_TS_GET(); /* Get timestamp */
#if OS_CFG_ISR_POST_DEFERRED_EN > 0u
if (OSIntNestingCtr > (OS_NESTING_CTR)0) {
OS_IntQPost((OS_OBJ_TYPE)OS_OBJ_TYPE_TASK_MSG, /* Post to ISR queue */
(void *)p_tcb,
(void *)p_void,
(OS_MSG_SIZE)msg_size,
(OS_FLAGS )0,
(OS_OPT )opt,
(CPU_TS )ts,
(OS_ERR *)p_err);
return;
}
#endif
OS_TaskQPost(p_tcb,
p_void,
msg_size,
opt,
ts,
p_err);
}
#endif
/*$PAGE*/
/*
************************************************************************************************************************
* GET THE CURRENT VALUE OF A TASK REGISTER
*
* Description: This function is called to obtain the current value of a task register. Task registers are application
* specific and can be used to store task specific values such as 'error numbers' (i.e. errno), statistics,
* etc.
*
* Arguments : p_tcb is a pointer to the OS_TCB of the task you want to read the register from. If 'p_tcb' is a
* NULL pointer then you will get the register of the current task.
*
* id is the 'id' of the desired task variable. Note that the 'id' must be less than
* OS_CFG_TASK_REG_TBL_SIZE
*
* p_err is a pointer to a variable that will hold an error code related to this call.
*
* OS_ERR_NONE if the call was successful
* OS_ERR_REG_ID_INVALID if the 'id' is not between 0 and OS_CFG_TASK_REG_TBL_SIZE-1
*
* Returns : The current value of the task's register or 0 if an error is detected.
************************************************************************************************************************
*/
#if OS_CFG_TASK_REG_TBL_SIZE > 0u
OS_REG OSTaskRegGet (OS_TCB *p_tcb,
OS_REG_ID id,
OS_ERR *p_err)
{
OS_REG value;
CPU_SR_ALLOC();
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return ((OS_REG)0);
}
#endif
#if OS_CFG_ARG_CHK_EN > 0u
if (id >= OS_CFG_TASK_REG_TBL_SIZE) {
*p_err = OS_ERR_REG_ID_INVALID;
return ((OS_REG)0);
}
#endif
CPU_CRITICAL_ENTER();
if (p_tcb == (OS_TCB *)0) {
p_tcb = OSTCBCurPtr;
}
value = p_tcb->RegTbl[id];
CPU_CRITICAL_EXIT();
*p_err = OS_ERR_NONE;
return ((OS_REG)value);
}
#endif
/*$PAGE*/
/*
************************************************************************************************************************
* ALLOCATE THE NEXT AVAILABLE TASK REGISTER ID
*
* Description: This function is called to obtain a task register ID. This function thus allows task registers IDs to be
* allocated dynamically instead of statically.
*
* Arguments : p_err is a pointer to a variable that will hold an error code related to this call.
*
* OS_ERR_NONE if the call was successful
* OS_ERR_NO_MORE_ID_AVAIL if you are attempting to assign more task register IDs than you
* have available through OS_CFG_TASK_REG_TBL_SIZE.
*
* Returns : The next available task register 'id' or OS_CFG_TASK_REG_TBL_SIZE if an error is detected.
************************************************************************************************************************
*/
#if OS_CFG_TASK_REG_TBL_SIZE > 0u
OS_REG_ID OSTaskRegGetID (OS_ERR *p_err)
{
OS_REG_ID id;
CPU_SR_ALLOC();
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return ((OS_REG_ID)OS_CFG_TASK_REG_TBL_SIZE);
}
#endif
CPU_CRITICAL_ENTER();
if (OSTaskRegNextAvailID >= OS_CFG_TASK_REG_TBL_SIZE) { /* See if we exceeded the number of IDs available */
*p_err = OS_ERR_NO_MORE_ID_AVAIL; /* Yes, cannot allocate more task register IDs */
CPU_CRITICAL_EXIT();
return ((OS_REG_ID)OS_CFG_TASK_REG_TBL_SIZE);
}
id = OSTaskRegNextAvailID; /* Assign the next available ID */
OSTaskRegNextAvailID++; /* Increment available ID for next request */
CPU_CRITICAL_EXIT();
*p_err = OS_ERR_NONE;
return (id);
}
#endif
/*$PAGE*/
/*
************************************************************************************************************************
* SET THE CURRENT VALUE OF A TASK REGISTER
*
* Description: This function is called to change the current value of a task register. Task registers are application
* specific and can be used to store task specific values such as 'error numbers' (i.e. errno), statistics,
* etc.
*
* Arguments : p_tcb is a pointer to the OS_TCB of the task you want to set the register for. If 'p_tcb' is a NULL
* pointer then you will change the register of the current task.
*
* id is the 'id' of the desired task register. Note that the 'id' must be less than
* OS_CFG_TASK_REG_TBL_SIZE
*
* value is the desired value for the task register.
*
* p_err is a pointer to a variable that will hold an error code related to this call.
*
* OS_ERR_NONE if the call was successful
* OS_ERR_REG_ID_INVALID if the 'id' is not between 0 and OS_CFG_TASK_REG_TBL_SIZE-1
*
* Returns : none
************************************************************************************************************************
*/
#if OS_CFG_TASK_REG_TBL_SIZE > 0u
void OSTaskRegSet (OS_TCB *p_tcb,
OS_REG_ID id,
OS_REG value,
OS_ERR *p_err)
{
CPU_SR_ALLOC();
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
#if OS_CFG_ARG_CHK_EN > 0u
if (id >= OS_CFG_TASK_REG_TBL_SIZE) {
*p_err = OS_ERR_REG_ID_INVALID;
return;
}
#endif
CPU_CRITICAL_ENTER();
if (p_tcb == (OS_TCB *)0) {
p_tcb = OSTCBCurPtr;
}
p_tcb->RegTbl[id] = value;
CPU_CRITICAL_EXIT();
*p_err = OS_ERR_NONE;
}
#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 : p_tcb Is a pointer to the task's OS_TCB to resume
*
* p_err Is a pointer to a variable that will contain an error code returned by this function
*
* OS_ERR_NONE if the requested task is resumed
* OS_ERR_STATE_INVALID if the task is in an invalid state
* OS_ERR_TASK_RESUME_ISR if you called this function from an ISR
* OS_ERR_TASK_RESUME_SELF You cannot resume 'self'
* OS_ERR_TASK_NOT_SUSPENDED if the task to resume has not been suspended
*
* Returns : none
************************************************************************************************************************
*/
#if OS_CFG_TASK_SUSPEND_EN > 0u
void OSTaskResume (OS_TCB *p_tcb,
OS_ERR *p_err)
{
CPU_SR_ALLOC();
#ifdef OS_SAFETY_CRITICAL
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
#if (OS_CFG_ISR_POST_DEFERRED_EN == 0u) && \
(OS_CFG_CALLED_FROM_ISR_CHK_EN > 0u)
if (OSIntNestingCtr > (OS_NESTING_CTR)0) { /* Not allowed to call from an ISR */
*p_err = OS_ERR_TASK_RESUME_ISR;
return;
}
#endif
CPU_CRITICAL_ENTER();
#if OS_CFG_ARG_CHK_EN > 0u
if ((p_tcb == (OS_TCB *)0) || /* We cannot resume 'self' */
(p_tcb == OSTCBCurPtr)) {
CPU_CRITICAL_EXIT();
*p_err = OS_ERR_TASK_RESUME_SELF;
return;
}
#endif
CPU_CRITICAL_EXIT();
#if OS_CFG_ISR_POST_DEFERRED_EN > 0u
if (OSIntNestingCtr > (OS_NESTING_CTR)0) { /* See if called from an ISR */
OS_IntQPost((OS_OBJ_TYPE)OS_OBJ_TYPE_TASK_RESUME, /* Post to ISR queue */
(void *)p_tcb,
(void *)0,
(OS_MSG_SIZE)0,
(OS_FLAGS )0,
(OS_OPT )0,
(CPU_TS )0,
(OS_ERR *)p_err);
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -