📄 ide_x_hw.c
字号:
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2002 - 2003 SEGGER Microcontroller Systeme GmbH *
* *
* Internet: 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 : Generic IDE hardware layer
----------------------------------------------------------------------
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"
/*********************************************************************
*
* #define Macros
*
**********************************************************************
*/
/* */
#define IDE_BASEADDR 0x600200
#define IDE_DATA *(volatile unsigned short*)(IDE_BASEADDR+0)
#define IDE_FEATURE *(volatile unsigned char*) (IDE_BASEADDR+1)
#define IDE_SECTOR_COUNT *(volatile unsigned char*) (IDE_BASEADDR+2)
#define IDE_SECTORNO *(volatile unsigned char*) (IDE_BASEADDR+3)
#define IDE_CYLINDERLOW *(volatile unsigned char*) (IDE_BASEADDR+4)
#define IDE_CYLINDERHIGH *(volatile unsigned char*) (IDE_BASEADDR+5)
#define IDE_DEVICE *(volatile unsigned char*) (IDE_BASEADDR+6)
#define IDE_COMMAND *(volatile unsigned char*) (IDE_BASEADDR+7)
#define IDE_BASEADDR2 0x600300
#define IDE_DEVICECONTROL *(volatile unsigned char*)(IDE_BASEADDR2+6)
#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
*
**********************************************************************
*/
/*********************************************************************
*
* 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_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_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, FS_U16 Data) {
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) {
return IDE_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) {
IDE_FEATURE = 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) {
return IDE_FEATURE;
}
/*********************************************************************
*
* 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) {
IDE_SECTOR_COUNT = 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_U8 Unit) {
return IDE_SECTOR_COUNT;
}
/*********************************************************************
*
* 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) {
IDE_SECTORNO = 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_U8 Unit) {
return IDE_SECTORNO;
}
/*********************************************************************
*
* 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) {
IDE_CYLINDERLOW = 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_U8 Unit) {
return IDE_CYLINDERLOW;
}
/*********************************************************************
*
* 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) {
IDE_CYLINDERHIGH = 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_U8 Unit) {
return IDE_CYLINDERHIGH;
}
/*********************************************************************
*
* 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_U8 Unit, unsigned char Data) {
IDE_DEVICE = 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_U8 Unit) {
return IDE_DEVICE;
}
/*********************************************************************
*
* 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_U8 Unit, unsigned char Data) {
IDE_COMMAND = 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_U8 Unit) {
return IDE_DEVICE;
}
/*********************************************************************
*
* 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) {
IDE_DEVICECONTROL = 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) {
return IDE_DEVICECONTROL;
}
/*********************************************************************
*
* 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) {
int Present;
unsigned char a;
unsigned char b;
FS_IDE_HW_X_SetDevice(Unit, 0xa0);
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);
Present = (a == 0x55);
Present = Present && (b == 0xaa);
/* if Present is 1, we will return 0 */
/* we have found a device */
return (!Present);
}
/*********************************************************************
*
* 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_U8 Unit) {
if (Unit != 0) {
return;
}
}
/*********************************************************************
*
* 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -