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

📄 ide_x_hw.c

📁 at91rm9200硬盘的接口代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                            uC/FS
*
*             (c) Copyright 2001 - 2003, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

----------------------------------------------------------------------
File        : ide_X_hw.c
Purpose     : IDE hardware layer for EP7312
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
---------------------------END-OF-HEADER------------------------------
*/

/*********************************************************************
*
*             #include Section
*
**********************************************************************
*/
#include "AT91RM9200.h"
#include "lib_AT91RM9200.h"

#include "fs_port.h"
#include "fs_conf.h"

#if FS_USE_IDE_DRIVER

#include "ide_x_hw.h"

/*********************************************************************
*
*             #define Macros
*
**********************************************************************
*/

/* SFR definition of EP7312 */
#define __PBDR                  *(volatile unsigned char*)0x80000001
#define __PDDR                  *(volatile unsigned char*)0x80000003
#define __PBDDR                 *(volatile unsigned char*)0x80000041
#define __PDDDR                 *(volatile unsigned char*)0x80000043
#define __SYSCON1               *(volatile unsigned int*)0x80000100
#define __SYSFLG1               *(volatile unsigned int*)0x80000140
#define __MEMCFG2               *(volatile unsigned int*)0x800001C0
#define __INTSR1                *(volatile unsigned int*)0x80000240
#define __INTMR1                *(volatile unsigned int*)0x80000280
#define __TC1D                  *(volatile unsigned short*)0x80000300
#define __TC2D                  *(volatile unsigned short*)0x80000340
#define __UARTDR1               *(volatile unsigned short*)0x80000480
#define __UBRLCR1               *(volatile unsigned int*)0x800004C0
#define __TC1EOI                *(volatile unsigned int*)0x800006C0
#define __TC2EOI                *(volatile unsigned int*)0x80000700
#define __SYSFLG2               *(volatile unsigned int*)0x80001140
#define __INTMR2                *(volatile unsigned int*)0x80001280
#define __SYSCON3               *(volatile unsigned int*)0x80002200
#define __PLLW                  *(volatile unsigned int*)0x80002610

/* CSB238 IDE-Bus */
#define __IDE_DATA              *(volatile unsigned short*) 0x50000000
#define __IDE_FC                *(volatile unsigned char*)0x50000001
#define __IDE_SC                *(volatile unsigned char*)0x50000002
#define __IDE_SN                *(volatile unsigned char*)0x50000003
#define __IDE_CL                *(volatile unsigned char*)0x50000004
#define __IDE_CH                *(volatile unsigned char*)0x50000005
#define __IDE_DH                *(volatile unsigned char*)0x50000006
#define __IDE_CMD               *(volatile unsigned char*)0x50000007
#define __IDE_DC                *(volatile unsigned char*)0x5000000e
#define __IDE_PIO3              *(volatile unsigned char*)0x50010000


#define HW__DELAY400NS          FS_IDE_HW_X_GetAltStatus(Unit); FS_IDE_HW_X_GetAltStatus(Unit); \
                                FS_IDE_HW_X_GetAltStatus(Unit); FS_IDE_HW_X_GetAltStatus(Unit)


/*********************************************************************
*
*             Local Variables        
*
**********************************************************************
*/

static char _HW_DevicePresent[2];


/*********************************************************************
*
*             Global functions section
*
**********************************************************************
*/

/*********************************************************************
*
*             FS_IDE_HW_X_BusyLedOn
*
  Description:
  FS driver hardware layer function. Turn on busy led.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  None.
*/

void FS_IDE_HW_X_BusyLedOn(FS_u32 Unit) {
     //struct _AT91S_EBI *PS_ebi = (struct _AT91S_EBI *) (AT91C_BASE_EBI) ;
    AT91F_PIO_CfgPeriph(AT91C_BASE_PIOB, AT91C_PIO_PB25, 0);
    AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB25);    
}


/*********************************************************************
*
*             FS_IDE_HW_X_BusyLedOff
*
  Description:
  FS driver hardware layer function. Turn off busy led.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  None.
*/

void FS_IDE_HW_X_BusyLedOff(FS_u32 Unit) {
    AT91F_PIO_CfgPeriph(AT91C_BASE_PIOB, AT91C_PIO_PB25, 0);
    AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB25);    
}


/*********************************************************************
*
*             FS_IDE_HW_X_SetData
*
  Description:
  FS driver hardware layer function. Set the WR DATA register.

  Parameters:
  Unit        - Unit number.
  Data        - Data to be set.
 
  Return value:
  None.
*/

void FS_IDE_HW_X_SetData(FS_u32 Unit, FS_u16 Data) {
  __MEMCFG2   = 0x1c13;     /* CS5 16 bit */
  __IDE_DATA  = Data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_GetData
*
  Description:
  FS driver hardware layer function. Read the RD DATA register.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  Value of the RD DATA register.
*/

FS_u16 FS_IDE_HW_X_GetData(FS_u32 Unit) {
  FS_u16 data;

  __MEMCFG2   = 0x1c13;     /* CS5 16 bit */
  data = __IDE_DATA;
  return data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_SetFeatures
*
  Description:
  FS driver hardware layer function. Set the FEATURES register.

  Parameters:
  Unit        - Unit number.
  Data        - Value to write to the FEATURES register.
 
  Return value:
  None.
*/

void FS_IDE_HW_X_SetFeatures(FS_u32 Unit, unsigned char Data) {
  __MEMCFG2   = 0x1f13;     /* CS5 8 bit */
  __IDE_FC    = Data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_GetError
*
  Description:
  FS driver hardware layer function. Read the ERROR register.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  Value of the ERROR register.
*/

unsigned char FS_IDE_HW_X_GetError(FS_u32 Unit) {
  unsigned char data;

  __MEMCFG2   = 0x1f13;     /* CS5 8 bit */
  data = __IDE_FC;
  return data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_SetSectorCount
*
  Description:
  FS driver hardware layer function. Set the SECTOR COUNT register.

  Parameters:
  Unit        - Unit number.
  Data        - Value to write to the SECTOR COUNT register.
 
  Return value:
  None.
*/

void FS_IDE_HW_X_SetSectorCount(FS_u32 Unit, unsigned char Data) {
  __MEMCFG2   = 0x1f13;     /* CS5 8 bit */
  __IDE_SC    = Data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_GetSectorCount
*
  Description:
  FS driver hardware layer function. Read the SECTOR COUNT register.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  Value of the SECTOR COUNT register.
*/

unsigned char FS_IDE_HW_X_GetSectorCount(FS_u32 Unit) {
  unsigned char data;

  __MEMCFG2   = 0x1f13;     /* CS5 8 bit */
  data = __IDE_SC;
  return data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_SetSectorNo
*
  Description:
  FS driver hardware layer function. Set the SECTOR NUMBER register.

  Parameters:
  Unit        - Unit number.
  Data        - Value to write to the SECTOR NUMBER register.
 
  Return value:
  None.
*/

void FS_IDE_HW_X_SetSectorNo(FS_u32 Unit, unsigned char Data) {
  __MEMCFG2   = 0x1f13;     /* CS5 8 bit */
  __IDE_SN    = Data;
}


/*********************************************************************
*
*             FS_IDE_HW_X_GetSectorNo
*
  Description:
  FS driver hardware layer function. Read the SECTOR NUMBER register.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  Value of the SECTOR NUMBER register.
*/

unsigned char FS_IDE_HW_X_GetSectorNo(FS_u32 Unit) {
  unsigned char data;

⌨️ 快捷键说明

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