UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Participant arda.shah
Participant
15,904 Views
Registered: ‎10-31-2012

undefined reference to math functions in SDK 14.3

Jump to solution

 

 

 

Hello,

this code has a problem with undefined reference to `cosl' , `sinl' functions

 
Have an idea how to solve this problem?

 

Xilinx Software Development Kit  Release 14.3 Build SDK_P.40xd  under Win7 x64 with included math.h and with -O0 or -O3 optimization

 

/***************************** Include Files ********************************/

#include "xsysmon.h"
#include "xparameters.h"
#include "xstatus.h"
#include "xil_exception.h"
#include "sleep.h"
#include "stdio.h"
#include "math.h"
#include <stdlib.h>
#include "xscugic.h"
#include "xil_printf.h"


/************************** Constant Definitions ****************************/

/*
 * The following constants map to the XPAR parameters created in the
 * xparameters.h file. They are defined here such that a user can easily
 * change all the needed parameters in one place.
 */
#define SYSMON_DEVICE_ID	XPAR_SYSMON_0_DEVICE_ID
#ifdef XPAR_INTC_0_DEVICE_ID	/* Interrupt Controller */
#define INTC_DEVICE_ID		XPAR_INTC_0_DEVICE_ID
#define INTR_ID			XPAR_INTC_0_SYSMON_0_VEC_ID
#else	/* SCUGIC Interrupt Controller */
#define INTC_DEVICE_ID		XPAR_SCUGIC_SINGLE_DEVICE_ID
#define INTR_ID			XPAR_FABRIC_SYSMON_0_VEC_ID
#endif /* XPAR_INTC_0_DEVICE_ID */

#ifdef XPAR_INTC_0_DEVICE_ID	/* Interrupt Controller */
#define INTC			XIntc
#define INTC_HANDLER		XIntc_InterruptHandler
#else	/* SCUGIC Interrupt Controller */
#define INTC			XScuGic
#define INTC_HANDLER		XScuGic_InterruptHandler
#endif /* XPAR_INTC_0_DEVICE_ID */

/**************************** Type Definitions ******************************/

/***************** Macros (Inline Functions) Definitions ********************/

/************************** Function Prototypes *****************************/

static int SysMonSingleChannelIntrExample4(INTC* IntcInstPtr,
			XSysMon* SysMonInstPtr,
			u16 SysMonDeviceId,
			u16 SysMonIntrId);


static void SysMonInterruptHandler(void *CallBackRef);

static int SysMonSetupInterruptSystem(INTC* IntcInstPtr,
				      XSysMon *SysMonPtr,
				      u16 IntrId );
static int SysMonFractionToInt(float FloatNum);

/************************** Variable Definitions ****************************/


static XSysMon SysMonInst; 	  /* System Monitor driver instance */
//static XIntc InterruptController; /* Instance of the XIntc driver. */
static INTC IntcInst; 		/* Instance of the XIntc driver */

/*
 * Shared variables used to test the callbacks.
 */
volatile static int EocFlag = FALSE;	  	/* EOC interrupt */
volatile static int VccintIntr = FALSE;	  	/* VCCINT alarm interrupt */


/****************************************************************************/
/**
*
* Main function that invokes the Single Channel Interrupt example.
*
* @param	None.
*
* @return
*		- XST_SUCCESS if the example has completed successfully.
*		- XST_FAILURE if the example has failed.
*
* @note		None.
*
*****************************************************************************/
int SysMonSingleChannelIntr4(void)
{
	int Status;
    xil_printf("\n\r**SysMonSingleChannelIntrExample Test**\n\r");

    /*
	 * Run the SysMonitor interrupt example, specify the parameters that
	 * are generated in xparameters.h.
	 */
	Status = SysMonSingleChannelIntrExample4
				   (&IntcInst,
				   &SysMonInst,
				   SYSMON_DEVICE_ID,
				   INTR_ID);
	if (Status != XST_SUCCESS) {
//		xil_printf("SysMonSingleChannelIntrExample Test FAILED\r\n");
		return XST_FAILURE;
	}
//	xil_printf("Successfully run SysMonSingleChannelIntrExample Test\r\n");
	return XST_SUCCESS;

}


/****************************************************************************/
/**
*
* This function runs a test on the System Monitor/ADC device using the
* driver APIs.
*
* The function does the following tasks:
*	- Initiate the System Monitor/ADC device driver instance
*	- Run self-test on the device
*	- Reset the device
*	- Set up alarm for VCCINT
*	- Set up the configuration registers for single channel continuous mode
*	for VCCINT channel
*	- Setup interrupt system
*	- Enable interrupts
*	- Wait until the VCCINT alarm interrupt occurs
*
* @param	IntcInstancePtr is a pointer to the Interrupt Controller
*		driver Instance.
* @param	SysMonInstPtr is a pointer to the XSysMon driver Instance.
* @param	SysMonDeviceId is the XPAR_<SYSMON_ADC_instance>_DEVICE_ID value
*		from xparameters.h.
* @param	SysMonIntrId is
*		XPAR_<INTC_instance>_<SYSMON_ADC_instance>_VEC_ID
*		value from xparameters.h
*
* @return
*		- XST_SUCCESS if the example has completed successfully.
*		- XST_FAILURE if the example has failed.
*
* @note		This function may never return if no interrupt occurs.
*
****************************************************************************/
static int SysMonSingleChannelIntrExample4(INTC* IntcInstPtr,
					XSysMon* SysMonInstPtr,
					u16 SysMonDeviceId,
					u16 SysMonIntrId)
{

	long double Y[256];
	long double Y_s[256][128];
	long double Y_c[256][128];
//	long double Sum_ampl[128];
	long double SUM_1_real[128]={0.0},SUM_1_image[128]={0.0};
	long double A[128], B[128], C[128];
	int Status, i, n, m, N=256;
	XSysMon_Config *ConfigPtr;
	u16 VPVNData,
//	VPVNDataTR,
	Matr[256], Sum, Matr_1[256];
	u32 IntrStatus;
//	float Y[256];


	/*
	 * Initialize the SysMon driver. w/ XSysMon_Reset
	 */
	ConfigPtr = XSysMon_LookupConfig(SysMonDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XSysMon_CfgInitialize(SysMonInstPtr, ConfigPtr, ConfigPtr->BaseAddress);

	/*
	 * Self Test the System Monitor/ADC device. w/ 2 x XSysMon_Reset
	 */
	Status = XSysMon_SelfTest(SysMonInstPtr);
	if (Status != XST_SUCCESS) {
		xil_printf("XSysMon_SelfTest failed\r\n");
		return XST_FAILURE;
	}
	/*
	 * TODO Set the ADCCLK frequency equal to 1/32 of
	 * System clock for the System
	 * Monitor/ADC in the Configuration Register 2.
	 * Desired ADC Sample Rate when Clock divider=4 is 961,54 KS/sec
	 * div 5=769,23 KS/sec
	 * div 6=641,03 KS/sec
	 * div 8=480,77 KS/sec
	 * div 16=240,38 KS/sec
	 */

	XSysMon_SetAdcClkDivisor(SysMonInstPtr, 4);

	/*
	 * TODO Set the sequencer in Single channel mode.
	 */
	XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_SINGCHAN);


	/*
	 * TODO Set the configuration registers for single channel continuous mode
	 * of operation for the VPVN channel and Differential (Bipolar) mode.
	 */
	Status=  XSysMon_SetSingleChParams(SysMonInstPtr, XSM_CH_VPVN,
						FALSE, FALSE, TRUE);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	/*
	 * Disable all the alarms in the Configuration Register 1.
	 */
	XSysMon_SetAlarmEnables(SysMonInstPtr, 0x0);

	/*
	 * Set up Alarm threshold registers for the VCCINT
	 * High limit and lower limit so that the alarm does not occur.
	 */
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCINT_UPPER, 0xFFFF);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCINT_LOWER, 0x0);

	/*
	 * Setup the interrupt system.
	 */
	Status = SysMonSetupInterruptSystem(IntcInstPtr,
					    SysMonInstPtr,
					    SysMonIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Clear any bits set in the Interrupt Status Register.
	 */
	IntrStatus = XSysMon_IntrGetStatus(SysMonInstPtr);
	XSysMon_IntrClear(SysMonInstPtr, IntrStatus);

	/*
	 * Enable EOC interrupt.
	 */
	XSysMon_IntrEnable(SysMonInstPtr, XSM_IPIXR_EOC_MASK);

	/*
	 * Enable global interrupt of System Monitor.
	 */
	XSysMon_IntrGlobalEnable(SysMonInstPtr);
	for (i=0; i<=255; i++)
	{
	/*
	 * Wait till the End of Conversion occurs.
	 */
	EocFlag = FALSE; 		/* Clear the EOC Flag */
	while (EocFlag != TRUE);
//	for (i=0; i<=255; i++)
//	{

	/*
	* Read the ADC converted Data from the data registers for VPVN.
	* MAX DATA IN UNIPOLAR MODE IS FFF=1VOLT
	*/
	VPVNData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_VPVN);

//	if (i == 0) xil_printf("\rThe 1th ADC VPVN Data=0x%x.\r\n",(VPVNData));
//	if (i == 10) xil_printf("\rThe 10th ADC VPVN Data=0x%x.\r\n",(VPVNData));
	Matr_1[i] = VPVNData;
	}
//	VPVNDataTR = VPVNData >> 4;
	  for(n=0;n<=255;n++)
	  {
	   Matr[n]=Matr_1[n]>>4;
	   if((Matr[n]>=0x0)&&(Matr[n]<=0x7FF))
	   Y[n]=Matr[n];
	   if((Matr[n]>=0x800)&&(Matr[n]<=0xFFF))
	    {
	     Y[n]=0xFFF-Matr[n];
	     Y[n]=-Y[n];
	    }
	   }
	for (i=0; i<=255; i++){
			printf("\rThe Current Matr 0x%x.\r\n",(Matr[i]));
		}
	xil_printf("\r------------------------------------------------\r\n");
	for (n=0; n<=255; n++){
		//printf("\rThe Current trans %03d\r\n", SysMonFractionToInt(Y[n]));
		printf("\rThe Current trans %Lf\r\n", Y[n]);
	}

	//TODO FFT
//	 m=N/2;

	 for(n=0;n<=N-1;n++)
	  {
	   Y[n]=sinl(2*M_PI*n/N);
	   for(m=0;m<=N/2-1;m++)
	    {
	     Y_s[n][m]=sinl(2*M_PI*n*m/N);
	     Y_c[n][m]=cosl(2*M_PI*n*m/N);
	    }
	  }
//	fun_my();

	 for(m=0;m<=N/2-1;m++)
	 {
	  for(n=0;n<=N-1;n++)
	    {
	     SUM_1_real[m]=SUM_1_real[m]+Y[n]*Y_c[n][m];
	     SUM_1_image[m]=SUM_1_image[m]+Y[n]*Y_s[n][m];
	     }
	 }

		for (n=0; n<=127; n++){
			A[n] = SUM_1_real[n]*SUM_1_real[n];
			B[n] = SUM_1_image[n]*SUM_1_image[n];
			C[n] = A[n] + B[n];
			printf("\rThe amplitude is %d, %Lf\r\n", n, C[n]);
		}

	XSysMon_IntrGlobalDisable(SysMonInstPtr);

	return XST_SUCCESS;
}

/*****************************************************************************/
/**
*
* This function is the Interrupt Service Routine for the System Monitor device.
* It will be called by the processor whenever an interrupt is asserted
* by the device.
*
* There are 8 different interrupt types supported
*	- Over Temperature
*	- ALARM 0
*	- ALARM 1
*	- ALARM 2
*	- End of Sequence
*	- End of Conversion
*	- Over Temperature DeActivated
*	- ALARM 0 DeActivated
*
* This function only handles the EOC interrupt and ALARM 1 interrupt.
* User of this code should modify the code to meet needs of the application.
*
* @param	CallBackRef is the callback reference passed from the Interrupt
*		controller driver, which in our case is a pointer to the
*		driver instance.
*
* @return	None.
*
* @note		This function is called within interrupt context.
*
******************************************************************************/
static void SysMonInterruptHandler(void *CallBackRef)
{
	u32 IntrStatusValue;
	XSysMon *SysMonPtr = (XSysMon *)CallBackRef;

	/*
	 * Get the interrupt status from the device and check the value.
	 */
	IntrStatusValue = XSysMon_IntrGetStatus(SysMonPtr);

	if (IntrStatusValue & XSM_IPIXR_EOC_MASK) {
		/*
		 * Set End of Conversion  interrupt flag so the code
		 * in application context can be aware of this interrupt.
		 */
		EocFlag = TRUE;
		XSysMon_GetStatus(SysMonPtr); /* Clear the latched status */
	}

	if (IntrStatusValue & XSM_IPIXR_VCCINT_MASK) {
		/*
		 * Set VCCINT interrupt flag so the code in application context
		 * can be aware of this interrupt.
		 */
		VccintIntr = TRUE;
	}

	/*
	 * Clear all bits in Interrupt Status Register.
	 */
	XSysMon_IntrClear(SysMonPtr, IntrStatusValue);
 }

/****************************************************************************/
/**
*
* This function sets up the interrupt system so interrupts can occur for the
* System Monitor/ADC.  The function is application-specific since the actual
* system may or may not have an interrupt controller. The System Monitor/ADC
* device could be directly connected to a processor without an interrupt
* controller. The user should modify this function to fit the application.
*
* @param	IntcInstancePtr is a pointer to the Interrupt Controller
*		driver Instance
* @param	SysMonPtr is a pointer to the driver instance for the System
* 		Monitor device which is going to be connected to the interrupt
*		controller
* @param	IntrId is XPAR_<INTC_instance>_<SYSMON_ADC_instance>_VEC_ID
*		value from xparameters.h
*
* @return	XST_SUCCESS if successful, or XST_FAILURE.
*
* @note		None.
*
*
****************************************************************************/
static int SysMonSetupInterruptSystem(INTC* IntcInstPtr,
				      XSysMon *SysMonPtr,
				      u16 IntrId )
{
	int Status;

	XScuGic_Config *IntcConfig;

	/*
	 * Initialize the interrupt controller driver so that it is ready to
	 * use.
	 */
	IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
	if (NULL == IntcConfig) {
		return XST_FAILURE;
	}

	Status = XScuGic_CfgInitialize(IntcInstPtr, IntcConfig,
					IntcConfig->CpuBaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	XScuGic_SetPriorityTriggerType(IntcInstPtr, IntrId, 0xA0, 0x3);

	/*
	 * Connect the interrupt handler that will be called when an
	 * interrupt occurs for the device.
	 */
	Status = XScuGic_Connect(IntcInstPtr, IntrId,
				 (Xil_ExceptionHandler)SysMonInterruptHandler,
				 SysMonPtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}

	/*
	 * Enable the interrupt for the System Monitor/ADC device
	 */
	XScuGic_Enable(IntcInstPtr, IntrId);

	/*
	 * Initialize the exception table.
	 */
	Xil_ExceptionInit();

	/*
	 * Register the interrupt controller handler with the exception table.
	 */
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
				(Xil_ExceptionHandler) INTC_HANDLER,
				IntcInstPtr);
	/*
	 * Enable exceptions.
	 */
	Xil_ExceptionEnable();


	return XST_SUCCESS;
}

/****************************************************************************/
/*
*
* This function converts the fraction part of the given floating point number
* (after the decimal point)to an integer.
*
* @param	FloatNum is the floating point number.
*
* @return	Integer number to a precision of 3 digits.
*
* @note
* This function is used in the printing of floating point data to a STDIO
* device using the xil_printf function. The xil_printf is a very small
* foot-print printf function and does not support the printing of floating
* point numbers.
*
*****************************************************************************/
int SysMonFractionToInt(float FloatNum)
{
	float Temp;

	Temp = FloatNum;
	if (FloatNum < 0) {
		Temp = -(FloatNum);
	}

	return( ((int)((Temp -(float)((int)Temp)) * (1000.0f))));
}
/*****************************************************************************/

 

0 Kudos
1 Solution

Accepted Solutions
Participant arda.shah
Participant
22,212 Views
Registered: ‎10-31-2012

Re: undefined reference to math functions in SDK 14.3

Jump to solution
compiled if you use g++ compiler instead gcc
0 Kudos
4 Replies
Highlighted
Participant arda.shah
Participant
15,887 Views
Registered: ‎10-31-2012

Re: undefined reference to math functions in SDK 14.3

Jump to solution
please help, the project is not compiled with this error
0 Kudos
Participant arda.shah
Participant
22,213 Views
Registered: ‎10-31-2012

Re: undefined reference to math functions in SDK 14.3

Jump to solution
compiled if you use g++ compiler instead gcc
0 Kudos
Scholar stephenm
Scholar
15,773 Views
Registered: ‎05-06-2012

Re: undefined reference to math functions in SDK 14.3

Jump to solution
Participant arda.shah
Participant
15,758 Views
Registered: ‎10-31-2012

Re: undefined reference to math functions in SDK 14.3

Jump to solution

Thanks, stephenm for help!

0 Kudos