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

📄 filedemo.c

📁 nucleus file NUCLEUS的文件系统源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
/* @@@@@@@@@@@@@@@@@@@@ UART.C VERSION @@@@@@@@@@@@@@@@@@@@@@@@@@ */
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */

/* Include necessary Nucleus PLUS files.  */
/* #include  "nucleus.h" */
#include  "file\pcdisk.h"

/* Uncomment this #define to allow for demo data to stream out */
/* of the second serial port.  See display_task below for      */
/* baud rate and port settings.                                */
#define NU_SERIAL    1 
 
#ifdef NU_SERIAL
//#include "plus\urt_extr.h"
//#include "plus\urt_defs.h"
extern void Convert_Number(char *,UNSIGNED);
void    display_task(UNSIGNED argc, VOID *argv);
NU_TASK   Display_Task; 
//UART_INIT       uart_init;
#endif

/* Debug */
/*#define  USE_SERIAL */
#ifdef USE_SERIAL
#define PRINTF(X)   UART_Put_Str(X)
#else
#define PRINTF(X)
#endif

/* Function prototypes  */
void    task_0(UNSIGNED argc, VOID *argv);
void    task_1(UNSIGNED argc, VOID *argv);
void    task_2(UNSIGNED argc, VOID *argv);
void    task_3(UNSIGNED argc, VOID *argv);
void    task_4(UNSIGNED argc, VOID *argv);
void    bail_out(void);
STATUS format_ramdisk(INT16 driveno);

/* Declare Nucleus Tasks */
NU_TASK         Task_0;
NU_TASK         Task_1;
NU_TASK         Task_2;
NU_TASK         Task_3;
NU_TASK         Task_4;

/* Define tasks numbers for array access */
#define TASK0         0
#define TASK1         1
#define TASK2         2
#define TASK3         3
#define TASK4         4
#define NUM_TASKS     5

/* Define events for tasks */
#define TASK0_EVENT  1
#define TASK1_EVENT  2
#define TASK2_EVENT  4
#define TASK3_EVENT  8
#define TASK4_EVENT  16

/* Declarations for global counters.  */
int     Files_Created[NUM_TASKS];
int     Files_Renamed[NUM_TASKS];
int     Files_Read[NUM_TASKS];
int     Files_Deleted[NUM_TASKS];
int     Directories_Created[NUM_TASKS];
int     Directories_Deleted[NUM_TASKS];
int     Errors[NUM_TASKS];

/* Declarations for other globals */
CHAR outbuf[512];      /* Buffer for writing file data */ 
CHAR inbuf[512];       /* Buffer for reading in file data */  

/* Declare memory pool */
NU_MEMORY_POOL  System_Memory;

/* Declare event group */
NU_EVENT_GROUP  Event_Group_0;

/* These #defines are used in the demo tasks */
#define         DEMO_DRIVE    0       /* 0   Used for ramdisk demo */
#define         DEMO_DISK     "A:"    /* A:  Used for ramdisk demo */  
#define         DEMO_ROOT     "A:\\"  /* A:\ Used for ramdisk demo */    

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "Application_Initialize"         */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function sets up the Nucleus PLUS application environment. */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                                                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Allocate_Memory                  Allocate memory for task.   */
/*      NU_Create_Event_Group               Create an Event Group.      */
/*      NU_Create_Memory_Pool               Create system memory pool.  */
/*      NU_Create_Task                      Create a task.              */
/*      pc_memfill                          Fill memory locations.      */
/*                                                                      */
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void    Application_Initialize(void *first_available_memory)
{
STATUS  status;                 /* Return value from funtion calls */
VOID  *pointer;                 /* Pointer to memory */


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

    /* Create each task in the system.  */

    /* Create task 0.  This task will setup the Ram Disk */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 0x2000, NU_NO_SUSPEND); /*TS v */
    status = NU_Create_Task(&Task_0, "TASK 0", task_0, 0, NU_NULL, pointer, 0x2000, 1, 2,
													NU_NO_PREEMPT, NU_START);

    /* Create task 1 */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 0x2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NU_NULL, pointer, 0x2000, 1, 2,
													NU_PREEMPT, NU_NO_START);

    /* Create task 2 */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 0x2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_2, "TASK 2", task_2, 0, NU_NULL, pointer, 0x2000, 1, 2,
													NU_PREEMPT, NU_NO_START);

    /* Create task 3 */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 0x2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_3, "TASK 3", task_3, 0, NU_NULL, pointer, 0x2000, 1, 2,
													NU_PREEMPT, NU_NO_START);

    /* Create task 4 */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 0x2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_4, "TASK 4", task_4, 0, NU_NULL, pointer, 0x2000, 1, 2,
													NU_PREEMPT, NU_NO_START);


