- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying print the result from a FFT calculation using DMA. However, I am not sure how to use printf to accomplish that. I suspect tha it would look something like this: alt_u32 test = 1; printf("%alt_u32", test); But I am not sure how printf would handle the 32 bit data. I also read somewhere that it may be better to just print the data byte by byte. I just want to verify that the FFT component is actually calculating the data corectly Any suggestions?Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
printf("%d", test) for decimal output
printf("%x", test) for hexadecimal output- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! Is there a way to describe the alt_u32, alt_32, or other altera types directly? Or is it better to just use the builtin type, which defines the altera type?
For example: %f for float %i for integer %????? for altera types?? Thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The % format codes are somewhat a C language standard. Although printf() actually is a library function and is not strictly related to the language itself, almost every compiler/C tools defines the printf function and these formats in the exactly same way.
IMHO there is no need for extra formats for alt_xx type, since they are simple integer types. So you will always use %d or %x depending if you want them displayed in dec or hex. You could possibly use %f for float format but this makes no sense for integers. Maybe you'd like extra format directives, i.e. %04x for printing 4 digits and padding with zeros on the left. Example: alt_u32 a; a = 100; printf("%d", a); displays "100" printf("%x", a); displays "64" printf("%f", a); displays "64.000000" (I'm not sure) printf("%06x", a); displays "000064" Look in any C library manual and you'll find all the format codes. Cris- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Cris!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
%d %i %u and %x are in fact for the C "int" and "unsigned int" types. This also works with alt_u32 because in the C compiler used with the Nios architecture, the int type is defined as 32 bits. This is true for most architectures, but if you want to be sure that your code is really portable, it would be best to cast it to (int) or (unsigned int) in the printf call:printf("%d", (int)a);
If you'll only run your code on Nios 2 you don't need to do that, but you never know when your code will be reused elsewhere...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nice! I checked the typedef for alt_*, and you are correct.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page