mirror of
https://github.com/quorten/macsehw.git
synced 2024-06-04 01:29:31 +00:00
Fix bug with calling decodePramCmd(), improve comments.
Other minor code cleanup.
This commit is contained in:
parent
6328347304
commit
6c1b2ba7d9
|
@ -119,7 +119,7 @@ volatile byte pram[PRAM_SIZE] = {}; // PRAM initialized as zeroed data
|
||||||
volatile byte writeProtect = 0;
|
volatile byte writeProtect = 0;
|
||||||
|
|
||||||
#define shiftReadPB(output, bitNum, portBit) \
|
#define shiftReadPB(output, bitNum, portBit) \
|
||||||
bitWrite(output, bitNum, (PINB&_BV(portBit)) ? 1 : 0)
|
bitWrite(output, bitNum, ((PINB&_BV(portBit))) ? 1 : 0)
|
||||||
|
|
||||||
// Configure a pin to be an open-drain output, currently does nothing
|
// Configure a pin to be an open-drain output, currently does nothing
|
||||||
// as using digitalWriteOD() does all required setup and leaving the
|
// as using digitalWriteOD() does all required setup and leaving the
|
||||||
|
@ -257,7 +257,7 @@ void handleSerClockInterrupt(void) {
|
||||||
*/
|
*/
|
||||||
uint8_t decodePramCmd(boolean writeRequest) {
|
uint8_t decodePramCmd(boolean writeRequest) {
|
||||||
// Discard the first bit and the last two bits, it's not pertinent
|
// Discard the first bit and the last two bits, it's not pertinent
|
||||||
// to command interpretation.
|
// to address interpretation.
|
||||||
address = (address&~(1<<7))>>2;
|
address = (address&~(1<<7))>>2;
|
||||||
if (address < 8) {
|
if (address < 8) {
|
||||||
// Little endian clock data byte
|
// Little endian clock data byte
|
||||||
|
@ -327,12 +327,12 @@ void loop(void) {
|
||||||
} else {
|
} else {
|
||||||
boolean finished = false;
|
boolean finished = false;
|
||||||
// Decode the command/address.
|
// Decode the command/address.
|
||||||
switch (decodePramCmd(writeRequest)) {
|
switch (decodePramCmd(false)) {
|
||||||
case SECONDS_CMD:
|
case SECONDS_CMD:
|
||||||
// Read little endian clock data byte.
|
// Read little endian clock data byte.
|
||||||
cli(); // Ensure that reads are atomic.
|
cli(); // Ensure that reads are atomic.
|
||||||
address = (address&0x03)<<3;
|
address = (address&0x03)<<3;
|
||||||
serialData = (seconds>>(address))&0xff;
|
serialData = (seconds>>address)&0xff;
|
||||||
sei();
|
sei();
|
||||||
break;
|
break;
|
||||||
case SUCCESS_ADDR:
|
case SUCCESS_ADDR:
|
||||||
|
@ -363,20 +363,20 @@ void loop(void) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Decode the command/address.
|
// Decode the command/address.
|
||||||
switch (decodePramCmd(writeRequest)) {
|
switch (decodePramCmd(true)) {
|
||||||
case SECONDS_CMD:
|
case SECONDS_CMD:
|
||||||
if (!writeProtect) {
|
if (!writeProtect) {
|
||||||
// Write little endian clock data byte.
|
// Write little endian clock data byte.
|
||||||
cli(); // Ensure that writes are atomic.
|
cli(); // Ensure that writes are atomic.
|
||||||
address = (address&0x03)<<3;
|
address = (address&0x03)<<3;
|
||||||
seconds &= ~(0xff<<(address));
|
seconds &= ~(0xff<<address);
|
||||||
seconds |= serialData<<(address);
|
seconds |= serialData<<address;
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WRPROT_CMD:
|
case WRPROT_CMD:
|
||||||
// Update the write-protect register.
|
// Update the write-protect register.
|
||||||
writeProtect = (serialData & 0x80) ? 1 : 0;
|
writeProtect = ((serialData & 0x80)) ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
case SUCCESS_ADDR:
|
case SUCCESS_ADDR:
|
||||||
if (!writeProtect)
|
if (!writeProtect)
|
||||||
|
@ -421,6 +421,7 @@ void loop(void) {
|
||||||
address = ((address&0x07)<<5) | ((serialData&0x7c)>>2);
|
address = ((address&0x07)<<5) | ((serialData&0x7c)>>2);
|
||||||
|
|
||||||
if (writeRequest) {
|
if (writeRequest) {
|
||||||
|
// Read the data byte before continuing.
|
||||||
serialState = RECEIVING_XCMD_DATA;
|
serialState = RECEIVING_XCMD_DATA;
|
||||||
serialBitNum = 0;
|
serialBitNum = 0;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user