#ifdef NU_SERIAL
    /* Create task - Display Task */
    status = NU_Allocate_Memory(&System_Memory, &pointer, 0x1000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Display_Task, "DISPLAY TASK", display_task, 0, NU_NULL, pointer, 0x1000, 1, 2,
													NU_PREEMPT, NU_NO_START);

#endif

    /* Create event flag group */
    NU_Create_Event_Group(&Event_Group_0, "EVGROUP0"); 

    
	/* Initialize global write buffer */
    pc_memfill(outbuf, 512, 'A');
    


}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "task_0"                         */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This task is responsible for initializing the file system       */
/*      and then starting the other tasks in the demonstration.         */
/*      It then begins creating files in the root directory and         */
/*      writing 512 bytes to each file.  Then it deletes all files      */
/*      it created in the root directory using a wildcard.  The         */
/*      creating, writing, and deleting are repeated in an endless      */
/*      loop.                                                           */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                              Started upon creation.      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      bail_out                            Error reporting routine.    */
/*      NU_Become_File_User                 Registers this task as a    */
/*                                          user of the file system.    */
/*      NU_Close                            Close a file.               */
/*      NU_Delete                           Delete a file(s).           */
/*      NU_Open                             Open a file for access.     */
/*      NU_Resume_Task                      Resume suspended task.      */
/*      NU_Set_Default_Drive                Select default drive.       */
/*      NU_Write                            Write data to a file.       */
/*                                          on the disk.                */
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void   task_0(UNSIGNED argc, VOID *argv)
{
int fd;                         /* File descriptor for file access */ 
int ii;                         /* Local loop variable */
STATUS  status;                 /* Return value from funtion calls */
int task_id = TASK0;            /* Task number for this task */ 
CHAR fname[] = "T0F0FILE.TXT";  /* Base file name */


    /* Access argc and argv just to avoid compilation warnings.  */
    status = (STATUS)argc + (STATUS)argv;

    
    /* Initialize the File System            */
	/* NOTE: This task does NOT need to call */
	/* NU_Become_File_User or NU_Open_Disk   */
	/* since this is done in file_init()     */
	status = file_init();
    if (status != NU_SUCCESS)
    {
        PRINTF("File Initialization error!");
        bail_out();
    }

	/* Activate the other tasks now that the file system is initialized */
	NU_Resume_Task(&Task_1);
 	NU_Resume_Task(&Task_2);
	NU_Resume_Task(&Task_3);
	NU_Resume_Task(&Task_4);
#ifdef NU_SERIAL
	NU_Resume_Task(&Display_Task);
#endif


    /* Set the default drive to A: */
    status = NU_Set_Default_Drive(DEMO_DRIVE);

    /* Set current directory to root */
    status = NU_Set_Current_Dir (DEMO_ROOT);

    /* do forever loop */
    while (1)
	{
		/* Create 10 files in the root directory */
		for ( ii = 0; ii < 10; ii++)
		{
			/* Make unique file name for each */
            fname[3] = 0x30 + ii;  /* ascii numbers 0-4 */

			/* Create File */
			fd = NU_Open(fname,(PO_TEXT|PO_RDWR|PO_CREAT|PO_TRUNC),
				               (PS_IWRITE | PS_IREAD));

            /* Write 512 bytes to the new file */
            status = NU_Write(fd, outbuf, 512);

			/* Check status for number of bytes written */
			if (status == 512)
			{
                Files_Created[task_id]++;  /* Increment Task0 Files Created */
			}
			else
			{
			    Errors[task_id]++;  /* Log error */
			}

			/* Close file */
 	        status = NU_Close(fd);

		}  /* End For (ii ) */

		/* Delete all files */
		status = NU_Delete("*.TXT");

		/* Check status for success */
		if( status == NU_SUCCESS )
		{
            Files_Deleted[task_id] += 10;  /* Increment Task0 Files Deleted */
		}
		else

⌨️ 快捷键说明

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