/**********************************************************************/
/*                                                                    */
/* File name: uip_kernel_message.c                                    */
/*                                                                    */
/* Since:     2007-02-25                                              */
/*                                                                    */
/* Version:   uip Kernel v1.09                                        */
/*            Copyright (C) 2006..2018 Wang Baojin.                   */
/*                                                                    */
/* Author:    Designed by Wang Baojin(Íõ±£½ø)                         */
/*                                                                    */
/*                                                                    */
/* Purpose:   Support uip kernel message communication.               */
/*                                                                    */
/* Distribution: This file is part of uip kernel.                     */
/*            uip Kernel is free software, you can redistribute it    */
/*            and/or modify it under the terms of the GNU General     */
/*            Public License as published by the Free Software        */
/*            Foundation either version 2, or (at your option)        */
/*            any later version.                                      */
/*                                                                    */
/*            uip Kernel is distributed in the hope that it will be   */
/*            useful, but WITHOUT ANY WARRANTY without even the       */
/*            implied warranty of MERCHANTABILITY or FITNESS FOR A    */
/*            PuipICULAR PURPOSE.  See the GNU General Public         */
/*            License for more details.                               */
/*                                                                    */
/*            You should have received a copy of the GNU General      */
/*            Public License along with gpsim see the file            */
/*            COPYING.txt. If not, write to the Free Software         */
/*            Foundation, 59 Temple Place - Suite 330,                */
/*            Boston, MA 02111-1307, USA.                             */
/*                                                                    */
/*          > A special exception to the GPL can be applied should    */
/*            you wish to distribute a combined work that includes    */
/*            uip Kernel, without being obliged to provide the        */
/*            source code for any proprietary components.             */
/*                                                                    */
/* History:                                                           */
/*   2007/02/25  [WBJ] Create this file.                              */
/*                                                                    */
/**********************************************************************/

