- summary: Store FLASH image in XRAM --> btnut - Store FLASH image in XRAM
xbank_retrieve_from_flash(u_long version):
to get the current flash imager from FLASH ROM and store it in XRAM for code distribution. This can be used to update a single node in the network via e.g. the bootloader and then spreading the image over the net (e.g. using the Chipcon CC1000. :)
Example implementation:
/**
* store current flash image in XRAM
* PRE: xbank_init()
* POST: current ROM image is XRAM but not activated
*/
void load_program_from_flash(u_long size, u_long version, char * name){
xbank_prog_info_t prog_info;
const u_char buffer_size = 128;
u_char buffer[buffer_size];
u_long address = 0;
// store ROM again
xbank_invalidate_program();
prog_info.type = REPROG_BTNODE_PROGRAM_DATA;
prog_info.size = 0L; // set later
prog_info.boot_addr = address; // unused
prog_info.version = version;
strcpy( &prog_info.name[0], name);
xbank_set_prog_info(&prog_info);
xbank_init_prog_write();
u_char u;
xbank_write_prog_record(address);
while (address < size) {
u_char bytes_to_store = buffer_size;
if (size - address < buffer_size) {
bytes_to_store = size - address;
}
for (u=0; u < bytes_to_store ; u++, address++) {
buffer[u] = pgm_read_byte_far( address );
}
xbank_write_prog_data( buffer, bytes_to_store);
}
xbank_write_prog_crc( (void*) 0);
xbank_set_prog_boot_addr( 0 );
xbank_update_prog_header();
}