public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
* diagnostic output to custom handler
@ 2008-12-24 14:24 Simon Kallweit
  2008-12-24 16:17 ` Bart Veer
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Kallweit @ 2008-12-24 14:24 UTC (permalink / raw)
  To: eCos Patches List

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

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

[-- Attachment #2: diag_custom_output.patch --]
[-- Type: text/x-diff, Size: 3156 bytes --]

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))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: diagnostic output to custom handler
  2008-12-24 14:24 diagnostic output to custom handler Simon Kallweit
@ 2008-12-24 16:17 ` Bart Veer
  2008-12-24 17:42   ` Simon Kallweit
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Veer @ 2008-12-24 16:17 UTC (permalink / raw)
  To: Simon Kallweit; +Cc: ecos-patches

>>>>> "Simon" == Simon Kallweit <simon.kallweit@intefo.ch> writes:

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

What is the point of this, given that you can already insert your own
putc function using diag_init_putc()? The only gain appears to be that
your custom write_char function would not need to worry about
carriage return/linefeed handling, whereas a custom putc may need to
do so - depending on the output destination. That is not worth
imposing a bit more code and data bloat on everybody.

Bart

-- 
Bart Veer                                   eCos Configuration Architect
eCosCentric Limited    The eCos experts      http://www.ecoscentric.com/
Barnwell House, Barnwell Drive, Cambridge, UK.      Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: diagnostic output to custom handler
  2008-12-24 16:17 ` Bart Veer
@ 2008-12-24 17:42   ` Simon Kallweit
  2008-12-24 18:44     ` Bart Veer
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Kallweit @ 2008-12-24 17:42 UTC (permalink / raw)
  To: Bart Veer; +Cc: ecos-patches

Bart Veer schrieb:
>>>>>> "Simon" == Simon Kallweit <simon.kallweit@intefo.ch> writes:
>>>>>>             
>
>     Simon> This patch adds the possibility to override the
>     Simon> diag_write_char function at run-time, allowing diagnostic
>     Simon> output to be redirected to a custom handler. I need this
>     Simon> functionality as I want the diagnostic output to be written
>     Simon> into a ring buffer in flash. I think this function may be
>     Simon> useful to others too?!?
>
> What is the point of this, given that you can already insert your own
> putc function using diag_init_putc()? 

This won't change the output function for some of the diagnostic output 
calls, but on a second glance it would probably cover most of the 
diagnostic output and might be just fine for my purpose.

> The only gain appears to be that
> your custom write_char function would not need to worry about
> carriage return/linefeed handling, whereas a custom putc may need to
> do so - depending on the output destination. That is not worth
> imposing a bit more code and data bloat on everybody.
>   

Would it make sense to allow overriding the write_char INSTEAD of the 
putc call?

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: diagnostic output to custom handler
  2008-12-24 17:42   ` Simon Kallweit
@ 2008-12-24 18:44     ` Bart Veer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Veer @ 2008-12-24 18:44 UTC (permalink / raw)
  To: Simon Kallweit; +Cc: ecos-patches

>>>>> "Simon" == Simon Kallweit <simon.kallweit@intefo.ch> writes:

    Simon> Bart Veer schrieb:
    >>>>>>> "Simon" == Simon Kallweit <simon.kallweit@intefo.ch> writes:
    >>>>>>> 
    >> 
    Simon> This patch adds the possibility to override the
    Simon> diag_write_char function at run-time, allowing diagnostic
    Simon> output to be redirected to a custom handler. I need this
    Simon> functionality as I want the diagnostic output to be written
    Simon> into a ring buffer in flash. I think this function may be
    Simon> useful to others too?!?

    >> What is the point of this, given that you can already insert
    >> your own putc function using diag_init_putc()?

    Simon> This won't change the output function for some of the
    Simon> diagnostic output calls, but on a second glance it would
    Simon> probably cover most of the diagnostic output and might be
    Simon> just fine for my purpose.

    >> The only gain appears to be that your custom write_char
    >> function would not need to worry about carriage return/linefeed
    >> handling, whereas a custom putc may need to do so - depending
    >> on the output destination. That is not worth imposing a bit
    >> more code and data bloat on everybody.

    Simon> Would it make sense to allow overriding the write_char
    Simon> INSTEAD of the putc call?

I think it would be better to stick with _putc, and fix any diagnostic
calls that currently don't use _putc to make them consistent with the
rest of the diag code.

An alternative approach is to tackle things at a lower level: fix the
HAL so that HAL_DIAG_WRITE_CHAR() does the right thing for your
platform, e.g. write data into flash. That may or may not be easy,
depending on the target hardware and the HAL packages involved.

Bart

-- 
Bart Veer                                   eCos Configuration Architect
eCosCentric Limited    The eCos experts      http://www.ecoscentric.com/
Barnwell House, Barnwell Drive, Cambridge, UK.      Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-24 18:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-24 14:24 diagnostic output to custom handler Simon Kallweit
2008-12-24 16:17 ` Bart Veer
2008-12-24 17:42   ` Simon Kallweit
2008-12-24 18:44     ` Bart Veer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).