42 #include <sys/types.h> 48 #include "avrmalloc.h" 63 static int flash_load_from_bin_file (Flash *flash,
char *file);
76 extern inline uint16_t
flash_read (Flash *flash,
int addr);
89 storage_writew ((Storage *)flash, addr * 2, val);
100 storage_writeb ((Storage *)flash, addr * 2 + 1, val);
111 storage_writeb ((Storage *)flash, addr * 2, val);
139 storage_construct ((Storage *)flash, base, size);
142 for (i = 0; i < size; i++)
143 storage_writeb ((Storage *)flash, i, 0xff);
158 storage_destroy (flash);
169 return flash_load_from_bin_file (flash, file);
180 flash_load_from_bin_file (Flash *flash,
char *file)
186 fd = open (file, O_RDONLY);
188 avr_error (
"Couldn't open binary flash image file: %s: %s", file,
191 while ((res = read (fd, &inst,
sizeof (inst))) != 0)
194 avr_error (
"Error reading binary flash image file: %s: %s", file,
212 return storage_get_size ((Storage *)flash);
225 int size = storage_get_size ((Storage *)flash) / 2;
233 line[0] = last_line[0] =
'\0';
235 fprintf (f_core,
"Program Flash Memory Dump:\n");
236 for (i = 0; i < size; i++)
238 if (((i % ndat) == 0) && strlen (line))
240 if (strncmp (line, last_line, 80) == 0)
247 fprintf (f_core,
" -- last line repeats --\n");
248 fprintf (f_core,
"%04x : %s\n", i - ndat, line);
251 strncpy (last_line, line, 80);
254 snprintf (buf, 80,
"%04x ",
flash_read (flash, i));
255 strncat (line, buf, 80 - strlen(line) - 1);
259 fprintf (f_core,
" -- last line repeats --\n");
260 fprintf (f_core,
"%04x : %s\n", i - ndat, line);
#define avr_new(type, count)
Macro for allocating memory.
Flash * flash_new(int size)
Allocate a new Flash object.
uint16_t flash_read(Flash *flash, int addr)
Reads a 16-bit word from flash.
void flash_dump_core(Flash *flash, FILE *f_core)
Dump the contents of the flash to a file descriptor in text format.
#define avr_warning(fmt, args...)
Print a warning message to stderr.
void flash_write_lo8(Flash *flash, int addr, uint8_t val)
Write the low-order byte of an address.
#define avr_error(fmt, args...)
Print an error message to stderr and terminate program.
int flash_load_from_file(Flash *flash, char *file, int format)
Load program data into flash from a file.
void flash_write_hi8(Flash *flash, int addr, uint8_t val)
Write the high-order byte of an address.
void flash_construct(Flash *flash, int size)
Constructor for the flash object.
void display_flash(int addr, int len, uint16_t *vals)
Update a block of flash addresses in the display.
int flash_get_size(Flash *flash)
Accessor method to get the size of a flash.
void flash_write(Flash *flash, int addr, uint16_t val)
Reads a 16-bit word from flash.
void class_overload_destroy(AvrClass *klass, AvrClassFP_Destroy destroy)
Overload the default destroy method.
void flash_destroy(void *flash)
Destructor for the flash class.