firm_upgrade.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void firm_upgrade_run (void)
 This function runs the upgrade process.


Detailed Description

This file contains the feature USB host bootloader with Udisk (see AppNote AVR916).

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file firm_upgrade.h.


Function Documentation

void firm_upgrade_run ( void   ) 

This function runs the upgrade process.

//! The status of process is display on UART and writed in a status file on U-Disk.
//! 

Definition at line 108 of file firm_upgrade.c.

References St_hex_line::datas, file_close(), file_eof(), file_open(), file_seek(), firm_upgrade_displayzone(), firm_upgrade_readhexline(), firm_upgrade_searchfile(), firm_upgrade_status(), flash_lib_check(), flash_rd_byte(), flash_wr_block(), FOPEN_MODE_R, FS_SEEK_SET, MAX_DATA_LINE, nav_file_getname(), nav_getindex(), nav_gotoindex(), St_hex_line::u16_add, St_hex_line::u8_nb_data, St_hex_line::u8_type, UPGRADE_ADDR, and UPGRADE_SIZE_MAX.

00109 {
00110    Fs_index sav_index;
00111    U8 u8_i, save_int;
00112    St_hex_line hex_line;
00113    U8 datas[MAX_DATA_LINE];
00114    char filename[30];
00115 
00116    hex_line.datas    = datas; // Init data buffer used
00117    hex_line.u8_type  = 0;     // Autotrize only type 0
00118 
00119    // Save current position to resolve it before exit routine
00120    sav_index = nav_getindex();
00121    
00122    printf("\n\rDislpay upgrade zone BEFORE upgrade:\n\r");
00123    firm_upgrade_displayzone();
00124 
00125    printf("Search upgrade file\n\r...\r");
00126    if( !firm_upgrade_searchfile( "upgrade*" ) )
00127    {
00128       firm_upgrade_status("No upgrade file");
00129       nav_gotoindex(&sav_index);
00130       return;
00131    }
00132    
00133    nav_file_getname( filename, 50 );
00134    printf("Open upgrade file \"%s\"\n\r...\r", filename );
00135    if( !file_open(FOPEN_MODE_R) )
00136    {
00137       firm_upgrade_status("!! Error to open upgrade file");
00138       nav_gotoindex(&sav_index);       // Restore previous position
00139       return;
00140    }
00141    
00142    printf("Check upgrade file\n\r...\r");
00143    while (!file_eof())
00144    { 
00145       // For each text line, check upgrade zone
00146       hex_line.u8_nb_data = MAX_DATA_LINE;
00147       if( !firm_upgrade_readhexline( &hex_line ) )
00148       {
00149          file_close();
00150          firm_upgrade_status("!! Error in HEX file format");
00151          nav_gotoindex(&sav_index);
00152          return;
00153       }
00154 
00155       if( (hex_line.u16_add                      <  UPGRADE_ADDR)
00156       ||  (hex_line.u16_add+hex_line.u8_nb_data) > (UPGRADE_ADDR+UPGRADE_SIZE_MAX) )
00157       {
00158          file_close();
00159          firm_upgrade_status("!! Upgrade zone not autorized");
00160          nav_gotoindex(&sav_index);
00161          return;
00162       }
00163    }
00164    
00165    printf("Program FLASH\n\r...\r");
00166    // Check bootloader
00167    if( !flash_lib_check() )
00168    {
00169       file_close();
00170       firm_upgrade_status("!! The bootloder if not loaded");
00171       nav_gotoindex(&sav_index);
00172       return;
00173    }
00174    
00175    file_seek(0,FS_SEEK_SET);              // Restart at beginning of file
00176    while (!file_eof())
00177    { 
00178       // For each text line, check upgrade zone
00179       hex_line.u8_nb_data = MAX_DATA_LINE;
00180       if( !firm_upgrade_readhexline( &hex_line ) )
00181       {
00182          file_close();
00183          firm_upgrade_status("!! Error in HEX file format");
00184          nav_gotoindex(&sav_index);
00185          return;
00186       }
00187 
00188       // Disabling the interrupt
00189       save_int=Get_interrupt_state();
00190       Disable_interrupt();
00191       // Writing the flash with a check of highest flash address 
00192       flash_wr_block( hex_line.datas, hex_line.u16_add, hex_line.u8_nb_data );
00193       // Read data in flash and check programmation with buffer
00194       for( u8_i=0; u8_i<hex_line.u8_nb_data; u8_i++ )
00195       {
00196          if( hex_line.datas[u8_i] != flash_rd_byte((U8 farcode*)hex_line.u16_add) )
00197          {
00198             file_close();
00199             firm_upgrade_status("!! Programmation in flash BAD\n\r!!! Check if the bootloader is loaded in chip.");
00200             nav_gotoindex(&sav_index);
00201             return;
00202          }
00203          hex_line.u16_add++;
00204       }     
00205       // Restore interrupt state
00206       if(save_int) { Enable_interrupt(); }
00207    }
00208 
00209    file_close();
00210    firm_upgrade_status("Upgrade successfull");
00211    nav_gotoindex(&sav_index);
00212    
00213    printf("Dislpay upgrade zone AFTER upgrade:\n\r");
00214    firm_upgrade_displayzone();
00215 }

Here is the call graph for this function:


Generated on Fri May 15 15:41:41 2009 for ATMEL by  doxygen 1.5.3