• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
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 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 /* This file defines error code across the SDK.
16  *
17  * Rules for defining error code:
18  * 1. Define the module error code base here
19  * 2. Define the module error code in module specific headers
20  * 3. Keep the error code unique across the whole SDK
21  * 4. Carefully avoid to define same error code as 3rd party code, such as LWIP etc.
22  *
23  * Rules for using error code:
24  * 1. Error code kXxx, such as kNoMemoryErr, are used for RTOS only, don't use it for
25  *    other modules
26  * 2. The return error code type SHALL be bk_err_t for new non-RTOS SDK API
27  * 3. The return error code type for new beken modules SHALL be bk_err_t
28  * 4. Don't return hard-coded error code, return the error code macro
29  * 5. Recommend to check the API return value via BK_ERR_CHECK
30  *
31  * TODO:
32  * 1. Update return error code type of non-RTOS API from bk_err_t to bk_err_t in v4.0
33  *
34  * */
35 
36 #pragma once
37 
38 #include <stdint.h>
39 #include <stddef.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 typedef int bk_err_t;
46 
47 #define ERR_TAG "err"
48 
49 #define BK_OK                      0
50 #define BK_FAIL                    -1
51 
52 #define BK_ERR_COMMON_BASE         (-0x1000)
53 #define BK_ERR_WIFI_BASE           (-0x1200)
54 #define BK_ERR_WPA_BASE            (-0x1400)
55 #define BK_ERR_BLE_BASE            (-0x1600)
56 #define BK_ERR_RWNX_BASE           (-0x1800)
57 #define BK_ERR_HITF_BASE           (-0x1900)
58 #define BK_ERR_EVENT_BASE          (-0x1b00)
59 #define BK_ERR_NETIF_BASE          (-0x1c00)
60 #define BK_ERR_PWM_BASE            (-0x1d00)
61 #define BK_ERR_PWM_HAL_BASE        (-0x1e00)
62 #define BK_ERR_TIMER_BASE          (-0x1f00)
63 #define BK_ERR_GPIO_BASE           (-0x2000)
64 #define BK_ERR_DMA_BASE            (-0x2100)
65 #define BK_ERR_DMA_HAL_BASE        (-0x2200)
66 #define BK_ERR_RF_BASE             (-0x2300)
67 #define BK_ERR_UART_BASE           (-0x2400)
68 #define BK_ERR_INT_BASE            (-0x2500)
69 #define BK_ERR_WDT_BASE            (-0x2600)
70 #define BK_ERR_TRNG_BASE           (-0x2700)
71 #define BK_ERR_EFUSE_BASE          (-0x2800)
72 #define BK_ERR_MAC_BASE            (-0x2820)
73 #define BK_ERR_TEMPD_BASE          (-0x2840)
74 #define BK_ERR_ADC_BASE            (-0x2900)
75 #define BK_ERR_SPI_BASE            (-0x2a00)
76 #define BK_ERR_MAILBOX_BASE        (-0x2b00)
77 #define BK_ERR_QSPI_BASE           (-0x2c00)
78 #define BK_ERR_I2C_BASE            (-0x2d00)
79 #define BK_ERR_VAULT_BASE          (-0x2e00)
80 #define BK_ERR_AON_RTC_BASE        (-0x2f00)
81 #define BK_ERR_JPEG_BASE           (-0x3000)
82 #define BK_ERR_AUD_BASE            (-0x3100)
83 #define BK_ERR_FFT_BASE            (-0x3200)
84 #define BK_ERR_TOUCH_BASE          (-0x3300)
85 #define BK_ERR_I2S_BASE            (-0x3400)
86 #define BK_ERR_CALENDAR_BASE       (-0x3500)
87 #define BK_ERR_SBC_BASE            (-0x3600)
88 #define BK_ERR_FLASH_BASE          (-0x3700)
89 #define BK_ERR_SDIO_BASE           (-0x3800)
90 #define BK_ERR_SDIO_HOST_BASE      (-0x3900)
91 #define BK_ERR_MPC_BASE            (-0x3a00)
92 #define BK_ERR_PSRAM_BASE          (-0x3b00)
93 #define BK_ERR_PRRO_BASE           (-0x3c00)
94 #define BK_ERR_AON_WDT_BASE        (-0x3d00)
95 
96 /* -0x1a2c to -0x1a7b is reserved for kXxx error code
97  * #define kGenericErrorBase           -6700
98  * #define kGenericErrorEnd            -6779
99  * */
100 #define BK_ERR_RTOS_BASE           (-0x1a2c) //-6700
101 
102 #define BK_ERR_NOT_INIT            (BK_ERR_COMMON_BASE)
103 #define BK_ERR_PARAM               (BK_ERR_COMMON_BASE - 1)
104 #define BK_ERR_NOT_FOUND           (BK_ERR_COMMON_BASE - 2)
105 #define BK_ERR_OPEN                (BK_ERR_COMMON_BASE - 3)
106 #define BK_ERR_IN_PROGRESS         (BK_ERR_COMMON_BASE - 4)
107 #define BK_ERR_NO_MEM              (BK_ERR_COMMON_BASE - 5)
108 #define BK_ERR_TIMEOUT             (BK_ERR_COMMON_BASE - 6)
109 #define BK_ERR_STATE               (BK_ERR_COMMON_BASE - 7)
110 #define BK_ERR_TRY_AGAIN           (BK_ERR_COMMON_BASE - 8)
111 #define BK_ERR_NULL_PARAM          (BK_ERR_COMMON_BASE - 9)
112 #define BK_ERR_NOT_SUPPORT         (BK_ERR_COMMON_BASE - 10)
113 #define BK_ERR_BUSY                (BK_ERR_COMMON_BASE - 11)
114 
115 
116 #define BK_LOG_ON_ERR(_x) do {\
117 	bk_err_t _err = (_x);\
118 	if (_err != BK_OK) {\
119 		BK_LOGE(ERR_TAG, "%s %d: ret=-0x%x\n", __FUNCTION__, __LINE__, -_err);\
120 	}\
121 } while(0)
122 
123 #define BK_RETURN_ON_ERR(_x) do {\
124 	bk_err_t _err = (_x);\
125 	if (_err != BK_OK) {\
126 		return _err;\
127 	}\
128 } while(0)
129 
130 #define BK_ABORT_ON_ERR(_x) do {\
131 	bk_err_t _err = (_x);\
132 	if (_err != BK_OK) {\
133 		BK_LOGE(ERR_TAG, "%s %d: ret=-0x%x\n", __FUNCTION__, __LINE__, -_err);\
134 		bk_reboot();\
135 	}\
136 } while(0)
137 
138 #define BK_RETURN_ON_NULL(_x) do {\
139 	if (!(_x)) {\
140 		return BK_ERR_NULL_PARAM;\
141 	}\
142 } while(0)
143 
144 #ifdef __cplusplus
145 }
146 #endif
147