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

📄 lowlvl.c

📁 CF卡读卡程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
; ***********************************************************************
; *             Intel Corporation                                       *
; *             Copyright (C) Intel Corporation 1994-97                 *
; *             All Rights Reserved.                                    *
; ***********************************************************************
; ***********************************************************************
;    INTEL OEM SOFTWARE LICENSE AGREEMENT
;
; BY USING THIS SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE TERMS OF THIS 
; AGREEMENT.  DO NOT USE THE SOFTWARE UNTIL YOU HAVE CAREFULLY READ AND AGREED 
; TO THE FOLLOWING TERMS AND CONDITIONS.  IF YOU DO NOT AGREE TO THE TERMS OF
; THIS AGREEMENT, PROMPTLY RETURN THE SOFTWARE PACKAGE AND ANY ACCOMPANYING
; ITEMS. YOU MUST BE AN ORIGINAL EQUIPMENT MANUFACTURER ("OEM") SYSTEM
; DEVELOPER TO ACQUIRE ANY RIGHTS IN THE SOFTWARE UNDER THIS LICENSE AGREEMENT.
;
; LICENSE: Intel Corporation ("Intel") grants you the non-exclusive and
; royalty-free right to use the enclosed software program ("Software") in
; source code form on the terms set forth below.  You will not use, copy,
; modify, rent, sell or transfer the Software or any portion thereof, except
; as provided in this Agreement.
;
; OEM System Developers may:
;
; 1. Copy the Software for support, backup or archival purposes;
; 2. Install or distribute the Software in object code form only;
; 3. Modify and/or use Software source code that Intel directly ships to you
;    as an OEM;
; 4. Allow authorized contractors ("Subcontractors") engaged by You for the
;    sole purpose of product development work to have access to the Software
;    solely for that purpose.  Subcontractors do NOT acquire any of the OEM
;    rights to the Software provided in this Agreement;
; 5. Install, use, modify, distribute, and/or make or have made derivative
;    works based on the Software ("Derivatives") subject to the terms and
;    conditions in this Agreement.
;
; RESTRICTIONS:
; YOU WILL NOT:
;
; 1.  Copy, disclose or distribute the Software, in whole or in part, except 
;     as provided for in this Agreement;
; 2.  Remove or modify the "Compatibility" module, if any,  in the Software or
;     in any Derivative work,
; 3.  Decompile or reverse engineer any Software  delivered in object code form.
; 
; TRANSFER:  Except as provided above, you may not transfer or disclose the
; Software to another party .
;
; OWNERSHIP AND COPYRIGHT OF SOFTWARE: Title to the Software and all copies
; thereof remain with Intel.  The Software is copyrighted and is protected by
; United States and international copyright laws.  You will not remove the
; copyright notice from the Software.  You agree to prevent any unauthorized
; copying of the Software.
;
; DERIVATIVE WORK: You will not be required to provide Intel with a copy of the
; source or object code for any Derivatives created by You.   You are authorized
; to use, market, sell, and/or distribute Derivatives, other than any source
; code for the Software, at your own risk and expense. Title to Derivatives,
; other than the portion of the Derivative consisting of any of the Software,
; shall remain with you.
;
; CONFIDENTIALITY: You will maintain the confidentiality of the source code for
; the Software with at least the same degree of care that you use to protect
; your own confidential and proprietary information, but with no less than a
; reasonable degree under the circumstances. Disclosure will only be made to
; Your employees on a need-to-know basis. Subject to the licenses granted
; hereunder, You agree to maintain the Software source code and all other
; proprietary information relating to the Software in confidence and shall not
; disclose to others any such source code or other Intel proprietary information
; relating to the Software. Any Subcontractors to whom you disclose the source
; code for the Software must sign a written confidentiality agreement which
; contains terms regarding the Software no less restrictive than those set forth
; in this Agreement.
;
; DUAL MEDIA SOFTWARE:  If the Software package contains multiple media, you
; may only use the medium appropriate for your system.
; 
; WARRANTY:  The Software is provided "AS IS". Intel warrants that the media on
; which the Software is furnished will be free from defects in material and
; workmanship for a period of one (1) year from the date of purchase.  Upon
; return of such defective media, Intel's entire liability and your exclusive
; remedy shall be the replacement of the Software.
; 
; THE ABOVE WARRANTIES ARE THE ONLY WARRANTIES OF ANY KIND GIVEN BY INTEL UNDER
; THIS AGREEMENT. INTEL SPECIFICALLY DISCLAIMS ANY OTHER WARRANTIES, EXPRESS OR
; IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT OR FITNESS
; FOR ANY PARTICULAR PURPOSE.
;
; LIMITATION OF LIABILITY:    NEITHER INTEL NOR ITS VENDORS OR AGENTS SHALL BE
; LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA, INTERRUPTION OF
; BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF
; ANY KIND WHETHER UNDER THIS AGREEMENT OR OTHERWISE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGES.
;
; TERMINATION OF THIS LICENSE:  Intel reserves the right to conduct or have
; conducted audits to verify your compliance with this Agreement.  Intel may
; terminate this Agreement at any time if you are in breach of any of its terms
; and conditions.  Upon termination, you will immediately destroy, and certify
; in writing the destruction of, the Software or return all copies of the
; Software and documentation to Intel.
;
; U.S. GOVERNMENT RESTRICTED RIGHTS:  The Software and documentation were
; developed at private expense and are provided with "RESTRICTED RIGHTS".
; Use, duplication or disclosure by the Government is subject to restrictions
; as set forth in FAR52.227-14 and DFAR252.227-7013 et seq. or its successor.
;
; EXPORT LAWS:  You agree that the distribution and export/re-export of the
; Software is in compliance with the laws, regulations, orders or other
; restrictions of the U.S. Export Administration Regulations.
;
; APPLICABLE LAW:  This Agreement is governed by the laws of the State of
; Delaware and the United States, including patent and copyright laws.  Any
; claim arising out of this Agreement will be brought in Santa Clara County,
; California.
;*************************************************************************
*/


#include "type.h"
#include "lowlvl.h"

/* Based on Ver70 of LOWLVL.ASM */

/* This pragma hides warning messages about suspicious pointer conversions */
/* that Borland picks up. The warnings do not affect the operation of the  */
/* program on x86 processors whatsoever. The problem arises because of the */
/* definition of the fucntion pointer conflicting with the compatibility of*/
/* TechnologyTable in TABLE.C. If this code is moved to another platform   */
/* that has different architechture, this method may not work as well, and */
/* might need to be changed. Since function pointers are not allowed in a  */
/* struct, then we used regular pointers instead, and it reassigns a bit   */
/* odd as far as the compilier is concerned.                               */
#if SEGMENTED
#pragma warn -sus

/* needed if using PCIC interface */
extern WORD FTLTablePtr;
#endif

#define WINDOWED     TRUE
#define SMARTSLIDE   TRUE
#define ERR_NOT_FOUND 0xFFFF
/* Flash-specific definitions.                                             */
/* These encompass all the commands and status checks the program makes.   */
#define FlashCommandReadID      0x90
#define FlashCommandRead        0xFF
#define FlashCommandErase       0x20
#define FlashCommandConfirm     0xD0
#define FlashCommandClear       0x50
#define FlashCommandWrite       0x40
#define FlashCommandLoadPB      0xE0
#define FlashCommandPBWrite     0x0C
#define FlashCommandStatus      0x70
#define FlashCommandSuspend     0xB0
#define FlashCommandResume      0xD0
#define FlashCommandReadESR     0x71
#define FlashCommandQueryCFI    0x98
#define FlashCommandSCSErase    0x28
#define FlashCommandSCSWrite    0xE8
#define FlashStatusReady        0x80
#define FlashStatusSuspended    0x40
#define FlashStatusError        0x3E
#define FlashStatusBlockError   0x3F

#if CFI_OPTIONAL
#define FlashCommandLock        0x60
#define FlashCommandUnlock      0x60
#define FlashCommandLockConfirm 0x01
#define FlashCommandChipErase 0x30
#define FlashCommandConfigureStatus 0xB8
#endif

#define FlashCommandPrefix1     0xAA
#define FlashCommandPrefix2     0x55

