?? ide_x_hw.c
字號:
/*
**********************************************************************
* 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 Segger SED137XE board accessing
a CF card in true IDE mode with P7,P8,P9,P10.
CF CPU
=============================================
A00 - A02 <- P70 - P72
A03 - A10 <- GND
PDIAG <-> PU
DASP <-> PU
CD1 - CD2 -> P80 - P81
CS0 - CS1 <- P73 - P74
CSEL <- GND
D00 - D15 <-> P90 - P107
IORD <- P75
IOWR <- P76
ATA SEL <- GND
INTRQ -> P83
REG <- VCC
RESET <- P77
VS1 -> PU
VS2 -> PU
IORDY -> P82
WE <- VCC
VCC <- VCC switched by P84
=============================================
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
---------------------------END-OF-HEADER------------------------------
*/
/*********************************************************************
*
* #include Section
*
**********************************************************************
*/
#include "fs_port.h"
#include "fs_conf.h"
#if FS_USE_IDE_DRIVER
#include "ide_x_hw.h"
/*
The following header file is part of the IAR compiler for M16C/80.
If you use a different compiler, you may have to include a different
file or you may even have to replace the SFR access within this
file.
*/
#include <IOMC80.H>
/*********************************************************************
*
* #define Macros
*
**********************************************************************
*/
/*
To meet timing specification, you may have to add delays here
when porting to a different CPU. For MC80 at 16MHz, there is no
delay required.
*/
#define FS__IDE_DELAY_WRITE
#define FS__IDE_DELAY_READ
#define FS__IDE_DELAY_RESET
/*********************************************************************
*
* Local functions
*
**********************************************************************
*/
/*********************************************************************
*
* _FS_IDE_HW_SetA0A2
*
Description:
FS driver internal function. Set the address lines of the IDE
interface.
Parameters:
Unit - Unit number.
Address - Value for A0..A2.
Return value:
None.
*/
static void _FS_IDE_HW_SetA0A2(FS_u32 Unit, unsigned char Addr) {
unsigned char x;
if (Unit != 0) {
return;
}
x = P7 & 0xf8;
x |= (Addr & 0x07);
P7 = x;
}
/*********************************************************************
*
* _FS_IDE_HW_SetCS0CS1
*
Description:
FS driver internal function. Set the CS0CS1 lines of the IDE
interface.
Parameters:
Unit - Unit number.
Data - Value for CS0..CS1.
Return value:
None.
*/
static void _FS_IDE_HW_SetCS0CS1(FS_u32 Unit, unsigned char Data) {
unsigned char x;
if (Unit != 0) {
return;
}
x = P7 & 0xe7;
x |= ((Data & 3) << 3);
P7 = x;
}
/*********************************************************************
*
* _FS_IDE_HW_SetD0D15
*
Description:
FS driver internal function. Set the data lines of the IDE interface.
Parameters:
Unit - Unit number.
Data - Value for D0..D15.
Return value:
None.
*/
static void _FS_IDE_HW_SetD0D15(FS_u32 Unit, FS_u16 Data) {
if (Unit != 0) {
return;
}
/* Set mode output */
PRCR |= 0x04;
PD9 = 0xff;
PD10 = 0xff;
PRCR &= 0xfb;
/* Set Data */
P9 = Data & 0xff;
P10 = ((Data >> 8) & 0xff);
}
/*********************************************************************
*
* _FS_IDE_HW_GetD0D15
*
Description:
FS driver internal function. Read the data lines of the IDE interface.
Parameters:
Unit - Unit number.
Return value:
Value of D0..D15.
*/
static FS_u16 _FS_IDE_HW_GetD0D15(FS_u32 Unit) {
FS_u16 x;
if (Unit != 0) {
return 0;
}
/* Set mode input */
PRCR |= 0x04;
PD9 = 0x00;
PD10 = 0x00;
PRCR &= 0xfb;
/* Get data */
x = P10;
x = x << 8;
x |= P9;
return x;
}
/*********************************************************************
*
* _FS_IDE_HW_SetIORD
*
Description:
FS driver internal function. Set the IORD line of the IDE interface.
Parameters:
Unit - Unit number.
Data - Value for IORD.
Return value:
None.
*/
static void _FS_IDE_HW_SetIORD(FS_u32 Unit, unsigned char Data) {
if (Unit != 0) {
return;
}
if (Data) {
P7 |= 0x20;
}
else {
P7 &= 0xdf;
}
}
/*********************************************************************
*
* _FS_IDE_HW_SetIOWR
*
Description:
FS driver internal function. Set the IOWR line of the IDE interface.
Parameters:
Unit - Unit number.
Data - Value for IOWR.
Return value:
None.
*/
static void _FS_IDE_HW_SetIOWR(FS_u32 Unit, unsigned char Data) {
if (Unit != 0) {
return;
}
if (Data) {
P7 |= 0x40;
}
else {
P7 &= 0xbf;
}
}
/*********************************************************************
*
* _FS_IDE_HW_GetIORDY
*
Description:
FS driver internal function. Read the IORDY line of the IDE interface.
Parameters:
Unit - Unit number.
Return value:
==0 - Value of IORDY.
==1 - Value of IORDY.
==0xff - An error has occured.
*/
static char _FS_IDE_HW_GetIORDY(FS_u32 Unit) {
if (Unit != 0) {
return 0xff;
}
if (P8 & 0x04) {
return 1;
}
return 0;
}
/*********************************************************************
*
* _FS_IDE_HW_WriteBUS
*
Description:
FS driver internal function. Write a value to an IDE register.
Parameters:
Unit - Unit number.
CS - Value for CS0..CS1.
Addr - Address of the register.
Data - Data to be written to the register
Return value:
None.
*/
static void _FS_IDE_HW_WriteBUS(FS_u32 Unit, unsigned char CS, unsigned char Addr, FS_u16 Data) {
_FS_IDE_HW_SetA0A2(Unit, Addr);
_FS_IDE_HW_SetCS0CS1(Unit, CS);
_FS_IDE_HW_SetD0D15(Unit, Data);
_FS_IDE_HW_SetIOWR(Unit, 0);
FS__IDE_DELAY_WRITE; /* delay */
while (!_FS_IDE_HW_GetIORDY(Unit)) {
}
_FS_IDE_HW_SetIOWR(Unit, 1);
_FS_IDE_HW_SetCS0CS1(Unit, 0x03); /* Standby Mode */
_FS_IDE_HW_SetA0A2(Unit, 0x00);
}
/*********************************************************************
*
* _FS_IDE_HW_ReadBUS
*
Description:
FS driver internal function. Read value of an IDE register.
Parameters:
Unit - Unit number.
CS - Value for CS0..CS1.
Addr - Address of the register.
Return value:
Value of the IDE register.
*/
static FS_u16 _FS_IDE_HW_ReadBUS(FS_u32 Unit, unsigned char CS, unsigned char Addr) {
FS_u16 data;
_FS_IDE_HW_SetA0A2(Unit, Addr);
_FS_IDE_HW_SetCS0CS1(Unit, CS);
_FS_IDE_HW_SetIORD(Unit, 0);
FS__IDE_DELAY_READ; /* delay */
while (!_FS_IDE_HW_GetIORDY(Unit)) {
}
data = _FS_IDE_HW_GetD0D15(Unit);
_FS_IDE_HW_SetIORD(Unit, 1);
_FS_IDE_HW_SetCS0CS1(Unit, 0x03); /* Standby Mode */
_FS_IDE_HW_SetA0A2(Unit, 0x00);
return data;
}
/*********************************************************************
*
* 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) {
}
/*********************************************************************
*
* 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) {
}
/*********************************************************************
*
* 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) {
_FS_IDE_HW_WriteBUS(Unit, 0x02, 0x00, Data);
}
/*********************************************************************
*
* FS_IDE_HW_X_GetData
*
Description:
FS driver hardware layer function. Read the RD DATA register.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -