]> rtime.felk.cvut.cz Git - arc.git/commitdiff
Optimized RAMLOG with smaller memory footprint.
authorMattias Ekberg <mattias.ekberg@arccore.com>
Fri, 12 Mar 2010 14:56:04 +0000 (15:56 +0100)
committerMattias Ekberg <mattias.ekberg@arccore.com>
Fri, 12 Mar 2010 14:56:04 +0000 (15:56 +0100)
arch/hc1x/hcs12d/drivers/Gpt.c
boards/hcs12_elmicro_card12/build_config.mk
common/newlib_port.c
common/printf.c
common/ramlog.c

index c03bd41782c35dcee9688f6d82571da5e587ab8e..8deb8cefdcacc0d36e63e4f1c2e7785171c0b228 100644 (file)
@@ -211,7 +211,7 @@ void Gpt_Init(const Gpt_ConfigType *config)
     {\r
       if (cfg->GptNotification != NULL)\r
       {\r
-       TaskType tid;\r
+       TaskType tid = 0;\r
        switch (ch) {\r
        case 0:\r
                tid = Os_Arc_CreateIsr(Gpt_Isr_0, 1, "Gpt_Isr_0");\r
@@ -345,7 +345,7 @@ Gpt_ValueType Gpt_GetTimeRemaining(Gpt_ChannelType channel)
   VALIDATE_W_RV( (Gpt_Global.initRun == STD_ON), GPT_GETTIMEREMAINING_SERVICE_ID, GPT_E_UNINIT, 0 );\r
   VALIDATE_W_RV( VALID_CHANNEL(channel),GPT_GETTIMEREMAINING_SERVICE_ID, GPT_E_PARAM_CHANNEL, 0 );\r
   VALIDATE_W_RV( (Gpt_Unit[channel].state == GPT_STATE_STARTED), GPT_GETTIMEREMAINING_SERVICE_ID, GPT_E_NOT_STARTED, 0 );\r
-  Gpt_ValueType remaining;\r
+  Gpt_ValueType remaining = 0;\r
 \r
   if (channel <= GPT_CHANNEL_7)\r
   {\r
@@ -366,7 +366,7 @@ Gpt_ValueType Gpt_GetTimeRemaining(Gpt_ChannelType channel)
 #if ( GPT_TIME_ELAPSED_API == STD_ON )\r
 Gpt_ValueType Gpt_GetTimeElapsed(Gpt_ChannelType channel)\r
 {\r
-  Gpt_ValueType elapsed;\r
+  Gpt_ValueType elapsed = 0;\r
 \r
   VALIDATE_W_RV( (Gpt_Global.initRun == STD_ON), GPT_GETTIMEELAPSED_SERVICE_ID, GPT_E_UNINIT ,0 );\r
   VALIDATE_W_RV( VALID_CHANNEL(channel),GPT_GETTIMEELAPSED_SERVICE_ID, GPT_E_PARAM_CHANNEL, 0 );\r
index faf86507d52dbbd5933fd86c3ba89a10f83b2071..0f3911f159d88788c0d07a507c7102d673a29dd0 100644 (file)
@@ -9,7 +9,7 @@ CFG=HC1X HCS12D MC912DG128A BRD_HCS12_ELMICRO_CARD12 SIMULATOR
 
 # What buildable modules does this board have, 
 # default or private
-MOD_AVAIL=KERNEL MCU T32_TERM WINIDEA_TERM SIMPLE_PRINTF GPT
+MOD_AVAIL=KERNEL MCU T32_TERM WINIDEA_TERM SIMPLE_PRINTF GPT RAMLOG
 
 # Needed by us
 MOD_USE=KERNEL MCU
index 620c7f4de939f9b7a0d16748d5f8d68c72cb430d..c6e03443b685d488e6c801f013a34c75d4fe1947 100644 (file)
@@ -244,9 +244,9 @@ int write(  int fd, char *buf, int nbytes)
        return (nbytes);
 }
 
-int arc_putchar(int c) {
+int arc_putchar(int fd, int c) {
        char cc = c;
-       write( 1,&cc,1);
+       write( fd,&cc,1);
 
        return 0;
 }
index 2d767725313c26ec0274b0f0fb0d8d2f4f8602cf..6d2b13b2d12e0f0168dde1d69a363108771d7a48 100644 (file)
@@ -19,6 +19,7 @@
 #include "simple_printf.h"
 
 #define BUF_SIZE       60
+#define STD_OUT 1
 
 #if 0
 //char *
@@ -66,26 +67,24 @@ int dbg_printf(const char *fmt, ...) {
 #define putchar(c) outbyte(c)
 */
 
-// newlib std function
-extern int putchar(int c);
 
-extern int arc_putchar(int c);
+extern int arc_putchar(int fd, int c);
 
-static void printchar(char **str, int c)
+static void printchar(int fd, char **str, int c)
 {
        if (str) {
                **str = c;
                ++(*str);
        }
        else {
-               (void)arc_putchar(c);
+               (void)arc_putchar(fd, c);
        }
 }
 
 #define PAD_RIGHT 1
 #define PAD_ZERO 2
 
-static int prints(char **out, const char *string, int width, int pad)
+static int prints(int fd, char **out, const char *string, int width, int pad)
 {
        register int pc = 0, padchar = ' ';
 
@@ -99,16 +98,16 @@ static int prints(char **out, const char *string, int width, int pad)
        }
        if (!(pad & PAD_RIGHT)) {
                for ( ; width > 0; --width) {
-                       printchar (out, padchar);
+                       printchar (fd, out, padchar);
                        ++pc;
                }
        }
        for ( ; *string ; ++string) {
-               printchar (out, *string);
+               printchar (fd, out, *string);
                ++pc;
        }
        for ( ; width > 0; --width) {
-               printchar (out, padchar);
+               printchar (fd, out, padchar);
                ++pc;
        }
 
@@ -120,7 +119,7 @@ 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
 
-static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase)
+static int printi(int fd, char **out, int i, int b, int sg, int width, int pad, int letbase)
 {
        char print_buf[PRINT_BUF_LEN];
        register char *s;
@@ -130,7 +129,7 @@ static int printi(char **out, int i, int b, int sg, int width, int pad, int letb
        if (i == 0) {
                print_buf[0] = '0';
                print_buf[1] = '\0';
-               return prints (out, print_buf, width, pad);
+               return prints (fd, out, print_buf, width, pad);
        }
 
        if (sg && b == 10 && i < 0) {
@@ -151,7 +150,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, '-');
+                       printchar (fd, out, '-');
                        ++pc;
                        --width;
                }
@@ -160,10 +159,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 + prints (fd, out, s, width, pad);
 }
 
-static int print(char **out, const char *format, va_list args )
+static int print(int fd, char **out, const char *format, va_list args )
 {
        int width, pad;
        int pc = 0;
@@ -189,36 +188,36 @@ static int print(char **out, const char *format, va_list args )
                        }
                        if( *format == 's' ) {
                                char *s = (char *)va_arg( args, int );
-                               pc += prints (out, s?s:"(null)", width, pad);
+                               pc += prints (fd, out, s?s:"(null)", width, pad);
                                continue;
                        }
                        if( *format == 'd' ) {
-                               pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
+                               pc += printi (fd, 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 += printi (fd, 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 += printi (fd, 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 += printi (fd, 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 += prints (fd, out, scr, width, pad);
                                continue;
                        }
                }
                else {
                out:
-                       printchar (out, *format);
+                       printchar (fd, out, *format);
                        ++pc;
                }
        }
@@ -227,13 +226,7 @@ static int print(char **out, const char *format, va_list args )
        return pc;
 }
 
-int simple_printf(const char *format, ...)
-{
-        va_list args;
 
-        va_start( args, format );
-        return print( 0, format, args );
-}
 
 #if 0
 int arc_fprintf(FILE *fd, const char *format, ...);
@@ -251,12 +244,28 @@ int simple_fprintf(FILE *fd, const char *format, ...)
 }
 #endif
 
+int simple_printf(const char *format, ...)
+{
+        va_list args;
+
+        va_start( args, format );
+        return print( STD_OUT, 0, format, args );
+}
+
 int simple_sprintf(char *out, const char *format, ...)
 {
         va_list args;
 
         va_start( args, format );
-        return print( &out, format, args );
+        return print(STD_OUT, &out, format, args );
+}
+
+int standard_simple_sprintf(int fd, char *out, const char *format, ...)
+{
+        va_list args;
+
+        va_start( args, format );
+        return print(fd, &out, format, args );
 }
 
 #ifdef TEST_PRINTF
index 2409df3a7c5fc124f1e371624b2a6b305c14e4f6..b7b59fc134d55b19396ea7840e2e2408a3e6455c 100644 (file)
@@ -41,7 +41,8 @@ static unsigned char ramlog[CFG_RAMLOG_SIZE] __attribute__ ((section (".ramlog")
 static unsigned ramlog_curr __attribute__ ((section (".ramlog")));
 static unsigned ramlog_session __attribute__ ((section (".ramlog")));
 
-static FILE *ramlogFile = 0;
+#define RAMLOG_FD 3
+
 
 
 /**
@@ -72,6 +73,7 @@ void ramlog_puts( char *str ) {
  *
  * @param format The format string.
  */
+extern int standard_simple_sprintf(int fd, char *out, const char *format, ...);
 void ramlog_printf( const char *format, ... ) {
 
        // Fast and ugly ramlog support.
@@ -79,7 +81,7 @@ void ramlog_printf( const char *format, ... ) {
        va_list args;
        va_start(args,format);
 
-       rv = vfprintf(ramlogFile,format, args);
+       rv = standard_simple_sprintf(RAMLOG_FD, 0, format, args);
        va_end(args);
 }
 
@@ -96,8 +98,6 @@ void ramlog_init()
       ramlog_session = 0;
     }
 
-    ramlogFile = fopen("ramlog","a");
-
     ramlog_session++;
 
     simple_sprintf(buf, "Session (%d)\n", ramlog_session);