Assertion messages keep printing infinitely
Opened this issue · 1 comments
Deleted user commented
The assertion messages keeps printing. For example in Buzzer_set() there is an assertion for _time which, in case of a wrong time given as argument, keeps printing the error
source/LibraryFiles/src/Buzzer.c:86 _time >= BUZZER_MIN_TIME && _time <= BUZZER_MAX_TIME -- assertion failed>
This gets quite annoying if it's printed 1000 times..
Tried to alter the assert function to add an infinite loop, and making a custom assert define with an infinite loop. Both did not work.
Deleted user commented
Closed in 2b4dbcd
Now a file called MyAssert.h
is implemented and provides an ASSERT
macro which can be used the same way as the normal assert
. This macro uses the standard device defined by PRINTF
and is only available if DEBUG
is defined and NDEBUG
is not defined.
DEBUG |
NDEBUG |
Assertion usage |
---|---|---|
NO | NO | ASSERT is wrapped to assert which prints only the first assertion failure and resets the device. See Assertion messages 1. |
NO | YES | ASSERT is a void 0 expression. See Assertion messages 2. |
YES | NO | ASSERT is the custom assertion, which prints only the first assertion failure and then halts the program execution. See Assertion messages 3. |
YES | YES | ASSERT is a void 0 expression. Also prints a warning message because both DEBUG and NDEBUG are defined, which is confusing. See Assertion messages 2. and 4. |
Assertion messages
- Infinitely prints the following message, which is the fist assertion failure. The second and the rest of the assertion failures are not printed because the device is reset after the first assertion failure.
source/CubeControl/src/LedCube.c:122 0 <= _x && 7 >= _x -- assertion failed ABRT
ASSERT
doesn't do anything, the device proceeds program execution as normal. TheASSERT
macro is avoid 0
expression:# define ASSERT(expr) ((void)0)
.- Prints the following message once, which is the fist assertion failure. The second and the rest of the assertion failures are not printed because the program execution is halted.
DEBUG: source/CubeControl/src/LedCube.c:124:LedCube_setPixel(): LEDCUBE_MIN_XYZ <= _y && LEDCUBE_MAX_XYZ >= _y -- assertion failed, program halted...
- Prints a warning message:
#warning Both DEBUG and NDEBUG are defined!
Functionality
- The
ASSERT
macro uses the standard device defined byPRINTF
(in this case Uart1_printf).
# define PRINTF Uart1_printf
ASSERT
prints the assertion failed message only once and then halts by setting the CPU interrupt priority level to 7 and entering a while 1 loop.
# define ASSERT(expression) { \
if(expression) { \
_HELPER_ASSERT(#expression); \
SET_CPU_IPL(7); \
while(1); \
} }(void) 0