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

📄 flsystem.h

📁 M-System DOC(Disk on a Chip) Flash芯片映像读写工具, 可以进行二片Flash芯片的内容互相拷贝, 提高烧录程序的效率.
💻 H
字号:
/************************************************************************/
/*                                                                      */
/*              FAT-FTL Lite Software Development Kit                   */
/*              Copyright (C) M-Systems Ltd. 1995-2003               */
/*                                                                      */
/************************************************************************/

#ifndef FLSYSTEM_H
#define FLSYSTEM_H

#include "defines.h"
#include "flcustom.h"

/* #include <memory.h> */
/* #include <windows.h> */
/* #include <winbase.h> */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "exos.h"
#include "exhelper.h"

/* Naming convention for functions that uses non-default convention.
 *
 * In case the calling application uses a different convention then the one
 * used to compile TrueFFS you can use the NAMING_CONVENTION definition.
 * The NAMING_CONVENTION definition is added as a qualifier to all TrueFFS
 * exported API. A good example is a c++ application that uses TrueFFS,
 * which was compiled using standard C.If this is not the case simply leave
 * the NAMING_CONVENTION defined as empty macro.
 */
/* #pragma option -p */      /* Default pascal calling convention */
#define NAMING_CONVENTION cdecl


/* CPU target
 *
 * Use compiler switches or insert a #pragma here to select the CPU type
 * you are targeting.
 *
 * If the target is an Intel 80386 or above, also uncomment the CPU_i386
 * definition.
 */
#pragma option -3       /* Select 80386 CPU */
#define CPU_i386




/* NULL constant
 *
 * Some compilers require a different definition for the NULL pointer.
 */

/* #include <_null.h> */

/* Little-endian/big-endian
 *
 * If your machine uses the big-endian (Motorola) format, uncomment the
 * following line.
 *
 * This compilation flag makes sure that FAT and translation layer structures
 * will be written in little-endian (Intel) format for integers. It also
 * affects the way DiskOnChip 16 bits registers are analized.
 */

/* #define FL_BIG_ENDIAN */


/* Far pointers
 *
 * Specify here which pointers may be far, if any.
 * Far pointers are usually relevant only to 80x86 architectures.
 *
 * Specify FAR_LEVEL:
 *   0 - If using a flat memory model or having no far pointers.
 *   1 - If only the socket window may be far
 *   2 - If only the socket window and caller's read/write buffers
 *       may be far.
 *   3 - If socket window, caller's read/write buffers and the
 *       caller's I/O request packet may be far.
 */

#define FAR_LEVEL       2


/* Memory routines for RAM buffers
 *
 * The library routines memcpy, memset, and memcmp are standard for ANSI-C
 * compilers. However, there may be variations in which a #include defines
 * them, and variations such as the Borland's _fmemcpy, _fmemset, and _fmemcmp
 * routines also exist. To overcome such nuances, the TrueFFS code uses memory
 * handling macros called tffsRAMcpy, tffsRAMset, and tffsRAMcmp, with prototypes
 * identical to the standard memcpy, memset, memcmp. Provide the correct
 * #include directive, and incorporate C macros that define the tffsxxx
 * routines to the names of your library routines (or user-supplied routines
 * to manually code these routines).
 */

#if FAR_LEVEL > 0
#define tffsRAMcpy _fmemcpy
#define tffsRAMcmp _fmemcmp
#define tffsRAMset _fmemset
#else /* FAR_LEVEL > 0 */
#define tffsRAMcpy memcpy
#define tffsRAMcmp memcmp
#define tffsRAMset memset
#endif /* FAR_LEVEL > 0 */


/* Memory routines for DiskOnChip memory window
 *
 * TrueFFS uses similar memory routines for accesing the DiskOnChip memory
 * window. However since DiskOnChip window is not indentical to RAM buffers,
 * TrueFFS will use a diffrent version of the above macros:
 * (tffscpy, tffscmp, tffsset).
 *
 * Make sure this set of routines will be implemented using macros, allowing
 * TrueFFS to use the #ifdef directive.
 */

#define tffscpy tffsRAMcpy
#define tffscmp tffsRAMcmp
#define tffsset tffsRAMset



