📄 fileinit.c
字号:
/*******************************************************************/
/* */
/* File Initialization Module */
/* */
/* */
/* This module contains functions used to initialize the hardware */
/* in your system. It must be modified for your individual setup. */
/* The function file_init() must be called from a task to setup */
/* the file system before any other tasks attempt to use it. */
/* The task that calls file_init() will automatically be setup */
/* as a File User. */
/* */
/* NOTE: This module is linked in with File.lib. After you make */
/* changes, you must rebuild File.lib. */
/* */
/*******************************************************************/
/* Include necessary Nucleus PLUS files. */
#include "plus\nucleus.h"
#include "file\pcdisk.h"
/* These #defines are used for initialization */
#define RAM_DRIVE 0 /* 0 */
#define RAM_DISK "A:" /* A: */
#define NOR_DRIVE 1 /* 1 */
#define NOR_DISK "B:" /* B: */
#define MMC_DRIVE 2 /* 2 */
#define MMC_DISK "C:" /* C: */
#define NAND_DRIVE 3 /* 2 */
#define NAND_DISK "D:" /* C: */
#define HARD_DRIVE /* reserved */
#define HARD_DISK
/* Function prototypes */
#ifdef RAMDISK /* Defined in pcdisk.h */
STATUS setup_ramdisk(VOID);
#endif
#ifdef MMC
STATUS setup_mmcdisk(VOID);
STATUS pc_get_mmcparams(INT16 driveno, FMTPARMS * pfmt);
#endif
#ifdef NOR_FLASH
STATUS setup_norflash(VOID);
STATUS pc_get_norparams(INT16 driveno, FMTPARMS * pfmt);
#endif
#ifdef NAND_FLASH
STATUS setup_nandflash(VOID);
STATUS pc_get_nandparams(INT16 driveno, FMTPARMS * pfmt);
#endif
void DGB_Close_Disk(void){ FAL_Close_Disk(NAND_DRIVE);}
/************************************************************************/
/* */
/* FUNCTION "file_init" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is responsible for initializing the file system */
/* This module needs to be modified to reflect the actual */
/* hardware present in your system. */
/* */
/* ROUTINES CALLED */
/* */
/* NU_Become_File_User Registers this task as a */
/* user of the file system. */
/* setup_ramdisk Sets up the ramdisk */
/* setup_disk Sets up a hard disk. */
/* on the disk. */
/* */
/* INPUTS */
/* NONE. */
/* */
/* OUTPUTS */
/* status Status from NU_Open_Disk or */
/* Status from NU_Format */
/* */
/************************************************************************/
STATUS file_init(INT Default_Drive)
{
OPTION preempt_status;
STATUS status; /* Return value from funtion calls */
/* Disable time slice until ramdisk is set up */
preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);
/* Initialize memory. This only needs to be done once system wide */
if (!pc_memory_init())
{
return(NUF_INTERNAL);
}
status = NU_Become_File_User();
/* Each task must register as a File User user */
if (status != YES)
{
return (NUF_BAD_USER);
}
/* Set up the RAMDISK for use */
if(Default_Drive == RAMDISK)
{
status = setup_ramdisk();
if(status != NU_SUCCESS)
return status;
}
/* Set up the NOR FLASH hard disk for use */
if(Default_Drive == NOR_FLASH)
{
status = setup_norflash();
if(status != NU_SUCCESS)
return status;
}
/* Set up the MMC hard disk for use */
if(Default_Drive == MMC)
{
status = setup_mmcdisk();
if(status != NU_SUCCESS)
return status;
}
/* Set up the NAND FLASH hard disk for use */
if(Default_Drive == NAND_FLASH)
{
status = setup_nandflash();
if(status != NU_SUCCESS)
return status;
}
/* Set up the Default and Current(Root) hard disk for use */
if(Default_Drive == NOR_FLASH)
{
if(status == NU_SUCCESS)
status = NU_Set_Default_Drive(Default_Drive);
if(status == NU_SUCCESS)
status = NU_Set_Current_Dir(NOR_DISK);
}
/* Enable time slice */
NU_Change_Preemption(preempt_status);
return(status);
}
#ifdef RAMDISK
/**************************************************************************/
/* */
/* FUNCTION "setup_ramdisk" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This task will set up the format parameters and then */
/* call NU_Format() to format the ramdisk. */
/* */
/* AUTHOR */
/* Accelerated Technology */
/* CALLED FROM */
/* */
/* file_init */
/* */
/* ROUTINES CALLED */
/* */
/* NU_Format Formats the disk */
/* user of the file system. */
/* on the disk. */
/* */
/* INPUTS */
/* driveno The number of the */
/* drive to format */
/* OUTPUTS */
/* NU_SUCCESS If the filesystem disk was */
/* successfully initialized. */
/* NUF_BAD_USER Not a file user. */
/* NUF_BADDRIVE Invalid drive specified. */
/* NUF_NOT_OPENED The disk is not opened yet. */
/* NUF_FATCORE Fat cache table too small. */
/* NUF_BADPARM Invalid parameter specified. */
/* NUF_BADDISK Bad Disk. */
/* NUF_NO_PARTITION No partition in disk. */
/* NUF_NOFAT No FAT type in this */
/* partition. */
/* NUF_FMTCSIZE Too many clusters for this */
/* partition. */
/* NUF_FMTFSIZE File allocation table too */
/* small. */
/* NUF_FMTRSIZE Numroot must be an even */
/* multiple of 16. */
/* NUF_INVNAME Volume lable includes */
/* invalid character. */
/* NUF_NO_MEMORY Can't allocate internal */
/* buffer. */
/* NUF_NO_BLOCK No block buffer available. */
/* NUF_IO_ERROR Driver IO error. */
/* NUF_INTERNAL Nucleus FILE internal error. */
/* */
/**************************************************************************/
STATUS setup_ramdisk(VOID)
{
STATUS status;
FMTPARMS fmt;
/* Since the ramdisk is not yet formatted, this call will */
/* return an NUF_FORMAT error. This is normal operation. */
/* After the ramdisk is formatted, other calls to NU_Open_Disk */
/* will return an NU_SUCCES */
status = NU_Open_Disk(RAM_DISK); /* Open the ramdisk for use */
/* Setup Format parameters */
fmt.oemname[0] = 'A';
fmt.oemname[1] = 'S';
fmt.oemname[2] = 'I';
fmt.oemname[3] = 'C';
fmt.oemname[4] = 'f';
fmt.oemname[5] = 's';
fmt.oemname[6] = ' ';
fmt.oemname[7] = ' ';
fmt.oemname[8] = '\0';
fmt.secpalloc = (UINT8) 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 = (UINT16) 1;
fmt.numfats = (UINT8) 1;
/* since redundant fats aren't used
only have one fat. */
fmt.numroot = (UINT16) 64; /* number of files in root */
fmt.bytepsec = (UINT16) 512;
fmt.mediadesc = (UINT8) 0xFD;
fmt.partdisk = (UINT8)0;
/* No partition */
fmt.secptrk = (UINT32) NRAMDISKBLOCKS/4;
fmt.numhead = (UINT16) 2;
fmt.numcyl = (UINT16) 2;
fmt.physical_drive_no = 0;
fmt.binary_volume_label = 0x12345678L;
fmt.text_volume_label[0] = '\0'; /* 11 chars max */
/* The sector number of each erase operation. PESSIA (20041105) */
fmt.secperase = NUF_ERASESIZE_A;
/* Format the Ram Disk */
status = NU_Format(RAM_DRIVE, &fmt);
/* Return status from NU_Format() */
return(status);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -