fassert.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fassert.h
  15. * Date: 2021-04-07 09:53:07
  16. * LastEditTime: 2022-02-17 18:04:35
  17. * Description:  This files is for assertion defintion
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. * 1.0 huanghe 2021.4 init commit
  23. * 1.1 zhugengyu 2022.3 re-define assert macro
  24. */
  25. #ifndef FT_ASSERT_H
  26. #define FT_ASSERT_H
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /***************************** Include Files *********************************/
  32. #include "fprintk.h"
  33. #include "ferror_code.h"
  34. #include "ftypes.h"
  35. /************************** Constant Definitions *****************************/
  36. /**************************** Type Definitions *******************************/
  37. typedef enum
  38. {
  39. FASSERT_NONE = 0,
  40. FASSERT_OCCURRED
  41. } FAssertStatus; /* 断言状态 */
  42. /* 断言处理回调函数 */
  43. typedef void (*FAssertCB)(const char *file, s32 line, int ret);
  44. /************************** Variable Definitions *****************************/
  45. /***************** Macros (Inline Functions) Definitions *********************/
  46. #define FASSERT_MSG(expression, fmt, ...) \
  47. { \
  48. if (expression) \
  49. { \
  50. FAssertSetStatus(FASSERT_NONE); \
  51. } \
  52. else \
  53. { \
  54. FAssertSetStatus(FASSERT_OCCURRED); \
  55. f_printk(fmt, ##__VA_ARGS__); \
  56. FAssert(__FILE__, __LINE__, 0xff); \
  57. } \
  58. }
  59. #define FASSERT(expression)\
  60. { \
  61. if (expression) \
  62. { \
  63. FAssertSetStatus(FASSERT_NONE); \
  64. } \
  65. else \
  66. { \
  67. FAssertSetStatus(FASSERT_OCCURRED); \
  68. FAssert(__FILE__, __LINE__, 0xff); \
  69. } \
  70. }
  71. /* 检查静态断言状态 */
  72. #define FASSERT_STATIC(expression) \
  73. extern int assert_static[(expression) ? 1 : -1]
  74. /************************** Function Prototypes ******************************/
  75. /* 设置断言状态 */
  76. void FAssertSetStatus(FAssertStatus status);
  77. /* 获取当前断言状态 */
  78. FAssertStatus FAssertGetStatus(void);
  79. /* 设置断言回调函数 */
  80. void FAssertSetCB(FAssertCB cb);
  81. /* 断言实现 */
  82. void FAssert(const char *file, s32 line, int code);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif // !