Speed up for WriteS3
Posted: Tue Jul 21, 2009 1:41 am
Hi All,
Been messing with FTP to allow download of the current app and updating. Using Firefox with the Download Statusbar Extension, I noticed that the download speed from the Netburner was pretty punky, about 53KBytes per second average for a large app (3.36MB S3 file size). So looking over the code in StreamUpdate.cpp, at the bottom of the loop is WriteS3, which was using siprintf and strlen to add each byte to the output buffer.
I present here a modest change which results in more than a factor of 5 speed up, to 330KBytes per second.
mrc
Been messing with FTP to allow download of the current app and updating. Using Firefox with the Download Statusbar Extension, I noticed that the download speed from the Netburner was pretty punky, about 53KBytes per second average for a large app (3.36MB S3 file size). So looking over the code in StreamUpdate.cpp, at the bottom of the loop is WriteS3, which was using siprintf and strlen to add each byte to the output buffer.
I present here a modest change which results in more than a factor of 5 speed up, to 330KBytes per second.
mrc
Code: Select all
const char BinToHex[]={"0123456789ABCDEF"};
void WriteS3( int fd, unsigned long &cur_addr, unsigned char *&cp, unsigned long mklen )
{
char *ufb = ( char * ) user_flash_buffer;
int pos=0;
char c;
ufb[pos]= 'S';
ufb[++pos]= '3';
ufb[++pos]= BinToHex[((mklen + 5) >> 4)& 0x0f];
ufb[++pos]= BinToHex[((mklen + 5) & 0x0f)];
ufb[++pos]= BinToHex[(cur_addr >> 28)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr >> 24)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr >> 20)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr >> 16)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr >> 12)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr >> 8)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr >> 4)& 0x0f];
ufb[++pos]= BinToHex[(cur_addr) & 0x0f];
// siprintf( ufb, "S3%02X%08X", mklen + 5, cur_addr );
unsigned char * cpsum = ( unsigned char * ) &cur_addr;
unsigned char csum;
csum = ( mklen + 5 ) + cpsum[0] + cpsum[1] + cpsum[2] + cpsum[3];
while ( mklen )
{
c = *cp;
ufb[++pos]= BinToHex[(c >> 4)&0x0f];
ufb[++pos]= BinToHex[(c & 0x0f)];
// siprintf( ( char * ) ufb + strlen( ufb ), "%02X", ( int ) * cp );
csum += c;
++cp;
++cur_addr;
--mklen;
}
csum = ( ~csum );
ufb[++pos]= BinToHex[(csum >> 4)&0x0f];
ufb[++pos]= BinToHex[(csum & 0x0f)];
ufb[++pos]= '\r';
ufb[++pos]= '\n';
ufb[++pos]= NULL;
// siprintf( ( char * ) ufb + strlen( ufb ), "%02X\r\n", csum );
writestring( fd, ufb );
}