This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

diagnostic output to custom handler


This patch adds the possibility to override the diag_write_char function at run-time, allowing diagnostic output to be redirected to a custom handler. I need this functionality as I want the diagnostic output to be written into a ring buffer in flash. I think this function may be useful to others too?!?

Simon
diff -r b190c02bd4f7 packages/infra/current/ChangeLog
--- a/packages/infra/current/ChangeLog	Tue Dec 23 09:32:09 2008 +0100
+++ b/packages/infra/current/ChangeLog	Wed Dec 24 15:20:51 2008 +0100
@@ -1,3 +1,9 @@
+2008-12-24  Simon Kallweit  <simon.kallweit@intefo.ch>
+
+	* include/diag.h:
+	* src/diag.cxx: Implemented a further indirection for
+	diag_write_char to allow diagnostic output to a custom handler.
+
 2008-10-02  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* src/gccsupport.cxx (fwrite, fputc): New functions since GCC can
diff -r b190c02bd4f7 packages/infra/current/include/diag.h
--- a/packages/infra/current/include/diag.h	Tue Dec 23 09:32:09 2008 +0100
+++ b/packages/infra/current/include/diag.h	Wed Dec 24 15:20:51 2008 +0100
@@ -64,6 +64,8 @@
 
 externC void diag_init(void);         /* Initialize, call before any others*/
 
+externC void diag_set_write_char(void (*write_char)(char c));
+
 externC void diag_write_char(char c); /* Write single char to output       */
 
 externC void diag_write_string(const char *psz); /* Write zero terminated string */
diff -r b190c02bd4f7 packages/infra/current/src/diag.cxx
--- a/packages/infra/current/src/diag.cxx	Tue Dec 23 09:32:09 2008 +0100
+++ b/packages/infra/current/src/diag.cxx	Wed Dec 24 15:20:51 2008 +0100
@@ -90,39 +90,53 @@
                                       CYGBLD_ATTRIB_INIT_AFTER(CYG_INIT_HAL);
 
 /*----------------------------------------------------------------------*/
-/* Write single char to output                                          */
-
-externC void diag_write_char(char c)
-{    
-    /* Translate LF into CRLF */
-    
-    if( c == '\n' )
-    {
-        HAL_DIAG_WRITE_CHAR('\r');        
-    }
-
-    HAL_DIAG_WRITE_CHAR(c);
-}
-
-// Default wrapper function used by diag_printf
-static void
-_diag_write_char(char c, void **param)
-{
-    diag_write_char(c);
-}
-
-/*----------------------------------------------------------------------*/
 /* Initialize. Call to pull in diag initializing constructor            */
 
 externC void diag_init(void)
 {
 }
 
+// Default wrapper function used by diag_write_char
+static void
+_diag_write_char(char c)
+{
+    HAL_DIAG_WRITE_CHAR(c);        
+}
+
+static void (*_write_char)(char c) = _diag_write_char;
+
+externC void diag_set_write_char(void (*write_char)(char c))
+{
+    _write_char = write_char;
+}
+
+/*----------------------------------------------------------------------*/
+/* Write single char to output                                          */
+
+externC void diag_write_char(char c)
+{
+    /* Translate LF into CRLF */
+    
+    if( c == '\n' )
+    {
+        _write_char('\r');        
+    }
+
+    _write_char(c);
+}
+
+// Default wrapper function used by diag_printf
+static void
+_diag_putc(char c, void **param)
+{
+    diag_write_char(c);
+}
+
 //
 // This routine is used to send characters during 'printf()' functions.
 // It can be replaced by providing a replacement via diag_init_putc().
 //
-static void (*_putc)(char c, void **param) = _diag_write_char;
+static void (*_putc)(char c, void **param) = _diag_putc;
 
 void
 diag_init_putc(void (*putc)(char c, void **param))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]