XDK API  3.6.0
Documentation
Files | Macros | Typedefs | Functions
Assertion

Enhanced Assertion functionality. More...

+ Collaboration diagram for Assertion:

Files

file  BCDS_Assert.h
 

Macros

#define __FILE_   "Filename not defined"
 
#define __LINE__   0
 
#define assert(expression)   do{ if (!(expression)) { Assert_Dynamic((unsigned long)__LINE__,(unsigned char*)__FILE__); } } while (0)
 Program assertion macro. More...
 
#define ASSERT_CONCAT(a, b)   ASSERT_CONCAT_(a, b)
 
#define ASSERT_CONCAT_(a, b)   a##b
 
#define static_assert(expression, message)   enum { ASSERT_CONCAT(ASSERT_LINE_, __LINE__) = 1/(!!(expression)) };
 Static (compilation time) assertion macro. More...
 

Typedefs

typedef void(* Assert_Callback_T )(const unsigned long line, const unsigned char *const file)
 This data type represents a function pointer which would be executed when an assertion is triggered. More...
 

Functions

void Assert_Dynamic (const unsigned long line, const unsigned char *const file)
 Dynamic assert function. The dynamic assert function calls a user mapped callback function (where atleast all the interrupts disabling is expected) and would freeze the system by entering an endless loop. More...
 
Retcode_T Assert_Initialize (Assert_Callback_T callback)
 This function initializes the Assert module. It registers an assertion callback function. When an assertion is hit, registered callback function is called. More...
 
 BCDS_DEPRECATED (Retcode_T Assert_initialize(Assert_Callback_T callback))
 This function initializes the Assert module. It registers an assertion callback function. When an assertion is hit, registered callback function is called. More...
 
 BCDS_DEPRECATED (void Assert_dynamic(const unsigned long line, const unsigned char *const file))
 Dynamic assert function. The dynamic assert function calls a user mapped callback function (where atleast all the interrupts disabling is expected) and would freeze the system by entering an endless loop. More...
 

Detailed Description

This module offers several helpful functions for assertion, like:

Macro Definition Documentation

#define __FILE_   "Filename not defined"

Check for usage of the C99 standard or PC-Lint in order to provide support of the static assertion functionality

#define __LINE__   0
#define assert (   expression)    do{ if (!(expression)) { Assert_Dynamic((unsigned long)__LINE__,(unsigned char*)__FILE__); } } while (0)

The program assertion macro implements an assertion, which can be used to verify assumptions made by the program and get notified of this information through a callback if this assumption is false and stop program execution. Program assertion is behaving differently in debug and release builds.

Note
Release builds must be built with the NDEBUG symbol defined.
Parameters
[in]expression: A logical statement which can be true or false.
#define ASSERT_CONCAT (   a,
 
)    ASSERT_CONCAT_(a, b)
#define ASSERT_CONCAT_ (   a,
 
)    a##b
#define static_assert (   expression,
  message 
)    enum { ASSERT_CONCAT(ASSERT_LINE_, __LINE__) = 1/(!!(expression)) };
Warning
This macro can't be used twice on the same LINE number. The user must ensure that even in header files the LINE number is always unique. Protect header files against multiple time inclusions and if possible put static assertions into C files instead of headers.

The C99 standard does not support static assertions, nor the sizeof() keyword in preprocessor macros. To be able to perform compilation time variable size related checks, this macro is provided as a workaround. Note that the macro has some limitations.

Check if the int integer type is 4 bytes long, the following static assertion can be used:

1 static_assert(sizeof(int) == 4, "The int type shall be 32 bits long.");
Parameters
[in]expression: A logical statement which can be true or false.
[in]message: A string about the test case - note that it is not compiled into the code.

Typedef Documentation

typedef void(* Assert_Callback_T)(const unsigned long line, const unsigned char *const file)
Note
Ideally the first operation that is expected from the API implementing this functionality is to disable all the Interrupts of the system (based on the Hardware) and if required, it can trace / LOG the line number and filename from where the assertion came.
Parameters
[in]line: The line number of the source code from where the assert() is called.
[in]file: The file name of the source code from where the assert() is called.

Function Documentation

void Assert_Dynamic ( const unsigned long  line,
const unsigned char *const  file 
)
Note
Release builds must be built with the NDEBUG symbol defined. User shall not use this API and rather call the assert() macro with required assertion expression. Defining the ASSERT_USE_STD_EXIT macro in CFLAGS_DEBUG make variable would use the standard C exit() API.
Parameters
[in]line: The line number of the source code from where the assert() is called.
[in]file: The file name of the source code from where the assert() is called.
Retcode_T Assert_Initialize ( Assert_Callback_T  callback)

Ideally, the first thing to be done in the callback function it to disable the interrupts of the system (hardware dependent). For trouble shooting, it can also trace / log the line number and filename from where the assertion came.

Note
Release builds must be built with the NDEBUG symbol defined. This API should be called before making use of any one of the assertion API's except for the static_assert().
Parameters
[in]callback: A callback function which is executed when an assertion is triggered.
Return values
RETCODE_OKon success
RETCODE_INVALID_PARAMif callback is not valid

+ Here is the caller graph for this function:

BCDS_DEPRECATED ( Retcode_T   Assert_initializeAssert_Callback_T callback)
Deprecated:
since version vxx.xx.xx, replaced by Assert_Initialize
     Ideally, the first thing to be done in the callback function it to
     disable the interrupts of the system (hardware dependent). For trouble shooting,
     it can also trace / log the line number and filename from where the assertion
     came.
Note
Release builds must be built with the NDEBUG symbol defined. This API should be called before making use of any one of the assertion API's except for the static_assert().
Parameters
[in]callback: A callback function which is executed when an assertion is triggered.
Return values
RETCODE_OKon success
RETCODE_INVALID_PARAMif callback is not valid
BCDS_DEPRECATED ( void   Assert_dynamicconst unsigned long line, const unsigned char *const file)
Deprecated:
since version vxx.xx.xx, replaced by Assert_Dynamic
Note
Release builds must be built with the NDEBUG symbol defined. User shall not use this API and rather call the assert() macro with required assertion expression. Defining the ASSERT_USE_STD_EXIT macro in CFLAGS_DEBUG make variable would use the standard C exit() API.
Parameters
[in]line: The line number of the source code from where the assert() is called.
[in]file: The file name of the source code from where the assert() is called.

All rights reserved. The use is subject to the XDK SDK EULA by Bosch Connected Devices and Solutions GmbH.
This documentation file has been automatically generated on Thu Mar 14 2019 19:12:53 by doxygen 1.8.8