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

📄 em.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "EM_Check_Events"           */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function checks the supplied event flag group, relative    */
/*      to the supplied operation, with the event flag group of the     */
/*      selected ID.  This routine returns a NU_SUCCES if the event     */
/*      request is currently satisfied.  Otherwise, the routine returns */
/*      a NU_EVENTS_NOT_PRESENT.                                        */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that set event flags                           */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      event_group_id                      Event group identification  */
/*      event_operation                     How to apply the events     */
/*      event_flags                         New event flags             */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                                                  */
/*                                                                      */
/************************************************************************/
signed int EM_Check_Events(signed int event_group_id,
            signed int event_operation, unsigned int event_flags,
            unsigned int *actual)
{

struct EM_EVENT_CONTROL_STRUCT  
                  *ECB_ptr;                 /* Pointer to ECB entry     */
unsigned int       compare;                 /* Event compare field      */
signed int         status;                  /* Status of request        */
    
    /* Point to the event group control block.  */
    ECB_ptr =  &EM_ECB_List[event_group_id];
    
    /* Initialize status to a false.  */    
    status =  NU_EVENTS_NOT_PRESENT;
    
    /* Put the actual events of this group into a place for the caller.  */
    *actual =  ECB_ptr -> em_event_flags;

    /* Check the new event flags against this group.  */
    if ((event_operation == NU_EVENT_AND) ||
        (event_operation == NU_EVENT_AND_CONSUME))
    {
    
        /* Need all of the bits in the request set in the event group
           to return a true.  */
        compare =  ECB_ptr -> em_event_flags & event_flags;
            
        /* If compare is equal to the value supplied, return a true.  */
        if (compare == event_flags)
        {    
            /* Return success.  */
            status =  NU_SUCCESS;

            /* Determine if the request specifies a consume.  */
            if (event_operation == NU_EVENT_AND_CONSUME)
                
                /* Consume the bits used by this request.  */
                ECB_ptr -> em_event_flags =  ECB_ptr -> em_event_flags &
                                                        ~event_flags;
        }
    }
    else
    {
        
        /* Need just one of the bits in the request to return a true.  */
        compare =  ECB_ptr -> em_event_flags & event_flags;
            
        /* If compare has any bits set, at least one of the bits in the
           request is set.  */
        if (compare)
        {            
            /* Set the status to success.  */
            status =  NU_SUCCESS;

            /* Determine if the request specifies a consume.  */
            if (event_operation == NU_EVENT_OR_CONSUME)
                
                /* Consume the bits used by this request.  */
                ECB_ptr -> em_event_flags =  ECB_ptr -> em_event_flags &
                                                        ~event_flags;
        }
    }
            

    /* Return the status to the caller.  */
    return(status);
}                                           /* end of EM_Check_Events   */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "EM_Wait_For_Events"        */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function suspends the task that needs to wait for          */
/*      system events.                                                  */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that wait for events                           */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      EM_Place_On_List                    Place a suspend block on lst*/
/*      EM_Remove_From_List                 Remove suspend block        */
/*      SKP_Suspend_Task                    Suspend the task            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      task_id                             Task identification         */
/*      event_group_id                      Event group identification  */
/*      operation                           Event operation on events   */
/*      events                              Actual events requested     */
/*      actual                              Place to return the actual  */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                                                  */
/*                                                                      */
/************************************************************************/
signed int EM_Wait_For_Events(signed int task_id, signed int event_group_id,
            signed int operation, unsigned int events,
            unsigned int *actual)
{

struct EM_SUSPENSION_STRUCT  
                   suspend_block;           /* Suspension control block */
signed int         status;                  /* Status of request        */
    
    /* Initialize the status variable as NU_EVENT_TIMEOUT.  */
    status =  NU_EVENT_TIMEOUT;

    /* Build the suspension block.  */
    suspend_block.em_task_id =      task_id;
    suspend_block.em_return_addr =  &status;
    suspend_block.em_operation =    operation;
    suspend_block.em_flags =        events;
    suspend_block.em_flags_value =  actual;
    suspend_block.em_next_susp =    NU_NULL;
    suspend_block.em_prev_susp =    NU_NULL;
    
    /* Place the suspend block on the suspension for associated
       event group.  */
    EM_Place_On_List(&(EM_ECB_List[event_group_id].em_wait_head),
                      &(EM_ECB_List[event_group_id].em_wait_tail),
                      &suspend_block);
    
    /* Suspend the task.  */
    SKP_Suspend_Task(task_id, NU_EVENT_SUSPEND);
    
    /* Check to see if a timeout occurred.  In this case the suspend block
       is still part of the list, remove it!  */
    if (status == NU_EVENT_TIMEOUT)
    {

        /* Put the actual events back into the destination.  */
        *suspend_block.em_flags_value =  
                  EM_ECB_List[event_group_id].em_event_flags;

        /* Remove the suspend block from the list.  */
        EM_Remove_From_List(&(EM_ECB_List[event_group_id].em_wait_head),
                             &(EM_ECB_List[event_group_id].em_wait_tail),
                             &suspend_block);
    }

    /* Return the status to the caller.  */
    return(status);
}                                           /* end of EM_Wait_For_Events */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "EM_Max_Event_Groups"       */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function returns the total number of system event groups.  */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that make event requests                       */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(EM_Total_Event_Groups)                                   */
/*                                                                      */
/************************************************************************/
signed int  EM_Max_Event_Groups()
{

    /* Return the number of event groups to the caller.  */
    return(EM_Total_Event_Groups);
}                                           /* end of EM_Max_Event_Groups */

⌨️ 快捷键说明

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