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

📄 ramdemo.c

📁 嵌入式操作系统Nucleus Plus中使用的文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:
    fmt.mediadesc =      (UTINY)  0xFD;

    fmt.secptrk     =    (UCOUNT) (UCOUNT) NRAMDISKBLOCKS/4;
    fmt.numhead     =    (UCOUNT) 2;
    fmt.numcyl     =     (UCOUNT) 2;
    fmt.physical_drive_no =   0;
    fmt.binary_volume_label = 0x12345678L;
    my_strcpy(fmt.text_volume_label, "VOLUMELABE"); 


    /*  This function actually opens the disk and must be done before any
        other activities are performed.  */
    if (pc_bdevsw[driveno].open_proc(driveno))
    {

        /*  The device opened successfully, so format it.  */
#if (RAMDISK)
        if (NU_Format(driveno, &fmt )) 
        {
            ret_val = YES;        
        }
#else        
        ret_val = YES;
#endif
    }

    /*  Let other tasks run again.  */
    NU_Change_Preemption(preempt_status);

    return(ret_val);
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "nuf_task_0"                     */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This task is responsible for initializing the file system       */
/*      and then starting the other tasks in the demonstration.         */
/*      It then begins scanning the disk and collecting statistics      */
/*      on the number of files and directories scanned.  Those          */
/*      statistics are then reported by display_task.                   */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                              Started upon creation.      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      pc_memry_init                       File system memory init.    */
/*      NU_Become_File_User                 Registers this task as a    */
/*                                          user of the file system.    */
/*      bail_out                            Error reporting routine.    */
/*      RAM_disk_init                      Disk initialization routine.*/
/*      NU_Resume_Task                      Starts other tasks.         */
/*      NU_Open_Disk                        Prepares disk for use.      */
/*      looping                             Checks for user input.      */
/*      scan_drive                          Performs various activities */
/*                                          on the disk.                */
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void nuf_task_0()
{
static char scan_stack[30][13];
static char path[EMAXPATH];


	/* if using puts, zero our counter */
#if (USE_PUTS)	
	gPutsCounter = 0;
#endif
    /* Initialize memory. This only needs to be done once system wide */
    if (!pc_memory_init())
        bail_out(MEM_FAILURE);

	/* init the pcmcia if necessary */
#if (INIT_PCMCIA)
	init_pcmcia();
#endif

    /* Each task must register as a Nucleus user */
	if (!NU_Become_File_User())
        bail_out(CANT_REGISTER);

    /* Initialize and format the disk. */
    if (RAM_disk_init())
    {

        /*  Start the other tasks.  */
        NU_Resume_Task(NUIP_PLUS_To_RTX[TASK1]);
        NU_Resume_Task(NUIP_PLUS_To_RTX[TASK2]);
        NU_Resume_Task(&display_task_CB);
    }

    /*  Prepare the RAM disk for use by this task.  */
    if (!NU_Open_Disk(__RAM))
        bail_out(CANT_OPEN_DISK);

    /*  Indicate that the task is running.  Used to indicate whether the
        task needs to be stopped by the user (see looping below).  */
    task_is_running[TASK0] = YES;

    /*  Check for user input. */
    while(looping())
    {
        /*  Read directories, etc.  */
        scan_drive(0, __RAM, scan_stack, path);
    }
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "nuf_task_1"                     */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine removes all files from subdirectory A, deletes     */
/*      subdirectory A, creates 20 files, renames the file, and repeats.*/
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                              Started by nuf_task_0.      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Become_File_User                 Registers this task as a    */
/*                                          user of the file system.    */
/*      NU_Open_Disk                        Prepares disk for use.      */
/*      pc_set_default_drive                Sets RAM as default drive. */
/*      looping                             Checks for user input.      */
/*      bail_out                            Error reporting routine.    */
/*      write_test                          Performs writes to the disk.*/
/*      NU_Relinquish                       Gives control to other tasks*/
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void nuf_task_1()
{


    /* Each task must register as a Nucleus user */
	if (!NU_Become_File_User())
        bail_out(CANT_REGISTER);

    /* Prepare the disk for use by this task. */
    if (!NU_Open_Disk(__RAM))
        bail_out(CANT_OPEN_DISK);

    /* Indicate that this task is running, used by looping to determine if
       user wants to stop the task.  */
    task_is_running[TASK1] = YES;

    /* Set the default drive to the RAM disk. */
    if (!pc_set_default_drive(__RAM))
        bail_out(CANT_SEL_DEF_DSK);

    /* Check for user input.  */
    while(looping())
    {
        /* Peform the write test to SUBDIR1 (created by nuf_task_0). */
        write_test( 1, "SUBDIR1");

        /* Let other tasks run.  */
        NU_Relinquish();
    }
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "nuf_task_2"                     */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine removes all files from subdirectory B, deletes     */
/*      subdirectory B, creates 20 files, renames the file, and repeats.*/
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      nuf_task_0                          Initiator task.             */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Become_File_User                 Registers this task as a    */
/*                                          user of the file system.    */
/*      NU_Open_Disk                        Prepares disk for use.      */
/*      pc_set_default_drive                Sets RAM as default drive. */
/*      looping                             Checks for user input.      */
/*      bail_out                            Error reporting routine.    */
/*      write_test                          Performs writes to the disk.*/
/*      NU_Relinquish                       Gives control to other tasks*/
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void nuf_task_2()
{

    /* Each task must register as a Nucleus user */
	if (!NU_Become_File_User())
        bail_out(CANT_REGISTER);

    /* Prepare the disk for use by this task. */
    if (!NU_Open_Disk(__RAM))
        bail_out(CANT_OPEN_DISK);

    /* Indicate that this task is running, used by looping to determine if
       user wants to stop the task.  */
    task_is_running[TASK2] = YES;

    /* Set the default drive to drive_id */
    if (!pc_set_default_drive(__RAM))
        bail_out(CANT_SEL_DEF_DSK);

    /* Check for user input.  */
    while(looping())
    {
        /* Peform the write test to SUBDIR2 (created by nuf_task_0). */
        write_test( 2, "SUBDIR2");

        /* Let other tasks run.  */
        NU_Relinquish();
    }
}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "write_test"                     */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine accepts a directory name and deletes all of the    */
/*      files in the directory, deletes the directory, creates the      */
/*      directory again, fills the directory with 20 files, and then    */
/*      renames the files.                                              */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      nuf_task_1                          Writer task 1.              */
/*      nuf_task_2                          Writer task 2.              */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      pc_memfill                          Fills memory with a char.   */
/*      NU_Is_Dir                           Determines if the entry is  */
/*                                          a directory.                */
/*      NU_Set_Current_Dir                  Indicates current directory.*/
/*      NU_Get_First                        Gets the first file in a    */
/*                                          directory.                  */
/*      mkname                              Constructs a valid file name*/
/*      NU_Get_Next                         Gets the next file in a     */
/*                                          directory started by        */
/*                                          NU_Get_First.               */
/*      NU_Done                             Cleans up after searching   */

⌨️ 快捷键说明

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