📄 sysata.c
字号:
/* includes */
#include "vxWorks.h"
#include "ataDrv.h"
#include "config.h"
IMPORT void sysMsDelay(UINT delay);
IMPORT void sysUsDelay(UINT32 us);
IMPORT STATUS ataPread(int ctrl, int drive, void *p);
ATA_RESOURCE ataResources[ATA_MAX_CTRLS];
ATA_TYPE ataTypes [ATA_MAX_CTRLS][2] =
{
{
{1, 0, 0, 512, 0xff}, /* controller 0, drive 0 */
{1, 0, 0, 512, 0xff}, /* controller 0, drive 1 */
}
};
#define CALC_TIMING(t) ((t + clkPeriod - 1) / clkPeriod)
typedef struct ata5200PioTimes
{
UINT32 pio_t0;
UINT32 pio_t2_8;
UINT32 pio_t2_16;
UINT32 pio_t4;
UINT32 pio_t1;
UINT32 pio_ta;
}ATA_5200_PIO_TIMES;
const ATA_5200_PIO_TIMES ataPioTimes[5] =
{
{600, 290, 165, 30, 70, 35},
{383, 290, 125, 20, 50, 35},
{240, 290, 100, 15, 30, 35},
{180, 80, 80, 10, 30, 35},
{120, 70, 70, 10, 25, 35},
};
struct mdmaspec {
UINT32 t0M[3];
UINT32 td[3];
UINT32 th[3];
UINT32 tj[3];
UINT32 tkw[3];
UINT32 tm[3];
UINT32 tn[3];
};
static struct mdmaspec mdmaspec66 = {
{32, 10, 8},
{15, 6, 5},
{2, 1, 1},
{2, 1, 1},
{15, 4, 2},
{4, 2, 2},
{1, 1, 1}
};
static struct mdmaspec mdmaspec132 = {
{64, 20, 16},
{29, 11, 10},
{3, 2, 2},
{3, 1, 1},
{29, 7, 4},
{7, 4, 4},
{2, 2, 2}
};
struct udmaspec {
UINT32 tcyc[3];
UINT32 t2cyc[3];
UINT32 tds[3];
UINT32 tdh[3];
UINT32 tdvs[3];
UINT32 tdvh[3];
UINT32 tfs_min[3];
UINT32 tli_max[3];
UINT32 tmli[3];
UINT32 taz[3];
UINT32 tzah[3];
UINT32 tenv_min[3];
UINT32 tsr[3];
UINT32 trfs[3];
UINT32 trp[3];
UINT32 tack[3];
UINT32 tss[3];
};
struct udmaspec udmaspec66 = {
{8, 5, 4},
{16, 11, 8},
{1, 1, 1},
{1, 1, 1},
{5, 4, 3},
{1, 1, 1},
{0, 0, 0},/* {16, 14, 12}, */
{10, 10, 10},
{2, 2, 2},
{1, 1, 1},
{2, 2, 2},
{2, 2, 2},
{4, 2, 2},
{5, 4, 4},
{11, 9, 7},
{2, 2, 2},
{4, 4, 4}
};
struct udmaspec udmaspec132 = {
{15, 10, 8},
{32, 21, 16},
{2, 2, 1},
{1, 1, 1},
{10, 7, 5},
{1, 1, 1},
{0, 0, 0},/*{31, 27, 23},*/
{20, 20, 20},
{3, 3, 3},
{2, 2, 2},
{3, 3, 3},
{3, 3, 3},
{7, 4, 4},
{10, 8, 7},
{21, 17, 14},
{3, 3, 3},
{7, 7, 7}
};
void mpc5200_calc_pio_timings(UINT32 pio_mode)
{
UINT32 pio_t0, pio_t2_8, pio_t2_16, pio_t1, pio_t4, pio_ta;
UINT32 clkPeriod = 1000000000 / IPB_CLOCK; /* period in ns */
pio_t0 = CALC_TIMING (ataPioTimes[pio_mode].pio_t0);
pio_t2_8 = CALC_TIMING (ataPioTimes[pio_mode].pio_t2_8);
pio_t2_16 = CALC_TIMING (ataPioTimes[pio_mode].pio_t2_16);
pio_t4 = CALC_TIMING (ataPioTimes[pio_mode].pio_t4);
pio_t1 = CALC_TIMING (ataPioTimes[pio_mode].pio_t1);
pio_ta = CALC_TIMING (ataPioTimes[pio_mode].pio_ta);
* ATA_PIO_TIME1 = (pio_t0 << 24) | (pio_t2_8 << 16) | (pio_t2_16 << 8);
* ATA_PIO_TIME2 = (pio_t4 << 24) | (pio_t1 << 16) | (pio_ta << 8);
}
void mpc5200_calc_mdma_timings(UINT32 mdma_mode)
{
UINT32 t0M, td, tkw, tm, th, tj, tn;
if(IPB_CLOCK == 132000000)
{
t0M = mdmaspec132.t0M[mdma_mode];
td = mdmaspec132.td[mdma_mode];
tkw = mdmaspec132.tkw[mdma_mode];
tm = mdmaspec132.tm[mdma_mode];
th = mdmaspec132.th[mdma_mode];
tj = mdmaspec132.tj[mdma_mode];
tn = mdmaspec132.tn[mdma_mode];
}
else
{
t0M = mdmaspec66.t0M[mdma_mode];
td = mdmaspec66.td[mdma_mode];
tkw = mdmaspec66.tkw[mdma_mode];
tm = mdmaspec66.tm[mdma_mode];
th = mdmaspec66.th[mdma_mode];
tj = mdmaspec66.tj[mdma_mode];
tn = mdmaspec66.tn[mdma_mode];
}
*ATA_MDMA_TIME1 = (t0M << 24) | (td << 16) | (tkw << 8) | (tm);
*ATA_MDMA_TIME2 = (th << 24) | (tj << 16) | (tn << 8);
}
void mpc5200_calc_udma_timings(UINT32 udma_mode)
{
UINT32 t2cyc, tcyc, tds, tdh, tdvs, tdvh, tfs, tli, tmli, taz, tenv, tsr, tss, trfs, trp, tack, tzah;
if(IPB_CLOCK == 132000000)
{
t2cyc = udmaspec132.t2cyc[udma_mode];
tcyc = udmaspec132.tcyc[udma_mode];
tds = udmaspec132.tds[udma_mode];
tdh = udmaspec132.tdh[udma_mode];
tdvs = udmaspec132.tdvs[udma_mode];
tdvh = udmaspec132.tdvh[udma_mode];
tfs = udmaspec132.tfs_min[udma_mode];
tmli = udmaspec132.tmli[udma_mode];
tenv = udmaspec132.tenv_min[udma_mode];
tss = udmaspec132.tss[udma_mode];
trp = udmaspec132.trp[udma_mode];
tack = udmaspec132.tack[udma_mode];
tzah = udmaspec132.tzah[udma_mode];
taz = udmaspec132.taz[udma_mode];
trfs = udmaspec132.trfs[udma_mode];
tsr = udmaspec132.tsr[udma_mode];
tli = udmaspec132.tli_max[udma_mode];
}
else
{
t2cyc = udmaspec66.t2cyc[udma_mode];
tcyc = udmaspec66.tcyc[udma_mode];
tds = udmaspec66.tds[udma_mode];
tdh = udmaspec66.tdh[udma_mode];
tdvs = udmaspec66.tdvs[udma_mode];
tdvh = udmaspec66.tdvh[udma_mode];
tfs = udmaspec66.tfs_min[udma_mode];
tmli = udmaspec66.tmli[udma_mode];
tenv = udmaspec66.tenv_min[udma_mode];
tss = udmaspec66.tss[udma_mode];
trp = udmaspec66.trp[udma_mode];
tack = udmaspec66.tack[udma_mode];
tzah = udmaspec66.tzah[udma_mode];
taz = udmaspec66.taz[udma_mode];
trfs = udmaspec66.trfs[udma_mode];
tsr = udmaspec66.tsr[udma_mode];
tli = udmaspec66.tli_max[udma_mode];
}
*ATA_UDMA_TIME1 = (t2cyc << 24) | (tcyc << 16) | (tds << 8)| (tdh);
*ATA_UDMA_TIME2 = (tdvs << 24) | (tdvh << 16) | (tfs << 8) | (tli);
*ATA_UDMA_TIME3 = (tmli << 24) | (taz << 16) | (tenv << 8) | (tsr);
*ATA_UDMA_TIME4 = (tss << 24) | (trfs << 16) | (trp << 8) | (tack);
*ATA_UDMA_TIME5 = (tzah << 24);
}
void sysAtaReset(int ctrl)
{
/* logMsg("sysAtaReset() : %d\n", ctrl);
*/
if(ctrl == 0)
{
/* IDE reset */
/* Configure PSC1_4 as GPIO output for ATA reset */
* GPW_WE |= 0x01000000; /* PSC1_4 */
* GPW_DD |= 0x01000000;
* GPW_DO |= 0x01000000;
* GPW_DO &= (~0x01000000);
sysMsDelay(500);
* GPW_DO |= 0x01000000;
sysMsDelay(250);
}
}
void sysAtaInit(int ctrl)
{
* GPIO_PCR = ((*GPIO_PCR)&(~0x03000000)) | 0x01000000; /* 01 = ATA cs0/1 on csb_4/5 */
*ATA_SHARE_COUNT = 0x1000000;
/* Configure and reset host */
* ATA_HOST_CONFIG = ATA_HOSTCONF_SMR | ATA_HOSTCONF_FR | ATA_HOSTCONF_IORDY;
sysMsDelay(1);
* ATA_HOST_CONFIG = ATA_HOSTCONF_IORDY;
mpc5200_calc_pio_timings(0);
mpc5200_calc_mdma_timings(0);
mpc5200_calc_udma_timings(0);
/* * SDMA_PTD_CTRL |= SDMA_PTD_CTRL_PE; */ /* Disable prefetch on Commbus */
/* 按照DMA读方式设定ATA_FIFO */
*ATA_FIFO_ALARM = 0x80;
*ATA_FIFO_CTRL = 0x7000000;
/* IDE reset */
/* Configure PSC1_4 as GPIO output for ATA reset */
* GPW_WE |= 0x01000000; /* PSC1_4 */
* GPW_DD |= 0x01000000;
* GPW_DO |= 0x01000000;
* GPW_DO &= (~0x01000000);
sysMsDelay(500);
* GPW_DO |= 0x01000000;
sysMsDelay(250);
ataResources[0].resource.ioStart[0] = ATA_BASE_ADRS;
ataResources[0].resource.ioStart[1] = ATA_BASE_ADRS;
ataResources[0].ctrlType = IDE_LOCAL;
ataResources[0].drives = 2;
ataResources[0].intVector = (int)IV_ATA;
ataResources[0].intLevel = (int)INUM_ATA;
ataResources[0].configType = ( ATA_DMA_AUTO | ATA_GEO_PHYSICAL | ATA_BITS_16 );
ataResources[0].semTimeout = 0;
ataResources[0].wdgTimeout = 0;
}
/*******************************************************************************
*
* sysIntEnablePIC - enable an ISA/PCI interrupt
*
* This function call is used to enable an ISA/PCI interrupt.
*
* RETURNS: OK, always.
*/
STATUS sysIntEnablePIC( int intNum)
{
* ATA_DEV_CTRL &= ~(ATA_DEV_CTRL_SRST | ATA_DEV_CTRL_nIEN);
* ATA_HOST_CONFIG |= ATA_HOSTCONF_IE;
return (intEnable (intNum));
}
/*****************************************************************************
*
* ataIoInWordString - reads a string of words from an io address.
*
* This function reads a word string from a specified io address.
*
* RETURNS: N/A
*/
void ataIoInWordString(ULONG ioAddr, UINT16 * bufPtr, int nWords)
{
int loopCtr;
/* logMsg("ataIoInWordString(): io=0x%x, ptr=0x%x, %d\n", ioAddr, bufPtr,nWords,4,5,6);
*/
for (loopCtr = 0; loopCtr < nWords; loopCtr++)
{
EIEIO;
*bufPtr++ = *(volatile UINT16 *)ioAddr;
}
}
/*****************************************************************************
*
* ataIoOutWordString - writes a string of words to an io address.
*
* This function writes a word string from a specified io address.
*
* RETURNS: N/A
*/
void ataIoOutWordString(ULONG ioAddr, UINT16 * bufPtr, int nWords)
{
int loopCtr;
/* logMsg("ataIoOutWordString(): io=0x%x, ptr=0x%x, %d\n", ioAddr, bufPtr,nWords,4,5,6);
*/
for (loopCtr = 0; loopCtr < nWords; loopCtr++)
{
EIEIO;
*(volatile UINT16 *)ioAddr = *bufPtr++;
}
}
/*****************************************************************************
*
* ataIoInWordStringRev - reads a string of words that are byte reversed
*
* This function reads a string of words that are byte reversed from a
* specified io address.
*
* RETURNS: N/A
*/
void ataIoInWordStringRev(ULONG ioAddr, UINT16 * bufPtr, int nWords)
{
int loopCtr;
UINT16 val;
/* logMsg("ataIoInWordStringRev(): io=0x%x, ptr=0x%x, %d\n", ioAddr, bufPtr,nWords,4,5,6);
*/
for (loopCtr = 0; loopCtr < nWords; loopCtr++)
{
val = *(volatile UINT16 *)ioAddr;
EIEIO;
*bufPtr++ = (val << 8) | (val>>8);
}
}
/*****************************************************************************
*
* ataIoInLongString - reads a string of longwords from an io address.
*
* This function reads a longword string from a specified io address.
*
* RETURNS: N/A
*/
void ataIoInLongString(ULONG ioAddr, ULONG * bufPtr, int nLongs)
{
int loopCtr;
/* logMsg("ataIoInLongString(): io=0x%x, ptr=0x%x, %d\n", ioAddr, bufPtr,nLongs,4,5,6); */
for (loopCtr = 0; loopCtr < nLongs; loopCtr++)
{
EIEIO;
*bufPtr++ = *(volatile UINT32 *)ioAddr;
}
}
/*****************************************************************************
*
* ataIoOutLongString - writes a string of longwords to an io address.
*
* This function writes a longword string from a specified io address.
*
* RETURNS: N/A
*/
void ataIoOutLongString(ULONG ioAddr, ULONG * bufPtr, int nLongs)
{
int loopCtr;
/* logMsg("ataIoOutLongString(): io=0x%x, ptr=0x%x, %d\n", ioAddr, bufPtr,nLongs,4,5,6); */
for (loopCtr = 0; loopCtr < nLongs; loopCtr++)
{
EIEIO;
*(volatile UINT32 *)ioAddr = *bufPtr++;
}
}
UINT8 ataIoInByte(ULONG ioAddr)
{
UINT8 val;
EIEIO;
val = *(volatile UINT8 *)(ioAddr);
return val;
}
UINT8 ataIoOutByte(ULONG ioAddr, UINT8 byte)
{
UINT8 val;
EIEIO;
*(volatile UINT8 *)(ioAddr) = byte;
return val;
}
/* Wait until Busy bit is off, or timeout (in ms) * Return last status */
UINT8 ataWaitStatus(ULONG ioStatus, ULONG ms)
{
ULONG delay = 10 * ms; /* poll every 100 us */
UINT8 c;
while((c = ataIoInByte(ioStatus)) & ATA_STAT_BUSY)
{
sysUsDelay(100);
if(delay -- == 0)
{
break;
}
}
return c;
}
#include "dpartCbio.h"
/*
* copy src to dest, skipping leading and trailing blanks and null
* terminate the string
* "len" is the size of available memory including the terminating '\0'
*/
static void srcCharCopy (unsigned char *dst, unsigned char *src, unsigned int len)
{
unsigned char *end, *last;
last = dst;
end = src + len - 1;
/* reserve space for '\0' */
if (len < 2)
goto OUT;
/* skip leading white space */
while ((*src) && (src<end) && (*src==' '))
++src;
/* copy string, omitting trailing white space */
while ((*src) && (src<end)) {
*dst++ = *src;
if (*src++ != ' ')
last = dst;
}
OUT:
*last = '\0';
}
void sysIdeInfo()
{
ATA_PARAM pParam;
UINT32 sectors;
int ctrl, drive;
char model[sizeof(pParam.model)+1];
char rev[sizeof(pParam.rev)+1];
char serial[sizeof(pParam.serial)+1];
ctrl = 0;
for(drive =0; drive < 1; drive++)
{
printf("Bus %d Device %d : ", ctrl, drive);
if (ataPread (ctrl, drive, &pParam) == ERROR)
{
printf("no available\n");
continue;
}
srcCharCopy(model, pParam.model, sizeof(pParam.model));
srcCharCopy(rev, pParam.rev, sizeof(pParam.rev));
srcCharCopy(serial, pParam.serial, sizeof(pParam.serial));
printf("%s\n", (pParam.type == 0)? " ": "Hard Disk" );
printf("%14s : %s\n", "Model", model);
printf("%14s : %s\n", "Firmware#", rev);
printf("%14s : %s\n", "Serial#", serial);
if (pParam.capabilities & 0x0200) /* if (drive supports LBA) */
{
sectors = (((UINT32) ((pParam.sectors0) & 0x0000ffff)) << 0) |
(((UINT32) ((pParam.sectors1) & 0x0000ffff)) << 16);
}
else
{
sectors = pParam.currentSectors * pParam.currentHeads * pParam.currentCylinders;
}
printf("%14s : %.2f MB = %.2f GB (%d x 512)\n", "Capacity", (float)sectors * 512.0/(1024.0*1024.0),
(float) sectors * 512.0/(1024.0*1024.0*1024.0), sectors);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -