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

📄 ide_x_hw.c

📁 Release notes for emFile Version 2.40c
💻 C
📖 第 1 页 / 共 2 页
字号:

/*********************************************************************
*
*       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_U8 Unit) {
  unsigned char data;
  FS_USE_PARA(Unit);         /* Only one Unit supported, avoid compiler warning  */
  data = __IDE_SECTOR >> 8;  /* Sector number is upper byte of sector data       */
  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_U8 Unit, unsigned char Data) {
  FS_U16 Cylinder;
  FS_USE_PARA(Unit);         /* Only one Unit supported, avoid compiler warning  */
  Cylinder = __IDE_CYLINDER;
  Cylinder &= 0xFF00;        /* Cylinder low is lower byte of cylinder settings */
  Cylinder |= Data;
  __IDE_CYLINDER = Cylinder;
}

/*********************************************************************
*
*       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_U8 Unit) {
  unsigned char data;
  FS_USE_PARA(Unit);      /* Only one Unit supported, avoid compiler warning  */
  data = __IDE_CYLINDER;  /* Cylinder low is lower byte of cylinder settings  */
  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_U8 Unit, unsigned char Data) {
  FS_U16 Cylinder;
  FS_USE_PARA(Unit);                  /* Only one Unit supported, avoid compiler warning  */
  Cylinder = __IDE_CYLINDER;
  Cylinder &= 0x00FF;
  Cylinder |= (FS_U16) (Data << 8);   /* Cylinder high is upper byte of cylinder settings */
  __IDE_CYLINDER = Cylinder;
}

/*********************************************************************
*
*       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_U8 Unit) {
  unsigned char data;
  FS_USE_PARA(Unit);            /* Only one Unit supported, avoid compiler warning  */
  data = __IDE_CYLINDER >> 8;   /* Cylinder high is upper byte of cylinder settings */
  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.

  Problems:   When 16 bit memory access is used, this register can only be
              written together with command register.
  Return value:
  None.
*/

void FS_IDE_HW_X_SetDevice(FS_U8 Unit, unsigned char Data) {
  FS_USE_PARA(Unit);     /* Only one Unit supported, avoid compiler warning     */
  _HeadRegister = Data;  /* Save new Device/Head settings for command writes    */
#if _FS_IDE_HW_WRITE_DEVICE       /* directly write into Device / Head register */ 
  _WaitNotBusy(Unit);
  __IDE_DH_CMD  = (FS_U16) Data;  /* Upper byte = 0x00 => NOP command           */
  _WaitNotBusy(Unit);             /* ensure, command is executed                */
#endif  
}

/*********************************************************************
*
*       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_U8 Unit) {
  FS_USE_PARA(Unit);    /* Only one Unit supported, avoid compiler warning  */
#if _FS_IDE_HW_WRITE_DEVICE
  return __IDE_DH_CMD;  /* Lower byte of device/command register = Device/Head settings */ 
#else
  return _HeadRegister;
#endif
}

/*********************************************************************
*
*       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.

  Problems:   When 16 bit memory access is used, this register can only be
              written together with Select card / head register.

  Return value:
  None.
*/

void FS_IDE_HW_X_SetCommand(FS_U8 Unit, unsigned char Data) {
  FS_USE_PARA(Unit);                           /* Only one Unit supported, avoid compiler warning  */
  __IDE_DH_CMD = _HeadRegister | (Data << 8);  /* Command is upper byte of DH_CMD register */
}

/*********************************************************************
*
*       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_U8 Unit) {
  unsigned char data;
  FS_USE_PARA(Unit);         /* Only one Unit supported, avoid compiler warning  */
  data = __IDE_DH_CMD >> 8;  /* Status is upper byte of Head / command register  */
  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_U8 Unit, unsigned char Data) {
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
  __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_U8 Unit) {
  unsigned char data;
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
  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_U8 Unit) {
  unsigned char a;
  unsigned char b;
  if (Unit == 0) {
    FS_IDE_HW_X_SetDevice(Unit, 0xE0);
  } else {
    FS_IDE_HW_X_SetDevice(Unit, 0xF0);
  }
  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);
  if ((a == 0x55) && (b == 0xaa)) {
    _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, you could add a soft reset command.

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

void FS_IDE_HW_X_HWReset(FS_U8 Unit) {
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
}


/*********************************************************************
*
*       FS_IDE_HW_X_Delay400ns
*
*  Description:
*    This function is called whenever a delay of 400 ns is required.
*    After sending a command or sending the parameter to the integrated
*    controller on the IDE/CF drive. Slow cards need a delay of 400ns.
*    New driver are quite fast enough, so that a delay may not be
*    required. So this function can be empty.
*
*  Parameters:
*  Unit        - Unit number.
* 
*  Return value:
*  None.
*/
void FS_IDE_HW_X_Delay400ns(FS_U8 Unit) {
  FS_USE_PARA(Unit);
}

/********************************************************************/

#endif /* FS_USE_IDE_DRIVER */

/****** EOF *********************************************************/

⌨️ 快捷键说明

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