Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use chip size for selected commands where it makes sense #70

Merged
merged 8 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TommyPROM/PromDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PromDevice
byte readData(uint32_t address) { return readByte(address); }
void resetDebugStats();
void printDebugStats();
uint32_t end() const { return mSize-1; }

virtual void begin() = 0;
virtual const char * getName() = 0;
Expand Down
61 changes: 42 additions & 19 deletions TommyPROM/TommyPROM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "XModem.h"


static const char * MY_VERSION = "3.4";
static const char * MY_VERSION = "3.5";


// Global status
Expand Down Expand Up @@ -95,6 +95,8 @@ XModem xmodem(prom, cmdStatus);
* CLI parse functions
*/
const char hex[] = "0123456789abcdef";
const uint32_t unspec = ~0;
inline uint32_t if_unspec(uint32_t val, uint32_t repl) { return val == unspec? repl: val; }

enum {
// CLI Commands
Expand Down Expand Up @@ -220,7 +222,7 @@ byte hexDigit(char c)
* @param pointer to string with the hex value of the word (modified)
* @return unsigned int represented by the digits
************************************************************/
uint32_t getHex32(char *& pData, uint32_t defaultValue=0)
uint32_t getHex32(char *& pData, uint32_t defaultValue=unspec)
{
uint32_t u32 = 0;

Expand Down Expand Up @@ -346,7 +348,7 @@ word checksumBlock(uint32_t start, uint32_t end)
/**
* Read data from the device and dump it in hex and ascii.
**/
void dumpBlock(uint32_t start, uint32_t end)
uint32_t dumpBlock(uint32_t start, uint32_t end)
{
char line[81];
// 01234567891 234567892 234567893 234567894 234567895 234567896 234567897 23456789
Expand Down Expand Up @@ -393,7 +395,7 @@ void dumpBlock(uint32_t start, uint32_t end)
Serial.println(line);
if (checkForBreak())
{
return;
return addr;
}
memset(line, ' ', sizeof(line));
count = 0;
Expand All @@ -404,6 +406,8 @@ void dumpBlock(uint32_t start, uint32_t end)
{
Serial.println();
}

return end+1;
}


Expand Down Expand Up @@ -476,7 +480,7 @@ void pokeBytes(char * pCursor)
//first value returned is the starting address
start = getHex32(pCursor, 0);

while (((val = getHex32(pCursor, 0xffff)) != 0xffff) && (byteCtr < BLOCK_SIZE))
while (((val = getHex32(pCursor)) != unspec) && (byteCtr < BLOCK_SIZE))
{
data[byteCtr++] = byte(val);
}
Expand Down Expand Up @@ -682,7 +686,7 @@ void setup()
char line[120];
uint32_t start = 0;
uint32_t end = 0xff;
byte val = 0xff;
uint32_t val = 0xff;

void loop()
{
Expand All @@ -695,9 +699,9 @@ void loop()
Serial.println();
byte cmd = parseCommand(line[0]);
char * pCursor = line+1;
start = getHex32(pCursor, 0);
end = getHex32(pCursor, 0xff);
val = (byte) getHex32(pCursor, 0);
start = getHex32(pCursor, start);
end = getHex32(pCursor);
val = (byte) getHex32(pCursor);

if ((cmd != CMD_LAST_STATUS) && (cmd != CMD_INVALID))
{
Expand All @@ -707,10 +711,12 @@ void loop()
switch (cmd)
{
case CMD_BLANK:
erasedBlockCheck(start, end);
erasedBlockCheck(if_unspec(start, 0), if_unspec(end, prom.end()));
break;

case CMD_CHECKSUM:
start = if_unspec(start, 0);
end = if_unspec(end, prom.end());
w = checksumBlock(start, end);
Serial.print(F("Checksum "));
printWord(start);
Expand All @@ -722,16 +728,30 @@ void loop()
break;

case CMD_DUMP:
dumpBlock(start, end);
start = dumpBlock(start, start + if_unspec(end, 0xff));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be
if_unspec(end, start+0xff)
otherwise d 100 1ff would dump from 100 to 2ff instead of 100 to 1ff
Am I reading that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right; will fix.

break;

case CMD_ERASE:
printRetStatus(prom.erase(start, end));
if (start == unspec || end == unspec)
{
Serial.println(F("Erase requires explicit start, end"));
}
else
{
printRetStatus(prom.erase(start, end));
}
break;

case CMD_FILL:
prom.resetDebugStats();
fillBlock(start, end, val);
if (start == unspec || end == unspec || val == unspec)
{
Serial.println(F("Fill requires explicit start, end and value"));
}
else
{
prom.resetDebugStats();
fillBlock(start, end, (byte)val);
}
break;

case CMD_LOCK:
Expand All @@ -745,10 +765,12 @@ void loop()
break;

case CMD_READ:
if (xmodem.SendFile(start, uint32_t(end) - start + 1))
start = if_unspec(start, 0);
end = if_unspec(end, prom.end());
if (xmodem.SendFile(start, end - start + 1))
{
cmdStatus.info("Send complete.");
cmdStatus.setValueDec(0, "NumBytes", uint32_t(end) - start + 1);
cmdStatus.setValueDec(0, "NumBytes", end - start + 1);
}
break;

Expand All @@ -759,6 +781,7 @@ void loop()

case CMD_WRITE:
prom.resetDebugStats();
start = if_unspec(start, 0);
numBytes = xmodem.ReceiveFile(start);
if (numBytes)
{
Expand All @@ -777,16 +800,16 @@ void loop()
break;

case CMD_SCAN:
scanBlock(start, end);
scanBlock(if_unspec(start, 0), if_unspec(end, prom.end()));
break;

case CMD_TEST:
testAddr(start);
testAddr(if_unspec(start, 0));
break;

case CMD_ZAP:
prom.resetDebugStats();
zapTest(start);
zapTest(if_unspec(start, 0));
break;
#endif /* ENABLE_DEBUG_COMMANDS */

Expand Down