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

📄 ide_x_hw.c

📁 at91rm9200硬盘的接口代码
💻 C
📖 第 1 页 / 共 2 页
字号:

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


/*********************************************************************
*
*             FS_IDE_HW_X_SetCylLow
*
  Description:
  FS driver hardware layer function. Set the CYLINDER LOW register.

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_GetCylLow
*
  Description:
  FS driver hardware layer function. Read the CYLINDER LOW register.

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

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_SetCylHigh
*
  Description:
  FS driver hardware layer function. Set the CYLINDER HIGH register.

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_GetCylHigh
*
  Description:
  FS driver hardware layer function. Read the CYLINDER HIGH register.

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

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_SetDevice
*
  Description:
  FS driver hardware layer function. Set the DEVICE/HEAD register.

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_GetDevice
*
  Description:
  FS driver hardware layer function. Read the DEVICE/HEAD register.

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

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_SetCommand
*
  Description:
  FS driver hardware layer function. Set the COMMAND register.

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_GetStatus
*
  Description:
  FS driver hardware layer function. Read the STATUS register.

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

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_SetDevControl
*
  Description:
  FS driver hardware layer function. Set the DEVICE CONTROL register.

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_GetAltStatus
*
  Description:
  FS driver hardware layer function. Read the ALTERNATE STATUS register.

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

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

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


/*********************************************************************
*
*             FS_IDE_HW_X_DetectStatus
*
  Description:
  FS driver hardware layer function. Check if the device is present.

  Parameters:
  Unit        - Unit number.
 
  Return value:
  ==0         - Device is connected.
  !=0         - Device has not been found.
*/

char FS_IDE_HW_X_DetectStatus(FS_u32 Unit) {
  static char init;
  int lexp;
  unsigned char a;
  unsigned char b;

  if (!init) {
    init  = 1;
    __MEMCFG2  = 0x1f13;        /* CS5 8 bit */
    __SYSCON1 |= 0x40000ul;     /* enable expansion clock */
  }
  if (Unit == 0) {
    FS_IDE_HW_X_SetDevice(Unit, 0xa0);
  }
  else {
    FS_IDE_HW_X_SetDevice(Unit, 0xe0);
  }
  HW__DELAY400NS;
  FS_IDE_HW_X_SetSectorCount(Unit, 0x55);
  FS_IDE_HW_X_SetSectorNo(Unit, 0xaa);
  FS_IDE_HW_X_SetSectorCount(Unit, 0xaa);
  FS_IDE_HW_X_SetSectorNo(Unit, 0x55);
  FS_IDE_HW_X_SetSectorCount(Unit, 0x55);
  FS_IDE_HW_X_SetSectorNo(Unit, 0xaa);
  a = FS_IDE_HW_X_GetSectorCount(Unit);
  b = FS_IDE_HW_X_GetSectorNo(Unit);
  lexp = (a == 0x55);
  lexp = lexp && (b == 0xaa);
  if (lexp) {
    _HW_DevicePresent[Unit] = 1;
  }
  else {
    _HW_DevicePresent[Unit] = 0;
  }
  return (!_HW_DevicePresent[Unit]);
}


/*********************************************************************
*
*             FS_IDE_HW_X_HWReset
*
  Description:
  FS driver hardware layer function. This function is called, when 
  the driver detects a new media is present. For ATA HD drives, there 
  is no action required and this function can be empty.
  When using a CF card, please be aware, that the card needs to be
  power cycled while ~OE is grounded. If the card is inserted, VCC & 
  GND will provide the card before ~OE is connected and the card will 
  be in PC Card ATA mode.

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

   
*/

void FS_IDE_HW_X_HWReset(FS_u32 Unit) {
  if (Unit != 0) {
    return;
  }
}

#endif /* FS_USE_IDE_DRIVER */

⌨️ 快捷键说明

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