cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer
Observer
2,870 Views
Registered: ‎06-13-2016

How to make use of assert?

Jump to solution

 

In a lot of my code I see stuff like this:

	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(ConfigPtr != NULL);

Sometimes the assert gets triggered and my program just freezes. It would be nice if something would print instead! In this file XilinxProcessorIPLib/drivers/v_hdmirxss/examples/xhdmi_example.c I see they do stuff like this:

void Xil_AssertCallbackRoutine(u8 *File, s32 Line)
{
	  xil_printf("Assertion in File %s, on line %0d\n\r", File, Line);
}


...

  Xil_ExceptionInit();

  /*
   * Register the interrupt controller handler with the exception table.
   */
#if defined(__arm__)
  Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
					   (Xil_ExceptionHandler)XScuGic_InterruptHandler,
					   (XScuGic *)IntcInstPtr);
#else
  Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
					   (Xil_ExceptionHandler)XIntc_InterruptHandler,
					   (XIntc *)IntcInstPtr);
#endif

...

  /* Enable exceptions. */
  Xil_AssertSetCallback((Xil_AssertCallback) Xil_AssertCallbackRoutine);
  Xil_ExceptionEnable();

...so what is this stuff and how do I use it in my code?? Thanks for any help!

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Observer
Observer
3,658 Views
Registered: ‎06-13-2016

Re: How to make use of assert?

Jump to solution

This is what I ended up doing:

// Make sure to call Xil_AssertSetCallback
static void AssertPrint(const char8 *file, s32 line) {
	xil_printf("\r\nAssertion in file %s on line %d\r\n", file, line);
}

void ExceptionHandler(void *data) {
	xil_printf("\r\nException %d\r\nHalting\r\n", data);
	_Exit(0);
}

int main() {
	print("Starting...\r\n");
	Xil_AssertSetCallback((Xil_AssertCallback) AssertPrint);

	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_DATA_ABORT_INT,
			ExceptionHandler, (void *) XIL_EXCEPTION_ID_DATA_ABORT_INT);

	// Your code here

	return 0;
}

View solution in original post

0 Kudos
1 Reply
Highlighted
Observer
Observer
3,659 Views
Registered: ‎06-13-2016

Re: How to make use of assert?

Jump to solution

This is what I ended up doing:

// Make sure to call Xil_AssertSetCallback
static void AssertPrint(const char8 *file, s32 line) {
	xil_printf("\r\nAssertion in file %s on line %d\r\n", file, line);
}

void ExceptionHandler(void *data) {
	xil_printf("\r\nException %d\r\nHalting\r\n", data);
	_Exit(0);
}

int main() {
	print("Starting...\r\n");
	Xil_AssertSetCallback((Xil_AssertCallback) AssertPrint);

	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_DATA_ABORT_INT,
			ExceptionHandler, (void *) XIL_EXCEPTION_ID_DATA_ABORT_INT);

	// Your code here

	return 0;
}

View solution in original post

0 Kudos