第一个函数(获得信号量、互斥量、邮箱或者队列名字的函数)的流程图和分析图如下所示:
/*$PAGE*/
/*
*********************************************************************************************************
* GET THE NAME OF A SEMAPHORE, MUTEX, MAILBOX or QUEUE
* 获得信号量、互斥量、邮箱或队列的名称
* Description: This function is used to obtain the name assigned to a semaphore, mutex, mailbox or queue.
*该功能用来获得信号量、互斥量、邮箱或者队列的名称
* Arguments : pevent is a pointer to the event group. 'pevent' can point either to a semaphore,
* 参数 a mutex, a mailbox or a queue. Where this function is concerned, the actual
* type is irrelevant.
* pevent是一个指向事件组的指针,也可以指向信号量、互斥量、邮箱或队列。在功能方面,实际的类型无关
* pname is a pointer to a pointer to an ASCII string that will receive the name of the semaphore,
* mutex, mailbox or queue.
* pname是一个指向代表信号量、互斥量、邮箱或队列名称的ASCII码字符串的指针
* perr is a pointer to an error code that can contain one of the following values:
* perr是一个指向错误码的指针。错误码包括以下几种:
* OS_ERR_NONE if the name was copied to 'pname' --名字被复制到pname,无错误
* OS_ERR_EVENT_TYPE if 'pevent' is not pointing to the proper event
* control block type. --pevent指向的事件控制块(ECB)类型错误
* OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'--pname指针为空
* OS_ERR_PEVENT_NULL if you passed a NULL pointer for 'pevent'--pevent指针为空指针
* OS_ERR_NAME_GET_ISR if you are trying to call this function from an ISR --调用中断函数
*
* Returns : The length of the string or 0 if the 'pevent' is a NULL pointer.
返回值:当pevent不是空指针时返回0或者字符串长度
*********************************************************************************************************
*/
#if (OS_EVENT_EN) && (OS_EVENT_NAME_EN > 0u) /*如果可以产生事件并且可以给事件命名*/
INT8U OSEventNameGet(OS_EVENT *pevent, /*获得时间名称函数(指向事件组的指针,事件名称,错误码指针)*/
INT8U **pname,
INT8U *perr)
{
INT8U len;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register 中断类型为3,断点*/
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL /*定义安全中断*/
if (perr == (INT8U *)0) { /*如果错误码为0.调用安全中断异常函数OS_SAFETY_CRITICAL_EXCEPTION()*/
OS_SAFETY_CRITICAL_EXCEPTION();
}
#endif
#if OS_ARG_CHK_EN > 0u /*检查参数*/
if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? 如果指向事件的指针为空 */
*perr = OS_ERR_PEVENT_NULL; /*将错误码指针设为OS_ERR_PEVENT_NULL*/
return (0u);
}
if (pname == (INT8U **)0) { /* Is 'pname' a NULL pointer? 如果pname为空指针 */
*perr = OS_ERR_PNAME_NULL; /*将错误码指针设为OS_ERR_PNAME_NULL*/
return (0u);
}
#endif
if (OSIntNesting > 0u) { /* See if trying to call from an ISR 如果嵌套中断>0,即检测是否要调用中断函数*/
*perr = OS_ERR_NAME_GET_ISR; /*将错误码指针设为 OS_ERR_NAME_GET_ISR*/
return (0u);
}
switch (pevent->OSEventType) { /*如果pevent指向的是事件类型*/
case OS_EVENT_TYPE_SEM: /*OS_EVENT_TYPE_SEM,OS_EVENT_TYPE_MUTEX,OS_EVENT_TYPE_MBOX,OS_EVENT_TYPE_Q四个+*/
case OS_EVENT_TYPE_MUTEX: /*+事件类型处理为空*/
case OS_EVENT_TYPE_MBOX:
case OS_EVENT_TYPE_Q:
break;
default: /*默认情况下,将错误码设置成OS_ERR_EVENT_TYPE*/
*perr = OS_ERR_EVENT_TYPE;
return (0u);
}
//====以上是各种if下的情况,下面是该函数主体===//
OS_ENTER_CRITICAL(); /*关中断*/
*pname = pevent->OSEventName; /*将事件名字赋给pname指针*/
len = OS_StrLen(*pname); /*得到名字的长度len*/
OS_EXIT_CRITICAL(); /*开中断*/
*perr = OS_ERR_NONE; /*将错误码设置为OS_ERR_NONE,即无错误*/
return (len); /*返回len*/
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* ASSIGN A NAME TO A SEMAPHORE, MUTEX, MAILBOX or QUEUE
* 给信号量、互斥量、邮箱或队列设置名字
* Description: This function assigns a name to a semaphore, mutex, mailbox or queue.
*描述:该功能是给信号量、互斥量、邮箱或队列设置名字
* Arguments : pevent is a pointer to the event group. 'pevent' can point either to a semaphore,
* a mutex, a mailbox or a queue. Where this function is concerned, it doesn't
* matter the actual type.
* pervent是指向事件组的指针,也可以指向信号量、互斥量、邮箱或队列。
* pname is a pointer to an ASCII string that will be used as the name of the semaphore,
* mutex, mailbox or queue.
* pname是一个指向代表信号量、互斥量、邮箱或队列名称的ASCII码字符串的指针
* perr is a pointer to an error code that can contain one of the following values:
* perr是一个指向错误码的指针。错误码包括以下几种:
* OS_ERR_NONE if the requested task is resumed--所请求的任务是恢复
* OS_ERR_EVENT_TYPE if 'pevent' is not pointing to the proper event
* control block type.--pevent没有正确指向事件控制块类型
* OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'--pname指针为空
* OS_ERR_PEVENT_NULL if you passed a NULL pointer for 'pevent'--pevent为空指针
* OS_ERR_NAME_SET_ISR if you called this function from an ISR--中断
*
* Returns : None--无返回值
*********************************************************************************************************
*/
#if (OS_EVENT_EN) && (OS_EVENT_NAME_EN > 0u) /*如果可以生成时间并且可以设置名称*/
void OSEventNameSet(OS_EVENT *pevent, /*调用设置名称函数(指向事件组的指针,指向名称的指针,指向错误码的指针)*/
INT8U *pname,
INT8U *perr)
{
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register 将中断类型设置为3 */
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL /*定义安全中断*/
if (perr == (INT8U *)0) { /*如果错误码为0*/
OS_SAFETY_CRITICAL_EXCEPTION(); /*调用安全中断异常函数OS_SAFETY_CRITICAL_EXCEPTION()*/
}
#endif
#if OS_ARG_CHK_EN > 0u /*检查参数*/
if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? --pevent是空指针么? */
*perr = OS_ERR_PEVENT_NULL; /*将错误码设为OS_ERR_PEVENT_NULL*/
return; /*无返回值*/
}
if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? --pname是空指针么? */
*perr = OS_ERR_PNAME_NULL; /*将错误码设为OS_ERR_PNAME_NULL*/
return; /*无返回值*/
}
#endif
if (OSIntNesting > 0u) { /* See if trying to call from an ISR 检查是否要进行中断 */
*perr = OS_ERR_NAME_SET_ISR; /*将错误码设为OS_ERR_NAME_SET_ISR*/
return; /*无返回值*/
}
switch (pevent->OSEventType) {
case OS_EVENT_TYPE_SEM:
case OS_EVENT_TYPE_MUTEX:
case OS_EVENT_TYPE_MBOX:
case OS_EVENT_TYPE_Q:
break;
default:
*perr = OS_ERR_EVENT_TYPE;
return;
}
OS_ENTER_CRITICAL(); /*关中断*/
pevent->OSEventName = pname; /*设置名称*/
OS_EXIT_CRITICAL(); /*开中断*/
*perr = OS_ERR_NONE; /*将错误码设置为OS_ERR_NONE*/
}
#endif