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

📄 nufi.c

📁 嵌入式操作系统Nucleus Plus中使用的文件系统
💻 C
字号:
/* Include necessary Nucleus PLUS files.  */

#include  "nucleus.h"
#include  "pcdisk.h"

/* If printf facilities are available set this macro to 1 otherwise, use 0. */
#define PRINT_OUT           0



/* Define a pointer to the main memory pool used for the application and
   Nucleus FILE.  */
NU_MEMORY_POOL  System_Memory;


/* Define Application data structures.  */

#if (EBS_FLOPPY)
NU_TASK floppy_timer_task_CB;
#endif

NU_TASK         nuf_task_0_CB;
NU_TASK         nuf_task_1_CB;
NU_TASK         nuf_task_2_CB;
NU_TASK         display_task_CB;



/*  The following table maintains a mapping between Nucleus PLUS pointers
    and Nucleus RTX type Task IDs.  */
NU_TASK     *NUIP_PLUS_To_RTX[3];





/* Define prototypes for function references.  */
#if (EBS_FLOPPY)
/* If the floppy disk driver is installed it needs a special task to manage
   turning the floppy motors off */ 
void floppy_timer_task(UNSIGNED argc, VOID *argv);
#endif


void    nuf_task_0(UNSIGNED argc, VOID *argv);
void    nuf_task_1(UNSIGNED argc, VOID *argv);
void    nuf_task_2(UNSIGNED argc, VOID *argv);
void    display_task(UNSIGNED argc, VOID *argv);








/* Externally define the Nucleus FILE intialization routine to intialize the
   Nucleus PLUS components that it needs.  */
int NUFP_Initialize(void);

/* Define the Application_Initialize routine that determines the initial
   Nucleus PLUS application environment.  */

   
void    Application_Initialize(void *first_available_memory)
{

VOID           *pointer;
int             init_status;
int             status;

    /* Create a system memory pool that will be used to allocate task stacks,
       queue areas, etc.  */
    NU_Create_Memory_Pool(&System_Memory, "SYSMEM", 
                        first_available_memory, 200000, 50, NU_FIFO);






    /* Initialize the Nucleus PLUS environment for the File System. */
    init_status = NUFP_Initialize();

    /*  Make sure everything went OK.  This is very target dependent and
        needs to be changed for non-dos systems.  */
    if (init_status != NU_SUCCESS)
    {
        if (init_status == -1)
        {
#if (PRINT_OUT)
            printf("System Memory Allocation Failed\n\r");
#endif
        }
          if (init_status == -2)
        {
#if (PRINT_OUT)
            printf("Component Creation Failed\n\r");
#endif
        }
    }
     
    /* Create each task in the system.  */
    
#if (EBS_FLOPPY)
/* Create Floppy timer task. Highest priority. No timeslice or preemption.
   This task basically sleeps all the time waking only to shut off the
   floppy motor or reset the motor timer. */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 430, NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed allocating memory for floppy timer task\n\r");
#endif
    }
    status = NU_Create_Task(&floppy_timer_task_CB, "FLOPPY", floppy_timer_task, 0, NU_NULL,
                    pointer, 400, 3, 20, NU_NO_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed creating floppy task 0\n\r");
#endif
    }
#endif

    /* Create task 0.  */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 3000, NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed allocating memory for task 0\n\r");
#endif
    }
    status = NU_Create_Task(&nuf_task_0_CB, "TASK 0", nuf_task_0, 0, NU_NULL,
                    pointer, 3000, 10, 20, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed creating task 0\n\r");
#endif
    }

    /* Create task 1.  */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 3000, NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed allocating memory for task 1\n\r");
#endif
    }
    status = NU_Create_Task(&nuf_task_1_CB, "TASK 1", nuf_task_1, 0, NU_NULL,
                    pointer, 3000, 10, 20, NU_PREEMPT, NU_NO_START);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed creating task 1\n\r");
#endif
    }

    /* Create task 2.  */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 3000, NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed allocating memory for task 2\n\r");
#endif
    }
    status = NU_Create_Task(&nuf_task_2_CB, "TASK 2", nuf_task_2, 0, NU_NULL,
                    pointer, 3000, 10, 20, NU_PREEMPT, NU_NO_START);
    if (status != NU_SUCCESS)
    {
#if (PRINT_OUT)
        printf("Failed creating task 2\n\r");
#endif
    }


    /* Create display task.  */

    status = NU_Allocate_Memory(&System_Memory, &pointer, 3000, NU_NO_SUSPEND);

    status = NU_Create_Task(&display_task_CB, "DISPLAY", display_task, 0, NU_NULL,
                    pointer, 3000, 10, 20, NU_PREEMPT, NU_NO_START);



    /*  Set up the Task Pointer to Task ID conversion table.  */
    NUIP_PLUS_To_RTX[0] = &nuf_task_0_CB;
    NUIP_PLUS_To_RTX[1] = &nuf_task_1_CB;
    NUIP_PLUS_To_RTX[2] = &nuf_task_2_CB;


}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "NUIP_Current_Task_ID"      */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function replaces the Nucleus RTX equivalent by            */
/*      converting a Task Pointer to a Task ID.                         */
/*                                                                      */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      Neil F. Henderson           Accelerated Technology, Inc.        */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      DEMO.C                      Various Tasks                       */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      task_id                     The id of the task that represents  */
/*                                  the task pointer.                   */
/*                                                                      */
/************************************************************************/
signed int  NUIP_Current_Task_ID(void)
{
    NU_TASK     *current_task_ptr;
    signed int  rtx_id;

    /*  Intialize the rtx_id. */
    rtx_id = 0;

    /*  Get the Task Pointer to the current task. */
    current_task_ptr = NU_Current_Task_Pointer();

    /*  Search for the Task Pointer.  */
    for (rtx_id = 0; rtx_id < 5; rtx_id++)
    {
        /*  If we found the entry, then return the ID.  */
        if (NUIP_PLUS_To_RTX[rtx_id] == current_task_ptr)
            return(rtx_id);
    }

    /*  If we are here, there is no more room for additional tasks.  */
    return(-1);

}   /*  end of NUFP_Current_Task_ID.  */

⌨️ 快捷键说明

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