mirror of
https://github.com/TomNisbet/TommyPROM.git
synced 2024-11-21 19:31:12 +00:00
Merge pull request #70 from jscrane/master
Use chip size for selected commands where it makes sense
This commit is contained in:
commit
90e29d2e50
@ -29,6 +29,7 @@ class PromDevice
|
|||||||
byte readData(uint32_t address) { return readByte(address); }
|
byte readData(uint32_t address) { return readByte(address); }
|
||||||
void resetDebugStats();
|
void resetDebugStats();
|
||||||
void printDebugStats();
|
void printDebugStats();
|
||||||
|
uint32_t end() const { return mSize-1; }
|
||||||
|
|
||||||
virtual void begin() = 0;
|
virtual void begin() = 0;
|
||||||
virtual const char * getName() = 0;
|
virtual const char * getName() = 0;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include "XModem.h"
|
#include "XModem.h"
|
||||||
|
|
||||||
|
|
||||||
static const char * MY_VERSION = "3.4";
|
static const char * MY_VERSION = "3.5";
|
||||||
|
|
||||||
|
|
||||||
// Global status
|
// Global status
|
||||||
@ -95,6 +95,8 @@ XModem xmodem(prom, cmdStatus);
|
|||||||
* CLI parse functions
|
* CLI parse functions
|
||||||
*/
|
*/
|
||||||
const char hex[] = "0123456789abcdef";
|
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 {
|
enum {
|
||||||
// CLI Commands
|
// CLI Commands
|
||||||
@ -220,7 +222,7 @@ byte hexDigit(char c)
|
|||||||
* @param pointer to string with the hex value of the word (modified)
|
* @param pointer to string with the hex value of the word (modified)
|
||||||
* @return unsigned int represented by the digits
|
* @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;
|
uint32_t u32 = 0;
|
||||||
|
|
||||||
@ -346,7 +348,7 @@ word checksumBlock(uint32_t start, uint32_t end)
|
|||||||
/**
|
/**
|
||||||
* Read data from the device and dump it in hex and ascii.
|
* 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];
|
char line[81];
|
||||||
// 01234567891 234567892 234567893 234567894 234567895 234567896 234567897 23456789
|
// 01234567891 234567892 234567893 234567894 234567895 234567896 234567897 23456789
|
||||||
@ -393,7 +395,7 @@ void dumpBlock(uint32_t start, uint32_t end)
|
|||||||
Serial.println(line);
|
Serial.println(line);
|
||||||
if (checkForBreak())
|
if (checkForBreak())
|
||||||
{
|
{
|
||||||
return;
|
return addr;
|
||||||
}
|
}
|
||||||
memset(line, ' ', sizeof(line));
|
memset(line, ' ', sizeof(line));
|
||||||
count = 0;
|
count = 0;
|
||||||
@ -404,6 +406,8 @@ void dumpBlock(uint32_t start, uint32_t end)
|
|||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return end+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -476,7 +480,7 @@ void pokeBytes(char * pCursor)
|
|||||||
//first value returned is the starting address
|
//first value returned is the starting address
|
||||||
start = getHex32(pCursor, 0);
|
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);
|
data[byteCtr++] = byte(val);
|
||||||
}
|
}
|
||||||
@ -680,9 +684,6 @@ void setup()
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
char line[120];
|
char line[120];
|
||||||
uint32_t start = 0;
|
|
||||||
uint32_t end = 0xff;
|
|
||||||
byte val = 0xff;
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
@ -695,9 +696,10 @@ void loop()
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
byte cmd = parseCommand(line[0]);
|
byte cmd = parseCommand(line[0]);
|
||||||
char * pCursor = line+1;
|
char * pCursor = line+1;
|
||||||
start = getHex32(pCursor, 0);
|
uint32_t start = getHex32(pCursor);
|
||||||
end = getHex32(pCursor, 0xff);
|
uint32_t end = getHex32(pCursor);
|
||||||
val = (byte) getHex32(pCursor, 0);
|
uint32_t val = getHex32(pCursor);
|
||||||
|
static uint32_t dump_next = 0;
|
||||||
|
|
||||||
if ((cmd != CMD_LAST_STATUS) && (cmd != CMD_INVALID))
|
if ((cmd != CMD_LAST_STATUS) && (cmd != CMD_INVALID))
|
||||||
{
|
{
|
||||||
@ -707,10 +709,12 @@ void loop()
|
|||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case CMD_BLANK:
|
case CMD_BLANK:
|
||||||
erasedBlockCheck(start, end);
|
erasedBlockCheck(if_unspec(start, 0), if_unspec(end, prom.end()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_CHECKSUM:
|
case CMD_CHECKSUM:
|
||||||
|
start = if_unspec(start, 0);
|
||||||
|
end = if_unspec(end, prom.end());
|
||||||
w = checksumBlock(start, end);
|
w = checksumBlock(start, end);
|
||||||
Serial.print(F("Checksum "));
|
Serial.print(F("Checksum "));
|
||||||
printWord(start);
|
printWord(start);
|
||||||
@ -722,16 +726,31 @@ void loop()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_DUMP:
|
case CMD_DUMP:
|
||||||
dumpBlock(start, end);
|
start = if_unspec(start, dump_next);
|
||||||
|
dump_next = dumpBlock(start, if_unspec(end, start + 0xff));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ERASE:
|
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;
|
break;
|
||||||
|
|
||||||
case CMD_FILL:
|
case CMD_FILL:
|
||||||
prom.resetDebugStats();
|
if (start == unspec || end == unspec || val == unspec)
|
||||||
fillBlock(start, end, val);
|
{
|
||||||
|
Serial.println(F("Fill requires explicit start, end and value"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prom.resetDebugStats();
|
||||||
|
fillBlock(start, end, (byte)val);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_LOCK:
|
case CMD_LOCK:
|
||||||
@ -745,10 +764,12 @@ void loop()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_READ:
|
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.info("Send complete.");
|
||||||
cmdStatus.setValueDec(0, "NumBytes", uint32_t(end) - start + 1);
|
cmdStatus.setValueDec(0, "NumBytes", end - start + 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -759,6 +780,7 @@ void loop()
|
|||||||
|
|
||||||
case CMD_WRITE:
|
case CMD_WRITE:
|
||||||
prom.resetDebugStats();
|
prom.resetDebugStats();
|
||||||
|
start = if_unspec(start, 0);
|
||||||
numBytes = xmodem.ReceiveFile(start);
|
numBytes = xmodem.ReceiveFile(start);
|
||||||
if (numBytes)
|
if (numBytes)
|
||||||
{
|
{
|
||||||
@ -777,16 +799,16 @@ void loop()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SCAN:
|
case CMD_SCAN:
|
||||||
scanBlock(start, end);
|
scanBlock(if_unspec(start, 0), if_unspec(end, prom.end()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_TEST:
|
case CMD_TEST:
|
||||||
testAddr(start);
|
testAddr(if_unspec(start, 0));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ZAP:
|
case CMD_ZAP:
|
||||||
prom.resetDebugStats();
|
prom.resetDebugStats();
|
||||||
zapTest(start);
|
zapTest(if_unspec(start, 0));
|
||||||
break;
|
break;
|
||||||
#endif /* ENABLE_DEBUG_COMMANDS */
|
#endif /* ENABLE_DEBUG_COMMANDS */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user