diff options
| author | Donald Delmar Davis <don@suspectdevices.com> | 2012-08-24 10:36:32 -0700 |
|---|---|---|
| committer | Donald Delmar Davis <don@suspectdevices.com> | 2012-08-24 10:36:32 -0700 |
| commit | 640ae654041d1a448540aff18a3dc91ee51b2331 (patch) | |
| tree | 726850e9e076d3f8779bae686335391fb6788b2a | |
| parent | 16e2e53c56ae4a41f54284feea2f1d747c8bbd9f (diff) | |
I may give up on the freertos vs stdio.
| -rwxr-xr-x | dumblogger/FreeRTOSConfig.h | 2 | ||||
| -rw-r--r-- | dumblogger/Monitor.cpp | 21 | ||||
| -rw-r--r-- | dumblogger/Monitor.h | 3 | ||||
| -rw-r--r-- | dumblogger/build/datalogger.build/Development/Program.build/Program~.dep | 0 | ||||
| -rwxr-xr-x | dumblogger/printf-stdarg.c | 104 | ||||
| -rw-r--r-- | dumblogger/rules.mk | 2 |
6 files changed, 68 insertions, 64 deletions
diff --git a/dumblogger/FreeRTOSConfig.h b/dumblogger/FreeRTOSConfig.h index 28ad3ed..324387a 100755 --- a/dumblogger/FreeRTOSConfig.h +++ b/dumblogger/FreeRTOSConfig.h @@ -21,7 +21,7 @@ #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 8000000 ) /* Clock setup from main.c in the demo application. */
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )
-#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 200 )
+#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 400 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 6000 ) )
#define configMAX_TASK_NAME_LEN ( 8 )
#define configUSE_TRACE_FACILITY 0
diff --git a/dumblogger/Monitor.cpp b/dumblogger/Monitor.cpp index 6c5398c..7b8875c 100644 --- a/dumblogger/Monitor.cpp +++ b/dumblogger/Monitor.cpp @@ -82,18 +82,23 @@ void toDevice(char *buff){ usart_tx(USART1, (uint8_t *)"\r\n", 2); ; } +extern "C" {int sdoPrintf(char *out, const char *format, ...);} -void toConsole(char *buff){ - +void toConsole(const char *format, ...){ + va_list args; + va_start( args, format ); + //int sdoPrintf(char *out, const char *format, ...) + //siprintf(actionBuffer, format, args ); + sdoPrintf(actionBuffer, format, args ); if(SerialUSB.isConnected() && (SerialUSB.getDTR() || SerialUSB.getRTS())) { - SerialUSB.write(buff); + SerialUSB.write(actionBuffer); SerialUSB.write("\r\n"); } } uint8_t NOPaction(uint8_t source) { if (source==CONSOLE) { - siprintf(actionBuffer, "DBG: Forwarding (%c%c%c)!", + toConsole("DBG: Forwarding (%c%c%c)!", consoleComm.line[0], consoleComm.line[1], consoleComm.line[2]); toConsole(actionBuffer); toDevice((char *)consoleComm.line); @@ -106,8 +111,7 @@ uint8_t NOPaction(uint8_t source) { } uint8_t ACKaction (uint8_t source) { if (source==CONSOLE) { - sprintf(actionBuffer, "ACK:"); - toConsole(actionBuffer); + toConsole("ACK:"); return COMMAND_OK; } else { toDevice("ACK:"); @@ -127,7 +131,7 @@ uint8_t NAKaction (uint8_t source) { uint8_t LSVaction (uint8_t source) { if (source==CONSOLE) { - toConsole(BOM_VERSION); + toConsole("LSV:%s",BOM_VERSION); return COMMAND_OK; } else { toDevice("NAK:"); @@ -152,8 +156,7 @@ uint8_t MEMaction (uint8_t source) { if (consoleComm.verb=='?') { int memory; memory=getFreeMemory(); - siprintf(actionBuffer,"MEM:%d",memory); - toConsole(actionBuffer); + toConsole(actionBuffer,"MEM:%d",memory);; return COMMAND_OK; } else { toConsole("NAK:"); diff --git a/dumblogger/Monitor.h b/dumblogger/Monitor.h index bb907ff..419241d 100644 --- a/dumblogger/Monitor.h +++ b/dumblogger/Monitor.h @@ -134,6 +134,7 @@ _DTM_,_DID_,_LVB_,_LSV_ * *----------------------------------------------------------------------------*/ #include <stdio.h> +#include <stdarg.h> #include <io.h> #include <ctype.h> #include <time.h> @@ -197,7 +198,7 @@ int lookupIndex(unsigned char *key); char *lookupKey(int ndx, unsigned char *keyBuffer); int handleDeviceInput(cmdBuffer *); int handleConsoleInput(cmdBuffer *); -void toConsole(char *); +void toConsole(const char *format, ...); void toDevice(char *); void registerAction(uint8_t, actionptr); char *actBuff(const char *format, ...); diff --git a/dumblogger/build/datalogger.build/Development/Program.build/Program~.dep b/dumblogger/build/datalogger.build/Development/Program.build/Program~.dep deleted file mode 100644 index e69de29..0000000 --- a/dumblogger/build/datalogger.build/Development/Program.build/Program~.dep +++ /dev/null diff --git a/dumblogger/printf-stdarg.c b/dumblogger/printf-stdarg.c index d2a1805..0f4ef09 100755 --- a/dumblogger/printf-stdarg.c +++ b/dumblogger/printf-stdarg.c @@ -28,7 +28,7 @@ #include <stdarg.h> -static void printchar(char **str, int c) +static void doPrintchar(char **str, int c) { extern int putchar(int c); @@ -42,7 +42,7 @@ static void printchar(char **str, int c) #define PAD_RIGHT 1 #define PAD_ZERO 2 -static int prints(char **out, const char *string, int width, int pad) +static int doPrints(char **out, const char *string, int width, int pad) { register int pc = 0, padchar = ' '; @@ -56,16 +56,16 @@ static int prints(char **out, const char *string, int width, int pad) } if (!(pad & PAD_RIGHT)) { for ( ; width > 0; --width) { - printchar (out, padchar); + doPrintchar (out, padchar); ++pc; } } for ( ; *string ; ++string) { - printchar (out, *string); + doPrintchar (out, *string); ++pc; } for ( ; width > 0; --width) { - printchar (out, padchar); + doPrintchar (out, padchar); ++pc; } @@ -73,19 +73,19 @@ static int prints(char **out, const char *string, int width, int pad) } /* the following should be enough for 32 bit int */ -#define PRINT_BUF_LEN 12 +#define doPrint_BUF_LEN 12 -static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) +static int doPrinti(char **out, int i, int b, int sg, int width, int pad, int letbase) { - char print_buf[PRINT_BUF_LEN]; + char doPrint_buf[doPrint_BUF_LEN]; register char *s; register int t, neg = 0, pc = 0; register unsigned int u = i; if (i == 0) { - print_buf[0] = '0'; - print_buf[1] = '\0'; - return prints (out, print_buf, width, pad); + doPrint_buf[0] = '0'; + doPrint_buf[1] = '\0'; + return doPrints (out, doPrint_buf, width, pad); } if (sg && b == 10 && i < 0) { @@ -93,7 +93,7 @@ static int printi(char **out, int i, int b, int sg, int width, int pad, int letb u = -i; } - s = print_buf + PRINT_BUF_LEN-1; + s = doPrint_buf + doPrint_BUF_LEN-1; *s = '\0'; while (u) { @@ -106,7 +106,7 @@ static int printi(char **out, int i, int b, int sg, int width, int pad, int letb if (neg) { if( width && (pad & PAD_ZERO) ) { - printchar (out, '-'); + doPrintchar (out, '-'); ++pc; --width; } @@ -115,10 +115,10 @@ static int printi(char **out, int i, int b, int sg, int width, int pad, int letb } } - return pc + prints (out, s, width, pad); + return pc + doPrints (out, s, width, pad); } -static int print( char **out, const char *format, va_list args ) +static int doPrint( char **out, const char *format, va_list args ) { register int width, pad; register int pc = 0; @@ -144,36 +144,36 @@ static int print( char **out, const char *format, va_list args ) } if( *format == 's' ) { register char *s = (char *)va_arg( args, int ); - pc += prints (out, s?s:"(null)", width, pad); + pc += doPrints (out, s?s:"(null)", width, pad); continue; } if( *format == 'd' ) { - pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); + pc += doPrinti (out, va_arg( args, int ), 10, 1, width, pad, 'a'); continue; } if( *format == 'x' ) { - pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); + pc += doPrinti (out, va_arg( args, int ), 16, 0, width, pad, 'a'); continue; } if( *format == 'X' ) { - pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); + pc += doPrinti (out, va_arg( args, int ), 16, 0, width, pad, 'A'); continue; } if( *format == 'u' ) { - pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); + pc += doPrinti (out, va_arg( args, int ), 10, 0, width, pad, 'a'); continue; } if( *format == 'c' ) { /* char are converted to int then pushed on the stack */ scr[0] = (char)va_arg( args, int ); scr[1] = '\0'; - pc += prints (out, scr, width, pad); + pc += doPrints (out, scr, width, pad); continue; } } else { out: - printchar (out, *format); + doPrintchar (out, *format); ++pc; } } @@ -182,35 +182,35 @@ static int print( char **out, const char *format, va_list args ) return pc; } -int printf(const char *format, ...) +int doPrintf(const char *format, ...) { va_list args; va_start( args, format ); - return print( 0, format, args ); + return doPrint( 0, format, args ); } -int sprintf(char *out, const char *format, ...) +int sdoPrintf(char *out, const char *format, ...) { va_list args; va_start( args, format ); - return print( &out, format, args ); + return doPrint( &out, format, args ); } -int snprintf( char *buf, unsigned int count, const char *format, ... ) +int sndoPrintf( char *buf, unsigned int count, const char *format, ... ) { va_list args; ( void ) count; va_start( args, format ); - return print( &buf, format, args ); + return doPrint( &buf, format, args ); } -#ifdef TEST_PRINTF +#ifdef TEST_doPrintF int main(void) { char *ptr = "Hello world!"; @@ -221,41 +221,41 @@ int main(void) char buf[80]; mi = (1 << (bs-1)) + 1; - printf("%s\n", ptr); - printf("printf test\n"); - printf("%s is null pointer\n", np); - printf("%d = 5\n", i); - printf("%d = - max int\n", mi); - printf("char %c = 'a'\n", 'a'); - printf("hex %x = ff\n", 0xff); - printf("hex %02x = 00\n", 0); - printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); - printf("%d %s(s)%", 0, "message"); - printf("\n"); - printf("%d %s(s) with %%\n", 0, "message"); - sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf); - sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf); - sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf); - sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf); - sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf); - sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf); - sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf); - sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf); + doPrintf("%s\n", ptr); + doPrintf("doPrintf test\n"); + doPrintf("%s is null pointer\n", np); + doPrintf("%d = 5\n", i); + doPrintf("%d = - max int\n", mi); + doPrintf("char %c = 'a'\n", 'a'); + doPrintf("hex %x = ff\n", 0xff); + doPrintf("hex %02x = 00\n", 0); + doPrintf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); + doPrintf("%d %s(s)%", 0, "message"); + doPrintf("\n"); + doPrintf("%d %s(s) with %%\n", 0, "message"); + sdoPrintf(buf, "justif: \"%-10s\"\n", "left"); doPrintf("%s", buf); + sdoPrintf(buf, "justif: \"%10s\"\n", "right"); doPrintf("%s", buf); + sdoPrintf(buf, " 3: %04d zero padded\n", 3); doPrintf("%s", buf); + sdoPrintf(buf, " 3: %-4d left justif.\n", 3); doPrintf("%s", buf); + sdoPrintf(buf, " 3: %4d right justif.\n", 3); doPrintf("%s", buf); + sdoPrintf(buf, "-3: %04d zero padded\n", -3); doPrintf("%s", buf); + sdoPrintf(buf, "-3: %-4d left justif.\n", -3); doPrintf("%s", buf); + sdoPrintf(buf, "-3: %4d right justif.\n", -3); doPrintf("%s", buf); return 0; } /* * if you compile this file with - * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c + * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_doPrintF -c doPrintf.c * you will get a normal warning: - * printf.c:214: warning: spurious trailing `%' in format + * doPrintf.c:214: warning: spurious trailing `%' in format * this line is testing an invalid % at the end of the format string. * * this should display (on 32bit int machine) : * * Hello world! - * printf test + * doPrintf test * (null) is null pointer * 5 = 5 * -2147483647 = - max int diff --git a/dumblogger/rules.mk b/dumblogger/rules.mk index 5ef99e1..e0f4a88 100644 --- a/dumblogger/rules.mk +++ b/dumblogger/rules.mk @@ -51,7 +51,7 @@ ASFLAGS_$(d) := ### Source files # cSRCS_$(d) are the C source files we want compiled. -#cSRCS_$(d) := monitor.c +cSRCS_$(d) := printf-stdarg.c # cppSRCS_$(d) are the C++ sources we want compiled. We have our own # main.cpp, and one additional file. |
