embARC_error.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* ------------------------------------------
  2. * Copyright (c) 2016, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2016.05
  25. * \date 2014-12-25
  26. * \author Wayne Ren(Wei.Ren@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \file
  30. * \ingroup EMBARC_ERROR
  31. * \brief header file to define common definitions error management
  32. */
  33. /**
  34. * \addtogroup EMBARC_ERROR
  35. * @{
  36. */
  37. #ifndef _EMBARC_ERROR_H_
  38. #define _EMBARC_ERROR_H_
  39. #include <stdint.h>
  40. #include "inc/arc/arc_builtin.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * \name Main Error Code Definitions
  46. * @{
  47. */
  48. #define E_OK (0) /*!< ok */
  49. #define E_SYS (-5) /*!< system error */
  50. #define E_NOSPT (-9) /*!< unsupported features */
  51. #define E_RSFN (-10) /*!< reserved function code */
  52. #define E_RSATR (-11) /*!< reserved attribute */
  53. #define E_PAR (-17) /*!< parameter error */
  54. #define E_ID (-18) /*!< invalid ID number */
  55. #define E_CTX (-25) /*!< context error */
  56. #define E_MACV (-26) /*!< memory access violation */
  57. #define E_OACV (-27) /*!< object access violation */
  58. #define E_ILUSE (-28) /*!< illegal service call use */
  59. #define E_NOMEM (-33) /*!< insufficient memory */
  60. #define E_NOID (-34) /*!< no ID number available */
  61. #define E_NORES (-35) /*!< no resource available */
  62. #define E_OBJ (-41) /*!< object state error */
  63. #define E_NOEXS (-42) /*!< non-existent object */
  64. #define E_QOVR (-43) /*!< queue overflow */
  65. #define E_RLWAI (-49) /*!< forced release from waiting */
  66. #define E_TMOUT (-50) /*!< polling failure or timeout */
  67. #define E_DLT (-51) /*!< waiting object deleted */
  68. #define E_CLS (-52) /*!< waiting object state changed */
  69. #define E_WBLK (-57) /*!< non-blocking accepted */
  70. #define E_BOVR (-58) /*!< buffer overflow */
  71. #define E_OPNED (-6) /*!< device is opened */
  72. #define E_CLSED (-7) /*!< device is closed */
  73. /** @} end of name */
  74. /**
  75. * \name Generate And Decompose Error Code
  76. * @{
  77. */
  78. #ifndef ERCD
  79. /** generate error code using main error code and sub error code */
  80. #define ERCD(mercd, sercd) \
  81. ((uint32_t)((((uint32_t) sercd) << 8) | (((uint32_t) mercd) & 0xffU)))
  82. #endif /* ERCD */
  83. #ifndef MERCD
  84. #ifdef INT8_MAX
  85. /** get main error code from error code */
  86. #define MERCD(ercd) ((uint32_t)((int8_t)(ercd)))
  87. #else /* INT8_MAX */
  88. /** get main error code from error code */
  89. #define MERCD(ercd) ((uint32_t)(((uint32_t) ercd) | ~0xffU))
  90. #endif /* INT8_MAX */
  91. #endif /* MERCD */
  92. #ifndef SERCD
  93. /** get sub error code from error code */
  94. #define SERCD(ercd) ((uint32_t)((ercd) >> 8))
  95. #endif /* SERCD */
  96. /** @} end of name */
  97. /**
  98. * \name Check Error
  99. * @{
  100. */
  101. /**
  102. * \brief check an expression to see if it is right, and when error
  103. * set the ercd, and goto exit_label
  104. * \param EXPR the expression that need to be checked (==0 failed)
  105. * \param ERCD MUST pass a variable to here to get the error code
  106. * \param ERROR_CODE error code that pass to ERCD
  107. * \param EXIT_LABEL a label to go when error happens
  108. */
  109. #define CHECK_EXP(EXPR, ERCD, ERROR_CODE, EXIT_LABEL) { \
  110. if (_arc_rarely(!(EXPR))) { \
  111. ERCD = (ERROR_CODE); \
  112. goto EXIT_LABEL; \
  113. } \
  114. }
  115. /**
  116. * \brief check an expression to see if it is right, and when error
  117. * directly goto exit_label
  118. * \param EXPR the expression that need to be checked (==0 failed)
  119. * \param EXIT_LABEL a label to go when error happens
  120. * \retval
  121. */
  122. #define CHECK_EXP_NOERCD(EXPR, EXIT_LABEL) { \
  123. if (_arc_rarely(!(EXPR))) { \
  124. goto EXIT_LABEL; \
  125. } \
  126. }
  127. /** check cnt bytes align, 1 for aligned, 0 for not-aligned */
  128. #define CHECK_ALIGN_BYTES(pointer, cnt) ((((uint32_t)(pointer)) & (cnt-1)) == 0)
  129. /** check 2 bytes align, 1 for aligned, 0 for not-aligned */
  130. #define CHECK_ALIGN_2BYTES(pointer) ((((uint32_t)(pointer)) & 0x1) == 0)
  131. /** check 4 bytes align, 1 for aligned, 0 for not-aligned */
  132. #define CHECK_ALIGN_4BYTES(pointer) ((((uint32_t)(pointer)) & 0x3) == 0)
  133. /** check 8 bytes align, 1 for aligned, 0 for not-aligned */
  134. #define CHECK_ALIGN_8BYTES(pointer) ((((uint32_t)(pointer)) & 0x7) == 0)
  135. /** @} end of name */
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* _EMBARC_ERROR_H_ */
  140. /** @} end of group EMBARC_ERROR */