drv_errno.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file drv_errno.h
  18. * @brief header file for error num
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. /******************************************************************************
  23. * @file
  24. * @details Error code field difination
  25. * Error number is devided into 4 field:
  26. * 0x8******* : 8 : means < 0
  27. * 0x*A****** : A : means type number: bsp(1), driver(2), hal(3), app(4)...
  28. * 0x**AB**** : AB : means module number: timer(1), rtc(2), ....
  29. * 0x****AB** : AB : means API number: module API's definition
  30. * 0x******AB : AB : means sub error number
  31. * 0 ~ 0x80 is common error such as EPERM, refer to errno.h
  32. * 0x80 ~ 0xFF is specific error, can difine in module
  33. *
  34. * For example 0x81020113 means:
  35. * 1. 0x8*******: value < 0, means error happened
  36. * 2. 0x*1******: type number is 1, means bsp error
  37. * 3. 0x**02****: module number is 02, means RTC error
  38. * 4. 0x****01**: module API is 01, means RTC's init
  39. * 5. 0x******13: specific error is 0x13=19=ENODEV, means no such device
  40. *
  41. * For special bsp module example, you can return:
  42. * (BSP_ERRNO_TIMER_BASE | BSP_API_RTC_INIT | EPERM) for rtc init error
  43. * (BSP_ERRNO_TIMER_BASE | BSP_API_RTC_SETTIME | ENXIO) for rtc settime error
  44. *
  45. * Here list the common sub error number (0x******AB) below(0~127 defined in errno.h as standard err code):
  46. * Code Hex Deci Meaning
  47. * -------------------------------------------------------
  48. * EPERM 0x01 1 Operation not permitted
  49. * EIO 0x05 5 I/O error
  50. * ENXIO 0x06 6 No such device or address
  51. * ENOMEM 0x0C 12 Out of memory
  52. * EACCES 0x0D 13 Permission denied
  53. * EINVAL 0x16 22 Invalid argument
  54. * ...
  55. * SPEC_ERR_BASE 0x80 128 module special error number base
  56. * ...
  57. * ERRNO_MAX 0xFF -- Max sub error number
  58. ******************************************************************************/
  59. #ifndef _DRV_ERRNO_H_
  60. #define _DRV_ERRNO_H_
  61. #include <errno.h>
  62. #define ERRNO_DRV_START 0X80
  63. /* drvier General return codes */
  64. typedef enum {
  65. EDRV = ERRNO_DRV_START, ///< Unspecified error
  66. EDRV_BUSY, ///< Driver is busy
  67. EDRV_TIMEOUT, ///< Timeout occurred
  68. EDRV_UNSUPPORTED, ///< Operation not supported
  69. EDRV_PARAMETER, ///< Parameter error
  70. EDRV_SPECIFIC ///< Start of driver specific errors
  71. } drv_common_err_e;
  72. /** Get error type */
  73. #define GET_ERROR_TYPE(errno) \
  74. (error & 0xFF000000 >> 24)
  75. /** Get error module */
  76. #define GET_ERROR_MODULE(error) \
  77. (error & 0x00FF0000 >> 16)
  78. /** Get error API */
  79. #define GET_ERROR_API(error) \
  80. (error & 0x0000FF00 >> 8)
  81. /** Get errno */
  82. #define GET_ERROR_NUM(error) \
  83. (error & 0x000000FF)
  84. #ifndef CSI_DRV_ERRNO_BASE
  85. /** means bsp errors */
  86. #define CSI_DRV_ERRNO_BASE 0x81000000
  87. #endif
  88. /** driver module id definition*/
  89. #define CSI_DRV_ERRNO_GPIO_BASE 0x81010000
  90. #define CSI_DRV_ERRNO_USART_BASE 0x81020000
  91. #define CSI_DRV_ERRNO_SPI_BASE 0x81030000
  92. #define CSI_DRV_ERRNO_I2C_BASE 0x81040000
  93. #define CSI_DRV_ERRNO_FLASH_BASE 0x81050000
  94. #define CSI_DRV_ERRNO_PWM_BASE 0x81060000
  95. #define CSI_DRV_ERRNO_RTC_BASE 0x81070000
  96. #define CSI_DRV_ERRNO_TIMER_BASE 0x81080000
  97. #define CSI_DRV_ERRNO_WDT_BASE 0x81090000
  98. #define CSI_DRV_ERRNO_AES_BASE 0x810A0000
  99. #define CSI_DRV_ERRNO_CRC_BASE 0x810B0000
  100. #define CSI_DRV_ERRNO_RSA_BASE 0x810C0000
  101. #define CSI_DRV_ERRNO_SHA_BASE 0x810D0000
  102. #define CSI_DRV_ERRNO_TRNG_BASE 0x810E0000
  103. #define CSI_DRV_ERRNO_EFLASH_BASE 0x810F0000
  104. #define CSI_DRV_ERRNO_DMA_BASE 0x81100000
  105. #endif /* CSI_DRV_ERRNO_H */