#define LETTERS_QQ 0x5151
#define LETTERS_RR 0x5252
#define LETTERS_YY 0x5959
#if SWAP
#define LETTER_Q 0x5100
#define LETTER_R 0x5200
#define LETTER_Y 0x5900
#else
#define LETTER_Q 0x0051
#define LETTER_R 0x0052
#define LETTER_Y 0x0059
#endif
#if SWAP
   #define SCSREADY 0x8000
   #define SCSWRTMSK 0x1A00
   #define SCSERSMSK 0x2A00
   #define SCSCFGMSK 0x3A00
   #define SCSLCKMSK 0x1A00
#else /*!SWAP */
   #define SCSREADY 0x0080
   #define SCSWRTMSK 0x001A
   #define SCSERSMSK 0x002A
   #define SCSCFGMSK 0x003A
   #define SCSLCKMSK 0x001A
#endif

/*
  Hardware implementation options, as indicated in the variable
  HWImplement.  This is a CFI/SCS option.
*/
#define Implementx8     0x01
#define Implementx16    0x02
#define Implementx8x16  0x04
#define ImplementPaired 0x08
#define Yes             0x01
#define No              0x00

/*
  Global internal variables
*/

/* These are pointers to the functions correct for the technology */
WORD (* FlashRead)(DWORD, DWORD, BYTE_PTR);
WORD (* FlashWrite)(DWORD, DWORD, BYTE_PTR);
WORD (* FlashErase)(DWORD);

#if ERASE_BACKGROUND
WORD (*FlashStatus)(DWORD);
WORD (*FlashSuspend)(void);
WORD (*FlashResume)(void);
#endif

#if CFI_OPTIONAL
WORD (*FlashLock)(DWORD);
WORD (*FlashUnlock)(void);
WORD (*FlashChipErase)(void);
WORD (*FlashConfigureStatus)(void);
#endif

/* These are SCS/CFI variables, mostly */
DWORD CFIDeviceSize;

#if !CFI_ERASE_REGIONS
WORD  CFIBlksPerDev;
#else
WORD  CFIBlksPerDev[MAX_ERASE_REGIONS];
#endif

BYTE  HWImplement;
BYTE  EraseQueue;
WORD  WriteQueueSize;
WORD  WriteQueueCount;
WORD  WriteQueueMask;

#if CFI_OPTIONAL
BYTE  ChipErase=0;
BYTE  LockUnlock = 0;
BYTE  ProgramSuspend = 0;
BYTE  BlockLockStatusSupported = 0;
BYTE  BlockValidStatusSupported = 0;

/* values are in millivolts or uSec */
WORD MinVcc;
WORD MaxVcc;
WORD OptVcc;
WORD MinVpp;
WORD MaxVpp;
WORD OptVpp;
WORD TypBytePgmTime;
WORD TypBufferPgmTime;
WORD TypBlockEraseTime;
WORD TypChipEraseTime;
WORD MaxBytePgmTime;
WORD MaxBufferPgmTime;
WORD MaxBlockEraseTime;
WORD MaxChipEraseTime;

DWORD ChipEraseLoops = ERASE_TIME_LIMIT;

#endif

DWORD PgmLoops = PROGRAM_TIME_LIMIT;
DWORD EraseLoops = ERASE_TIME_LIMIT;

extern MEDIA_INFO       Info;
extern DWORD erase_loop_ctr;
extern void ResetSocket(void);
extern void WindowSetup(void);

/*
  Local Function Prototypes
*/
WORD Intel8MbErase(DWORD);
WORD Intel8MbWrite(DWORD, DWORD, BYTE_PTR);
WORD Intel8MbRead(DWORD, DWORD, BYTE_PTR);
#if ERASE_BACKGROUND
WORD Intel8MbStatus(DWORD);
WORD Intel8MbSuspend(void);
WORD Intel8MbResume(void);
#endif

WORD IntelSCSErase(DWORD);
WORD IntelSCSWrite(DWORD, DWORD, BYTE_PTR);
WORD IntelSCSRead(DWORD, DWORD, BYTE_PTR);
#if ERASE_BACKGROUND
WORD IntelSCSStatus(DWORD);
WORD IntelSCSSuspend(void);
WORD IntelSCSResume(void);
#endif