/* Pointer arithmetic
 *
 * The following macros define machine- and compiler-dependent macros for
 * handling pointers to physical window addresses. The definitions below are
 * for PC real-mode Borland-C.
 *
 * 'physicalToPointer' translates a physical flat address to a (far) pointer.
 * Note that if your processor uses virtual memory, the code should
 * map the physical address to virtual memory, and return a pointer to that
 * memory (the size parameter tells how much memory should be mapped).
 *
 * 'addToFarPointer' increments to a pointer and returns a new
 * pointer. The increment may be as large as your window size. The code
 * below assumes that the increment may be larger than 64 KB and so performs
 * huge pointer arithmetic.
 */

#if FAR_LEVEL > 0
#include <dos.h>

#define physicalToPointer(physical,size,drive)          \
	MK_FP( ((int)((physical) >> 4)) , ((int) (physical) & 0xF) )

#define addToFarPointer(base,increment)         \
	MK_FP((FP_SEG(base) +                    \
		((unsigned short) ((FP_OFF(base) + (increment)) >> 16) << 12)), \
	      (FP_OFF(base) + (int) (increment)))

#define pointerToPhysical(ptr)                  \
	(((unsigned long) FP_SEG(ptr) << 4) + FP_OFF(ptr))

#define freePointer(ptr,size) 1

#else /* FAR_LEVEL > 0 */

#define physicalToPointer(physical,size,drive) pfn_Map_Memory(physical,size)

#define pointerToPhysical(ptr)  ((unsigned long)(ptr))

#define addToFarPointer(base,increment)         \
	((void *) ((unsigned char *) (base) + (increment)))

#define freePointer(ptr,size) 1

#endif  /* #if FAR_LEVEL > 0 */


/*
 * Signed/unsigned char
 *
 * It is assumed that 'char' is signed. If this is not your compiler
 * default, use compiler switches, or insert a #pragma here to define this.
 *
 */




/* Mutex type
 *
 * If you intend to access the TrueFFS API in a multi-tasking environment,
 * you may need to implement some resource management and mutual-exclusion
 * of TrueFFS with mutex & semaphore services that are available to you. In
 * this case, define here the Mutex type you will use, and provide your own
 * implementation of the Mutex functions in flcustom.c
 *
 * By default, a Mutex is defined as a simple counter, and the Mutex
 * functions in flcustom.c implement locking and unlocking by incrementing
 * and decrementing the counter. This will work well on all single-tasking
 * environments, as well as on many multi-tasking environments.
 */

typedef int FLMutex;


/* Memory allocation
 *
 * The translation layers (e.g. FTL, NFTL, INFTL, SAFTL) need to allocate
 * memory to handle the Flash media. The required size depends on the media
 * being handled.
 *
 * You may choose to use the standard 'malloc' and 'free' to handle such
 * memory allocations, provide your own equivalent routines, or you may
 * choose not to define any memory allocation routine. In this case, the
 * memory will be allocated statically at compile-time on the assumption of
 * the largest media configuration you need to support. This is the simplest
 * choice, but may cause your RAM requirements to be larger than you
 * actually need.
 *
 * If you define routines other than malloc & free, they should have the
 * same parameters and return types as malloc & free. You should either code
 * these routines in flcustom.c or include them when you link your application.
 */

#include <stdlib.h>

#define FL_MALLOC    malloc
#define FL_FREE(a)   free((void *)a)


/* Debug mode
 *
 * Customize the various TrueFFS debug print macros, to suite your application needs.
 */

#include <stdio.h>
/* #define ACTIVE_DEBUG_ZONE flCurrentDebugZone */

/*
 * The type of printed massages and the way they will be printed can
 * be customized using the 6 macros bellow:
 */

/*************************************/
/* TrueFFS 6.0 debug print mechanism */
/*************************************/
unsigned char GetPrintLevel(void);

#define DBG_PRINT_FLOW(zone,str)      if((GetPrintLevel() & 1)&&(zone&(ACTIVE_DEBUG_ZONE))) ExPrint(str)
#define DBG_PRINT_ERR(zone,str)       if((GetPrintLevel() & 2)&&(zone&(ACTIVE_DEBUG_ZONE))) ExPrint(str)
#define DBG_PRINT_WRN(zone,str)       if((GetPrintLevel() & 4)&&(zone&(ACTIVE_DEBUG_ZONE))) ExPrint(str)
#define DBG_PRINT_FLOW_PRM(zone,str)  if((GetPrintLevel() & 8)&&(zone&(ACTIVE_DEBUG_ZONE))) ExPrint str
#define DBG_PRINT_ERR_PRM(zone,str)   if((GetPrintLevel() & 16)&&(zone&(ACTIVE_DEBUG_ZONE))) ExPrint str
#define DBG_PRINT_WRN_PRM(zone,str)   if((GetPrintLevel() & 32)&&(zone&(ACTIVE_DEBUG_ZONE))) ExPrint str

