avrdude-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avrdude-dev] Big programmer cleanup ;-)


From: Jan-Hinnerk Reichert
Subject: [avrdude-dev] Big programmer cleanup ;-)
Date: Sun, 14 Dec 2003 14:17:38 +0100
User-agent: KMail/1.5.4

Hi all,

here is my proposal for a big programmer cleanup ;-)

Like Ted proposed it is going from large to small.

The general idea is to initialize the programmer-struct with function 
from a default-programmer. The programmer-init then changes every 
function that it can do better.

This way we get rid of all the checks for optional functions in 
"avr.c". I only present the write here, read is similar, but simpler. 
Init needs some work, too, but that's another story.

---------------------

Functions (the sementics of these functions should be explained in the 
header-file ;-):

pgm->write_mem(pgm, mem)
  Writes entire memory of one type.

pgm->write_entire_flash(pgm, mem)
pgm->write_entire_eeprom(pgm, mem)
pgm->write_entire_other_mem(pgm, mem)
  Writes entire memory of specific type

pgm->write_page_flash(pgm, mem, addr)
  Writes one page of memory (starting at addr)

pgm->write_page_flash_load_byte(pgm, mem, addr)
pgm->write_page_flash_doit(pgm, mem, addr)
  Obvious helper functions for write_page_flash

pgm->write_byte_flash(pgm, mem, addr, data)
pgm->write_byte_eeprom(pgm, mem, addr, data)
pgm->write_byte_other_mem(pgm, mem, addr, data)
  Writes data at addr. mem is only used for determining type.

pgm->write_delay(pgm, mem, addr, data)
  Do polling or delay

pgm->spi_command(pgm, buff)

--------------------

The defaults for these functions are:
spi_command()
  Fail ;-)
  Changing only this command should implement all functionality.
  However, this would be terribly slow on STK500 ;-)

write_byte_xxx()
write_page_flash_load_byte()
write_page_flash_doit()
  assemble the SPI-command
  call pgm->spi_command
  call pgm->write_delay

write_delay()
  do polling if possible
  else do delay

write_page_flash()
  iterate over flash and call pgm->write_page_flash_load_byte()
  Then call pgm->write_page_flash_doit()

write_entire_flash()
write_entire_eeprom()
write_entire_other_mem()
  Iterate over memory and call a write_byte or write_page function.
  skip empty pages optimization should go in here.

write_mem
  just a switch-statement ;-)

---------------------

Of course, you can use the same functions for several entries in 
pgm-struct, e.g. you can write a mypgm_write_byte() and then do
  pgm->write_byte_flash = mypgm_write_byte;
  pgm->write_byte_eeprom = mypgm_write_byte;
  pgm->write_byte_other_mem = mypgm_write_byte;

Advantages:
- We get rid of much switch and if-stuff in the programmers and in 
avr.c. Eventually, avr.c becomes empty ;-)
- The flow of control becomes clearer.
- Each programmer (the device, not the guy who is coding) only needs 
implement the functions that give some gain in speed.
  - usually the write_entire-functions will not be changed
  - however, it is possible, if neccessary
- Hopefully, it is easier to implement new programmers.

Disadvantges:
- Many, many function calls. However, performance should not be a 
problem.

TOTHINK:
- I'm not totally satisfied with the write_delay(), yet.

/Jan-Hinnerk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]