Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12745 Diskussionen

Floating Point operation doesn't display the result

OSeme
Einsteiger
3.750Aufrufe

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 Antworten
OSeme
Einsteiger
2.253Aufrufe

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
Neuer Beitragender II
2.253Aufrufe

Hello,

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

Br.

Johi.

Antworten