[En-Nut-Discussion] Nut/OS port for H8/300H.

Jan Dubiec jdx at slackware.pl
Wed Mar 17 16:11:48 CET 2004


On Wed, 17 Mar 2004 14:31:24 +0100, Harald Kipp <harald.kipp at egnite.de> wrote:
> Jan,
> 
> Answers come a bit late. Our DSL modem died and I have
> to use GPRS. Wow, that is so slow.
> 
> At 07:01 17.03.2004 +0100, you wrote:
> 
> >I thought that if puts_P is used to print "prog_char" strings then a function
> >without _P suffix (fprintf in this case) is used for simple "char" strigs.
> 
> This is correct.
> 
> 
> >But I have just noticed a possible bug. Lets consider two programs:
> >
> >1. fprintf(stream, "a text");
> >
> >2. prog_char fmt[] = "a text";
> >    fprintf(stream, fmt);
> 
> This will output garbage on AVR. It should be
> fprintf_P(stream, fmt)
> in the second case, as you mentioned.
> 
> 
> >Have I found a bug? :-) There are much more such places in the Nut/OS sources.
> 
> Either I completely misunderstood you, or you need some
> sleep. :-) There should be no such places.
I agree. I need asleep. :-) Anyway, I have just checked out 3.4.2-release
in order to get sources without my patch applied and looked into some files.
For example there is following code in heap.c (line 205) :

#ifdef NUTDEBUG
    if (__heap_trf)
        fprintf(__heap_trs, "\n[H%x,A%04d/%d] ", (u_int) fit, ((HEAPNODE *) (((u_short *) fit) - 1))->hn_size, size);
#endif

As far as I understand, this is a bug on AVRs because fprintf_P should
be used here. There is similar code also in thread.c, timer.c, event.c,
osdebug.c. I haven't looked in remaining files but I am sure that there
are such places in a few other files.

I was just astonished that I noticed this flaw so late, i.e. today
about 6:30 a.m. :-)

[.....]
> Back to the H8 port.
> 
> Why not simply use
> 
> #define prog_char const char
> 
> and
> 
> #define printf_P  printf
> 
> Then
> 
> static prog_char cstr[] = "Hello";
> printf_P(cstr);
>
> will work on both platform variants.
H8 port uses those defines. :-) Look at include/arch/h8.h.

Regards,
/J.D.
-- 
Jan Dubiec, jdx at slackware.pl, mobile: +48 602 101787

Głęboka wiara wymaga płytkiego rozumu i nikłej wiedzy.



More information about the En-Nut-Discussion mailing list