xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/dct_assert.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright 2016, Fuzhou Rockchip Electronics Co.Ltd . All rights reserved.
4  * No part of this work may be reproduced, modified, distributed, transmitted,
5  * transcribed, or translated into any language or computer format, in any form
6  * or by any means without written permission of:
7  * Fuzhou Rockchip Electronics Co.Ltd .
8  *
9  *
10  *****************************************************************************/
11 /**
12  *   @file dct_assert.h
13  *
14  *  This file defines the API for the assertion facility of the embedded lib.
15  *
16  *****************************************************************************/
17 /*****************************************************************************/
18 /**
19  * @defgroup module_assert Assert macros
20  *
21  *
22  * Example use of the assert system:
23  *
24  *
25  * - In your source file just use the macro
26  *
27  * @code
28  * void foo( uint8_t* pData, size_t size)
29  * {
30  *     DCT_ASSERT(pData != NULL);
31  *     DCT_ASSERT(size > 0);
32  * }
33  * @endcode
34  *
35  * @{
36  *
37  *****************************************************************************/
38 #ifndef ASSERT_H_
39 #define ASSERT_H_
40 typedef char CHAR;
41 
42 /**
43  * @brief   The type of the assert handler. @see assert_handler
44  *
45  *****************************************************************************/
46 typedef void (*ASSERT_HANDLER)(void);
47 
48 
49 /**
50  *          The assert handler is a function that is called in case an
51  *          assertion failed. If no handler is registered, which is the
52  *          default, exit() is called.
53  *
54  *****************************************************************************/
55 extern ASSERT_HANDLER   assert_handler;
56 
57 /**
58  *          Compile time assert. Use e.g. to check the size of certain data
59  *           types. As this is evaluated at compile time, it will neither cause
60  *           size nor speed overhead, and thus is does not need to be inside
61  *           the NDEBUG.
62  *
63  *****************************************************************************/
64 /* we need several levels of indirection to make unique enum names working
65  * we need unique enum names to be able to use DCT_ASSERT_STATIC more than
66  * one time per compilation unit
67  */
68 #define UNIQUE_ENUM_NAME(u)     assert_static__ ## u
69 #define GET_ENUM_NAME(x)        UNIQUE_ENUM_NAME(x)
70 #define DCT_ASSERT_STATIC(e)    enum { GET_ENUM_NAME(__LINE__) = 1/(e) }
71 
72 #if defined(ENABLE_ASSERT) || !defined(NDEBUG)
73 /**
74  *              Dump information on stderr and exit.
75  *
76  *  @param      file  Filename where assertion occured.
77  *  @param      line  Linenumber where assertion occured.
78  *
79  *****************************************************************************/
80 #ifdef __cplusplus
81 extern "C"
82 #endif
83 void exit_(const char* file, int line);
84 
85 
86 /**
87  *              The assert macro.
88  *
89  *  @param      exp Expression which assumed to be true.
90  *
91  *****************************************************************************/
92 #define DCT_ASSERT(exp) ((void)0)
93 #else
94 #define DCT_ASSERT(exp) ((void)0)
95 #endif
96 
97 /* @} module_tracer*/
98 
99 #endif /*ASSERT_H_*/
100