diag_printf

F

fazulu deen

hi all,

I am working in ARM9(AT91rm9200),I need to develop small diagniostic
code to test the configured gpio lines through loopback test(one end I
will write somthing in other end i need to read the same through
registers).

I am not able to print the datatypes (Other than character),While i am
trying to print some garbage value are printed.

with the following lines :

diag_printf ("\r\nConfigured Port A= %x", *(VULONG*)0XFFFFF418);
int gpio_data_counter = 0;
diag_printf("\r\n %d Noordeen\r\n",gpio_data_counter);

void
diag_printf (const char *format,...)
{
int *dataptr = (int *) &format;
char c, str[16];
unsigned long mask = 0xFFFFFFFF;

dataptr++;

while ((c = *(format++)) != 0)
{
if (c != '%')
diag_putchar (c);
else
switch (c = *(format++))
{
case 'b':
mask = 0xFF;
/* Fall down intentionally! */
case 'd':
case 'x':
case 'X':

case 'u':

*convert_to_ascii (str, c , *((unsigned long *) dataptr++) &
mask )= 0;

diag_putstr (str);
break;

case 'c':
diag_putchar ((*(dataptr++)) & 0xff);
break;

case 's':
diag_putstr ((char *) *(dataptr++));
break;
}
}
}

Kindly suggest...

regards,
fazal
 
J

John Harrison

fazulu said:
hi all,

I am working in ARM9(AT91rm9200),I need to develop small diagniostic
code to test the configured gpio lines through loopback test(one end I
will write somthing in other end i need to read the same through
registers).

I am not able to print the datatypes (Other than character),While i am
trying to print some garbage value are printed.

with the following lines :

diag_printf ("\r\nConfigured Port A= %x", *(VULONG*)0XFFFFF418);
int gpio_data_counter = 0;
diag_printf("\r\n %d Noordeen\r\n",gpio_data_counter);

void
diag_printf (const char *format,...)
{

That is not how you do it.

Look up the va_start, va_arg and va_end macros. Use those to manipulate
functions with variable arguments

http://www.dinkumware.com/manuals/default.aspx?manual=compleat&page=stdarg.html


john
 
F

fazulu deen

Hi john,

thanks for the reply..I am afraid it is working fine only for
characters...Wats wrong in the specified codes....diag_printf once
worked properly...wat has to done to use the same code without
changing..where i am wrong??

regards,
fazal
 
G

Gavin Deane

Please quote some context in your reply so your post can be read and
understood without having to look back up the thread at other posts.
Thanks. Meta-context added back in.

[Question about variadic function that wasn't working as expected.
Code didn't use standard method of variadic function parameters]

[Response suggested the use of va_start, va_arg and va_end]
Hi john,

thanks for the reply..I am afraid it is working fine only for
characters...Wats wrong in the specified codes....diag_printf once
worked properly...wat has to done to use the same code without
changing..where i am wrong??

Did you look up the variadic function macros John Harrison suggested?
Have you rewritten the function to use them? They are the only
standard way to achieve what you want. There may be some platform-
specific alternative solution. It seems you have two choices:

1. If you want the standard solution, look up the variadic function
macros and rewrite your function to use them. If you have any problems
with that, people here should be able to help.

2. If you think there is a platform-specific solution and you can get
this function working without using the standard variadic function
macros, you will need to ask for help from a group that knows your
platform. comp.lang.c++ won't be able to help you.

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,201
Latest member
JefferyBur

Latest Threads

Top