#include "config.h"
Go to the source code of this file.
Defines | |
| #define | DFU_DETACH 0x00 |
| #define | DFU_DNLOAD 0x01 |
| #define | DFU_UPLOAD 0x02 |
| #define | DFU_GETSTATUS 0x03 |
| #define | DFU_CLRSTATUS 0x04 |
| #define | DFU_GETSTATE 0x05 |
| #define | DFU_ABORT 0x06 |
| #define | RECORD_MARK ':' |
| #define | DATA_RECORD 0x00 |
| #define | PAGE_RECORD 0x04 |
| #define | ATMEL_VID VID_ATMEL |
| #define | AT90DFU_PID PID_AT90USB128_DFU |
| #define | MAX_DATA_PER_RECORD 16 |
| #define | Dfu_download(n) |
| #define | Dfu_upload(n) |
| #define | Dfu_get_status() |
| #define | Dfu_read_manuf_id() |
| #define | Dfu_erase() |
| #define | Dfu_set_page(n) |
| #define | Dfu_start_appli(n) |
| #define | FIRMWARE_NAME "FIRMWARE.HEX" |
| #define | SIZE_BUF_STR 36 |
Functions | |
| void | dfu_read (U16 start, U16 end, U8 *buf) |
| void | dfu_prog (U16 start, U16 end, U8 *buf) |
| U8 | dfu_load_hex (void) |
| void | dfu_flush_prog (void) |
| U8 | ascii_to_bin (U8 b) |
Variables | |
| U8 | dfu_connected |
Definition in file host_dfu_task.h.
| #define DFU_DETACH 0x00 |
Definition at line 55 of file host_dfu_task.h.
| #define DFU_DNLOAD 0x01 |
Definition at line 56 of file host_dfu_task.h.
| #define DFU_UPLOAD 0x02 |
Definition at line 57 of file host_dfu_task.h.
| #define DFU_GETSTATUS 0x03 |
Definition at line 58 of file host_dfu_task.h.
| #define DFU_CLRSTATUS 0x04 |
Definition at line 59 of file host_dfu_task.h.
| #define DFU_GETSTATE 0x05 |
Definition at line 60 of file host_dfu_task.h.
| #define DFU_ABORT 0x06 |
Definition at line 61 of file host_dfu_task.h.
| #define RECORD_MARK ':' |
| #define DATA_RECORD 0x00 |
| #define PAGE_RECORD 0x04 |
| #define ATMEL_VID VID_ATMEL |
| #define AT90DFU_PID PID_AT90USB128_DFU |
| #define MAX_DATA_PER_RECORD 16 |
| #define Dfu_download | ( | n | ) |
Value:
(usb_request.bmRequestType = USB_SETUP_SET_CLASS_INTER,\ usb_request.bRequest = DFU_DNLOAD,\ usb_request.wValue = 0,\ usb_request.wIndex = 0,\ usb_request.wLength = n,\ usb_request.uncomplete_read = FALSE,\ host_send_control(data_stage))
Definition at line 73 of file host_dfu_task.h.
Referenced by dfu_prog(), and dfu_read().
| #define Dfu_upload | ( | n | ) |
Value:
(usb_request.bmRequestType = USB_SETUP_GET_CLASS_INTER,\ usb_request.bRequest = DFU_UPLOAD,\ usb_request.wValue = 0,\ usb_request.wIndex = 0,\ usb_request.wLength = n,\ usb_request.uncomplete_read = FALSE,\ host_send_control(data_stage))
Definition at line 81 of file host_dfu_task.h.
Referenced by dfu_read().
| #define Dfu_get_status | ( | ) |
Value:
(usb_request.bmRequestType = USB_SETUP_GET_CLASS_INTER,\ usb_request.bRequest = DFU_GETSTATUS,\ usb_request.wValue = 0,\ usb_request.wIndex = 0,\ usb_request.wLength = 6,\ usb_request.uncomplete_read = FALSE,\ host_send_control(data_stage))
Definition at line 90 of file host_dfu_task.h.
| #define Dfu_read_manuf_id | ( | ) |
Value:
( data_stage[0]=0x05,\ data_stage[1]=0x01,\ data_stage[2]=0x30,\ Dfu_download(3),\ Dfu_upload(1))
Definition at line 98 of file host_dfu_task.h.
| #define Dfu_erase | ( | ) |
Value:
( data_stage[0]=0x04,\ data_stage[1]=0x00,\ data_stage[2]=0xFF,\ Dfu_download(3))
Definition at line 104 of file host_dfu_task.h.
Referenced by host_dfu_task(), ushell_cmddfu_erase(), and ushell_cmddfu_load().
| #define Dfu_set_page | ( | n | ) |
Value:
( data_stage[0]=0x06,\ data_stage[1]=0x03,\ data_stage[2]=0x00,\ data_stage[3]=n,\ Dfu_download(4))
Definition at line 109 of file host_dfu_task.h.
Referenced by dfu_load_hex().
| #define Dfu_start_appli | ( | n | ) |
Value:
( data_stage[0]=0x04,\ data_stage[1]=0x03,\ data_stage[2]=0x00,\ Dfu_download(3),\ Dfu_get_status())
Definition at line 115 of file host_dfu_task.h.
Referenced by ushell_cmddfu_start().
| #define FIRMWARE_NAME "FIRMWARE.HEX" |
Definition at line 121 of file host_dfu_task.h.
| #define SIZE_BUF_STR 36 |
Definition at line 122 of file host_dfu_task.h.
Definition at line 296 of file host_dfu_task.c.
References data_stage, Dfu_download, Dfu_upload, i, j, LSB, and MSB.
00297 { 00298 U16 j; 00299 U16 i; 00300 00301 data_stage[0]=0x03; 00302 data_stage[1]=0; 00303 data_stage[2]=MSB(start); 00304 data_stage[3]=LSB(start); 00305 data_stage[4]=MSB(end); 00306 data_stage[5]=LSB(end); 00307 Dfu_download(6); 00308 i=end-start+1; 00309 Dfu_upload(i); 00310 for(j=0;j<i;j++) 00311 { 00312 *buf=data_stage[j]; 00313 buf++; 00314 } 00315 }
This function sends a dfu USB programming frame to an AT90USXxxx DFU bootloader.
| start,: | start Address | |
| end,: | end Address | |
| *buf,: | pointer to data buffer |
Definition at line 263 of file host_dfu_task.c.
References data_stage, Dfu_download, i, j, LSB, and MSB.
00264 { 00265 U8 i; 00266 U16 j; 00267 U8 padding; 00268 00269 data_stage[0]=0x01; 00270 data_stage[1]=0; 00271 data_stage[2]=MSB(start); 00272 data_stage[3]=LSB(start); 00273 data_stage[4]=MSB(end); 00274 data_stage[5]=LSB(end); 00275 for(i=6;i<32;i++) 00276 { 00277 data_stage[i]=0; 00278 } 00279 padding=start%32; 00280 j=padding; 00281 while(j) 00282 { 00283 data_stage[i]=0x00; 00284 i++; j--; 00285 } 00286 j=end-start+1; 00287 while(j) 00288 { 00289 data_stage[i]=*buf; 00290 buf++; 00291 j--;i++; 00292 } 00293 Dfu_download(32+end-start+1+padding); 00294 }
| U8 dfu_load_hex | ( | void | ) |
This function program an intel hexfile to the on-chip flash memory of an AT90USXxxx connected in DFU bootloader.
| none |
Definition at line 160 of file host_dfu_task.c.
References ascii_to_bin(), buf, DATA_RECORD, dfu_flush_prog(), Dfu_set_page, dfu_status, end_addr, FALSE, file_close(), file_eof(), file_getc(), file_open(), FOPEN_MODE_R, i, Led0_off, MAX_DATA_PER_RECORD, PAGE_RECORD, pgm_index, pgm_nb_data, prog_buf, RECORD_MARK, start_addr, and TRUE.
00161 { 00162 U8 record_type; 00163 U16 addr; 00164 U8 nb_data; 00165 U8 i; 00166 U8 stop=0; 00167 00168 dfu_status=TRUE; 00169 file_open(FOPEN_MODE_R); // Open hex firmware file 00170 while (file_eof()==FALSE) 00171 { 00172 i=file_getc(); 00173 while(i!=RECORD_MARK) 00174 { 00175 i=file_getc(); 00176 if(file_eof()) 00177 { 00178 stop=1; 00179 break; 00180 } 00181 } 00182 if(stop) break; 00183 // Build the hex record information from file 00184 nb_data=ascii_to_bin(file_getc()); 00185 nb_data=nb_data<<4; 00186 nb_data+=ascii_to_bin(file_getc()); 00187 addr=ascii_to_bin(file_getc()); 00188 addr=addr<<4; 00189 addr+=ascii_to_bin(file_getc()); 00190 addr=addr<<4; 00191 addr+=ascii_to_bin(file_getc()); 00192 addr=addr<<4; 00193 addr+=ascii_to_bin(file_getc()); 00194 record_type=ascii_to_bin(file_getc()); 00195 record_type=record_type<<4; 00196 record_type+=ascii_to_bin(file_getc()); 00197 for(i=0;i<nb_data;i++) 00198 { 00199 buf[i]=ascii_to_bin(file_getc()); 00200 buf[i]=buf[i]<<4; 00201 buf[i]+=ascii_to_bin(file_getc()); 00202 } 00203 // Decode record type 00204 switch(record_type) 00205 { 00206 case DATA_RECORD: 00207 if(addr!=end_addr+1 && pgm_index!=0) //None consecutive addr, first flush previous buffer 00208 { 00209 dfu_flush_prog(); 00210 } 00211 // Add new data to prog buffer 00212 for(i=0;i<nb_data;i++) 00213 { 00214 prog_buf[pgm_index]=buf[i]; 00215 pgm_index++; 00216 } 00217 // Update nb of data to load 00218 pgm_nb_data+=nb_data; 00219 // Compute last byte add to load 00220 if(pgm_nb_data>nb_data) 00221 { // Data exist in buffer 00222 end_addr=end_addr+nb_data; 00223 } 00224 else // first load 00225 { 00226 end_addr=addr+nb_data-1; 00227 start_addr=addr; 00228 } 00229 //If enough data flush prog buffer 00230 if(pgm_index>=10*MAX_DATA_PER_RECORD) 00231 { 00232 dfu_flush_prog(); 00233 } 00234 break; 00235 case PAGE_RECORD: 00236 if(pgm_index) // Prog buffer not empty ? 00237 { 00238 dfu_flush_prog(); // Then flush it 00239 } 00240 Dfu_set_page(buf[1]); // Send page change frame 00241 default: //Ignore all other record types 00242 break; 00243 } 00244 } 00245 // Remaining data in buffer before quit? 00246 if(pgm_index>0) 00247 { 00248 dfu_flush_prog(); 00249 } 00250 file_close(); 00251 Led0_off(); 00252 return dfu_status; 00253 }
| void dfu_flush_prog | ( | void | ) |
Definition at line 317 of file host_dfu_task.c.
References check_buf, dfu_prog(), dfu_read(), dfu_status, end_addr, FALSE, i, Led0_toggle, Leds_on, MSB, pgm_index, pgm_nb_data, prog_buf, and start_addr.
00318 { 00319 U8 i; 00320 // All buffer in the same flash memory page ? 00321 if( MSB(start_addr)== MSB(end_addr)) 00322 { 00323 dfu_prog(start_addr,end_addr,prog_buf); 00324 } 00325 else // No, program in two times 00326 { 00327 i=(end_addr%FLASH_PAGE_SIZE); 00328 dfu_prog(start_addr,end_addr-i-1,prog_buf); 00329 dfu_prog(end_addr-i,end_addr,&prog_buf[pgm_nb_data-i-1]); 00330 } 00331 // Verify on the fly... 00332 dfu_read(start_addr,end_addr,check_buf); 00333 for(i=0;i<pgm_nb_data;i++) 00334 { 00335 if(prog_buf[i]!=check_buf[i]) 00336 { 00337 Leds_on(); 00338 dfu_status=FALSE; 00339 } 00340 } 00341 Led0_toggle(); 00342 pgm_index=0; 00343 pgm_nb_data=0; 00344 }
Definition at line 346 of file host_dfu_task.c.
00347 { 00348 b|='a'-'A'; // to_lower: '0'=>'0', 'A'=>'a', 'a'=>'a' 00349 return ( (b <= '9') ? (b-'0') : (b+10-'a') ); 00350 }
1.5.3