17.01.2015 Views

QDK PIC24/dsPIC-XC16 - Quantum Leaps

QDK PIC24/dsPIC-XC16 - Quantum Leaps

QDK PIC24/dsPIC-XC16 - Quantum Leaps

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>QDK</strong><br />

<strong>PIC24</strong>/<strong>dsPIC</strong>-<strong>XC16</strong><br />

www.state-machine.com/pic<br />

6.5 Assertion Handling Policy in Q_onAssert()<br />

As described in Chapter 6 of [PSiCC2], all QP components use internally assertions to detect errors in the<br />

way application is using the QP services. You need to define how the application reacts in case of<br />

assertion failure by providing the callback function Q_onAssert(). Typically, you would put the system in<br />

a fail-safe state and try to reset. It is also a good idea to log some information as to where the assertion<br />

failed.<br />

The following code fragment shows the Q_onAssert() callback for <strong>PIC24</strong>/<strong>dsPIC</strong>. The function keeps<br />

locking interrupts in an endless loop. You can then break into the code with the debugger and inspect the<br />

cause of the assertion by backtracking the call stack.<br />

NOTE: This policy is only adequate for testing, but is not adequate for production release.<br />

void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {<br />

(void)file; /* avoid compiler warning */<br />

(void)line; /* avoid compiler warning */<br />

QF_INT_DISABLE(); /* make sure that interrupts are disabled */<br />

for (;;) {<br />

}<br />

}<br />

Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />

29 of 35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!