Fix a few minor issues

I noticed that after I implemented the SPI optimization of cycle
counting instead of polling on SPIF, the first "normal" SPI transaction
I tried would fail. This is because nothing was clearing the SPIF flag
anymore, and the normal SPI driver still looks at it. So it was thinking
that the latest transaction was already completed (it wasn't). Worked
around this by making sure we clear the flag in SPI_Assert. I'm not
concerned about performance impact here because the actual clean SPI
driver is not used in performance-bound situations.

Fixed an issue that identified the wrong pins as shorted to ground in
the electrical test functionality. Whoops!
This commit is contained in:
Doug Brown 2020-11-26 19:38:57 -08:00 committed by Doug Brown
parent 39f34d67c4
commit 82df6ea459
3 changed files with 40 additions and 34 deletions

View File

@ -101,7 +101,7 @@ void ParallelBus_Init(void)
// Set all data lines to pulled-up inputs
ParallelBus_SetDataDir(0);
ParallelBus_SetDataPullups(0xFFFFFFFF);
ParallelBus_SetDataPullups(0xFFFFFFFFUL);
dataIsOutput = false;
// Note: During normal operation of read/write cycles, the pullups in the
// MCP23S17 will remember they are enabled, so we can do an optimization

View File

@ -157,6 +157,18 @@ void SPI_ReleaseBus(SPIDevice *spi)
void SPI_Assert(SPIDevice *spi)
{
GPIO_SetOff(spi->csPin);
// Due to the optimization we do in ParallelBus talking directly to the
// SPI hardware without going through this driver, we need to make sure
// that the SPIF flag is cleared here. Otherwise we may think we're done
// too early, which would cause us to screw up the next SPI transfer.
// This happens because the optimized code doesn't look at SPSR, so the
// SPIF flag never gets cleared from the previous SPI operation.
if (SPSR & (1 << SPIF))
{
// Reading the data register clears the flag if it's set
(void)SPDR;
}
}
/** Deasserts an SPI device's chip select pin

View File

@ -93,7 +93,7 @@ int SIMMElectricalTest_Run(void (*errorHandler)(uint8_t, uint8_t))
// (We have to ignore them during the second phase of the test)
SIMMElectricalTest_ResetGroundShorts();
// First check for anything shorted to ground. Set all lines as inputs wit
// First check for anything shorted to ground. Set all lines as inputs with
// a weak pull-up resistor. Then read the values back and check for any
// zeros. This would indicate a short to ground.
ParallelBus_SetAddressDir(0);
@ -116,53 +116,47 @@ int SIMMElectricalTest_Run(void (*errorHandler)(uint8_t, uint8_t))
// Read the address pins back first
uint32_t readback = ParallelBus_ReadAddress();
if (readback != SIMM_ADDRESS_PINS_MASK)
// Check each bit for a LOW which would indicate a short to ground
for (i = 0; i <= SIMM_HIGHEST_ADDRESS_LINE; i++)
{
// Check each bit for a LOW which would indicate a short to ground
for (i = 0; i <= SIMM_HIGHEST_ADDRESS_LINE; i++)
// Did we find a low bit?
if (!(readback & 1))
{
// Did we find a low bit?
if (!(readback & 1))
// That means this pin is shorted to ground.
// So notify the caller that we have a ground short on this pin
if (errorHandler)
{
// That means this pin is shorted to ground.
// So notify the caller that we have a ground short on this pin
if (errorHandler)
{
errorHandler(curPin, GROUND_FAIL_INDEX);
}
// Add it to our internal list of ground shorts also.
SIMMElectricalTest_AddGroundShort(curPin);
// And of course increment the error counter.
numErrors++;
errorHandler(curPin, GROUND_FAIL_INDEX);
}
// No matter what, though, move on to the next bit and pin.
readback >>= 1;
curPin++;
// Add it to our internal list of ground shorts also.
SIMMElectricalTest_AddGroundShort(curPin);
// And of course increment the error counter.
numErrors++;
}
// No matter what, though, move on to the next bit and pin.
readback >>= 1;
curPin++;
}
// Repeat the exact same process for the data pins
readback = ParallelBus_ReadData();
if (readback != SIMM_DATA_PINS_MASK)
for (i = 0; i <= SIMM_HIGHEST_DATA_LINE; i++)
{
for (i = 0; i <= SIMM_HIGHEST_DATA_LINE; i++)
if (!(readback & 1))
{
if (!(readback & 1))
if (errorHandler)
{
if (errorHandler)
{
errorHandler(curPin, GROUND_FAIL_INDEX);
}
SIMMElectricalTest_AddGroundShort(curPin);
numErrors++;
errorHandler(curPin, GROUND_FAIL_INDEX);
}
readback >>= 1;
curPin++;
SIMMElectricalTest_AddGroundShort(curPin);
numErrors++;
}
readback >>= 1;
curPin++;
}
// Check chip select in the same way...