Community
cancel
Showing results for 
Search instead for 
Did you mean: 
OSeme
Beginner
1,664 Views

Floating Point operation doesn't display the result

I am doing a simple test of the floating point functionality for the Nios II processor. I pass two integer numbers to Nios FPU2 and perform a square root operation and division. Result of the operation expected to be a floating point. However, when I do a printf to see the result nothing displayed. Anyone knows what am I doing wrong here? See below C code and Platform Designer architecture of the system.

#include <math.h> #include "system.h" #include "float2_gcc.h" #include <stdio.h> #include <stdlib.h> #include "altera_avalon_pio_regs.h"     #define PORT1_BASE 0x00021000 #define PORT2_BASE 0x00021010 #define read_io(addr) (*(volatile int *)(addr))   int main(void) {   int in1; int d1, d2; float result, result2; volatile float test = 1.5f;   in1 = read_io(PORT1_BASE); //my macro   d1 = IORD_ALTERA_AVALON_PIO_DATA(PORT1_BASE); d2 = IORD_ALTERA_AVALON_PIO_DATA(PORT2_BASE);   result = d1/5; result2 = sqrtf(d1/5);   printf("Operand 1 integer value >>> %d \n", d1); printf("Operand 2 integer value >>> %d \n", d2); printf("Result of operation >>> %g \n", result); printf("Result of operation 2 >>> %f \n", result2); printf("Test float >>> %g \n", test);   int ret = show_gcc_inference();   /* Return value just to prevent compiler from optimizing out code. */ return ret;   }

 

I am working of float2_gcc example provided with Quartus Prime Lite 18.0 software.

 

Thanks!

0 Kudos
2 Replies
OSeme
Beginner
165 Views

Found error. I should have used type casting since d1 and d2 are integers. Also, found another thread on this forum that says that Small C library doesn't carry float data type. If Small C library option is not chosen it looks like I need at least 41k bytes more of memory. Is there way around it to be able to use float and double data types?

JOHI
New Contributor II
165 Views

Hello,

If your calculations are minimal, you could do floating point in the fpga part of the soc.

Br.

Johi.

Reply