#if CFI_OPTIONAL
WORD IntelSCSLock(DWORD CardAddress);
WORD IntelSCSUnlock(void);
WORD IntelSCSChipErase(void);
WORD IntelSCSConfigureStatus(BYTE Mode);
#endif

#if FALCON
WORD Intel16MbWrite(DWORD, DWORD, BYTE_PTR);
#endif
#if SRAM_MEDIA
WORD SRAMErase(DWORD);
WORD SRAMWrite(DWORD, DWORD, BYTE_PTR);
DWORD RAMSize(WORD);            /* Finds out size of SRAM cards */
#endif
WORD WriteProtectWrite(DWORD,DWORD,BYTE_PTR);
WORD WriteProtectErase(DWORD);
WORD WriteProtectSusRes(void);
WORD SRAMROMRead(DWORD, DWORD, BYTE_PTR);
WORD QueryCFI(MEDIA_INFO *);    /* Queries CFI for info */

extern DEVICE_TABLE FlashTechnologyTable[];
extern CFI_TABLE CFITable[];
BYTE Offset;

#define INTEL_SCS_RESUME (*(FULL_WORD_PTR)MC_ADDR = FlashCommandResume*0x101)

#define WIND_NUM_MSK (MC_WIND_MSK ^ 0xFFFFFFFF)

#if !SMARTSLIDE
DWORD CurrentAddress = 0;  /* The Last Known Position of the Memory Window */
#endif

/* If SMARTSLIDE is defined as TRUE above, it creates the least amount of  */
/* code, and is simplest for the LOWLVL.C file. With it on, the mem window */
/* flip checks to see if the window has moved, which is fastest.           */
#if !SMARTSLIDE
   #define PreLowSlideWindow(Add2)                                         \
   {                                                                       \
      if ((Add2 & WIND_NUM_MSK) != CurrentAddress)                         \
      {CurrentAddress = (Add2 & WIND_NUM_MSK); SlideMemoryWindow(Add2);}   \
   }
#else
   #define PreLowSlideWindow(Add2) SlideMemoryWindow(Add2);
#endif

/* Define is SlideMemoryWindow is used. (None if no windowing)             */
#if WINDOWED
   #define LowSlideWindow(Add1) PreLowSlideWindow(Add1)
#else
   #define LowSlideWindow(Add1)
#endif

/* Define the pointer assignment method. Currently, it assumes that the    */
/* pointer is a DWORD, and writes the value of the base address (MC_ADDR), */
/* adding on the desired address for the card address. In non-windowed,    */
/* non-segmented architectures, this is simply a matter of adding the two  */
/* and assigning this value directly to the pointer. In windowed systems,  */
/* we also have to take into account the window size. In this case the     */
/* memory window that starts at MC_ADDR has a granularity defined by       */
/* MC_WIND_MSK, which we AND to the card address to generate the window    */
/* offset.                                                                 */
#if WINDOWED
   #define PointerAssignment(Pointer, Address) Pointer = (FULL_WORD_PTR)((DWORD)MC_ADDR + (Address & MC_WIND_MSK));
#else
   #if SEGMENTED
      #error Segmented architechtures with no Windowing are not supported. Read Comments.
   #else
      #define PointerAssignment(Pointer, Address) Pointer = (FULL_WORD_PTR)(MC_ADDR + Address);
   #endif
#endif

/* These two functions are available to increment and decrement the        */
/* pointer location by a certain number of BYTES. Usual inrementing and    */
/* decrementing will be done (Pointer++, etc) that will move the pointer   */
/* by the granularity of the pointer (a DWORD, maybe), but in some cases   */
/* It is neccesary to move the pointer by less or more, so in that case    */
/* these functions will be used. They do not currently take into account   */
/* any segment issues, although that could be added.                       */
#define PointerAddition(Pointer, Bytes)     Pointer = (FULL_WORD_PTR)((DWORD)Pointer + Bytes)
#define PointerSubtraction(Pointer, Bytes)  Pointer = (FULL_WORD_PTR)((DWORD)Pointer - Bytes)

⌨️ 快捷键说明

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