⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_msg.c

📁 UCOS-III
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
************************************************************************************************************************
*                                                      uC/OS-III
*                                                 The Real-Time Kernel
*
*                                  (c) Copyright 2009-2011; Micrium, Inc.; Weston, FL
*                           All rights reserved.  Protected by international copyright laws.
*
*                                              MESSAGE HANDLING SERVICES
*
* File    : OS_MSG.C
* By      : JJL
* Version : V3.02.00
*
* LICENSING TERMS:
* ---------------
*           uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 
*           for peaceful research.  If you plan or intend to use uC/OS-III in a commercial application/
*           product then, you need to contact Micrium to properly license uC/OS-III for its use in your 
*           application/product.   We provide ALL the source code for your convenience and to help you 
*           experience uC/OS-III.  The fact that the source is provided does NOT mean that you can use 
*           it commercially without paying a licensing fee.
*
*           Knowledge of the source code may NOT be used to develop a similar product.
*
*           Please help us continue to provide the embedded community with the finest software available.
*           Your honesty is greatly appreciated.
*
*           You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036.
************************************************************************************************************************
*/

#include <os.h>

#ifdef VSC_INCLUDE_SOURCE_FILE_NAMES
const  CPU_CHAR  *os_msg__c = "$Id: $";
#endif


#if OS_MSG_EN > 0u
/*
************************************************************************************************************************
*                                            EXTEND THE POOL OF 'OS_MSG'
*
* Description: This function is called by your application to add OS_MSGs to the free list of OS_MSGs
*
* Arguments  : p_msg        is a pointer to the base address of an array of OS_MSG and should be declared as follows:
*
*                           OS_MSG  MyNewMsgTbl[size];
*
*              size         is the size of the above array
*
*              p_err        is a pointer to a variable that will contain an error code returned by this function.
*
*                               OS_ERR_MSG_POOL_NULL_PTR
*                               OS_ERR_MSG_POOL_EMPTY
*                               OS_ERR_NONE
*
* Returns    : none
************************************************************************************************************************
*/

void  OSMsgPoolExtend (OS_MSG      *p_msg,
                       OS_MSG_QTY   size,
                       OS_ERR      *p_err)
{
#ifdef OS_SAFETY_CRITICAL
    if (p_err == (OS_ERR *)0) {
        OS_SAFETY_CRITICAL_EXCEPTION();
        return;
    }
#endif

#if OS_CFG_ARG_CHK_EN > 0u
    if (p_msg == (OS_MSG *)0) {
       *p_err = OS_ERR_MSG_POOL_NULL_PTR;
        return;
    }
    if (size == (OS_MSG_QTY)0) {
       *p_err = OS_ERR_MSG_POOL_EMPTY;
        return;
    }
#endif

    OS_MsgPoolCreate(p_msg,                                 /* Create the singly linked list                          */
                     size);
    p_msg[size - 1u].NextPtr = OSMsgPool.NextPtr;           /* Link last OS_MSG of new list to current pool           */
    OSMsgPool.NextPtr       = p_msg;
    OSMsgPool.NbrFree      += size;                         /* All new OS_MSGs are now available                      */
   *p_err                   = OS_ERR_NONE;
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                           CREATE A LINKED LIST OF 'OS_MSG'
*
* Description: This function is called to create a singly linked list of OS_MSGs which is used as a pool of available
*              OS_MSGs to be used for sending messages.
*
* Arguments  : p_msg        is a pointer to the base address of an array of OS_MSG and should be declared as follows:
*              -----
*                               OS_MSG  MyMsgTbl[size];
*
*              size         is the size of the above array
*
* Returns    : none
*
* Note(s)    : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
************************************************************************************************************************
*/

void  OS_MsgPoolCreate (OS_MSG      *p_msg,
                        OS_MSG_QTY   size)
{
    OS_MSG      *p_msg1;
    OS_MSG      *p_msg2;
    OS_MSG_QTY   i;
    OS_MSG_QTY   loops;



    p_msg1 = p_msg;
    p_msg2 = p_msg;
    p_msg2++;
    loops  = size - 1u;
    for (i = 0u; i < loops; i++) {                          /* Init. list of free OS_MSGs                             */
        p_msg1->NextPtr = p_msg2;
        p_msg1->MsgPtr  = (void      *)0;
        p_msg1->MsgSize = (OS_MSG_SIZE)0u;
        p_msg1->MsgTS   = (CPU_TS     )0u;
        p_msg1++;
        p_msg2++;
    }
    p_msg1->NextPtr = (OS_MSG    *)0;                       /* Last OS_MSG                                            */
    p_msg1->MsgPtr  = (void      *)0;
    p_msg1->MsgSize = (OS_MSG_SIZE)0u;
    p_msg1->MsgTS   = (CPU_TS     )0u;
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                            INITIALIZE THE POOL OF 'OS_MSG'
*
* Description: This function is called by OSInit() to initialize the free list of OS_MSGs.
*
* Argument(s): p_err     is a pointer to a variable that will contain an error code returned by this function.
*
*                            OS_ERR_MSG_POOL_NULL_PTR
*                            OS_ERR_MSG_POOL_EMPTY
*                            OS_ERR_NONE
*
* Returns    : none
*
* Note(s)    : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
************************************************************************************************************************
*/

void  OS_MsgPoolInit (OS_ERR  *p_err)
{
#ifdef OS_SAFETY_CRITICAL
    if (p_err == (OS_ERR *)0) {
        OS_SAFETY_CRITICAL_EXCEPTION();
        return;
    }
#endif

#if OS_CFG_ARG_CHK_EN > 0u
    if (OSCfg_MsgPoolBasePtr == (OS_MSG *)0) {
       *p_err = OS_ERR_MSG_POOL_NULL_PTR;
        return;
    }
    if (OSCfg_MsgPoolSize == (OS_MSG_QTY)0) {
       *p_err = OS_ERR_MSG_POOL_EMPTY;
        return;
    }
#endif

    OS_MsgPoolCreate(OSCfg_MsgPoolBasePtr,
                    OSCfg_MsgPoolSize);
    OSMsgPool.NextPtr =  OSCfg_MsgPoolBasePtr;
    OSMsgPool.NbrFree =  OSCfg_MsgPoolSize;
    OSMsgPool.NbrUsed = (OS_MSG_QTY)0;
   *p_err             =  OS_ERR_NONE;
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                        RESET MESSAGE QUEUE ENTRIES PEAK TRACKING
*
* Description: This function clear the peak detection mechanism of the message queue
*
* Arguments  : p_msg_q       is a pointer to the OS_MSG_Q structure
*              -------
*
* Returns    : none
*
* Note(s)    : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
************************************************************************************************************************
*/

void  OS_MsgQEntriesPeakReset (OS_MSG_Q  *p_msg_q)
{
    CPU_SR_ALLOC();


    CPU_CRITICAL_ENTER();
    p_msg_q->NbrEntriesMax = (OS_MSG_QTY)0;
    CPU_CRITICAL_EXIT();
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                        RELEASE ALL MESSAGE IN MESSAGE QUEUE
*
* Description: This function returns all the messages in a message queue to the free list.
*
* Arguments  : p_msg_q       is a pointer to the OS_MSG_Q structure containing messages to free.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -