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

📄 nu.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************************************************************/
/*                                                                      */
/*           Copyright 1990-1992 by Accelerated Technology              */
/*                                                                      */
/*  PROPRIETARY RIGHTS of Accelerated Technology are involved in the    */
/*  subject matter of this material.  All manufacturing, reproduction,  */
/*  use, and sales rights pertaining to this subject matter are         */
/*  governed by the license agreement.  The buyer or recipient of this  */
/*  package, implicitly accepts the terms of the license.               */
/*                                                                      */
/************************************************************************/

/************************************************************************/
/*                                                                      */
/*  FILE DESCRIPTION                                                    */
/*                                                                      */
/*  This file contains routines that interface between the nucleus      */
/*  executive and the application tasks.                                */
/*                                                                      */
/*  ROUTINES                                                            */
/*                                                                      */
/*      NU_Initialize                       Service routines initialize */
/*      NU_Retrieve_Item                    Retrieve an item from queue */
/*      NU_Send_Item                        Send an item to a queue     */
/*      NU_Retrieve_Item_Mult               Retrieve items from mult Qs */
/*      NU_Force_Item_In_Front              Force item to queue front   */
/*      NU_Sleep                            Sleep for a number of ticks */
/*      NU_Relinquish                       Relinquish task control     */
/*      NU_Start                            Start task that was stopped */
/*      NU_Stop                             Stop a ready task           */
/*      NU_Reset                            Reset a stopped task        */
/*      NU_Read_Time                        Read system time            */
/*      NU_Set_Time                         Set the system time         */
/*      NU_Change_Priority                  Change task's priority      */
/*      NU_Current_Task_ID                  Get the current task ID     */
/*      NU_Disable_Preemption               Disable task preemption     */
/*      NU_Enable_Preemption                Enable task preemption      */
/*      NU_Change_Time_Slice                Modify task time slice      */
/*      NU_Request_Resource                 Request a resource          */
/*      NU_Release_Resource                 Release a resource          */
/*      NU_Alloc_Partition                  Allocate a partition        */
/*      NU_Dealloc_Partition                Deallocate a partition      */
/*      NU_Available_Partitions             Number of free partitions   */
/*      NU_Alloc_Memory                     Allocate variable size mem  */
/*      NU_Dealloc_Memory                   Deallocate variable size mem*/
/*      NU_Available_Memory                 Amount of available memory  */
/*      NU_Control_Interrupts               Enable/Lockout interrupts   */
/*      NU_Retrieve_Queue_Status            Retrieve queue status       */
/*      NU_Retrieve_Resource_Status         Retrieve resource status    */
/*      NU_Retrieve_Task_Status             Retrieve task status        */
/*      NU_Set_Events                       Set events of an event group*/
/*      NU_Wait_For_Events                  Wait for events in event grp*/
/*      NU_Reset_Performance_Timer          Reset performance timer     */
/*      NU_Retrieve_Performance_Info        Retrieve performance timer  */
/*      NU_Start_Performance_Timer          Start a performance timer   */
/*      NU_Stop_Performance_Timer           Stop a performance timer    */
/*      NU_Retrieve_Next_History_Entry      Get the next history entry  */
/*      NU_Start_History_Saving             Initiate history saving     */
/*      NU_Stop_History_Saving              Stop history saving         */
/*                                                                      */
/*  NOTES                                                               */
/*                                                                      */
/*                                                                      */
/************************************************************************/

/* Define necessary include files.  */

#include   "nu_defs.h"           /* General constants        */
#include   "in_extr.h"           /* Alloc and error routines */
#include   "cl_extr.h"           /* Clock routine defs       */
#include   "qm_extr.h"           /* Queue routine defs       */
#include   "em_extr.h"           /* Event routine defs       */
#include   "rm_extr.h"           /* Resource routine defs    */
#include   "sk_extr.h"           /* Scheduler routine defs   */
#include   "fm_extr.h"           /* Fixed memory mgt defs    */
#include   "vm_extr.h"           /* Variable memory mgt defs */

#if defined(NU_ENABLE_TIMING) || defined(NU_ENABLE_HISTORY)

#include   "ds_extr.h"           /* Development system defs  */

#endif

/* Define global data structures to the initialization routines.  */

