📄 iictest.c
字号:
microsleep(2000);
iicWriteReg(EEPROM_ADDRESS, 13, 0xc3);
microsleep(2000);
iicWriteReg(EEPROM_ADDRESS, 14, 0x50);
microsleep(2000);
iicWriteReg(EEPROM_ADDRESS, 15, 0x00);
microsleep(2000);
for (i = 16; i < 255; i++) {
iicWriteReg(EEPROM_ADDRESS, i, i);
microsleep(2000);
}
break;
}
case 'h':
case '?':
printhelp();
break;
case 'q':
exit(0);
}
}
}
/****************************************/
static void
iicError2String(int error, char *str)
{
sprintf(str, "0x%X:", error);
error &= 0xFFF; /* take off common IIC ID */
if (error & IIC_ERR_BAD_ADDRESS)
strcat(str, " Unsupported address");
if (error & IIC_ERR_BAD_COUNT)
strcat(str, " Unsupported bytecount");
if (error & IIC_ERR_TIMEOUT)
strcat(str, " timeout");
if (error & IIC_ERR_ADDRESS_NACK)
strcat(str, " Address NACK");
if (error & IIC_ERR_DATA_NACK)
strcat(str, " Data NACK");
if (error & IIC_ERR_UNSUPPORTED)
strcat(str, " Unsupported request");
}
/*********************************************************
* called at boot time to verify basic IIC operation.
* Reads eeprom in single byte and then in multibyte modes.
* If the contents match, sanity is reported.
*/
static int checkSanity(void)
{
iicRequest_t req;
UInt d1;
Int i, instance, line, retval;
UInt8 xdata[256];
UInt8 ydata[256];
/* first read the EEPROM with a multi-byte read */
iicOpen(&instance);
/* write out the address */
for (i = 0; i < 255; i++)
xdata[i] = 0;
req.direction = IIC_WRITE;
req.type = IIC_SIMPLE;
req.data = xdata;
req.mode = IIC_Synchronous_By_Polling;
req.completion_function = Null;
req.byteCount = 1;
req.address = EEPROM_ADDRESS;
retval = iicDispatch(instance, &req);
if (retval) {
char errstr[80];
iicError2String(retval, errstr);
printf("Sanity Error %s writing subaddress\n", errstr);
return (1);
}
for (i = 0; i < 255; i++)
xdata[i] = 0;
/* read the data */
req.direction = IIC_READ;
req.type = IIC_SIMPLE;
req.data = xdata;
req.mode = IIC_Synchronous_By_Polling;
req.address = EEPROM_ADDRESS;
req.byteCount = 32;
req.completion_function = Null;
retval = iicDispatch(instance, &req);
if (retval) {
char errstr[80];
iicError2String(retval, errstr);
printf("Sanity Error %s reading \n", errstr);
return (2);
}
/* now compare against data from single byte reads: */
for (line = 0; line < 32; line++) {
retval = iicReadReg(EEPROM_ADDRESS, line, &d1);
if (retval) {
printf("Sanity error 0x%x reading EEPROM "
"byte %d.\n", retval, line);
return (3);
}
ydata[line] = d1;
}
retval = 0;
for (i = 0; i < 32; i++) {
/* printf("x: %x Y: %x \n", xdata[i], ydata[i]); */
if (xdata[i] != ydata[i]) {
printf("Sanity mismatch at %d. Multi: %x vs "
"Single: %x\n", i, xdata[i], ydata[i]);
retval++;
}
}
return (retval);
}
/********************************************************************************/
void dumpEEPROM(void)
{
int ii, jj, kk, line;
unsigned int d1, d2;
int e1;
unsigned char eepromData[1024];
for (line = 0; line < 32; line++) {
e1 = iicReadReg(EEPROM_ADDRESS, line, &d1);
if (e1)
printf("IIC Error 0x%x reading EEPROM "
"byte %d.\n", e1, line);
eepromData[line] = d1;
}
printf("\nContents of boot EEPROM at IIC "
"address 0x%X:\n", EEPROM_ADDRESS);
printf("Byte Offset:\tData:\n");
for (ii = 0; ii < IIC_EEPROM_SIZE; ii += 16) {
printf("0x%03x:\t\t", ii);
for (jj = 0; jj < 16; jj++) {
kk = ii + jj;
printf("%02x", 0xFF & eepromData[kk]);
if (((jj + 1) % 4) == 0)
printf(" ");
}
printf("\n");
}
printf("\n");
d1 = eepromData[0];
printf("\tSDRAM apperture is ");
switch (7 & (d1 >> 4)) {
case 0:
printf("1 Megabyte.\n");
break;
case 1:
printf("1 Megabyte.\n");
break;
case 2:
printf("2 Megabytes.\n");
break;
case 3:
printf("4 Megabytes.\n");
break;
case 4:
printf("8 Megabytes.\n");
break;
case 5:
printf("16 Megabytes.\n");
break;
case 6:
printf("32 Megabytes.\n");
break;
case 7:
printf("64 Megabytes.\n");
break;
}
printf("\tCrystal expected near ");
switch ((d1 & 0xC) >> 2) {
case 0:
printf("100 MHz\n");
break;
case 1:
printf("75 MHz\n");
break;
case 2:
printf("50 MHz\n");
break;
case 3:
printf("33 MHz\n");
break;
}
if (d1 & 2)
printf("\tEEPROM clock nominally 400 KHz\n");
else
printf("\tEEPROM clock nominally 100 KHz\n");
if (d1 & 1)
printf("\tBoot clock in test mode\n");
if (d1 & 0x80)
printf("\tEEPROM contains more than 256 bytes of data\n");
d2 = (eepromData[1] << 24) + (eepromData[2] << 16) +
(eepromData[3] << 8) + eepromData[4];
printf("\tSubsystem ID: Board = 0x%x : Manufacturer = 0x%x\n",
d2 >> 16, 0xFFFF & d2);
d2 = ((0xF & eepromData[5]) << 16) +
(eepromData[6] << 8) + eepromData[7];
printf("\tMM_CONFIG register reads 0x%x\n", d2);
d1 = eepromData[8];
if (d1 & 0x80)
printf("\tSDRAM PLL Bypassed\n");
if (d1 & 0x40)
printf("\tSDRAM PLL disabled\n");
if (d1 & 0x20)
printf("\tCPU PLL bypassed\n");
if (d1 & 0x10)
printf("\tCPU PLL Disabled\n");
if (d1 & 0x8) {
printf("\tMemory to External ratio is 3:1\n");
}
else {
printf("\tMemory to External ratio is 2:1\n");
}
printf("\tCPU to Memory clock ratio is ");
switch (d1 & 7) {
case 0:
printf("1:1\n");
break;
case 1:
printf("2:1\n");
break;
case 2:
printf("3:2\n");
break;
case 3:
printf("4:3\n");
break;
case 4:
printf("5:4\n");
break;
default:
printf("using a reserved value (%d)\n", d1 & 7);
break;
}
d1 = eepromData[9];
if (d1 & 0x80)
printf("\tAutonomous Boot selected\n");
else
printf("\tHost assisted boot selected\n");
printf("\tbytecount is %d\n\n", ((d1 & 7) << 8) + eepromData[10]);
}
void dumpProcSpeed(void)
{
int e1, line;
unsigned int d1;
char ic;
unsigned char eepromData[1024];
float cpuMult, memMult, val;
Bool changed = False;
pprocCapabilities_t procCap;
char ins[80];
/* read the eeprom */
procGetCapabilities(&procCap);
ins[0] = ' ';
while (ins[0] != 'q')
{
printf("\nProcessor Speed variable reports TM running at %3.2f MHz.\n",
0.000001 * (float) procCap->cpuClockFrequency);
for (line = 0; line < 32; line++) {
e1 = iicReadReg(EEPROM_ADDRESS, line, &d1);
if (e1)
printf("IIC Error 0x%x reading EEPROM "
"byte %d.\n", e1, line);
eepromData[line] = d1;
}
d1 = eepromData[8];
if (d1 & 0x8) {
printf("EEPROM reports Memory to External ratio is 3:1\n");
memMult = 3.0;
}
else {
printf("EEPROM reports Memory to External ratio is 2:1\n");
memMult = 2.0;
}
printf("EEPROM reports CPU to Memory clock ratio is ");
switch (d1 & 7) {
case 0:
printf("1:1\n");
cpuMult = 1.0;
break;
case 1:
printf("2:1\n");
cpuMult = 2.0;
break;
case 2:
printf("3:2\n");
cpuMult = 1.5;
break;
case 3:
printf("4:3\n");
cpuMult = 1.33;
break;
case 4:
printf("5:4\n");
cpuMult = 1.25;
break;
default:
printf("using a reserved value (%d)\n", d1 & 7);
cpuMult = 1.0;
break;
}
printf("\nYour memory is running at %g times the crystal frequency.\n", memMult);
printf("Your CPU is running at %g times the memory frequency.\n", cpuMult);
#ifdef __TCS_nohost__
return;
#endif
printf("\nWARNING:\n CHANGING THESE VALUES MAY MAKE YOUR SYSTEM UNSTABLE AT THE NEXT BOOT!\n");
printf("Press:\n m to change the memory multipler, \n c to change the CPU multipler, or \n q to exit this loop.\n");
gets(ins);
if (ins[0] == 'm')
{
val = memMult;
sscanf(ins, "%c %g", &ic, &val);
if (val == 2.0)
d1 = (d1 & 0xF7);
else if (val == 3.0)
d1 = (d1 & 0xF7) | 0x8;
else {
printf("%g is an illegal memory multipler. Only 2 and 3 are accepted\n", val);
continue;
}
if (val != memMult) {
printf("\n!!WARNING: CHANGING BOOT EEPROM\n");
iicWriteReg(0xA0, 8, d1);
changed = True;
}
}
else if (ins[0] == 'c')
{
val = cpuMult;
sscanf(ins, "%c %g", &ic, &val);
if (val == 1.0)
d1 = d1 & 0xF8;
else if (val == 2.0)
d1 = (d1 & 0xF8) | 1;
else if (val == 1.5)
d1 = (d1 & 0xF8) | 2;
else if ((val >= 1.3) && (val < 1.4)) {
val = 1.33;
d1 = (d1 & 0xF8) | 3;
}
else if (val == 1.25)
d1 = (d1 & 0xF8) | 4;
else {
printf("%g is an illegal cpu multipler. 1, 2, 1.5, 1.33, and 1.25 are accepted\n");
continue;
}
if (val != cpuMult) {
printf("\n!!WARNING: CHANGING BOOT EEPROM\n");
iicWriteReg(0xA0, 8, d1);
changed = True;
}
}
if (changed) {
printf("\nYou have changed your CPU or memory clock ratios.\n");
printf("The new value will be recognized the next time you reboot your PC\n\n");
}
}
}
/****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -