OSeme
New Contributor
7 years agoFloating 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!