esp_err.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <stdint.h>
  15. #include <stdio.h>
  16. #include <assert.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef int32_t esp_err_t;
  21. /* Definitions for error constants. */
  22. #define ESP_OK 0
  23. #define ESP_FAIL -1
  24. #define ESP_ERR_NO_MEM 0x101
  25. #define ESP_ERR_INVALID_ARG 0x102
  26. #define ESP_ERR_INVALID_STATE 0x103
  27. #define ESP_ERR_INVALID_SIZE 0x104
  28. #define ESP_ERR_NOT_FOUND 0x105
  29. #define ESP_ERR_NOT_SUPPORTED 0x106
  30. #define ESP_ERR_TIMEOUT 0x107
  31. #define ESP_ERR_INVALID_RESPONSE 0x108
  32. #define ESP_ERR_INVALID_CRC 0x109
  33. #define ESP_ERR_INVALID_VERSION 0x10A
  34. #define ESP_ERR_INVALID_MAC 0x10B
  35. #define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */
  36. void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) __attribute__((noreturn));
  37. #ifndef __ASSERT_FUNC
  38. /* This won't happen on IDF, which defines __ASSERT_FUNC in assert.h, but it does happen when building on the host which
  39. uses /usr/include/assert.h or equivalent.
  40. */
  41. #ifdef __ASSERT_FUNCTION
  42. #define __ASSERT_FUNC __ASSERT_FUNCTION /* used in glibc assert.h */
  43. #else
  44. #define __ASSERT_FUNC "??"
  45. #endif
  46. #endif
  47. /**
  48. * Macro which can be used to check the error code,
  49. * and terminate the program in case the code is not ESP_OK.
  50. * Prints the error code, error location, and the failed statement to serial output.
  51. *
  52. * Disabled if assertions are disabled.
  53. */
  54. #ifdef NDEBUG
  55. #define ESP_ERROR_CHECK(x) do { \
  56. esp_err_t rc = (x); \
  57. (void) sizeof(rc); \
  58. } while(0);
  59. #else
  60. #define ESP_ERROR_CHECK(x) do { \
  61. esp_err_t rc = (x); \
  62. if (rc != ESP_OK) { \
  63. _esp_error_check_failed(rc, __FILE__, __LINE__, \
  64. __ASSERT_FUNC, #x); \
  65. } \
  66. } while(0);
  67. #endif
  68. #ifdef __cplusplus
  69. }
  70. #endif