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

📄 ide_x_hw.c

📁 Release notes for emFile Version 2.40c
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
*                SEGGER MICROCONTROLLER SYSTEME GmbH                 *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 2002 - 2004  SEGGER Microcontroller Systeme GmbH        *
*                                                                    *
*        www.segger.com          Support:  support@segger.com        *
*                                                                    *
**********************************************************************

*****  emFile file system for embedded applications  *****************
emFile is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.

----------------------------------------------------------------------
File   : ide_X_hw.c
Purpose: IDE hardware layer for LH79520 with 16bit memory mapped layout
         for Compact Flash
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
-------- END-OF-HEADER -----------------------------------------------
*/

/*********************************************************************
*
*       #include Section
*
**********************************************************************
*/

#include "fs_conf.h"
#include "fs_ConfDefaults.h"

#if FS_USE_IDE_DRIVER

#include "ide_x_hw.h"

/*********************************************************************
*
*       defines, configurable
*
**********************************************************************
*/

/* Due to 16bit memory mapped layout, device/head configuration register can not be       */
/* written independently from command register. When writing to Device register, a NOP    */
/* command is automatically executed. Therefore, a busy check has to be performed after   */
/* writing to device/head register to ensure that card can accept following data or       */
/* command requests.                                                                      */ 
/* Decide whether Device/head register settings are directly written into card register   */
/* _FS_IDE_HW_WRITE_DEVICE might be set to 0 to increase speed. It has to be carefully    */
/* examined whether card is working with _FS_IDE_HW_WRITE_DEVICE set to 0                 */

#define _FS_IDE_HW_WRITE_DEVICE 1


/* Address layout for 16 bit memory mapped access. Byte access not supported by hardware  */

#define IDE_BASEADDRESS  0x50201000

/*********************************************************************
*
*       defines, fixed
*
**********************************************************************
*/

#define __IDE_DATA       *(volatile FS_U16*) (IDE_BASEADDRESS + 0x00008)  /* data register 16 bit, non overlapping address */       
#define __IDE_FC         *(volatile FS_U16*) (IDE_BASEADDRESS + 0x0000C)  /* Feature / error register address. 16 bit memory mapped access used */
#define __IDE_SECTOR     *(volatile FS_U16*) (IDE_BASEADDRESS + 0x00002)  /* Lower byte = sector count,  Upper byte = sector number */ 
#define __IDE_CYLINDER   *(volatile FS_U16*) (IDE_BASEADDRESS + 0x00004)  /* Lower byte = Cylinder low,  Upper byte = cylinder high */ 
#define __IDE_DH_CMD     *(volatile FS_U16*) (IDE_BASEADDRESS + 0x00006)  /* Lower byte = head register, Upper byte = command */
#define __IDE_DC         *(volatile FS_U16*) (IDE_BASEADDRESS + 0x0000e)  /* Lower byte = Device control during write, Alt status during read */

/*********************************************************************
*
*       Check configuration
*
**********************************************************************
*/

#ifndef _FS_IDE_HW_WRITE_DEVICE
  #define _FS_IDE_HW_WRITE_DEVICE 1
#endif  

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

static FS_U8 _HW_DevicePresent[2];
static FS_U8 _HeadRegister;

/*********************************************************************
*
*       Local functions        
*
**********************************************************************
*/

#define _HW_DELAY400NS()  FS_IDE_HW_X_GetAltStatus(Unit); FS_IDE_HW_X_GetAltStatus(Unit);

/*********************************************************************
*
*       _WaitNotBusy()
*
  Description:
  Internal function. Used in 16 bit memory mapped layout, when Device/Head
  register value is written directly to CF card register.
  This must only be done when card is not busy, because writing to device/head
  register will also write a NOP command, which can only be performed, 
  when card is not busy
  
  Parameters:
  None.
 
  Return value:
  None.
*/

#if _FS_IDE_HW_WRITE_DEVICE  

static void _WaitNotBusy(FS_U8 Unit) {
  unsigned char status;
  FS_U16 timeout;
  timeout = 1000;
  do {
    _HW_DELAY400NS();      /* Ensure a short delay to enable BUSY flag set    */
    status = FS_IDE_HW_X_GetAltStatus(Unit);
    timeout--;
    if (timeout == 0) {    /* Timeout occured, leave function                 */
      return;
    }  
  } while ((status  & 0x80) != 0);
}

#endif  /* _FS_IDE_HW_WRITE_DEVICE */

/*********************************************************************
*
*       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_U8 Unit) {
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
}

/*********************************************************************
*
*       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_U8 Unit) {
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
}

/*********************************************************************
*
*       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_U8 Unit, const FS_U16 Data) {
  FS_USE_PARA(Unit);    /* Only one Unit supported, avoid compiler warning  */
  __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_U8 Unit) {
  FS_U16 data;
  FS_USE_PARA(Unit);  /* Only one Unit supported, avoid compiler warning  */
  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_U8 Unit, unsigned char Data) {
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
  __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_U8 Unit) {
  unsigned char data;
  FS_USE_PARA(Unit);   /* Only one Unit supported, avoid compiler warning  */
  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_U8 Unit, unsigned char Data) {
  FS_U16 Sector;
  FS_USE_PARA(Unit);                  /* Only one Unit supported, avoid compiler warning  */
  Sector  = __IDE_SECTOR & 0xFF00;    /* Delete current sector information */
  Sector |= Data;
  __IDE_SECTOR = Sector;
}

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

⌨️ 快捷键说明

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