📄 sysata.c
字号:
/* includes */
#include "vxWorks.h"
#include "ataDrv.h"
#include "config.h"
#define CALC_TIMING(t) ((t + clkPeriod - 1) / clkPeriod)
IMPORT void sysMsDelay(UINT delay);
IMPORT STATUS ataPread(int ctrl, int drive, void *p);
ATA_RESOURCE ataResources[ATA_MAX_CTRLS];
ATA_TYPE ataTypes [ATA_MAX_CTRLS][2] =
{
{
{0, 0, 0, 512, 0xff}, /* controller 0, drive 0 */
{0, 0, 0, 512, 0xff}, /* controller 0, drive 1 */
},
};
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)
{
long clkPeriod;
long pio_t0, pio_t2_8, pio_t2_16;
long pio_t1, pio_t4, pio_ta;
* GPIO_PCR = ((*GPIO_PCR)&(~0x03000000)) | 0x01000000; /* 01 = ATA cs0/1 on csb_4/5 */
* ATA_SHARE_COUNT = 0;
/* Configure and reset host */
* ATA_HOST_CONFIG = ATA_HOSTCONF_SMR | ATA_HOSTCONF_FR | ATA_HOSTCONF_IORDY;
sysMsDelay(1);
* ATA_HOST_CONFIG = ATA_HOSTCONF_IORDY;
* SDMA_PTD_CTRL |= SDMA_PTD_CTRL_PE; /* Disable prefetch on Commbus */
/* Init timings : we use PIO mode 0 timings */
clkPeriod = 1000000000 / IPB_CLOCK; /* period in ns */
pio_t0 = CALC_TIMING (600);
pio_t2_8 = CALC_TIMING (290);
pio_t2_16 = CALC_TIMING (165);
* ATA_PIO_TIME1 = (pio_t0 << 24) | (pio_t2_8 << 16) | (pio_t2_16 << 8);
pio_t4 = CALC_TIMING (30);
pio_t1 = CALC_TIMING (70);
pio_ta = CALC_TIMING (35);
* ATA_PIO_TIME2 = (pio_t4 << 24) | (pio_t1 << 16) | (pio_ta << 8);
/* 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_PIO_AUTO | ATA_GEO_PHYSICAL | ATA_PIO_SINGLE | 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)
{
/* logMsg("sysIntEnablePIC(): %d\n", intNum, 2,3,4,5,6);
*/
* 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;
}
void sysUsDelay(ULONG us)
{
register int ticks;
ticks = tickGet();
ticks += (sysClkRateGet()/1000000 * us);
while(tickGet() < ticks);
}
/* 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 < 2; 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 + -