EEPROM dump (code D3)
This commit is contained in:
parent
9b4f786325
commit
691e7a24ed
5 changed files with 152 additions and 116 deletions
|
@ -1,5 +1,146 @@
|
|||
#include "Dcodes.h"
|
||||
#include "Marlin.h"
|
||||
//#include "Marlin.h"
|
||||
#include "language.h"
|
||||
#include "cmdqueue.h"
|
||||
#include <stdio.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
|
||||
#define DBG(args...) printf_P(args)
|
||||
|
||||
inline void print_hex_nibble(uint8_t val)
|
||||
{
|
||||
putchar((val > 9)?(val - 10 + 'a'):(val + '0'));
|
||||
}
|
||||
|
||||
void print_hex_byte(uint8_t val)
|
||||
{
|
||||
print_hex_nibble(val >> 4);
|
||||
print_hex_nibble(val & 15);
|
||||
}
|
||||
|
||||
void print_hex_word(uint16_t val)
|
||||
{
|
||||
print_hex_byte(val >> 8);
|
||||
print_hex_byte(val & 255);
|
||||
}
|
||||
|
||||
void print_eeprom(uint16_t address, uint16_t count, uint8_t countperline = 16)
|
||||
{
|
||||
while (count)
|
||||
{
|
||||
print_hex_word(address);
|
||||
putchar(' ');
|
||||
uint8_t count_line = countperline;
|
||||
while (count && count_line)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
putchar(' ');
|
||||
print_hex_byte(eeprom_read_byte((uint8_t*)address++));
|
||||
count_line--;
|
||||
count--;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
int parse_hex(char* hex, uint8_t* data, int count)
|
||||
{
|
||||
int parsed = 0;
|
||||
while (*hex)
|
||||
{
|
||||
if (count && (parsed >= count)) break;
|
||||
char c = *(hex++);
|
||||
if (c == ' ') continue;
|
||||
if (c == '\n') break;
|
||||
uint8_t val = 0x00;
|
||||
if ((c >= '0') && (c <= '9')) val |= ((c - '0') << 4);
|
||||
else if ((c >= 'a') && (c <= 'f')) val |= ((c - 'a' + 10) << 4);
|
||||
else return -parsed;
|
||||
c = *(hex++);
|
||||
if ((c >= '0') && (c <= '9')) val |= (c - '0');
|
||||
else if ((c >= 'a') && (c <= 'f')) val |= (c - 'a' + 10);
|
||||
else return -parsed;
|
||||
data[parsed] = val;
|
||||
parsed++;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperline = 16)
|
||||
{
|
||||
while (count)
|
||||
{
|
||||
if (type == 2)
|
||||
print_hex_nibble(address >> 16);
|
||||
print_hex_word(address);
|
||||
putchar(' ');
|
||||
uint8_t count_line = countperline;
|
||||
while (count && count_line)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
switch (type)
|
||||
{
|
||||
case 0: data = *((uint8_t*)address++); break;
|
||||
case 1: data = eeprom_read_byte((uint8_t*)address++); break;
|
||||
case 2: data = pgm_read_byte_far((uint8_t*)address++); break;
|
||||
}
|
||||
putchar(' ');
|
||||
print_hex_byte(data);
|
||||
count_line--;
|
||||
count--;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DCODE3
|
||||
#define EEPROM_SIZE 0x1000
|
||||
void dcode_3()
|
||||
{
|
||||
DBG(_N("D3 - Read/Write EEPROM\n"));
|
||||
uint16_t address = 0x0000; //default 0x0000
|
||||
uint16_t count = EEPROM_SIZE; //default 0x1000 (entire eeprom)
|
||||
if (code_seen('A')) // Address (0x0000-0x0fff)
|
||||
address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value();
|
||||
if (code_seen('C')) // Count (0x0001-0x1000)
|
||||
count = (int)code_value();
|
||||
address &= 0x1fff;
|
||||
if (count > EEPROM_SIZE) count = EEPROM_SIZE;
|
||||
if ((address + count) > EEPROM_SIZE) count = EEPROM_SIZE - address;
|
||||
if (code_seen('X')) // Data
|
||||
{
|
||||
uint8_t data[16];
|
||||
count = parse_hex(strchr_pointer + 1, data, 16);
|
||||
if (count > 0)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
eeprom_write_byte((uint8_t*)(address + i), data[i]);
|
||||
printf_P(_N("%d bytes written to EEPROM at address 0x%04x"), count, address);
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
count = 0;
|
||||
}
|
||||
print_mem(address, count, 1);
|
||||
/* while (count)
|
||||
{
|
||||
print_hex_word(address);
|
||||
putchar(' ');
|
||||
uint8_t countperline = 16;
|
||||
while (count && countperline)
|
||||
{
|
||||
uint8_t data = eeprom_read_byte((uint8_t*)address++);
|
||||
putchar(' ');
|
||||
print_hex_byte(data);
|
||||
countperline--;
|
||||
count--;
|
||||
}
|
||||
putchar('\n');
|
||||
}*/
|
||||
}
|
||||
#endif //DEBUG_DCODE3
|
||||
|
||||
#ifdef DEBUG_DCODES
|
||||
|
||||
|
@ -29,76 +170,9 @@ extern float current_temperature_pinda;
|
|||
extern float axis_steps_per_unit[NUM_AXIS];
|
||||
|
||||
|
||||
inline void print_hex_nibble(uint8_t val)
|
||||
{
|
||||
putchar((val > 9)?(val - 10 + 'a'):(val + '0'));
|
||||
}
|
||||
|
||||
void print_hex_byte(uint8_t val)
|
||||
{
|
||||
print_hex_nibble(val >> 4);
|
||||
print_hex_nibble(val & 15);
|
||||
}
|
||||
|
||||
void print_hex_word(uint16_t val)
|
||||
{
|
||||
print_hex_byte(val >> 8);
|
||||
print_hex_byte(val & 255);
|
||||
}
|
||||
|
||||
void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperline = 16)
|
||||
{
|
||||
while (count)
|
||||
{
|
||||
if (type == 2)
|
||||
print_hex_nibble(address >> 16);
|
||||
print_hex_word(address);
|
||||
putchar(' ');
|
||||
uint8_t count_line = countperline;
|
||||
while (count && count_line)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
switch (type)
|
||||
{
|
||||
case 0: data = *((uint8_t*)address++); break;
|
||||
case 1: data = eeprom_read_byte((uint8_t*)address++); break;
|
||||
case 2: data = pgm_read_byte_far((uint8_t*)address++); break;
|
||||
}
|
||||
putchar(' ');
|
||||
print_hex_byte(data);
|
||||
count_line--;
|
||||
count--;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
//#define LOG(args...) printf(args)
|
||||
#define LOG(args...)
|
||||
|
||||
int parse_hex(char* hex, uint8_t* data, int count)
|
||||
{
|
||||
int parsed = 0;
|
||||
while (*hex)
|
||||
{
|
||||
if (count && (parsed >= count)) break;
|
||||
char c = *(hex++);
|
||||
if (c == ' ') continue;
|
||||
if (c == '\n') break;
|
||||
uint8_t val = 0x00;
|
||||
if ((c >= '0') && (c <= '9')) val |= ((c - '0') << 4);
|
||||
else if ((c >= 'a') && (c <= 'f')) val |= ((c - 'a' + 10) << 4);
|
||||
else return -parsed;
|
||||
c = *(hex++);
|
||||
if ((c >= '0') && (c <= '9')) val |= (c - '0');
|
||||
else if ((c >= 'a') && (c <= 'f')) val |= (c - 'a' + 10);
|
||||
else return -parsed;
|
||||
data[parsed] = val;
|
||||
parsed++;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
void dcode__1()
|
||||
{
|
||||
printf("D-1 - Endless loop\n");
|
||||
|
@ -177,52 +251,6 @@ void dcode_2()
|
|||
}*/
|
||||
}
|
||||
|
||||
void dcode_3()
|
||||
{
|
||||
LOG("D3 - Read/Write EEPROM\n");
|
||||
uint16_t address = 0x0000; //default 0x0000
|
||||
uint16_t count = 0x2000; //default 0x2000 (entire eeprom)
|
||||
if (code_seen('A')) // Address (0x0000-0x1fff)
|
||||
address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value();
|
||||
if (code_seen('C')) // Count (0x0001-0x2000)
|
||||
count = (int)code_value();
|
||||
address &= 0x1fff;
|
||||
if (count > 0x2000) count = 0x2000;
|
||||
if ((address + count) > 0x2000) count = 0x2000 - address;
|
||||
if (code_seen('X')) // Data
|
||||
{
|
||||
uint8_t data[16];
|
||||
count = parse_hex(strchr_pointer + 1, data, 16);
|
||||
if (count > 0)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
eeprom_write_byte((uint8_t*)(address + i), data[i]);
|
||||
LOG(count, DEC);
|
||||
LOG(" bytes written to EEPROM at address ");
|
||||
print_hex_word(address);
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
count = 0;
|
||||
}
|
||||
print_mem(address, count, 1);
|
||||
/* while (count)
|
||||
{
|
||||
print_hex_word(address);
|
||||
putchar(' ');
|
||||
uint8_t countperline = 16;
|
||||
while (count && countperline)
|
||||
{
|
||||
uint8_t data = eeprom_read_byte((uint8_t*)address++);
|
||||
putchar(' ');
|
||||
print_hex_byte(data);
|
||||
countperline--;
|
||||
count--;
|
||||
}
|
||||
putchar('\n');
|
||||
}*/
|
||||
}
|
||||
|
||||
void dcode_4()
|
||||
{
|
||||
LOG("D4 - Read/Write PIN\n");
|
||||
|
|
|
@ -7125,11 +7125,11 @@ while (!lcd_clicked() && (counterBeep < 50)) {
|
|||
}
|
||||
} // end if(code_seen('T')) (end of T codes)
|
||||
|
||||
#ifdef DEBUG_DCODES
|
||||
else if (code_seen('D')) // D codes (debug)
|
||||
{
|
||||
switch((int)code_value())
|
||||
{
|
||||
#ifdef DEBUG_DCODES
|
||||
case -1: // D-1 - Endless loop
|
||||
dcode__1(); break;
|
||||
case 0: // D0 - Reset
|
||||
|
@ -7138,8 +7138,12 @@ while (!lcd_clicked() && (counterBeep < 50)) {
|
|||
dcode_1(); break;
|
||||
case 2: // D2 - Read/Write RAM
|
||||
dcode_2(); break;
|
||||
#endif //DEBUG_DCODES
|
||||
#ifdef DEBUG_DCODE3
|
||||
case 3: // D3 - Read/Write EEPROM
|
||||
dcode_3(); break;
|
||||
#endif //DEBUG_DCODE3
|
||||
#ifdef DEBUG_DCODES
|
||||
case 4: // D4 - Read/Write PIN
|
||||
dcode_4(); break;
|
||||
case 5: // D5 - Read/Write FLASH
|
||||
|
@ -7168,9 +7172,9 @@ while (!lcd_clicked() && (counterBeep < 50)) {
|
|||
dcode_9125(); break;
|
||||
#endif //FILAMENT_SENSOR
|
||||
|
||||
#endif //DEBUG_DCODES
|
||||
}
|
||||
}
|
||||
#endif //DEBUG_DCODES
|
||||
|
||||
else
|
||||
{
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
#define PAT9125
|
||||
#define FILAMENT_SENSOR
|
||||
|
||||
#define DEBUG_DCODE3
|
||||
|
||||
//#define DEBUG_BUILD
|
||||
#ifdef DEBUG_BUILD
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
#define PAT9125
|
||||
#define FILAMENT_SENSOR
|
||||
|
||||
#define DEBUG_DCODE3
|
||||
|
||||
//#define DEBUG_BUILD
|
||||
#ifdef DEBUG_BUILD
|
||||
|
|
|
@ -147,6 +147,8 @@
|
|||
#define MINTEMP_MINAMBIENT 25
|
||||
#define MINTEMP_MINAMBIENT_RAW 978
|
||||
|
||||
#define DEBUG_DCODE3
|
||||
|
||||
//#define DEBUG_BUILD
|
||||
//#define DEBUG_SEC_LANG //secondary language debug output at startup
|
||||
//#define DEBUG_W25X20CL //debug external spi flash
|
||||
|
|
Loading…
Reference in a new issue