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

📄 kev7a400_cf_driver.h

📁 CF读写驱动
💻 H
字号:
/**********************************************************************
 * $Workfile:   KEV7A400_cf_driver.h  $
 * $Revision:   1.1  $
 * $Author:   WellsK  $
 * $Date:   Aug 30 2002 13:23:40  $
 *
 * Project: Compact Flash interface driver
 *
 * Description:
 *  This package contains a set of standard functions used to retrieve
 *  and stored data (in sectors) on the Compact Flash (CF) card.
 *  Functions included are:
 *          cfif_init - Initialize CF interface driver
 *          cfif_shutdown - Shutdown CF interface driver
 *          cfif_is_card_inserted - Is the card inserted
 *          cfif_is_card_ready - Is the card ready for commands
 *          cfif_is_card_busy - Is the card busy (processing a command)
 *          cfif_set_sector - Set the cylinder, head, and sector (with
 *                            just a sector number)
 *          cfif_start_sector_read - Starts the read of a single or 
 *                                   block of sectors
 *          cfif_start_sector_write - Writes a block of data to a 
 *                                    single or block of sectors
 *          cfif_read_data - Read a block of data from the CF card
 *          cfif_write_data - Write a block of data to the CF card
 *          
 *
 * Notes:
 *  These functions are intended to be binded with a higher level
 *  driver for interfacing and controlling the structures on the
 *  card.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/CHIPS/archives/LH7A400/Compact Flash/Drivers/KEV7A400_cf_driver.h-arc  $
 * 
 *    Rev 1.1   Aug 30 2002 13:23:40   WellsK
 * Corrected C/C++ wrapper.
 * 
 *    Rev 1.0   Aug 22 2002 15:59:42   MaysR
 * Initial revision.
 * 
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 * COPYRIGHT (C) 2002 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *     CAMAS, WA
 *********************************************************************/
#ifndef KEV7A400_CF_DRIVER_H
#define KEV7A400_CF_DRIVER_H

#ifdef __cplusplus
#if __cplusplus
extern "C"
{
#endif // __cplusplus
#endif // __cplusplus

#include "sma_types.h"
#include "LH7A400_map.h"

typedef struct
{
   volatile UNS_16      data;
            UNS_16      unused_1;
   volatile UNS_16      error_features;
            UNS_16      unused_2;
   volatile UNS_16      sector_count;
            UNS_16      unused_3;
   volatile UNS_16      sector_no;
            UNS_16      unused_4;
   volatile UNS_16      cyl_low;
            UNS_16      unused_5;
   volatile UNS_16      cyl_hi;
            UNS_16      unused_6;
   volatile UNS_16      sel_card;
            UNS_16      unused_7;
   volatile UNS_16      status_command;
} CF_STATUS_REG;

typedef struct
{
            UNS_16      unused[10];
   volatile UNS_16      altStatus;
            UNS_16      unused_1;
   volatile UNS_16      driveAddress;
} CF_ALT_STATUS_REG;

#define CF_BUSY    _BIT(7)      // Status register: busy
#define CF_RDY     _BIT(6)      // Status register: Command ready
#define CF_DWF     _BIT(5)      // Status register: Write fault
#define CF_DSC     _BIT(4)      // Status register: CF card ready
#define CF_DRQ     _BIT(3)      // Status register: data request
#define CF_CORR    _BIT(2)      // Status register: Correctable error
#define CF_IDX     _BIT(1)      // Status register: reserved, always 0
#define CF_ERR     _BIT(0)      // Status register: error

#define CF_BBK     _BIT(7)      // Error register: Bad block
#define CF_UNC     _BIT(6)      // Error register: Uncorrectable error
#define CF_IDNF    _BIT(4)      // Error register: sector not found
#define CF_ABORT   _BIT(2)      // Error register: Abort error
#define CF_AMNF    _BIT(1)      // Error register: General error

#define CF_LBA     _BIT(4)      // Head register: LBA mode select
#define CF_RST     _BIT(2)      // Device control register: reset
#define CF_IEN     _BIT(1)      // Interrupt enable

// Status word check mask used in detection scheme
#define CF_DETECT_MASK (CF_BUSY | CF_RDY | CF_DSC | CF_IDX)

// Expected value from masked status in CF detection scheme
#define CF_DETECT_VALUE (CF_RDY | CF_DSC)

// CF-ATA commands used in this implementation
#define CFC_IDENT  0xEC         // Identify drive command
#define CFC_R_SECT 0x20         // Read sector command
#define CFC_W_SECT 0x30         // Write sector command
#define CFC_E_SECT 0xC0         // Erase sector command

#define CF_BASE_ADDRESS     SMC_CS6_BASE 
#define CF_ALT_ADDRESS      SMC_CS7_BASE 
#define CF_STAT             ((CF_STATUS_REG *)(CF_BASE_ADDRESS))
#define CF_ALT              ((CF_ALT_STATUS_REG *)(CF_ALT_ADDRESS))


//**********************************************************************
// Card functions
//**********************************************************************

INT_32 cfif_init(void);
void cfif_shutdown(void);
INT_32 cfif_is_card_inserted(void);
INT_32 cfif_is_card_ready (void);
INT_32 cfif_is_card_busy (void);
void cfif_set_sector (UNS_32 sectorno);
void cfif_send_command (UNS_32 command);
void cfif_start_sector_read (void);
void cfif_start_sector_write (void);
INT_32 cfif_read_data (void *data, INT_32 bytes);
INT_32 cfif_write_data (void *data, INT_32 bytes);
INT_32 cfif_erase_sector (INT_32 sectorno);

#ifdef __cplusplus
}
#endif
#endif // KEV7A400_CF_DRIVER_H

⌨️ 快捷键说明

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