diff --git a/external_mem.c b/external_mem.c index 0ae6327..86e44c9 100644 --- a/external_mem.c +++ b/external_mem.c @@ -9,7 +9,7 @@ #include "ports.h" #include -#define NUM_ADDRESS_LINES 20 +#define HIGHEST_ADDRESS_LINE 20 // Allow this to be initialized more than once. // In case we mess with the port settings, @@ -22,11 +22,11 @@ void ExternalMem_Init(void) // Disable all pull-ups, on both the address and data lines. They aren't needed // for normal operation. - Ports_AddressPullups_RMW(0, (1UL << (NUM_ADDRESS_LINES - 1)) - 1); + Ports_AddressPullups_RMW(0, (1UL << (HIGHEST_ADDRESS_LINE + 1)) - 1); Ports_DataPullups_RMW(0, 0xFFFFFFFFUL); // Configure all address lines as outputs - Ports_SetAddressDDR((1UL << (NUM_ADDRESS_LINES - 1)) - 1); + Ports_SetAddressDDR((1UL << (HIGHEST_ADDRESS_LINE - 1)) - 1); // Sensible defaults for address and data lines: // Write out address zero diff --git a/tests/simm_electrical_test.c b/tests/simm_electrical_test.c index adb46b0..e13e104 100644 --- a/tests/simm_electrical_test.c +++ b/tests/simm_electrical_test.c @@ -6,11 +6,37 @@ */ #include "simm_electrical_test.h" +#include "../ports.h" + +#define SIMM_HIGHEST_ADDRESS_LINE 18 int SIMMElectricalTest_Run(void) { // Returns number of errors found int numErrors = 0; + Ports_Init(); + + // 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. + Ports_SetAddressDDR(0); + Ports_SetDataDDR(0); + Ports_AddressPullups_RMW((1UL << (SIMM_HIGHEST_ADDRESS_LINE + 1)) - 1, (1UL << (SIMM_HIGHEST_ADDRESS_LINE + 1)) - 1); + Ports_DataPullups_RMW(0xFFFFFFFFUL, 0xFFFFFFFFUL); + + // TODO: Wait a sec? + + if (Ports_ReadAddress() != (1UL << (SIMM_HIGHEST_ADDRESS_LINE + 1)) - 1) + { + // TODO: Log all these errors somewhere? + numErrors++; + } + + if (Ports_ReadData() != 0xFFFFFFFFUL) + { + // TODO: Log all these errors somewhere? + numErrors++; + } + return numErrors; }