fmdhal.h

来自「该BSP是基于PXA270+WINCE的BSP」· C头文件 代码 · 共 226 行

H
226
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#ifndef  __FMDHAL_H__
#define __FMDHAL_H__
#include "tyax.h"

//#include <pkfuncs.h>
#include <bsp.h>

#if __cplusplus
extern "C" {
#endif


#define IOCTL_FMDHAL_FLASH_CMD CTL_CODE(FILE_DEVICE_HAL,4067, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define FMDHAL_BusConfigx16 0x0001
#define FMDHAL_BusConfigx32 0x0002

#define FMDHAL_CMD_INIT         0x1
#define FMDHAL_CMD_ERASE        0x2
#define FMDHAL_CMD_WRITE        0x4
#define FMDHAL_CMD_LOCK_BLOCK   0x8
#define FMDHAL_CMD_UNLOCK_BLOCK 0x10

    //#define FMDHAL_MAX_RELOCATED_AREA 2048
#define FMDHAL_MAX_RELOCATED_AREA (8192)

    typedef struct FMDHAL_RelocFuncStruct_t
    {
        BOOL(*CFIQuery)(void);
        BOOL(*WriteCommand)(volatile ULONG* pBaseAddress, ULONG uCmd, ULONG uConfig);
        BOOL(*ReadStatus)(volatile ULONG* pBaseAddress, ULONG uMask, ULONG uConfig);
        BOOL(*IsInterruptPending)(void);
        BOOL(*DoWrite)(void);
        BOOL(*DoErase)(void);
        BOOL(*DoBlockUnlock)(void);
        BOOL(*DoBlockLock)(void);
        BOOL(*FMDHAL_ASMInterruptEnable)();
        BOOL(*FMDHAL_ASMInterruptDisable)();

    } FMDHAL_RelocFuncStruct_t;

#define FMDHAL_ConfigStruct FMD_FLASH_INFO
    //typedef struct FMD_FLASH_INFO FMDHAL_ConfigStruct;

    typedef struct FMDHAL_CmdStruct
    {
        ULONG uCmd;
        ULONG uOffset;
        void *pTargetAddress;
        void *pSrcAddress;
        union
        {
            ULONG uBytesWritten;
            ULONG uBytesRead;
        };
        union
        {
            void *pReadBufferPtr;
            void *pWriteBufferPtr;
        };
        union
        {
            ULONG uBytesToWrite;
            ULONG uBytesToRead;
            ULONG ulNumBlocks;
        };

        UINT uRetVal;

    } FMDHAL_CmdStruct;
    BOOL FMDHAL_IOControl(ULONG uCmd, void *pOutVar, void *pInVar);
    BOOL FMDHAL_Init(volatile ULONG* pBaseAddress, ULONG uFlashLength);
    BOOL FMDHAL_DoWrite(void);
    BOOL FMDHAL_DoErase(void);
    BOOL FMDHAL_DoLockBlock(void);
    BOOL FMDHAL_DoUnlockBlock(void);
    BOOL FMDHAL_WriteCommand(volatile ULONG* pBaseAddress, ULONG uCmd, ULONG uConfig);
    BOOL FMDHAL_ReadStatus(volatile ULONG* pBaseAddress, ULONG uMask, ULONG uConfig);
    BOOL FMDHAL_IsInterruptPending(void);
    BOOL FMDHAL_CFIQuery(void);
    BOOL FMDHAL_RelocateCode(ULONG *pSourceAddress, ULONG *pDestinationAddress, ULONG uFunctionSize);
    //extern BOOLEAN SetBlockLock(DWORD blockID, ULONG NumBlocks, BOOL bLock);

    // Pulled in from fmdhal_asm.s
    extern BOOL FMDHAL_ASMInterruptEnable();
    extern BOOL FMDHAL_ASMInterruptDisable();
    extern BOOL FMDHAL_ASM_CallFuncWithNewStack();

    //status
#define FMDHAL_FLASH_STATUS_READY       0x0080
#define FMDHAL_FLASH_ERASE_SUSPENDED    0x0040

    //cmds
#define FMDHAL_FLASH_READ_ARRAY         0x00FF
#define FMDHAL_FLASH_ERASE_CMD          0x0020
#define FMDHAL_FLASH_ERASE_RESUME       0x00D0
#define FMDHAL_FLASH_ERASE_CONFIRM      0x00D0
#define FMDHAL_FLASH_WRITE_BUFFER_CMD   0x00E8
#define FMDHAL_FLASH_WRITE_CONFIRM      0x00D0
#define FMDHAL_FLASH_CLEAR_STATUS       0x5050
#define FMDHAL_FLASH_READ_STATUS        0x7070
#define FMDHAL_FLASH_ERASE_SUSPEND      0x00B0
#define FMDHAL_FLASH_WRITE_WORD         0x0040
#define FMDHAL_FLASH_UNLOCK_BLOCK_SETUP 0x0060
#define FMDHAL_FLASH_UNLOCK_BLOCK_CONFIRM 0x00D0
#define FMDHAL_FLASH_LOCK_BLOCK_SETUP   0x0060
#define FMDHAL_FLASH_LOCK_BLOCK_CONFIRM 0x0001

    /*
     * error status
     */
#define   IntelSCSStatusVoltageError      0x00000008
#define   IntelSCSStatusCmdSequenceError  0x00000030
#define   IntelSCSStatusBlockLockError    0x00000002
#define   IntelSCSStatusProgramError      0x00000010
#define   IntelSCSStatusEraseError        0x00000020
#define   IntelSCSStatusLockError         0x00000010
#define   IntelSCSStatusUnlockError       0x00000020

#if 0
    /* lock commands */
#define   IntelSCSCmdBlockReadIDCodes     0x00000090L
#define   IntelSCSCmdBlockLockSetup       0x00000060L
#define   IntelSCSCmdBlockLockConfirm     0x00000001L
#define   IntelSCSCmdBlockUnlockSetup     0x00000060L
#define   IntelSCSCmdBlockUnlockConfirm   0x000000D0L

    /*
     * status
     */
#define   IntelSCSStatusReady             0x00000080
#define   IntelSCSStatusBlockLocked       0x00000001
#define   IntelSCSSStatusEraseSuspend     0x00000040
#define   IntelSCSSStatusProgramSuspend   0x00000004
    // Commands.
#define READ_QUERY_CMD          0x0098
#define READ_IDENT_CMD          0x0090
#define READ_ARRAY_CMD          0x00FF
#define BYTEWORD_PROGRAM_CMD    0x0040
#define CLEAR_STATUS_CMD        0x5050
#define READ_STATUS_CMD         0x7070
#define BLOCK_LOCK_CMD          0x0060
#define BLOCK_PROCEED_CMD       0x00D0
#define BLOCK_SETLOCK_CMD       0x0001
#define BLOCK_ERASE_CMD         0x0020
#define BUFFER_WRITE_CMD        0x00E8

    // Status.
#define STATUS_ERROR_LOCKED     0x0002
#define STATUS_ERROR_VOLTAGE   0x0008
#define STATUS_ERROR_SR4           0x0010   // Can mean either erase or set lock bit error
#define STATUS_ERROR_SR5           0x0020   // Can mean either program or clear lock bit error
#define STATUS_ERROR_COMMAND 0x0030
#define STATUS_READY_MASK       0x0080

#endif
    /*************************************************************************
     *
     * mFMDHAL_ReadFlash
     *
     * DESCRIPTION:
     *    Reads a bus width's worth of data from flash.
     *
     * PARAMETERS:
     *    config - [IN] A configuration bit field specifying bus configuration
     *    addr - [IN] The physical address, of type ULONG, in flash to read
     *       the data from.
     *
     * RETURNS:
     *    The data, type casted to a 32-bit value (ULONG).
     *
     * ASSUMPTIONS:
     *    The bus to flash is either 16-bit or 32-bit.  The address specified
     *    is bus-width aligned.
     *
     ************************************************************************/
#if 0
#define mFMDHAL_ReadFlash(config, addr) \
   (( config & FMDHAL_BusConfigx16) ? \
      ((UINT32) *((volatile UINT16 *)(addr))) : \
      ((UINT32) *((volatile UINT32 *)(addr))))
#endif
#define mFMDHAL_ReadFlash(config, addr)        ((UINT32) (*(volatile UINT32 *)addr))


    /*************************************************************************
     *
     * CreateCommand
     *
     * DESCRIPTION:
     *    Creates a command (or mask) based on the flash bus-width and
     *    interleave.
     *
     * PARAMETERS:
     *    config - [IN] Configuration of flash being addressed
     *    cmd    - [IN] Command (or mask) to send to the flash.
     *
     * RETURNS:
     *    A command that can be sent to on the bus to flash that will address
     *    every flash device across that bus.
     *
     ************************************************************************/
#if 0
#define mFMDHAL_CmdCreate(config, cmd) \
   ((config & FMDHAL_BusConfigx16) ? \
      ((UINT32) (cmd)) : ((UINT32) (((cmd) << 16) | (cmd))))

#endif
#define mFMDHAL_CmdCreate(config, cmd) ((UINT32) ((((UINT16)cmd) << 16) | (UINT16)cmd))

#if __cplusplus
}
#endif

#endif /* __FMDHAL_H__ */

⌨️ 快捷键说明

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