configASSERT( x ) in privileged and task modes

Hi !

By default configASSERT is terminated like this:
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

I think it is suitable for usage when code run in privileged mode. But quite often some IPC should be created in nonprivileged task context and would be nice to have assert what work with any privileges.

Is any generic implementation can be suggested ?

Also infinitive loop

for( ;; ) can be optimized by compiler. have it sense to use more relaible tight loop ?


You can define the assert behavior to anything you want. The default you post is useful when you are running the code in a debugger, because it will halt all code execution then spin in the loop until you break the debugger - at which point you can see exactly where you are in the code and the call stack. It is less helpful when you are not using the debugger, in which case it is more normal to print out a message that gives you the file name and line number.

If you are using a Cortex-M in an unprivileged task I think the taskDISABLE_INTERRUPTS() call will just have no effect, but the for( ;; ) loop should still work without be optimised away. If for some reason it is optimised away you can do something like increment a volatile variable in the loop so the compiler sees that it does something.

One comment, for(;;); can NOT legally be optimized out. The standard only allows the assumption of loop completion if the control expression is NOT a constant. In this case, the control expression is the implied constant 1, so it must become an infinite loop.

1 Like