Started implementing electrical test that tells what pins are shorted to what

This commit is contained in:
Doug Brown 2011-12-18 10:18:30 -08:00
parent 52d33e077f
commit 9054aaff0f
3 changed files with 120 additions and 30 deletions

View File

@ -27,7 +27,10 @@ typedef enum ElectricalTestStage
DoneTesting DoneTesting
} ElectricalTestStage; } ElectricalTestStage;
int SIMMElectricalTest_Run(void) // TODO: Remember which lines shorted to ground and don't repeat those errors as being
// shorted to each other?
int SIMMElectricalTest_Run(void (*errorHandler)(uint8_t, uint8_t))
{ {
// Returns number of errors found // Returns number of errors found
int numErrors = 0; int numErrors = 0;
@ -51,33 +54,66 @@ int SIMMElectricalTest_Run(void)
DelayMS(DELAY_SETTLE_TIME_MS); DelayMS(DELAY_SETTLE_TIME_MS);
if (Ports_ReadAddress() != SIMM_ADDRESS_PINS_MASK) uint8_t testPinFailIndex;
uint8_t failIndex;
uint32_t readback = Ports_ReadAddress();
if (readback != SIMM_ADDRESS_PINS_MASK)
{ {
// TODO: Log all these errors somewhere? failIndex = FIRST_ADDRESS_LINE_FAIL_INDEX;
numErrors++;
// At this point, any errors will manifest as 0 bits. It's easier to test for errors by turning them
// into 1 bits, so invert the readback -- now, shorted pins are 1s and non-shorted pins are 0s
readback = ~readback & SIMM_ADDRESS_PINS_MASK;
// As long as there are any 1 bits, there is a short detected.
while (readback)
{
if (readback & 1) // failure here?
{
errorHandler(failIndex, GROUND_FAIL_INDEX);
} }
if (Ports_ReadData() != SIMM_DATA_PINS_MASK) readback >>= 1;
{ failIndex++;
// TODO: Log all these errors somewhere?
numErrors++; numErrors++;
} }
}
readback = Ports_ReadData();
if (readback != SIMM_DATA_PINS_MASK)
{
failIndex = FIRST_DATA_LINE_FAIL_INDEX;
readback = ~readback;
while (readback)
{
if (readback & 1) // failure here?
{
errorHandler(failIndex, GROUND_FAIL_INDEX);
}
readback >>= 1;
failIndex++;
numErrors++;
}
}
if (!Ports_ReadCS()) if (!Ports_ReadCS())
{ {
// TODO: Log all these errors somewhere? errorHandler(CS_FAIL_INDEX, GROUND_FAIL_INDEX);
numErrors++; numErrors++;
} }
if (!Ports_ReadOE()) if (!Ports_ReadOE())
{ {
// TODO: Log all these errors somewhere? errorHandler(OE_FAIL_INDEX, GROUND_FAIL_INDEX);
numErrors++; numErrors++;
} }
if (!Ports_ReadWE()) if (!Ports_ReadWE())
{ {
// TODO: Log all these errors somewhere? errorHandler(WE_FAIL_INDEX, GROUND_FAIL_INDEX);
numErrors++; numErrors++;
} }
@ -91,8 +127,12 @@ int SIMMElectricalTest_Run(void)
// Then read back all the other pins. If any of them read back as 0, // Then read back all the other pins. If any of them read back as 0,
// it means they are shorted to the pin we set as an output. // it means they are shorted to the pin we set as an output.
// This is the fail index of the pin we are outputting a 0 on.
testPinFailIndex = 0;
if (curStage == TestingAddressLines) if (curStage == TestingAddressLines)
{ {
testPinFailIndex = FIRST_ADDRESS_LINE_FAIL_INDEX + x; // fail index of this address line
uint32_t addressLineMask = (1UL << x); // mask of the address pin we're testing uint32_t addressLineMask = (1UL << x); // mask of the address pin we're testing
Ports_SetAddressDDR(addressLineMask); // set it as an output and all other address pins as inputs Ports_SetAddressDDR(addressLineMask); // set it as an output and all other address pins as inputs
@ -107,8 +147,10 @@ int SIMMElectricalTest_Run(void)
Ports_AddressPullups_RMW(SIMM_ADDRESS_PINS_MASK, SIMM_ADDRESS_PINS_MASK); Ports_AddressPullups_RMW(SIMM_ADDRESS_PINS_MASK, SIMM_ADDRESS_PINS_MASK);
} }
if (curStage == TestingDataLines) if (curStage == TestingDataLines)
{ {
testPinFailIndex = FIRST_DATA_LINE_FAIL_INDEX + x;
uint32_t dataLineMask = (1UL << x); uint32_t dataLineMask = (1UL << x);
Ports_SetDataDDR(dataLineMask); Ports_SetDataDDR(dataLineMask);
Ports_DataOut_RMW(0, dataLineMask); Ports_DataOut_RMW(0, dataLineMask);
@ -122,6 +164,7 @@ int SIMMElectricalTest_Run(void)
if (curStage == TestingCS) if (curStage == TestingCS)
{ {
testPinFailIndex = CS_FAIL_INDEX;
Ports_SetCSDDR(true); Ports_SetCSDDR(true);
Ports_SetCSOut(false); Ports_SetCSOut(false);
} }
@ -133,6 +176,7 @@ int SIMMElectricalTest_Run(void)
if (curStage == TestingOE) if (curStage == TestingOE)
{ {
testPinFailIndex = OE_FAIL_INDEX;
Ports_SetOEDDR(true); Ports_SetOEDDR(true);
Ports_SetOEOut(false); Ports_SetOEOut(false);
} }
@ -144,6 +188,7 @@ int SIMMElectricalTest_Run(void)
if (curStage == TestingWE) if (curStage == TestingWE)
{ {
testPinFailIndex = WE_FAIL_INDEX;
Ports_SetWEDDR(true); Ports_SetWEDDR(true);
Ports_SetWEOut(false); Ports_SetWEOut(false);
} }
@ -159,7 +204,7 @@ int SIMMElectricalTest_Run(void)
DelayMS(DELAY_SETTLE_TIME_MS); DelayMS(DELAY_SETTLE_TIME_MS);
uint32_t readback = Ports_ReadAddress(); readback = Ports_ReadAddress();
if (curStage == TestingAddressLines) if (curStage == TestingAddressLines)
{ {
// Insert a high bit so our test doesn't fail on the pin we were testing // Insert a high bit so our test doesn't fail on the pin we were testing
@ -170,15 +215,19 @@ int SIMMElectricalTest_Run(void)
// into 1 bits, so invert the readback so shorted pins are 1s and non-shorted pins are 0s // into 1 bits, so invert the readback so shorted pins are 1s and non-shorted pins are 0s
readback = ~readback & SIMM_ADDRESS_PINS_MASK; readback = ~readback & SIMM_ADDRESS_PINS_MASK;
failIndex = FIRST_ADDRESS_LINE_FAIL_INDEX;
// Count any shorted pins // Count any shorted pins
while (readback) while (readback)
{ {
numErrors++; if (readback & 1) // failure here?
{
errorHandler(testPinFailIndex, failIndex);
}
// The line below turns off the rightmost bit readback >>= 1;
// TODO: This will be useless unless I determine WHICH pin it is. failIndex++;
// But this makes a good placeholder for now. numErrors++;
readback = readback & (readback - 1);
} }
readback = Ports_ReadData(); readback = Ports_ReadData();
@ -191,24 +240,27 @@ int SIMMElectricalTest_Run(void)
// Again, invert readback so shorted pins are 1s and non-shorted pins are 0s // Again, invert readback so shorted pins are 1s and non-shorted pins are 0s
readback = ~readback; readback = ~readback;
failIndex = FIRST_DATA_LINE_FAIL_INDEX;
// Count any shorted pins // Count any shorted pins
while (readback) while (readback)
{ {
numErrors++; if (readback & 1) // failure here?
{
errorHandler(testPinFailIndex, failIndex);
}
// The line below turns off the rightmost bit readback >>= 1;
// TODO: This will be useless unless I determine WHICH pin it is. failIndex++;
// But this makes a good placeholder for now. numErrors++;
readback = readback & (readback - 1);
} }
if (curStage != TestingCS) if (curStage != TestingCS)
{ {
if (!Ports_ReadCS()) if (!Ports_ReadCS())
{ {
errorHandler(testPinFailIndex, CS_FAIL_INDEX);
numErrors++; numErrors++;
// TODO: Report this error
} }
} }
@ -216,9 +268,8 @@ int SIMMElectricalTest_Run(void)
{ {
if (!Ports_ReadOE()) if (!Ports_ReadOE())
{ {
errorHandler(testPinFailIndex, OE_FAIL_INDEX);
numErrors++; numErrors++;
// TODO: Report this error
} }
} }
@ -226,9 +277,8 @@ int SIMMElectricalTest_Run(void)
{ {
if (!Ports_ReadWE()) if (!Ports_ReadWE())
{ {
errorHandler(testPinFailIndex, WE_FAIL_INDEX);
numErrors++; numErrors++;
// TODO: Report this error
} }
} }

View File

@ -8,6 +8,18 @@
#ifndef SIMM_ELECTRICAL_TEST_H_ #ifndef SIMM_ELECTRICAL_TEST_H_
#define SIMM_ELECTRICAL_TEST_H_ #define SIMM_ELECTRICAL_TEST_H_
int SIMMElectricalTest_Run(void); #include <stdint.h>
#define GROUND_FAIL_INDEX 0xFF
#define FIRST_ADDRESS_LINE_FAIL_INDEX 0
#define LAST_ADDRESS_LINE_FAIL_INDEX (FIRST_ADDRESS_LINE_FAIL_INDEX + 20)
#define FIRST_DATA_LINE_FAIL_INDEX (LAST_ADDRESS_LINE_FAIL_INDEX + 1)
#define LAST_DATA_LINE_FAIL_INDEX (FIRST_DATA_LINE_FAIL_INDEX + 31)
#define CS_FAIL_INDEX (LAST_DATA_LINE_FAIL_INDEX + 1)
#define OE_FAIL_INDEX (CS_FAIL_INDEX + 1)
#define WE_FAIL_INDEX (OE_FAIL_INDEX + 1)
int SIMMElectricalTest_Run(void (*errorHandler)(uint8_t, uint8_t));
#endif /* SIMM_ELECTRICAL_TEST_H_ */ #endif /* SIMM_ELECTRICAL_TEST_H_ */

View File

@ -102,6 +102,17 @@ typedef enum ProgrammerWriteReply
ProgrammerWriteConfirmCancel ProgrammerWriteConfirmCancel
} ProgrammerWriteReply; } ProgrammerWriteReply;
typedef enum ProgrammerIdentifyReply
{
ProgrammerIdentifyDone
} ProgrammerIdentifyReply;
typedef enum ProgrammerElectricalTestReply
{
ProgrammerElectricalTestFail,
ProgrammerElectricalTestDone
};
static ProgrammerCommandState curCommandState = WaitingForCommand; static ProgrammerCommandState curCommandState = WaitingForCommand;
static uint8_t byteAddressReceiveCount = 0; static uint8_t byteAddressReceiveCount = 0;
static uint16_t curReadIndex; static uint16_t curReadIndex;
@ -112,6 +123,7 @@ void USBSerial_HandleWaitingForCommandByte(uint8_t byte);
void USBSerial_HandleReadingChipsByte(uint8_t byte); void USBSerial_HandleReadingChipsByte(uint8_t byte);
void USBSerial_SendReadDataChunk(void); void USBSerial_SendReadDataChunk(void);
void USBSerial_HandleWritingChipsByte(uint8_t byte); void USBSerial_HandleWritingChipsByte(uint8_t byte);
void USBSerial_ElectricalTest_Fail_Handler(uint8_t index1, uint8_t index2);
#define SendByte(b) CDC_Device_SendByte(&VirtualSerial_CDC_Interface, b) #define SendByte(b) CDC_Device_SendByte(&VirtualSerial_CDC_Interface, b)
#define ReadByte() CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface) #define ReadByte() CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface)
@ -231,7 +243,8 @@ void USBSerial_HandleWaitingForCommandByte(uint8_t byte)
break; break;
case DoElectricalTest: case DoElectricalTest:
SendByte(CommandReplyOK); SendByte(CommandReplyOK);
SIMMElectricalTest_Run(); SIMMElectricalTest_Run(USBSerial_ElectricalTest_Fail_Handler);
SendByte(ProgrammerElectricalTestDone);
curCommandState = WaitingForCommand; curCommandState = WaitingForCommand;
break; break;
case IdentifyChips: case IdentifyChips:
@ -239,7 +252,13 @@ void USBSerial_HandleWaitingForCommandByte(uint8_t byte)
struct ChipID chips[4]; struct ChipID chips[4];
SendByte(CommandReplyOK); SendByte(CommandReplyOK);
ExternalMem_IdentifyChips(chips); ExternalMem_IdentifyChips(chips);
// TODO: Send chip ID info back to receiver int x;
for (x = 0; x < 4; x++)
{
SendByte(chips[x].manufacturerID);
SendByte(chips[x].deviceID);
}
SendByte(ProgrammerIdentifyDone);
break; break;
} }
case ReadByte: case ReadByte:
@ -364,6 +383,15 @@ void USBSerial_HandleWritingChipsByte(uint8_t byte)
} }
} }
void USBSerial_ElectricalTest_Fail_Handler(uint8_t index1, uint8_t index2)
{
// Sends out a failure notice -- followed by indexes of the two shorted pins
SendByte(ProgrammerElectricalTestFail);
SendByte(index1);
SendByte(index2);
}
/** Event handler for the library USB Configuration Changed event. */ /** Event handler for the library USB Configuration Changed event. */