📄 ramdemo.c
字号:
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 */
/* a directory. */
/* looping Checks for user input. */
/* NU_Delete Delete a file. */
/* bail_out Error reporting routine. */
/* NU_Sleep Sleep for a number of ticks.*/
/* NU_Remove_Dir Delete a directory entry. */
/* NU_Make_Dir Make a directory entry. */
/* NU_Open Open a file. */
/* NU_Write Write a file. */
/* NU_Close Close a file. */
/* NU_Resume Resume a task. */
/* */
/* INPUTS */
/* */
/* task_id ID of the task running. */
/* dir_id Name of the directory */
/* */
/* OUTPUTS */
/* NONE */
/* */
/************************************************************************/
VOID write_test( int task_id, char *dir_id)
{
INT i;
char fname_1[14];
char fname_2[14];
DSTAT statobj;
BOOL more;
PCFD fd;
/* Something to write into the file */
pc_memfill(wr_buf, 512, 'A');
/* Delete the directory if it exists. */
if (NU_Is_Dir(dir_id))
{
/* Set the current working directory. */
if (!NU_Set_Current_Dir(dir_id))
bail_out(CANT_SET_WRK_DIR);
/* Get the first file in the current directory. */
if (NU_Get_First(&statobj, "*.*"))
{
/* Go through the entire directory and delete all of the
files in it. */
do {
/* Make sure that this is not a directory. */
if (!(statobj.fattribute & ADIRENT))
{
/* Get the name of this file. */
mkname(fname_1, &statobj);
/* Get next so the DROJ is no longer open */
more = NU_Get_Next(&statobj);
/* If there are no more files to process, close the
search. */
if (!more)
NU_Done(&statobj);
/* Check for input. */
while (looping())
{
/* Delete the file. */
if (NU_Delete(fname_1))
{
/* Indicate that the file was properly deleted
and get out of the while loop. */
RAM_Files_Deleted[task_id]++;
break;
}
/* If we were unable to delete the file because
of any reason other than someone else is using
it, then we will stop processing. */
else if (fs_user->p_errno != PEACCES)
bail_out(CANT_REM_FILE);
/* Wait to see if whoever was using the file gives it
up. */
else
NU_Sleep(5);
}
}
else
{
/* Get the next file in the list. */
more = NU_Get_Next(&statobj);
/* If there are no more files to get, clean up the
search. */
if (!more)
NU_Done(&statobj);
}
} while (more);
}
/* Set the current working directory to the root. */
if (!NU_Set_Current_Dir("\\"))
bail_out(CANT_SET_WRK_DIR);
/* Delete the directory. - Note it can fail if the scanner is
inside the directory. So we loop if EACCESS is the error */
while(looping())
{
/* Delete the directory. */
if (NU_Remove_Dir(dir_id))
{
/* Indicate that the directory has been deleted. */
RAM_Directories_Deleted[task_id]++;
break;
}
/* If we cannot delete the directory for any reason other than
another user is using it, then we will quit processing. */
else if (fs_user->p_errno != PEACCES)
bail_out(CANT_REM_DIR);
/* Wait for whoever is using the directory to release it. */
else
NU_Sleep(5);
}
}
/* Check for user input. */
looping();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -