[sky9x] Stack probe

[sky9x] No sprintf (needed heap)
[sky9x] Bug when retrieving available SD audio files
This commit is contained in:
bsongis
2012-10-02 19:11:22 +00:00
parent 36bd3a5caf
commit f2154feda1
9 changed files with 168 additions and 131 deletions
+87 -14
View File
@@ -78,17 +78,90 @@ Media medias[MAX_LUNS];
/** Device LUNs. */
MSDLun luns[MAX_LUNS];
char *bytes2Str(char *str, uint32_t bytes)
int itoa(int val, char* buf)
{
if (bytes < 1024*100)
sprintf(str, "%lu.%luK", bytes / 1024, (bytes % 1024) / 103);
else if (bytes < 1024*1024)
sprintf(str, "%luK", bytes / 1024);
else if (bytes < 1024*1024*100)
sprintf(str, "%lu.%luM", bytes / (1024*1024), (bytes % (1024*1024)) / 104858);
else
sprintf(str, "%luM", bytes / (1024*1024));
return str;
const unsigned int radix = 10;
char* p;
unsigned int a; //every digit
int len;
char* b; //start of the digit char
char temp;
unsigned int u;
p = buf;
#if 0
if (val < 0)
{
*p++ = '-';
val = 0 - val;
}
#endif
u = (unsigned int)val;
b = p;
do
{
a = u % radix;
u /= radix;
*p++ = a + '0';
} while (u > 0);
len = (int)(p - buf);
*p-- = 0;
//swap
do
{
temp = *p;
*p = *b;
*b = temp;
--p;
++b;
} while (b < p);
return len;
}
uint8_t write_bytes(char *str, uint32_t bytes)
{
uint8_t len;
if (bytes < 1024*100) {
len = itoa(bytes / 1024, str);
str[len] = '.';
str[len+1] = '0' + ((bytes % 1024) / 103);
str[len+2] = 'K';
str[len+3] = '\0';
len += 3;
}
else if (bytes < 1024*1024) {
len = itoa(bytes / 1024, str);
str[len] = 'K';
str[len+1] = '\0';
len += 1;
}
else if (bytes < 1024*1024*100) {
len = itoa(bytes / (1024*1024), str);
str[len] = '.';
str[len+1] = '0' + ((bytes % (1024*1024)) / 104858);
str[len+2] = 'M';
str[len+3] = '\0';
len += 3;
}
else {
len = itoa(bytes / (1024*1024), str);
str[len] = 'M';
str[len+1] = '\0';
len += 1;
}
return len;
}
static void MSDCallbacks_Data( unsigned char flowDirection, unsigned int dataLength,
@@ -99,10 +172,10 @@ static void MSDCallbacks_Data( unsigned char flowDirection, unsigned int dataLen
else
msdWriteTotal += dataLength;
char rdStr[10];
char wrStr[10];
sprintf(statusLineMsg, "USB Rd:%s Wr:%s", bytes2Str(rdStr, msdReadTotal), bytes2Str(wrStr, msdWriteTotal));
strcpy(statusLineMsg, "USB Rd:");
uint8_t len = write_bytes(statusLineMsg+7, msdReadTotal);
strcpy(statusLineMsg+7+len, " Wr:");
write_bytes(statusLineMsg+7+len+4, msdWriteTotal);
showStatusLine();
}