/* The variable "NU_Total_Queues" contains the total number of queues in
   the system.  */
   
signed int  NU_Total_Queues;


/* The signed variable "NU_Total_Tasks" contains the total number of
   system tasks.  */

signed int  NU_Total_Tasks;


/* The signed variable "NU_Total_Event_Groups" contains the total number of
   system event groups.  */
   
signed int  NU_Total_Event_Groups;


/* The signed variable "NU_Total_Resources" contains the total number of 
   system resources.  */
   
signed int  NU_Total_Resources;


/* The signed variable "NU_Total_Partitions" contains the total number of
   system partition IDs.  */

signed int  NU_Total_Partitions;


/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "NU_Initialize"             */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function sets up various variables that are required for   */
/*      the nucleus service routines.                                   */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      INP_Initialize                      High level initialization   */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      SKP_Maximum_Tasks                   Maximum number of tasks     */
/*      QM_Max_Queues                       Maximum number of queues    */
/*      RM_Max_Resources                    Maximum number of resources */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      NU_Total_Tasks                      Total number of tasks       */
/*      NU_Total_Queues                     Total number of queues      */
/*      NU_Total_Resources                  Total number of resources   */
/*                                                                      */
/************************************************************************/
void  NU_Initialize()

{

    /* Call "SKP_Maximum_Tasks" to get the maximum number of tasks.  */
    NU_Total_Tasks =  SKP_Maximum_Tasks();
    
    /* Call "QM_Max_Queues" to get the maximum number of queues.  */
    NU_Total_Queues =  QM_Max_Queues();

    /* Call "EM_Max_Event_Groups" to get the maximum number of event 
       groups.  */
    NU_Total_Event_Groups =  EM_Max_Event_Groups();

    /* Call "RM_Max_Resources" to get the maximum number of resources.  */
    NU_Total_Resources =  RM_Max_Resources();

    /* Call "FM_Max_Partitions" to get the maximum number of distinct 
       partition types.  */
    NU_Total_Partitions =  FM_Max_Partitions();
}                                           /* end of NU_Initialize     */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "NU_Retrieve_Item"          */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to retrieve an item from a queue.         */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Application Routines                                            */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      DS_Make_History_Entry               Make an history entry       */
/*      QM_Retrieve_Item                    Get an item from a queue    */
/*      CLP_Start_Timer                     Start timeout for wait      */
/*      CLP_Stop_Timer                      Stop timeout for wait       */
/*      QM_Wait_To_Retrieve                 Wait for an item            */
/*      IND_Set_Interrupt_Level             Disable/Enable Interrupts   */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      queue_id                            Queue to retrieve from      */
/*      destination_ptr                     Pointer to destination are  */
/*      wait_timeout                        How long to wait            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Queue and destination area                                      */
/*      return(status)                      Status of request           */
/*                                                                      */
/************************************************************************/
signed int  NU_Retrieve_Item(signed int queue_id,
             unsigned int *destination_ptr, signed int wait_timeout)
{

signed int         task_id;                 /* Current task's ID        */
int                interrupt_level;         /* Saved interrupt level    */
signed int         status;                  /* Return status            */

    /* Make an entry in the history table, if the conditional compilation
       flag is set.  */
    #ifdef  NU_ENABLE_HISTORY
    DS_Make_History_Entry(NU_HIST_NU_RETRIEVE_ITEM, 
                                            (unsigned int) queue_id, 
                                            (unsigned int) destination_ptr);
    #endif
        
    /* Lock out interrupts while checking.  */
    interrupt_level =  IND_Set_Interrupt_Level(NU_DISABLE_INTERRUPTS);
    
    /* Check for a valid queue entry.  */
    if ((queue_id >= 0) && (queue_id < NU_Total_Queues))
    {
    
        /* Call "QM_Retrieve_Item" to get an item from a queue.  */
        status =  QM_Retrieve_Item(queue_id, destination_ptr);
        
        /* Check to see if we have anything.  */
        if ((status == NU_QUEUE_EMPTY) && (wait_timeout != NU_NO_TIMEOUT))
        {
        
            /* Get the task_id.  */
            task_id =  SKP_Get_Task_ID();
        
            /* Check for a valid task ID.  */
            if (task_id != NU_SYSTEM)
            {
            

⌨️ 快捷键说明

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