-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsp_err_check.h
58 lines (49 loc) · 1.59 KB
/
bsp_err_check.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_check.h"
#include "sdkconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Assert on error, if selected in menuconfig. Otherwise return error code. */
#if CONFIG_BSP_ERROR_CHECK
#define BSP_ERROR_CHECK_RETURN_ERR(x) ESP_ERROR_CHECK(x)
#define BSP_ERROR_CHECK_RETURN_NULL(x) ESP_ERROR_CHECK(x)
#define BSP_ERROR_CHECK(x, ret) ESP_ERROR_CHECK(x)
#define BSP_NULL_CHECK(x, ret) assert(x)
#define BSP_NULL_CHECK_GOTO(x, goto_tag) assert(x)
#else
#define BSP_ERROR_CHECK_RETURN_ERR(x) do { \
esp_err_t err_rc_ = (x); \
if (unlikely(err_rc_ != ESP_OK)) { \
return err_rc_; \
} \
} while(0)
#define BSP_ERROR_CHECK_RETURN_NULL(x) do { \
if (unlikely((x) != ESP_OK)) { \
return NULL; \
} \
} while(0)
#define BSP_NULL_CHECK(x, ret) do { \
if ((x) == NULL) { \
return ret; \
} \
} while(0)
#define BSP_ERROR_CHECK(x, ret) do { \
if (unlikely((x) != ESP_OK)) { \
return ret; \
} \
} while(0)
#define BSP_NULL_CHECK_GOTO(x, goto_tag) do { \
if ((x) == NULL) { \
goto goto_tag; \
} \
} while(0)
#endif
#ifdef __cplusplus
}
#endif