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

📄 ramdemo.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 4 页
字号:
/*************************************************************************/
/*                                                                       */
/*            Copyright (c) 1998 Accelerated Technology, Inc.            */
/*                                                                       */
/* 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 recipient of this software implicitly  */
/* accepts the terms of the license.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME ramdemo.c                                 VERSION           */
/*                                                         1             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*           Demonstrates the use of Nucleus FILE with the RAM           */
/*           device driver.                                              */
/*                                                                       */
/* AUTHOR   -- Accelerated Technology                                    */
/* EDITED BY Neil Henderson                                              */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*     Neil Henderson     11-08-94                 Original version.     */
/*************************************************************************/
    
/*********************************************************************/
/*                                                                   */
/*  NON-PORTABLE EXTERNAL DEFINITIONS, REPLACE WITH TARGET SPECIFIC  */
/*                                                                   */
/*********************************************************************/
int  US_Is_Char(void);
int  US_fgetc(void);



/* Include necessary Nucleus definitions.  */
#include  "nucleus.h"

/* Other includes.  */
#include  "pcdisk.h"
#include  <stdlib.h>
#include  "stdio.h"
/* #include  <string.h>   */


/* If printf facilities are available set PRINT_OUT to 1 otherwise, use 0.
   If the ability to detect if a character is available for reading and if
   the character can be read, set INPUT_OK to 1, otherwise use 0. */
#define PRINT_OUT           0
#define INPUT_OK            0

/* Declare the RAM disk as the only disk.  This affects which FAT calculation
   is used.  Please see pcdisk.h for more information.  */
#define __RAM "A:"


/* Non fatal manifest constants used in conjunction with the following
   table.  */
#define     CANT_SELECT         0
#define     INVALID_DIR         1
#define     CANT_SET_DEF        2
#define     TOO_MANY_SUBS       3

/* Non fatal error strings.  */
char    RAM_NON_FATAL[4][32] = {
        "Can't select default disk",
        "Invalid Directory",
        "Can't set default directory",
        "Too many subdirs for this build"
};


/* Fatal manifest constants used in conjunction with the following table. */
#define     MEM_FAILURE         0
#define     CANT_REGISTER       1
#define     CANT_OPEN_DISK      2
#define     CANT_SEL_DEF_DSK    3
#define     CANT_SET_WRK_DIR    4
#define     CANT_REM_FILE       5
#define     CANT_REM_DIR        6
#define     CANT_CREAT_DIR      7
#define     CANT_OPEN_FILE      8
#define     CANT_WRITE_FILE     9
#define     CANT_REN_FILE       10

/* Fatal error strings.  */
char    RAM_FATAL[11][35] = {
        "Memory Failure",
        "Can't register as file system user",
        "Can't open Floppy",
        "Can't select default disk",
        "Can't Set working directory",
        "Can't remove file",
        "Can't remove directory",
        "Can't create directory",
        "Can't open file",
        "Can't write file",
        "Can't rename File"
};

/*  Declare the error arrays and counters. */
long    RAM_Errors[10];
long    RAM_Fatal_Errors[10];
long    RAM_Errors_Index;
long    RAM_Fatal_Errors_Index;

/*  Forward references.  */
void mkname(char *buffer, DSTAT *pstat);
BOOL scan_drive( int task_id, char *drive_id, char scan_stack[][13],
                 char *path);
int  error_log(int error_no);
void bail_out(int error_no);
BOOL looping();
void display_task(void);
VOID write_test( int task_id, char *dir_id);
int nu_strcmp(const char *s1, const char *s2);
char * nu_strcpy(char *s1, char *s2);


/*  External references.  */
signed  int     NUIP_Current_Task_ID(void);

/*  Externally define the table used for Task ID to Task Pointer.  */
IMPORT  NU_TASK     *NUIP_PLUS_To_RTX[5];
IMPORT  NU_TASK      display_task_CB;
IMPORT  PFILE_SYSTEM_USER fs_user;

/*  Manifest constants used to identify the task usage and reporting.  */
#define TASK0 0
#define TASK1 (TASK0 + 1)
#define TASK2 (TASK0 + 2)
#define HIGHEST_TASK TASK2
#define NUM_TASKS (HIGHEST_TASK + 1)

/*  Global data.  */
BOOL task_is_running[NUM_TASKS];
char wr_buf[512];

/*  Declarations for global counters.  */
int     RAM_Files_Created[NUM_TASKS];
int     RAM_Files_Renamed[NUM_TASKS];
int     RAM_Files_Deleted[NUM_TASKS];
int     RAM_Directories_Created[NUM_TASKS];
int     RAM_Directories_Deleted[NUM_TASKS];
int     RAM_Directories_Scanned[NUM_TASKS];
int     RAM_Files_Scanned[NUM_TASKS];

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "RAM_disk_init"                  */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine low level formats the disk, opens the disk for     */
/*      Nucleus FILE usage, and high level formats the disk.            */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      nuf_task_0                          Initiator task.             */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Change_Preemption                Changes task to non-preempt */
/*                                          during formatting and back  */
/*                                          to original state after.    */
/*      pc_bdevsw[].open_proc               Nucleus FILE open routine.  */
/*      NU_Format                           High level disk formatting. */
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
BOOL RAM_disk_init()
{
IMPORT _PC_BDEVSW pc_bdevsw[];
FMTPARMS fmt;
UCOUNT driveno;
BOOL ret_val;
OPTION      preempt_status;

    /*  Don't allow other tasks to start until we are done.  */
    preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);

    /*  Initialize return value.  */
    ret_val = NO;

    driveno = (UCOUNT) 0;        /* A: */

    /*  Build the format table.  This table is used by NU_Format to
        write the boot block, fat, and main directory to the disk.  */

    /*  The name in the boot block will be NUFILE to identify this disk
        as one formatted by Nucleus FILE.  */
    nu_strcpy(&fmt.oemname[0], "NUFILE");
    fmt.secpalloc =      (UTINY)  2;   /* must be a multiple of 2.  This
                                          number indicates the number of
                                          sectors (blocks) per cluster.
                                          This value is the minimum number
                                          of bytes that are written to or
                                          read from the disk at a time.  */
    fmt.secreserved =    (UCOUNT) 1;
    fmt.numfats     =    (UTINY)  1;   /* since redundant fats aren't used
                                          only have one fat.  */
    fmt.secpfat     =    (UCOUNT) 1;
    fmt.numroot     =    (UCOUNT) 16;
    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;
    nu_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 (NU_Format(driveno, &fmt ))
            ret_val = YES;
    }

    /*  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];


    /* Initialize memory. This only needs to be done once system wide */
    if (!pc_memory_init())
        bail_out(MEM_FAILURE);

    /* 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.  */

⌨️ 快捷键说明

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