#include "uip_kernel_api.h"

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_SendMessage                                     1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    The service updates the message object identified by <Message>  */
/*    with the application message referenced by the<DataRef>         */
/*    parameter.                                                      */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    Message                    Message identifier                   */
/*    DataRef                    Reference to the application's       */
/*                               message data to be transmitted       */
/*                                                                    */ 
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    E_OK                       Service operation completed          */
/*                               successfully.                        */ 
/*    E_OS_ID                    The parameter <Message> is out of    */
/*                               range or if refers to a message that */
/*                               is received or to a dynamic-length   */
/*                               or zero-length message.              */
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/ 
StatusType UIP_SendMessage(MsgType MsgID, AppDataRef DataRef)
{
    uip_INTERRUPT_STATE_SAVED;
    StatusType     status;
    UIP_INT32      data_size;
    uipMsgPtr      msgPtr;
    
    /* Check to see if MsgID is valid(not larger than uipMsgNumber) */
    if (MsgID > uipMsgNumber)
    {
        return (E_OS_ID);
    }  

    msgPtr = (uipMsgPtr)&uipMCBArray[MsgID];
    
    /* Check to see if application data buffer is valid */ 
    if (msgPtr -> uipQueueWriteHead == (UIP_UCHAR_PTR)DataRef)  
    {
        /* Return error information */
        return (uip_COM_BUFFER);                
    }

     /* Check to see if this message has been locked */ 
    if ((msgPtr -> uipMsgStatus & uip_MSG_LOCKED) != 0)  
    {
        /* Return error information */
        return (uip_COM_LOCKED);                
    }
    
    /* Enter critical area */
    uip_KERNEL_DISABLE_INTS;

    /* Lock message */
    msgPtr -> uipMsgStatus |= uip_MSG_LOCKED;

    /* Leave cirtical area */
    uip_KERNEL_RESTORE_INTS;

    /* Save message basing on message type */
    /* If it is unqueued message */
    if(msgPtr -> uipMsgType == uip_MSG_UNQUEUED)
    {
        for(data_size = 0; data_size < msgPtr -> uipMsgSize; data_size++)
        {
            *((UIP_UCHAR_PTR)(msgPtr -> uipQueueWriteHead) + data_size) = 
                                                      *((UIP_UCHAR_PTR)DataRef + data_size); 
        }                                                                        
        /* reset ReadHead */
        msgPtr -> uipQueueWriteHead = msgPtr -> uipMsgPtr;                                                                        
    } /* end of if */
    /* If it is queued message */
    else
    {
        if (((msgPtr -> uipMsgStatus) & uip_MSG_OVERFLOW) == 0)
        {
            for (data_size = 0; data_size < msgPtr -> uipMsgSize; data_size++)
            {
                *((UIP_UCHAR_PTR)(msgPtr -> uipQueueWriteHead) + data_size) = 
                                                          *((UIP_UCHAR_PTR)DataRef + data_size); 
            }                                                                        
            
            msgPtr -> uipQueueWriteHead += msgPtr -> uipMsgSize;
            /* modify '==' to '>='£¬for reliability */
            if ((UIP_UCHAR_PTR)(msgPtr -> uipQueueWriteHead) >= 
                              (UIP_UCHAR_PTR)(msgPtr -> uipQueueEnd)) /* end of queue reached */
            {                                   
                msgPtr -> uipMsgStatus |= uip_MSG_OVERFLOW;
                msgPtr -> uipQueueWriteHead = msgPtr -> uipMsgPtr;
            }
        }
    } /* end of else */

    /* Unlock message */
    msgPtr -> uipMsgStatus &= ~uip_MSG_LOCKED;
                                            
    /* If notification mechanism is callback routine */
    if (msgPtr -> uipMsgNotifyType == uip_COM_NOTIFICATION_CALLBACK)
    {
        /* Call callback routine */
        msgPtr -> uipMsgCallBack();                 
    }
    /* If notification mechanism is setting flag */
    else if (msgPtr -> uipMsgNotifyType == uip_COM_NOTIFICATION_FLAG)
    {
    	/* Enter critical area */
    	uip_KERNEL_DISABLE_INTS;
		
    	msgPtr -> uipMsgFlag = 1;
    	/* Leave cirtical area */
    	uip_KERNEL_RESTORE_INTS;
    }
    /* If notification mechanism is setting event */
    else if (msgPtr -> uipMsgNotifyType == uip_COM_NOTIFICATION_SETEVENT)
    {           
        status = UIP_SetEvent(msgPtr -> uipMsgNotifyTaskID, msgPtr -> uipMsgEvent);
        if (status != E_OK)
        {
            /* Return error information */
    	  	return (status);
        }
    }
    /* If notification mechanism is activating task directly */
    else if (msgPtr -> uipMsgNotifyType == uip_COM_NOTIFICATION_ACTIVATETASK)
    {           
        status = UIP_ActivateTask(msgPtr -> uipMsgNotifyTaskID);
        if (status != E_OK)
        {
            /* Return error information */
    	  	return (status);
        }    
    }
    
    /* No error */
    return (E_OK);                                    
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_ReceiveMessage                                  1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    The service updates the application message referenced by       */
/*    <DataRef> with the data in the message object identified by     */
/*    <Message>. It resets all flags (Notification classes 1 and 3)   */
/*    associated with <Message>.                                      */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    MsgID                      Message identifier                   */
/*                                                                    */ 
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    DataRef                    Reference to the application's       */
/*                               message buffer to saving data        */
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    E_OK                       Data in the queued or unqueued       */
/*                               message identified by <Message>      */
/*                               are available and returned to        */
/*                               the application successfully.        */ 
/*    E_OS_ID                    MsgID is valid(not larger than       */
/*                               uipMsgNumber                         */ 
/*    uip_COM_BUFFER             Data buffer is not valid             */ 
/*    uip_COM_LOCKED             Message has been locked              */ 
/*    uip_COM_BUFFER_EMPTY       There is no data in message buffer	  */ 
/*    uip_COM_OVERFLOW           Buffer has been overflow             */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/ 
StatusType UIP_ReceiveMessage(MsgType MsgID, AppDataRef DataRef)
{
    uip_INTERRUPT_STATE_SAVED;
    StatusType     status;
    UIP_UINT       data_size;    
    uipMsgPtr      msgPtr;

    status = E_OK;    
    /* Check to see if MsgID is valid(not larger than uipMsgNumber) */
    if (MsgID > uipMsgNumber)
    {
        return (E_OS_ID);
    }  

    msgPtr = (uipMsgPtr)&uipMCBArray[MsgID];

     /* Check to see if application data buffer is valid */ 
    if ((UIP_UCHAR_PTR)(msgPtr -> uipQueueReadHead) == (UIP_UCHAR_PTR)DataRef)  
    {
        /* Return error information */
        return (uip_COM_BUFFER);                
    }

     /* Check to see if this message has been locked */ 
    if (((msgPtr -> uipMsgStatus) & uip_MSG_LOCKED) != 0)  
    {
        /* Return error information */
        return (uip_COM_LOCKED);                
    }
    
    /* Enter critical area */
    uip_KERNEL_DISABLE_INTS;

    /* Lock message */
    msgPtr -> uipMsgStatus |= uip_MSG_LOCKED;

    /* Leave cirtical area */
    uip_KERNEL_RESTORE_INTS;

    /* Copy message basing on message type */
    /* If it is unqueued message */
    if (msgPtr -> uipMsgType == uip_MSG_UNQUEUED)
    {
        for (data_size = 0; data_size < msgPtr -> uipMsgSize; data_size++)
        {
            *((UIP_UCHAR_PTR)DataRef + data_size) = 
                        *((UIP_UCHAR_PTR)(msgPtr -> uipQueueReadHead) + data_size); 
        }
        /* reset ReadHead */
        msgPtr -> uipQueueReadHead = msgPtr -> uipMsgPtr;                                                                        
    }
    /* If it is queued message */
    else
    {
        /* If no overflow and readhead equ buffer start address, there is no data in 
           message buffer */
        if ((((msgPtr -> uipMsgStatus) & uip_MSG_OVERFLOW) == 0) && 
           ((msgPtr -> uipQueueReadHead) == (msgPtr -> uipQueueWriteHead)))
        {
            /* Unlock message */
            msgPtr -> uipMsgStatus &= ~uip_MSG_LOCKED;
            
            /* Return error information */
            return (uip_COM_BUFFER_EMPTY);            
        }
        /* If buffer has been overflow */
        if (((msgPtr -> uipMsgStatus) & uip_MSG_OVERFLOW) != 0)
        {
            status = uip_COM_OVERFLOW;
            msgPtr -> uipMsgStatus &= ~uip_MSG_OVERFLOW;
        }
       
        /* Move data */
        for (data_size = 0; data_size < msgPtr -> uipMsgSize; data_size++)
        {
            *((UIP_UCHAR_PTR)DataRef + data_size) = 
                        *((UIP_UCHAR_PTR)(msgPtr -> uipQueueReadHead) + data_size); 
        }                                                                        

        msgPtr -> uipQueueReadHead += msgPtr -> uipMsgSize;
            
        if ((UIP_UCHAR_PTR)(msgPtr -> uipQueueReadHead) >= 
                                     (UIP_UCHAR_PTR)(msgPtr -> uipQueueEnd))
        {                                   /* end of queue reached */
            msgPtr -> uipQueueReadHead = msgPtr -> uipMsgPtr;
        }

    } /* end of else */

    /* Unlock message */
    msgPtr -> uipMsgStatus &= ~uip_MSG_LOCKED;

    return (status);
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_GetMessageStatus                                1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    The service returns the current status of the message object    */
/*    <Message>.                                                      */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    MsgID                      Message identifier                   */
/*                                                                    */ 
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    E_OK                       Data in the queued or unqueued       */
/*                               message identified by <Message>      */
/*                               are available and returned to        */
/*                               the application successfully.        */ 
/*    E_OS_ID                    MsgID is valid(not larger than       */
/*                               uipMsgNumber                         */ 
/*    uip_COM_BUFFER             Data buffer is not valid             */ 
/*    uip_COM_LOCKED             Message has been locked              */ 
/*    uip_COM_BUFFER_EMPTY       There is no data in message buffer	  */ 
/*    uip_COM_OVERFLOW           Buffer has been overflow             */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/ 
StatusType UIP_GetMessageStatus(MsgType MsgID)
{
    uipMsgPtr      msgPtr;

    /* Check to see if MsgID is valid(not larger than uipMsgNumber) */
    if (MsgID > uipMsgNumber)
    {
        return (E_OS_ID);
    }  

    msgPtr = (uipMsgPtr)&uipMCBArray[MsgID];

    /* Check to see if this message has been locked */ 
    if (((msgPtr -> uipMsgStatus) & uip_MSG_LOCKED) != 0)  
    {
        /* Return error information */
        return (uip_COM_LOCKED);                
    } /* end of if ((msgPtr -> uipMsgStatus & uip_MSG_LOCKED) != 0) */

    if (msgPtr -> uipMsgType == uip_MSG_QUEUED)
    {
        /* If no overflow and readhead equ buffer start address, there is no data in 
           message buffer */
        if ((((msgPtr -> uipMsgStatus) & uip_MSG_OVERFLOW) == 0) && 
           (msgPtr -> uipQueueReadHead == msgPtr -> uipQueueWriteHead))
        {
            /* Return error information */
            return (uip_COM_BUFFER_EMPTY);            
        }
        /* If buffer has been overflow */
        if (((msgPtr -> uipMsgStatus) & uip_MSG_OVERFLOW) != 0)
        {
            return (uip_COM_OVERFLOW);
        }
    } /* end of if(msgPtr -> uipMsgType == uip_MSG_QUEUED) */
    
    return (E_OK);                                            
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_ReadFlag                                        1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    This service returns COM_TRUE if <Flag> is set, otherwise it    */
/*    returns COM_FALSE.                                              */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    MsgID                      Message identifier                   */
/*                                                                    */ 
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*   FlagValue                   Value of the flag                    */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/
FlagType UIP_ReadFlag(MsgType MsgID)
{
    FlagType       value;
    uipMsgPtr      msgPtr;

    msgPtr = (uipMsgPtr)&uipMCBArray[MsgID];

    value = msgPtr -> uipMsgFlag;
    
    return (value);
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_ResetFlag                                       1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    This service resets <Flag>                                      */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    MsgID                      Message identifier                   */
/*                                                                    */
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    E_OK                       Service operation completed          */
/*                               successfully.                        */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/
StatusType UIP_ResetFlag(MsgType MsgID)
{
    uip_INTERRUPT_STATE_SAVED;
    uipMsgPtr      msgPtr;

    msgPtr = (uipMsgPtr)&uipMCBArray[MsgID];

    /* Enter critical area */
    uip_KERNEL_DISABLE_INTS;

    msgPtr -> uipMsgFlag = 0;
    
    /* Leave cirtical area */
    uip_KERNEL_RESTORE_INTS;
        
    return (E_OK);
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_StartCOM                                        1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    The service starts and initialises the OSEK COM implementation  */
/*    in the requested application mode.                              */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    E_OK                       Service operation completed          */
/*                               successfully.                        */ 
/*    Implementation-specific    The initialisation was not completed */
/*    status code                successfully.                        */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/
StatusType UIP_StartCOM(void)
{
    StatusType         returnVal;

    /* Function defined by user  */
    returnVal = uipCOMInit();
    
    return (returnVal);
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    uipGeneralCounterHandler                            1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    The service close OSEK COM                                      */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/
StatusType UIP_CloseCOM(void)
{
    /* Function defined by user  */
    //
    
    return (E_OK);
} /* end */

/**********************************************************************/ 
/*                                                                    */ 
/*  Function name                                       Version       */ 
/*                                                                    */ 
/*    UIP_StopCOM                                         1.09        */ 
/*                                                                    */ 
/*  Author                                                            */ 
/*                                                                    */ 
/*    Wang Baojin                                                     */ 
/*                                                                    */ 
/*  Description                                                       */ 
/*                                                                    */ 
/*    The service UIP_StopCOM causes all OSEK COM activity to cease   */
/*    immediately. All resources used by OSEK COM are returned or     */
/*    left in an inactive state. Data loss is possible.               */ 
/*                                                                    */ 
/*  Note:                                                             */
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Parameter(In)                                                     */ 
/*                                                                    */ 
/*    ShutdownMode               Shutdown mode                        */ 
/*                                                                    */ 
/*  Parameter(Out)                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Return Status                                                     */ 
/*                                                                    */ 
/*    E_OK                       Service operation completed          */
/*                               successfully.                        */ 
/*    Implementation-specific    The initialisation was not completed */
/*    status code                successfully.                        */ 
/*                                                                    */ 
/*  Call functions                                                    */ 
/*                                                                    */ 
/*    None                                                            */ 
/*                                                                    */ 
/*  Called by                                                         */ 
/*                                                                    */ 
/*    Non preemptable task, Preemptable task                          */ 
/*                                                                    */ 
/*  Conformance:                                                      */
/*                                                                    */ 
/*  Release                                                           */ 
/*                                                                    */ 
/*  author name         release date              Description         */ 
/*                                                                    */ 
/*  Wang Baojin          2007.02.25            Initial Version 1.0    */ 
/*                                                                    */ 
/**********************************************************************/
StatusType UIP_StopCOM(UIP_UCHAR ShutdownMode)
{
    UIP_UINT     msgNumber; 
    uipMsgPtr      msgPtr;
 
    for (msgNumber = 0; msgNumber < uipMsgNumber; msgNumber++)
    {
        msgPtr = (uipMsgPtr)&uipMCBArray[msgNumber];

        if (((msgPtr -> uipMsgStatus) & (uip_MSG_LOCKED)) != 0) 
        { 
            return (uip_COM_LOCKED);
        } 
    }

    return (E_OK);
} /* end */

/***************************************************************************************/
/*                           End of File : uip_kernel_message.c                        */
/***************************************************************************************/