/*
 * First IOCTL function number
 *
 * When using TrueFFS' IOCTL functions you have to define the code of the first
 * TrueFFS IOCTL function (after that the functions get consecutive increasing numbers).
 * This number should be out of the range of the standard IOCTL codes used by your
 * operating system.
 *
 */

#ifdef IOCTL_INTERFACE
#define FL_IOCTL_START  0
#endif


/* Default calling convention
 *
 * C compilers usually use the C calling convention to routines (cdecl), but
 * often can also use the pascal calling convention, which is somewhat more
 * economical in code size. Some compilers also have specialized calling
 * conventions which may be suitable. Use compiler switches or insert a
 * #pragma here to select your favorite calling convention.
 */






/* System clean up routine
 *
 * This routine will be called every time TrueFFS exist.
 * The implementation is found in flsystem.c
 */

extern void flSysfunExit(void);

#define FL_SYS_FUNC_RELEASE flSysfunExit()


/* Control over the priority of the TrueFFS thread
 *
 * Some of TrueFFS time is spend on polling the flash ready\busy signal.
 * TrueFFS supplies a verity of ways to utilize this time, one of which is
 * to inform the OS that TrueFFS priority can be lowered for the time being.
 */

#define FL_LowerPriorityThread(flashPtr)
#define FL_RaisePriorityThread(flashPtr)


/*
 * Yielding the CPU
 *
 * TrueFFS utilizes the routine flSleep to yield the CPU while
 * waiting for time consuming operations like a flash erase.
 * If the routine is not implemented, then uncomment the define below.
 */

#define DO_NOT_YIELD_CPU


/*
 * Uncomment the FL_NO_INIT_MMU_PAGES definition for:
 *
 * In order to skip initialization of first and last byte of the given buffer.
 * When the user buffer resides on separated memory pages the read
 * operation may cause a page fault. Some CPU's return from a page
 * fault (after loading the new page) and reread the bytes that caused
 * the page fault from the new loaded page. In order to prevent such a
 * case the first and last bytes of the buffer are written.
 *
 */

/* #define FL_NO_INIT_MMU_PAGES */


/* Remove runtime controll over memory access routines
 *
 * When defined , TrueFFS will use your own macros , for accessing the DiskOnChip memory window
 * This implementation will provide better performance, at the expence of automatic detection
 * and ease of integration.
 *
 * Refer to Trueffs manual for more infromation.
 */

/* #define FL_NO_USE_FUNC */


/* Improoving performance by using native code.
 *
 * You can improove the way TrueFFS utilizes 32bit (or larger) native variables
 * by uncommenting the defintion bellow.
 */

/* #define FL_ASSUME_NATIVE_IS_32BITS */


/* Removing backward compatibility basic type definitions.
 *
 * TrueFFS 5.x used the byte, word, dword, Sbyte, Sword and Sdword basic types.
 * Since these names are used by several major OSs, such as Windows and
 * VxWorks, it was decided to rename these types with less general names
 * (See the FLxxx types below). As many TrueFFS-based applications already
 * use these types, TrueFFS still automatically defines them. If these
 * definitions cause your compiler to report redefinition errors, simple
 * define FL_DISABLE_OLD_TRUEFFS_TYPES and TrueFFS will automatically remove
 * the definition.

/* #define FL_DISABLE_OLD_TRUEFFS_TYPES */


/* Optionally you can define TrueFFS basic types:
 *
 * FLByte, FLWord, FLDword, FLSByte, FLSWord, FLSDword,
 */


/* Optionally you can Define I/O memory access macros for accessing the
 * DiskOnChip registers ( only needed if the device is not memory mapped)
 *
 * FLWRITE_IO_BYTE        , FLREAD_IO_BYTE
 * FLWRITE_IO_WORD        , FLREAD_IO_WORD
 * FLWRITE_IO_DWORD       , FLREAD_IO_DWORD
 * TFFSCPY_FROM_IO_8_BITS , TFFSCPY_FROM_IO_16_BITS
 * TFFSCPY_TO_IO_8_BITS   , TFFSCPY_TO_IO_16_BITS
 * TFFSSET_IO_8_BITS      , TFFSSET_IO_16_BITS
 */


#endif /* FLSYSTEM_H */

⌨️ 快捷键说明

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