Mistake on this page?
Report an issue in GitHub or email us
mbed_error.h
1 /** \addtogroup platform */
2 /** @{*/
3 /**
4  * \defgroup platform_error Error functions
5  * @{
6  */
7 /* mbed Microcontroller Library
8  * Copyright (c) 2006-2013 ARM Limited
9  * SPDX-License-Identifier: Apache-2.0
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 #ifndef MBED_ERROR_H
24 #define MBED_ERROR_H
25 
26 #include <stdbool.h>
27 #include "platform/mbed_retarget.h"
28 #include "platform/mbed_toolchain.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /** Define this macro to include filenames in error context. For release builds, do not include filename to save memory.
35  * MBED_PLATFORM_CONF_ERROR_FILENAME_CAPTURE_ENABLED
36  */
37 
38 /** Define this macro to enable error history
39  * MBED_PLATFORM_CONF_ERROR_HIST_ENABLED
40  */
41 
42 #ifndef MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN
43 #define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN 16
44 #else //MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN
45 #if MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN > 64
46 //We have to limit this to 64 bytes since we use mbed_error_printf for error reporting
47 //and mbed_error_vprintf uses 128bytes internal buffer which may not be sufficient for anything
48 //longer that 64 bytes with the current implementation.
49 #error "Unsupported error filename buffer length detected, max supported length is 64 chars. Please change MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN or max-error-filename-len in configuration."
50 #endif
51 #endif
52 
53 #define MBED_ERROR_STATUS_CODE_MASK (0x0000FFFF)
54 #define MBED_ERROR_STATUS_CODE_UNSHIFTED_MASK (0x0000FFFF)
55 #define MBED_ERROR_STATUS_CODE_POS (0)
56 #define MBED_ERROR_STATUS_CODE_FIELD_SIZE (16)
57 
58 #define MBED_ERROR_STATUS_MODULE_MASK (0x00FF0000)
59 #define MBED_ERROR_STATUS_MODULE_UNSHIFTED_MASK (0x000000FF)
60 #define MBED_ERROR_STATUS_MODULE_POS (16)
61 #define MBED_ERROR_STATUS_MODULE_FIELD_SIZE (8)
62 
63 #define MBED_ERROR_STATUS_TYPE_MASK (0x60000000)
64 #define MBED_ERROR_STATUS_TYPE_UNSHIFTED_MASK (0x00000003)
65 #define MBED_ERROR_STATUS_TYPE_POS (29)
66 #define MBED_ERROR_STATUS_TYPE_FIELD_SIZE (2)
67 
68 /* mbed_error_status_t Status Encoding */
69 //|31(1 bit) Always Negative|30-29(2 bits) |28-24 | 23-16(8 bits) | 15-0(16 bits) |
70 //|-1 |TYPE |(unused/reserved) | MODULE TYPE | ERROR CODE |
71 
72 #define MAKE_MBED_ERROR(type, module, error_code) (mbed_error_status_t) \
73  ((0x80000000) | \
74  ((mbed_error_status_t) (error_code & MBED_ERROR_STATUS_CODE_UNSHIFTED_MASK) << MBED_ERROR_STATUS_CODE_POS) | \
75  ((mbed_error_status_t) (module & MBED_ERROR_STATUS_MODULE_UNSHIFTED_MASK) << MBED_ERROR_STATUS_MODULE_POS) | \
76  ((mbed_error_status_t) (type & MBED_ERROR_STATUS_TYPE_UNSHIFTED_MASK) << MBED_ERROR_STATUS_TYPE_POS))
77 
78 #define MBED_GET_ERROR_TYPE( error_status ) ((error_status & MBED_ERROR_STATUS_TYPE_MASK) >> MBED_ERROR_STATUS_TYPE_POS)
79 #define MBED_GET_ERROR_MODULE( error_status ) ((error_status & MBED_ERROR_STATUS_MODULE_MASK) >> MBED_ERROR_STATUS_MODULE_POS)
80 #define MBED_GET_ERROR_CODE( error_status ) (int)((MBED_GET_ERROR_TYPE( error_status ) == MBED_ERROR_TYPE_POSIX)?(-error_status):((error_status & MBED_ERROR_STATUS_CODE_MASK) >> MBED_ERROR_STATUS_CODE_POS))
81 
82 /** mbed_error_status_t description
83  *
84  * mbed_error_status_t type represents the error status values under MbedOS. mbed_error_status_t values are signed integers and always be negative.\n
85  * Internally its encoded as below with bit-fields representing error type, module and error code:\n\n
86  * mbed_error_status_t Status Encoding:\n
87  *
88  \verbatim
89  | 31 Always Negative | 30-29(2 bits) | 28-24 | 23-16(8 bits) | 15-0(16 bits) |
90  | -1 | TYPE | (unused/reserved) | MODULE TYPE | ERROR CODE |
91  \endverbatim
92  *
93  * The error status value range for each error type is as follows:\n
94  * POSIX Error Status-es - 0xFFFFFFFF to 0xFFFFFF01(-1 -255) - This corresponds to POSIX error codes represented as negative.\n
95  * System Error Status-es - 0x80XX0100 to 0x80XX0FFF - This corresponds to System error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)\n
96  * Custom Error Status-es - 0xA0XX1000 to 0xA0XXFFFF - This corresponds to Custom error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)\n\n
97  *
98  * The ERROR CODE(values encoded into ERROR CODE bit-field in mbed_error_status_t) value range for each error type is also separated as below:\n
99  * POSIX Error Codes - 1 to 255.\n
100  * System Error Codes - 256 to 4095.\n
101  * Custom Error Codes - 4096 to 65535.\n
102  *
103  * @note POSIX error codes are always encoded as negative of their actual value. For example, EPERM is encoded as -EPERM.
104  * And, the MODULE TYPE for POSIX error codes are always encoded as MBED_MODULE_UNKNOWN.\n
105  * This is to enable easy injection of POSIX error codes into MbedOS error handling system without altering the actual POSIX error values.\n
106  * Accordingly, POSIX error codes are represented as -1 to -255 under MbedOS error status representation.
107  */
109 
110 /**
111  * Macro for defining a POSIX error status. This macro is mainly used to define POSIX error values in mbed_error_code_t enumeration.
112  * @param error_name Name of the error without the ERROR_ prefix
113  * @param error_code Error code value to be used, must be between 1 and 255(inclusive).
114  *
115  */
116 #define MBED_DEFINE_POSIX_ERROR( error_name, error_code ) \
117  MBED_ERROR_CODE_##error_name = error_code, \
118  MBED_ERROR_##error_name = -(MBED_POSIX_ERROR_BASE + error_code)
119 
120 /**
121  * Macro for defining a System error status. This macro is used to define System error values in mbed_error_code_t enumeration.
122  * @param error_name Name of the error without the ERROR_ prefix
123  * @param error_code Error code value to be used, must be between 256 and 4096(inclusive).
124  *
125  */
126 #define MBED_DEFINE_SYSTEM_ERROR( error_name, error_code ) \
127  MBED_ERROR_CODE_##error_name = MBED_SYSTEM_ERROR_BASE + error_code, \
128  MBED_ERROR_##error_name = MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, MBED_ERROR_CODE_##error_name)
129 
130 /**
131  * Macro for defining a Custom error status. This macro is used to define custom error values in mbed_error_code_t enumeration.
132  * @param error_name Name of the error without the ERROR_ prefix
133  * @param error_code Error code value to be used, must be between 4097 and 65535(inclusive).
134  *
135  */
136 #define MBED_DEFINE_CUSTOM_ERROR( error_name, error_code ) \
137  MBED_ERROR_CODE_##error_name = MBED_CUSTOM_ERROR_BASE + error_code, \
138  MBED_ERROR_##error_name = MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, MBED_MODULE_UNKNOWN, MBED_ERROR_CODE_##error_name)
139 
140 
141 /**
142  * Macros for setting a system warning. These macros will log the error, Its a wrapper for calling mbed_warning API.
143  * There are 2 versions of this macro. MBED_WARNING takes status and message. MBED_WARNING1 takes an additional context specific argument
144  * @param error_status mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
145  * @param error_msg The error message to be printed out to STDIO/Serial.
146  * @param error_value Value associated with the error status. This would depend on error code/error scenario.
147  *
148  * @code
149  *
150  * MBED_WARNING( ERROR_INVALID_SIZE, "MyDriver: Invalid size in read" )
151  * MBED_WARNING1( ERROR_INVALID_SIZE, "MyDriver: Invalid size in read", size_val )
152  *
153  * @endcode
154  * @note The macro calls mbed_warning API with filename and line number info without caller explicitly passing them.
155  * Since this macro is a wrapper for mbed_warning API callers should process the return value from this macro which is the return value from calling mbed_error API.
156  *
157  */
158 #ifdef NDEBUG
159 #define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)NULL, (uint32_t)error_value, NULL, 0 )
160 #define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)NULL, (uint32_t)0, NULL, 0 )
161 #else //NDEBUG
162 #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
163 #define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
164 #define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)0 , (const char *)MBED_FILENAME, __LINE__ )
165 #else //MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
166 #define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
167 #define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)0, NULL, 0 )
168 #endif
169 #endif
170 
171 /**
172  * Macros for setting a fatal system error. These macros will log the error, prints the error report and halts the system. Its a wrapper for calling mbed_error API.
173  * There are 2 versions of this macro. MBED_ERROR takes status and message. MBED_ERROR1 takes an additional context specific argument
174  * @param error_status mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
175  * @param error_msg The error message to be printed out to STDIO/Serial.
176  * @param error_value Value associated with the error status. This would depend on error code/error scenario. Only available with MBED_ERROR1
177  * @return Does not return
178  *
179  * @code
180  *
181  * MBED_ERROR( MBED_ERROR_MUTEX_LOCK_FAILED, "MyDriver: Can't lock driver Mutex" )
182  * MBED_ERROR1( MBED_ERROR_MUTEX_LOCK_FAILED, "MyDriver: Can't lock driver Mutex", &my_mutex )
183  *
184  * @endcode
185  * @note The macro calls mbed_error API with filename and line number info without caller explicitly passing them.
186  * Since this macro is a wrapper for mbed_error API callers should process the return value from this macro which is the return value from calling mbed_error API.
187  *
188  */
189 #ifdef NDEBUG
190 #define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)NULL, (uint32_t)error_value, NULL, 0 )
191 #define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)NULL, (uint32_t)0 , NULL, 0 )
192 #else //NDEBUG
193 #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
194 #define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
195 #define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)error_msg, (uint32_t)0 , (const char *)MBED_FILENAME, __LINE__ )
196 #else //MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
197 #define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
198 #define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)error_msg, (uint32_t)0 , NULL, 0 )
199 #endif
200 #endif
201 
202 //Error Type definition
203 /** mbed_error_type_t definition
204  * @note
205  * This enumeration defines the Error types supported. The value of these enum values will be encoded into mbed_error_status_t TYPE field.\n
206  * See mbed_error_status_t description for more info.\n
207  * MBED_ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.\n
208  * MBED_ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.\n
209  * MBED_ERROR_TYPE_POSIX - Used to indicate that the error status is of POSIX error type.\n
210  *
211  */
212 typedef enum _mbed_error_type_t {
213  MBED_ERROR_TYPE_SYSTEM = 0,
214  MBED_ERROR_TYPE_CUSTOM = 1,
215  //2 is reserved
216  //Use 3 for POSIX because we are mapping -1 to -255 to POSIX error codes
217  //and thus we must use 3 to match the type bits in error status representation which are from 0xFFFFFFFF to 0xFFFFFF00
218  MBED_ERROR_TYPE_POSIX = 3
220 
221 //Module type/id definitions
222 /** mbed_module_type_t definition
223  * @note
224  * This enumeration defines the module types. The value of these enum values will be encoded into mbed_error_status_t MODULE field.\n\n
225  * See mbed_error_status_t description for more info.\n
226  * MBED_MODULE_UNKNOWN - This module type can be used if caller of the mbed_error/mbed_warning doesn't know who is the actual originator of the error.\n
227  * Other module values can be used to provide more info on who/where the error originated from.\n\n
228  * For example, if I2C driver is the component originating the error you can use MBED_MODULE_DRIVER_I2C to provide more info.\n
229  * Its used in call to MBED_MAKE_ERROR/MBED_MAKE_SYSTEM_ERROR/MBED_MAKE_CUSTOM_ERROR macros.\n
230  *
231  * @code
232  * Example: mbed_error_status_t i2c_driver_error = MBED_MAKE_ERROR( MBED_MODULE_DRIVER_I2C, MBED_ERROR_CONFIG_UNSUPPORTED );
233  * @endcode
234  *
235  * @note
236  * \n Below are the module code mappings:\n
237  \verbatim
238  MBED_MODULE_APPLICATION 0 Application
239  MBED_MODULE_PLATFORM 1 Platform
240  MBED_MODULE_KERNEL 2 RTX Kernel
241  MBED_MODULE_NETWORK_STACK 3 Network stack
242  MBED_MODULE_HAL 4 HAL - Hardware Abstraction Layer
243  MBED_MODULE_MEMORY_SUBSYSTEM 5 Memory Subsystem
244  MBED_MODULE_FILESYSTEM 6 Filesystem
245  MBED_MODULE_BLOCK_DEVICE 7 Block device
246  MBED_MODULE_DRIVER 8 Driver
247  MBED_MODULE_DRIVER_SERIAL 9 Serial Driver
248  MBED_MODULE_DRIVER_RTC 10 RTC Driver
249  MBED_MODULE_DRIVER_I2C 11 I2C Driver
250  MBED_MODULE_DRIVER_SPI 12 SPI Driver
251  MBED_MODULE_DRIVER_GPIO 13 GPIO Driver
252  MBED_MODULE_DRIVER_ANALOG 14 Analog Driver
253  MBED_MODULE_DRIVER_DIGITAL 15 DigitalIO Driver
254  MBED_MODULE_DRIVER_CAN 16 CAN Driver
255  MBED_MODULE_DRIVER_ETHERNET 17 Ethernet Driver
256  MBED_MODULE_DRIVER_CRC 18 CRC Module
257  MBED_MODULE_DRIVER_PWM 19 PWM Driver
258  MBED_MODULE_DRIVER_QSPI 20 QSPI Driver
259  MBED_MODULE_DRIVER_USB 21 USB Driver
260  MBED_MODULE_TARGET_SDK 22 SDK
261  MBED_MODULE_BLE 23 BLE
262  MBED_MODULE_NETWORK_STATS 24 Network Statistics
263 
264  MBED_MODULE_UNKNOWN 255 Unknown module
265  \endverbatim
266  *
267  */
268 typedef enum _mbed_module_type {
269  MBED_MODULE_APPLICATION = 0,
270  MBED_MODULE_PLATFORM,
271  MBED_MODULE_KERNEL,
272  MBED_MODULE_NETWORK_STACK,
273  MBED_MODULE_HAL,
274  MBED_MODULE_MEMORY_SUBSYSTEM,
275  MBED_MODULE_FILESYSTEM,
276  MBED_MODULE_BLOCK_DEVICE,
277  MBED_MODULE_DRIVER,
278  MBED_MODULE_DRIVER_SERIAL,
279  MBED_MODULE_DRIVER_RTC,
280  MBED_MODULE_DRIVER_I2C,
281  MBED_MODULE_DRIVER_SPI,
282  MBED_MODULE_DRIVER_GPIO,
283  MBED_MODULE_DRIVER_ANALOG,
284  MBED_MODULE_DRIVER_DIGITAL,
285  MBED_MODULE_DRIVER_CAN,
286  MBED_MODULE_DRIVER_ETHERNET,
287  MBED_MODULE_DRIVER_CRC,
288  MBED_MODULE_DRIVER_PWM,
289  MBED_MODULE_DRIVER_QSPI,
290  MBED_MODULE_DRIVER_USB,
291  MBED_MODULE_DRIVER_WATCHDOG,
292  MBED_MODULE_TARGET_SDK,
293  MBED_MODULE_BLE,
294  MBED_MODULE_NETWORK_STATS,
295  /* Add More entities here as required */
296 
297  MBED_MODULE_UNKNOWN = 255,
298  MBED_MODULE_MAX = MBED_MODULE_UNKNOWN
300 
301 //Use MBED_SUCCESS(=0) or any positive number for successful returns
302 #define MBED_SUCCESS 0
303 
304 #define MBED_POSIX_ERROR_BASE 0
305 #define MBED_SYSTEM_ERROR_BASE 256
306 #define MBED_CUSTOM_ERROR_BASE 4096
307 
308 //Error Code definitions
309 /** mbed_error_code_t definition
310  *
311  * mbed_error_code_t enumeration defines the Error codes and Error status values for MBED_MODULE_UNKNOWN.\n
312  * It defines all of POSIX Error Codes/Statuses and Mbed System Error Codes/Statuses.\n\n
313  *
314  * @note
315  * POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR\n
316  * For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This effectively defines the following values:\n
317  * ERROR_CODE_EPERM = EPERM\n
318  * ERROR_EPERM = -EPERM\n
319  *
320  * POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR\n
321  * For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This macro defines the following values:\n
322  * ERROR_CODE_EPERM = MBED_POSIX_ERROR_BASE+EPERM\n
323  * ERROR_EPERM = -(MBED_POSIX_ERROR_BASE+EPERM)\n
324  * Its effectively equivalent to:\n
325  * ERROR_CODE_EPERM = 1\n
326  * ERROR_EPERM = -1\n
327  * All POSIX error codes currently supported by MbedOS(defined in mbed_retarget.h) are defined using the MBED_DEFINE_POSIX_ERROR macro.\n\n
328  * Below are the POSIX error codes and the description:\n
329  * \verbatim
330  EPERM 1 Operation not permitted
331  ENOENT 2 No such file or directory
332  ESRCH 3 No such process
333  EINTR 4 Interrupted system call
334  EIO 5 I/O error
335  ENXIO 6 No such device or address
336  E2BIG 7 Argument list too long
337  ENOEXEC 8 Exec format error
338  EBADF 9 Bad file number
339  ECHILD 10 No child processes
340  EAGAIN 11 Try again
341  ENOMEM 12 Out of memory
342  EACCES 13 Permission denied
343  EFAULT 14 Bad address
344  ENOTBLK 15 Block device required
345  EBUSY 16 Device or resource busy
346  EEXIST 17 File exists
347  EXDEV 18 Cross-device link
348  ENODEV 19 No such device
349  ENOTDIR 20 Not a directory
350  EISDIR 21 Is a directory
351  EINVAL 22 Invalid argument
352  ENFILE 23 File table overflow
353  EMFILE 24 Too many open files
354  ENOTTY 25 Not a typewriter
355  ETXTBSY 26 Text file busy
356  EFBIG 27 File too large
357  ENOSPC 28 No space left on device
358  ESPIPE 29 Illegal seek
359  EROFS 30 Read-only file system
360  EMLINK 31 Too many links
361  EPIPE 32 Broken pipe
362  EDOM 33 Math argument out of domain of func
363  ERANGE 34 Math result not representable
364  EDEADLK 35 Resource deadlock would occur
365  ENAMETOOLONG 36 File name too long
366  ENOLCK 37 No record locks available
367  ENOSYS 38 Function not implemented
368  ENOTEMPTY 39 Directory not empty
369  ELOOP 40 Too many symbolic links encountered
370  EWOULDBLOCK EAGAIN Operation would block
371  ENOMSG 42 No message of desired type
372  EIDRM 43 Identifier removed
373  ECHRNG 44 Channel number out of range
374  EL2NSYNC 45 Level 2 not synchronized
375  EL3HLT 46 Level 3 halted
376  EL3RST 47 Level 3 reset
377  ELNRNG 48 Link number out of range
378  EUNATCH 49 Protocol driver not attached
379  ENOCSI 50 No CSI structure available
380  EL2HLT 51 Level 2 halted
381  EBADE 52 Invalid exchange
382  EBADR 53 Invalid request descriptor
383  EXFULL 54 Exchange full
384  ENOANO 55 No anode
385  EBADRQC 56 Invalid request code
386  EBADSLT 57 Invalid slot
387  EDEADLOCK EDEADLK Resource deadlock would occur
388  EBFONT 59 Bad font file format
389  ENOSTR 60 Device not a stream
390  ENODATA 61 No data available
391  ETIME 62 Timer expired
392  ENOSR 63 Out of streams resources
393  ENONET 64 Machine is not on the network
394  ENOPKG 65 Package not installed
395  EREMOTE 66 Object is remote
396  ENOLINK 67 Link has been severed
397  EADV 68 Advertise error
398  ESRMNT 69 Srmount error
399  ECOMM 70 Communication error on send
400  EPROTO 71 Protocol error
401  EMULTIHOP 72 Multihop attempted
402  EDOTDOT 73 RFS specific error
403  EBADMSG 74 Not a data message
404  EOVERFLOW 75 Value too large for defined data type
405  ENOTUNIQ 76 Name not unique on network
406  EBADFD 77 File descriptor in bad state
407  EREMCHG 78 Remote address changed
408  ELIBACC 79 Can not access a needed shared library
409  ELIBBAD 80 Accessing a corrupted shared library
410  ELIBSCN 81 .lib section in a.out corrupted
411  ELIBMAX 82 Attempting to link in too many shared libraries
412  ELIBEXEC 83 Cannot exec a shared library directly
413  EILSEQ 84 Illegal byte sequence
414  ERESTART 85 Interrupted system call should be restarted
415  ESTRPIPE 86 Streams pipe error
416  EUSERS 87 Too many users
417  ENOTSOCK 88 Socket operation on non-socket
418  EDESTADDRREQ 89 Destination address required
419  EMSGSIZE 90 Message too long
420  EPROTOTYPE 91 Protocol wrong type for socket
421  ENOPROTOOPT 92 Protocol not available
422  EPROTONOSUPPORT 93 Protocol not supported
423  ESOCKTNOSUPPORT 94 Socket type not supported
424  EOPNOTSUPP 95 Operation not supported on transport endpoint
425  EPFNOSUPPORT 96 Protocol family not supported
426  EAFNOSUPPORT 97 Address family not supported by protocol
427  EADDRINUSE 98 Address already in use
428  EADDRNOTAVAIL 99 Cannot assign requested address
429  ENETDOWN 100 Network is down
430  ENETUNREACH 101 Network is unreachable
431  ENETRESET 102 Network dropped connection because of reset
432  ECONNABORTED 103 Software caused connection abort
433  ECONNRESET 104 Connection reset by peer
434  ENOBUFS 105 No buffer space available
435  EISCONN 106 Transport endpoint is already connected
436  ENOTCONN 107 Transport endpoint is not connected
437  ESHUTDOWN 108 Cannot send after transport endpoint shutdown
438  ETOOMANYREFS 109 Too many references: cannot splice
439  ETIMEDOUT 110 Connection timed out
440  ECONNREFUSED 111 Connection refused
441  EHOSTDOWN 112 Host is down
442  EHOSTUNREACH 113 No route to host
443  EALREADY 114 Operation already in progress
444  EINPROGRESS 115 Operation now in progress
445  ESTALE 116 Stale NFS file handle
446  EUCLEAN 117 Structure needs cleaning
447  ENOTNAM 118 Not a XENIX named type file
448  ENAVAIL 119 No XENIX semaphores available
449  EISNAM 120 Is a named type file
450  EREMOTEIO 121 Remote I/O error
451  EDQUOT 122 Quota exceeded
452  ENOMEDIUM 123 No medium found
453  EMEDIUMTYPE 124 Wrong medium type
454  ECANCELED 125 Operation Canceled
455  ENOKEY 126 Required key not available
456  EKEYEXPIRED 127 Key has expired
457  EKEYREVOKED 128 Key has been revoked
458  EKEYREJECTED 129 Key was rejected by service
459  EOWNERDEAD 130 Owner died
460  ENOTRECOVERABLE 131 State not recoverable
461  \endverbatim
462  *
463  * @note
464  * MbedOS System Error codes are defined using the macro MBED_DEFINE_SYSTEM_ERROR\n
465  * For example MBED_DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ) macro defines the following values:\n
466  * ERROR_CODE_INVALID_ARGUMENT = MBED_SYSTEM_ERROR_BASE+1\n
467  * ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)\n
468  * Its effectively equivalent to:\n
469  * ERROR_CODE_INVALID_ARGUMENT = 1\n
470  * ERROR_INVALID_ARGUMENT = 0x80FF0001\n (Note that MODULE field is set to MBED_MODULE_UNKNOWN)
471  * New System Error codes should be defined using MBED_DEFINE_SYSTEM_ERROR macro and must have an unique error code value\n
472  * passed as the second argument in the MBED_DEFINE_SYSTEM_ERROR macro.\n\n
473  * Below are the Mbed System error codes and the description:
474  * \verbatim
475  UNKNOWN 256 Unknown error
476  INVALID_ARGUMENT 257 Invalid Argument
477  INVALID_DATA 258 Invalid data
478  INVALID_FORMAT 259 Invalid format
479  INVALID_INDEX 260 Invalid Index
480  INVALID_SIZE 261 Invalid Size
481  INVALID_OPERATION 262 Invalid Operation
482  NOT_FOUND 263 Not Found
483  ACCESS_DENIED 264 Access Denied
484  NOT_SUPPORTED 265 Not supported
485  BUFFER_FULL 266 Buffer Full
486  MEDIA_FULL 267 Media/Disk Full
487  ALREADY_IN_USE 268 Already in use
488  TIMEOUT 269 Timeout error
489  NOT_READY 270 Not Ready
490  FAILED_OPERATION 271 Requested Operation failed
491  OPERATION_PROHIBITED 272 Operation prohibited
492  OPERATION_ABORTED 273 Operation failed
493  WRITE_PROTECTED 274 Attempt to write to write-protected resource
494  NO_RESPONSE 275 No response
495  SEMAPHORE_LOCK_FAILED 276 Semaphore lock failed
496  MUTEX_LOCK_FAILED 277 Mutex lock failed
497  SEMAPHORE_UNLOCK_FAILED 278 Semaphore unlock failed
498  MUTEX_UNLOCK_FAILED 279 Mutex unlock failed
499  CRC_ERROR 280 CRC error or mismatch
500  OPEN_FAILED 281 Open failed
501  CLOSE_FAILED 282 Close failed
502  READ_FAILED 283 Read failed
503  WRITE_FAILED 284 Write failed
504  INITIALIZATION_FAILED 285 Initialization failed
505  BOOT_FAILURE 286 Boot failure
506  OUT_OF_MEMORY 287 Out of memory
507  OUT_OF_RESOURCES 288 Out of resources
508  ALLOC_FAILED 289 Alloc failed
509  FREE_FAILED 290 Free failed
510  OVERFLOW 291 Overflow error
511  UNDERFLOW 292 Underflow error
512  STACK_OVERFLOW 293 Stack overflow error
513  ISR_QUEUE_OVERFLOW 294 ISR queue overflow
514  TIMER_QUEUE_OVERFLOW 295 Timer Queue overflow
515  CLIB_SPACE_UNAVAILABLE 296 Standard library error - Space unavailable
516  CLIB_EXCEPTION 297 Standard library error - Exception
517  CLIB_MUTEX_INIT_FAILURE 298 Standard library error - Mutex Init failure
518  CREATE_FAILED 299 Create failed
519  DELETE_FAILED 300 Delete failed
520  THREAD_CREATE_FAILED 301 Thread Create failed
521  THREAD_DELETE_FAILED 302 Thread Delete failed
522  PROHIBITED_IN_ISR_CONTEXT 303 Operation Prohibited in ISR context
523  PINMAP_INVALID 304 Pinmap Invalid
524  RTOS_EVENT 305 Unknown Rtos Error
525  RTOS_THREAD_EVENT 306 Rtos Thread Error
526  RTOS_MUTEX_EVENT 307 Rtos Mutex Error
527  RTOS_SEMAPHORE_EVENT 308 Rtos Semaphore Error
528  RTOS_MEMORY_POOL_EVENT 309 Rtos Memory Pool Error
529  RTOS_TIMER_EVENT 310 Rtos Timer Error
530  RTOS_EVENT_FLAGS_EVENT 311 Rtos Event flags Error
531  RTOS_MESSAGE_QUEUE_EVENT 312 Rtos Message queue Error
532  DEVICE_BUSY 313 Device Busy
533  CONFIG_UNSUPPORTED 314 Configuration not supported
534  CONFIG_MISMATCH 315 Configuration mismatch
535  ALREADY_INITIALIZED 316 Already initialized
536  HARDFAULT_EXCEPTION 317 HardFault exception
537  MEMMANAGE_EXCEPTION 318 MemManage exception
538  BUSFAULT_EXCEPTION 319 BusFault exception
539  USAGEFAULT_EXCEPTION 320 UsageFault exception
540  BLE_NO_FRAME_INITIALIZED, 321 BLE No frame initialized
541  BLE_BACKEND_CREATION_FAILED 322 BLE Backend creation failed
542  BLE_BACKEND_NOT_INITIALIZED 323 BLE Backend not initialized
543  ASSERTION_FAILED 324 Assertion Failed
544  AUTHENTICATION_FAILED 325 Authentication Failed
545  RBP_AUTHENTICATION_FAILED 326 Rollback Protect Authentication Failed
546  \endverbatim
547  *
548  * @note
549  * Custom Error codes can be defined using the macro DEFINE_CUSTOM_ERROR\n
550  * This is mainly meant to capture non-generic error codes specific to a device.
551  * For example DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR ,1 ) macro defines the following values:\n
552  * ERROR_CODE_MY_CUSTOM_ERROR = MBED_CUSTOM_ERROR_BASE+1\n
553  * ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MBED_MODULE_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)\n
554  * Its effectively equivalent to:\n
555  * ERROR_CODE_MY_CUSTOM_ERROR = 4097\n
556  * ERROR_MY_CUSTOM_ERROR = 0xA0FF1001\n (Note that MODULE field is set to MBED_MODULE_UNKNOWN) \n\n
557  *
558  * @note
559  * **Using error codes:** \n
560  * POSIX error codes may be used in modules/functions currently using POSIX error codes and switching them to Mbed-OS error codes
561  * may cause interoperability issues. For example, some of the filesystem, network stack implementations may need to use
562  * POSIX error codes in order to keep them compatible with other modules interfacing with them, and may continue to use POSIX error codes.
563  *
564  * In all other cases, like for any native development of Mbed-OS modules Mbed-OS error codes should be used.
565  * This makes it easy to use Mbed-OS error reporting/logging infrastructure and makes debugging error scenarios
566  * much more efficient.
567  *
568  * @note
569  * **Searching for error codes in mbed-os source tree:** \n
570  * If you get an error report as below which you want to search for in mbed-os source tree, first take note of "Error Code" number. \n
571  * For example, the below error report has an error code of \b 259. Find the error name associated with the error code and in this case its \b INVALID_FORMAT. \n
572  * Use that error name(\b INVALID_FORMAT) to search the source tree for code locations setting that specific error code. \n
573  * If the Error module reported is not 255(which indicates unknown module), you can also use that to narrow down to the specific component reporting the error.
574  * See mbed_module_type_t enum above for module mapping. \n
575  *
576  * \verbatim
577  ++ MbedOS Error Info ++
578  Error Status: 0x80FF013D Code: 317 Module: 255
579  Error Message: Fault exception
580  Location: 0x5CD1
581  Error Value: 0x4A2A
582  Current Thread: Id: 0x20001E80 Entry: 0x5EB1 StackSize: 0x1000 StackMem: 0x20000E80 SP: 0x2002FF90
583  For more info, visit: https://mbed.com/s/error?error=0x80FF013D&mbedos=999999&core=0x410FC241&compile=1&ver=5060528
584  -- MbedOS Error Info --
585  \endverbatim
586  */
587 
588 typedef enum _mbed_error_code {
589  //Below are POSIX ERROR CODE definitions, which starts at MBED_POSIX_ERROR_BASE(=0)
590  //POSIX ERROR CODE definitions starts at offset 0(MBED_POSIX_ERROR_BASE) to align them with actual POSIX Error Code
591  //defintions in mbed_retarget.h
592  // Error Name Error Code
593  MBED_DEFINE_POSIX_ERROR(EPERM, EPERM), /* 1 Operation not permitted */
594  MBED_DEFINE_POSIX_ERROR(ENOENT, ENOENT), /* 2 No such file or directory */
595  MBED_DEFINE_POSIX_ERROR(ESRCH, ESRCH), /* 3 No such process */
596  MBED_DEFINE_POSIX_ERROR(EINTR, EINTR), /* 4 Interrupted system call */
597  MBED_DEFINE_POSIX_ERROR(EIO, EIO), /* 5 I/O error */
598  MBED_DEFINE_POSIX_ERROR(ENXIO, ENXIO), /* 6 No such device or address */
599  MBED_DEFINE_POSIX_ERROR(E2BIG, E2BIG), /* 7 Argument list too long */
600  MBED_DEFINE_POSIX_ERROR(ENOEXEC, ENOEXEC), /* 8 Exec format error */
601  MBED_DEFINE_POSIX_ERROR(EBADF, EBADF), /* 9 Bad file number */
602  MBED_DEFINE_POSIX_ERROR(ECHILD, ECHILD), /* 10 No child processes */
603  MBED_DEFINE_POSIX_ERROR(EAGAIN, EAGAIN), /* 11 Try again */
604  MBED_DEFINE_POSIX_ERROR(ENOMEM, ENOMEM), /* 12 Out of memory */
605  MBED_DEFINE_POSIX_ERROR(EACCES, EACCES), /* 13 Permission denied */
606  MBED_DEFINE_POSIX_ERROR(EFAULT, EFAULT), /* 14 Bad address */
607  MBED_DEFINE_POSIX_ERROR(ENOTBLK, ENOTBLK), /* 15 Block device required */
608  MBED_DEFINE_POSIX_ERROR(EBUSY, EBUSY), /* 16 Device or resource busy */
609  MBED_DEFINE_POSIX_ERROR(EEXIST, EEXIST), /* 17 File exists */
610  MBED_DEFINE_POSIX_ERROR(EXDEV, EXDEV), /* 18 Cross-device link */
611  MBED_DEFINE_POSIX_ERROR(ENODEV, ENODEV), /* 19 No such device */
612  MBED_DEFINE_POSIX_ERROR(ENOTDIR, ENOTDIR), /* 20 Not a directory */
613  MBED_DEFINE_POSIX_ERROR(EISDIR, EISDIR), /* 21 Is a directory */
614  MBED_DEFINE_POSIX_ERROR(EINVAL, EINVAL), /* 22 Invalid argument */
615  MBED_DEFINE_POSIX_ERROR(ENFILE, ENFILE), /* 23 File table overflow */
616  MBED_DEFINE_POSIX_ERROR(EMFILE, EMFILE), /* 24 Too many open files */
617  MBED_DEFINE_POSIX_ERROR(ENOTTY, ENOTTY), /* 25 Not a typewriter */
618  MBED_DEFINE_POSIX_ERROR(ETXTBSY, ETXTBSY), /* 26 Text file busy */
619  MBED_DEFINE_POSIX_ERROR(EFBIG, EFBIG), /* 27 File too large */
620  MBED_DEFINE_POSIX_ERROR(ENOSPC, ENOSPC), /* 28 No space left on device */
621  MBED_DEFINE_POSIX_ERROR(ESPIPE, ESPIPE), /* 29 Illegal seek */
622  MBED_DEFINE_POSIX_ERROR(EROFS, EROFS), /* 30 Read-only file system */
623  MBED_DEFINE_POSIX_ERROR(EMLINK, EMLINK), /* 31 Too many links */
624  MBED_DEFINE_POSIX_ERROR(EPIPE, EPIPE), /* 32 Broken pipe */
625  MBED_DEFINE_POSIX_ERROR(EDOM, EDOM), /* 33 Math argument out of domain of func */
626  MBED_DEFINE_POSIX_ERROR(ERANGE, ERANGE), /* 34 Math result not representable */
627  MBED_DEFINE_POSIX_ERROR(EDEADLK, EDEADLK), /* 35 Resource deadlock would occur */
628  MBED_DEFINE_POSIX_ERROR(ENAMETOOLONG, ENAMETOOLONG), /* 36 File name too long */
629  MBED_DEFINE_POSIX_ERROR(ENOLCK, ENOLCK), /* 37 No record locks available */
630  MBED_DEFINE_POSIX_ERROR(ENOSYS, ENOSYS), /* 38 Function not implemented */
631  MBED_DEFINE_POSIX_ERROR(ENOTEMPTY, ENOTEMPTY), /* 39 Directory not empty */
632  MBED_DEFINE_POSIX_ERROR(ELOOP, ELOOP), /* 40 Too many symbolic links encountered */
633  MBED_DEFINE_POSIX_ERROR(EWOULDBLOCK, EAGAIN), /* EAGAIN Operation would block */
634  MBED_DEFINE_POSIX_ERROR(ENOMSG, ENOMSG), /* 42 No message of desired type */
635  MBED_DEFINE_POSIX_ERROR(EIDRM, EIDRM), /* 43 Identifier removed */
636  MBED_DEFINE_POSIX_ERROR(ECHRNG, ECHRNG), /* 44 Channel number out of range */
637  MBED_DEFINE_POSIX_ERROR(EL2NSYNC, EL2NSYNC), /* 45 Level 2 not synchronized */
638  MBED_DEFINE_POSIX_ERROR(EL3HLT, EL3HLT), /* 46 Level 3 halted */
639  MBED_DEFINE_POSIX_ERROR(EL3RST, EL3RST), /* 47 Level 3 reset */
640  MBED_DEFINE_POSIX_ERROR(ELNRNG, ELNRNG), /* 48 Link number out of range */
641  MBED_DEFINE_POSIX_ERROR(EUNATCH, EUNATCH), /* 49 Protocol driver not attached */
642  MBED_DEFINE_POSIX_ERROR(ENOCSI, ENOCSI), /* 50 No CSI structure available */
643  MBED_DEFINE_POSIX_ERROR(EL2HLT, EL2HLT), /* 51 Level 2 halted */
644  MBED_DEFINE_POSIX_ERROR(EBADE, EBADE), /* 52 Invalid exchange */
645  MBED_DEFINE_POSIX_ERROR(EBADR, EBADR), /* 53 Invalid request descriptor */
646  MBED_DEFINE_POSIX_ERROR(EXFULL, EXFULL), /* 54 Exchange full */
647  MBED_DEFINE_POSIX_ERROR(ENOANO, ENOANO), /* 55 No anode */
648  MBED_DEFINE_POSIX_ERROR(EBADRQC, EBADRQC), /* 56 Invalid request code */
649  MBED_DEFINE_POSIX_ERROR(EBADSLT, EBADSLT), /* 57 Invalid slot */
650  MBED_DEFINE_POSIX_ERROR(EDEADLOCK, EDEADLK), /* EDEADLK Resource deadlock would occur */
651  MBED_DEFINE_POSIX_ERROR(EBFONT, EBFONT), /* 59 Bad font file format */
652  MBED_DEFINE_POSIX_ERROR(ENOSTR, ENOSTR), /* 60 Device not a stream */
653  MBED_DEFINE_POSIX_ERROR(ENODATA, ENODATA), /* 61 No data available */
654  MBED_DEFINE_POSIX_ERROR(ETIME, ETIME), /* 62 Timer expired */
655  MBED_DEFINE_POSIX_ERROR(ENOSR, ENOSR), /* 63 Out of streams resources */
656  MBED_DEFINE_POSIX_ERROR(ENONET, ENONET), /* 64 Machine is not on the network */
657  MBED_DEFINE_POSIX_ERROR(ENOPKG, ENOPKG), /* 65 Package not installed */
658  MBED_DEFINE_POSIX_ERROR(EREMOTE, EREMOTE), /* 66 Object is remote */
659  MBED_DEFINE_POSIX_ERROR(ENOLINK, ENOLINK), /* 67 Link has been severed */
660  MBED_DEFINE_POSIX_ERROR(EADV, EADV), /* 68 Advertise error */
661  MBED_DEFINE_POSIX_ERROR(ESRMNT, ESRMNT), /* 69 Srmount error */
662  MBED_DEFINE_POSIX_ERROR(ECOMM, ECOMM), /* 70 Communication error on send */
663  MBED_DEFINE_POSIX_ERROR(EPROTO, EPROTO), /* 71 Protocol error */
664  MBED_DEFINE_POSIX_ERROR(EMULTIHOP, EMULTIHOP), /* 72 Multihop attempted */
665  MBED_DEFINE_POSIX_ERROR(EDOTDOT, EDOTDOT), /* 73 RFS specific error */
666  MBED_DEFINE_POSIX_ERROR(EBADMSG, EBADMSG), /* 74 Not a data message */
667  MBED_DEFINE_POSIX_ERROR(EOVERFLOW, EOVERFLOW), /* 75 Value too large for defined data type */
668  MBED_DEFINE_POSIX_ERROR(ENOTUNIQ, ENOTUNIQ), /* 76 Name not unique on network */
669  MBED_DEFINE_POSIX_ERROR(EBADFD, EBADFD), /* 77 File descriptor in bad state */
670  MBED_DEFINE_POSIX_ERROR(EREMCHG, EREMCHG), /* 78 Remote address changed */
671  MBED_DEFINE_POSIX_ERROR(ELIBACC, ELIBACC), /* 79 Can not access a needed shared library */
672  MBED_DEFINE_POSIX_ERROR(ELIBBAD, ELIBBAD), /* 80 Accessing a corrupted shared library */
673  MBED_DEFINE_POSIX_ERROR(ELIBSCN, ELIBSCN), /* 81 .lib section in a.out corrupted */
674  MBED_DEFINE_POSIX_ERROR(ELIBMAX, ELIBMAX), /* 82 Attempting to link in too many shared libraries */
675  MBED_DEFINE_POSIX_ERROR(ELIBEXEC, ELIBEXEC), /* 83 Cannot exec a shared library directly */
676  MBED_DEFINE_POSIX_ERROR(EILSEQ, EILSEQ), /* 84 Illegal byte sequence */
677  MBED_DEFINE_POSIX_ERROR(ERESTART, ERESTART), /* 85 Interrupted system call should be restarted */
678  MBED_DEFINE_POSIX_ERROR(ESTRPIPE, ESTRPIPE), /* 86 Streams pipe error */
679  MBED_DEFINE_POSIX_ERROR(EUSERS, EUSERS), /* 87 Too many users */
680  MBED_DEFINE_POSIX_ERROR(ENOTSOCK, ENOTSOCK), /* 88 Socket operation on non-socket */
681  MBED_DEFINE_POSIX_ERROR(EDESTADDRREQ, EDESTADDRREQ), /* 89 Destination address required */
682  MBED_DEFINE_POSIX_ERROR(EMSGSIZE, EMSGSIZE), /* 90 Message too long */
683  MBED_DEFINE_POSIX_ERROR(EPROTOTYPE, EPROTOTYPE), /* 91 Protocol wrong type for socket */
684  MBED_DEFINE_POSIX_ERROR(ENOPROTOOPT, ENOPROTOOPT), /* 92 Protocol not available */
685  MBED_DEFINE_POSIX_ERROR(EPROTONOSUPPORT, EPROTONOSUPPORT), /* 93 Protocol not supported */
686  MBED_DEFINE_POSIX_ERROR(ESOCKTNOSUPPORT, ESOCKTNOSUPPORT), /* 94 Socket type not supported */
687  MBED_DEFINE_POSIX_ERROR(EOPNOTSUPP, EOPNOTSUPP), /* 95 Operation not supported on transport endpoint */
688  MBED_DEFINE_POSIX_ERROR(EPFNOSUPPORT, EPFNOSUPPORT), /* 96 Protocol family not supported */
689  MBED_DEFINE_POSIX_ERROR(EAFNOSUPPORT, EAFNOSUPPORT), /* 97 Address family not supported by protocol */
690  MBED_DEFINE_POSIX_ERROR(EADDRINUSE, EADDRINUSE), /* 98 Address already in use */
691  MBED_DEFINE_POSIX_ERROR(EADDRNOTAVAIL, EADDRNOTAVAIL), /* 99 Cannot assign requested address */
692  MBED_DEFINE_POSIX_ERROR(ENETDOWN, ENETDOWN), /* 100 Network is down */
693  MBED_DEFINE_POSIX_ERROR(ENETUNREACH, ENETUNREACH), /* 101 Network is unreachable */
694  MBED_DEFINE_POSIX_ERROR(ENETRESET, ENETRESET), /* 102 Network dropped connection because of reset */
695  MBED_DEFINE_POSIX_ERROR(ECONNABORTED, ECONNABORTED), /* 103 Software caused connection abort */
696  MBED_DEFINE_POSIX_ERROR(ECONNRESET, ECONNRESET), /* 104 Connection reset by peer */
697  MBED_DEFINE_POSIX_ERROR(ENOBUFS, ENOBUFS), /* 105 No buffer space available */
698  MBED_DEFINE_POSIX_ERROR(EISCONN, EISCONN), /* 106 Transport endpoint is already connected */
699  MBED_DEFINE_POSIX_ERROR(ENOTCONN, ENOTCONN), /* 107 Transport endpoint is not connected */
700  MBED_DEFINE_POSIX_ERROR(ESHUTDOWN, ESHUTDOWN), /* 108 Cannot send after transport endpoint shutdown */
701  MBED_DEFINE_POSIX_ERROR(ETOOMANYREFS, ETOOMANYREFS), /* 109 Too many references: cannot splice */
702  MBED_DEFINE_POSIX_ERROR(ETIMEDOUT, ETIMEDOUT), /* 110 Connection timed out */
703  MBED_DEFINE_POSIX_ERROR(ECONNREFUSED, ECONNREFUSED), /* 111 Connection refused */
704  MBED_DEFINE_POSIX_ERROR(EHOSTDOWN, EHOSTDOWN), /* 112 Host is down */
705  MBED_DEFINE_POSIX_ERROR(EHOSTUNREACH, EHOSTUNREACH), /* 113 No route to host */
706  MBED_DEFINE_POSIX_ERROR(EALREADY, EALREADY), /* 114 Operation already in progress */
707  MBED_DEFINE_POSIX_ERROR(EINPROGRESS, EINPROGRESS), /* 115 Operation now in progress */
708  MBED_DEFINE_POSIX_ERROR(ESTALE, ESTALE), /* 116 Stale NFS file handle */
709  MBED_DEFINE_POSIX_ERROR(EUCLEAN, EUCLEAN), /* 117 Structure needs cleaning */
710  MBED_DEFINE_POSIX_ERROR(ENOTNAM, ENOTNAM), /* 118 Not a XENIX named type file */
711  MBED_DEFINE_POSIX_ERROR(ENAVAIL, ENAVAIL), /* 119 No XENIX semaphores available */
712  MBED_DEFINE_POSIX_ERROR(EISNAM, EISNAM), /* 120 Is a named type file */
713  MBED_DEFINE_POSIX_ERROR(EREMOTEIO, EREMOTEIO), /* 121 Remote I/O error */
714  MBED_DEFINE_POSIX_ERROR(EDQUOT, EDQUOT), /* 122 Quota exceeded */
715  MBED_DEFINE_POSIX_ERROR(ENOMEDIUM, ENOMEDIUM), /* 123 No medium found */
716  MBED_DEFINE_POSIX_ERROR(EMEDIUMTYPE, EMEDIUMTYPE), /* 124 Wrong medium type */
717  MBED_DEFINE_POSIX_ERROR(ECANCELED, ECANCELED), /* 125 Operation Canceled */
718  MBED_DEFINE_POSIX_ERROR(ENOKEY, ENOKEY), /* 126 Required key not available */
719  MBED_DEFINE_POSIX_ERROR(EKEYEXPIRED, EKEYEXPIRED), /* 127 Key has expired */
720  MBED_DEFINE_POSIX_ERROR(EKEYREVOKED, EKEYREVOKED), /* 128 Key has been revoked */
721  MBED_DEFINE_POSIX_ERROR(EKEYREJECTED, EKEYREJECTED), /* 129 Key was rejected by service */
722  MBED_DEFINE_POSIX_ERROR(EOWNERDEAD, EOWNERDEAD), /* 130 Owner died */
723  MBED_DEFINE_POSIX_ERROR(ENOTRECOVERABLE, ENOTRECOVERABLE), /* 131 State not recoverable */
724 
725  //Below are MBED SYSTEM ERROR CODE definitions
726  //MBED SYSTEM ERROR CODE definitions starts at offset MBED_SYSTEM_ERROR_BASE, see above.
727  // Error Name Error Offset Error Code
728  MBED_DEFINE_SYSTEM_ERROR(UNKNOWN, 0), /* 256 Unknown error */
729  MBED_DEFINE_SYSTEM_ERROR(INVALID_ARGUMENT, 1), /* 257 Invalid Argument */
730  MBED_DEFINE_SYSTEM_ERROR(INVALID_DATA_DETECTED, 2), /* 258 Invalid data detected */
731  MBED_DEFINE_SYSTEM_ERROR(INVALID_FORMAT, 3), /* 259 Invalid format */
732  MBED_DEFINE_SYSTEM_ERROR(INVALID_INDEX, 4), /* 260 Invalid Index */
733  MBED_DEFINE_SYSTEM_ERROR(INVALID_SIZE, 5), /* 261 Invalid Size */
734  MBED_DEFINE_SYSTEM_ERROR(INVALID_OPERATION, 6), /* 262 Invalid Operation */
735  MBED_DEFINE_SYSTEM_ERROR(ITEM_NOT_FOUND, 7), /* 263 Item Not Found */
736  MBED_DEFINE_SYSTEM_ERROR(ACCESS_DENIED, 8), /* 264 Access Denied */
737  MBED_DEFINE_SYSTEM_ERROR(UNSUPPORTED, 9), /* 265 Unsupported */
738  MBED_DEFINE_SYSTEM_ERROR(BUFFER_FULL, 10), /* 266 Buffer Full */
739  MBED_DEFINE_SYSTEM_ERROR(MEDIA_FULL, 11), /* 267 Media/Disk Full */
740  MBED_DEFINE_SYSTEM_ERROR(ALREADY_IN_USE, 12), /* 268 Already in use */
741  MBED_DEFINE_SYSTEM_ERROR(TIME_OUT, 13), /* 269 Timeout error */
742  MBED_DEFINE_SYSTEM_ERROR(NOT_READY, 14), /* 270 Not Ready */
743  MBED_DEFINE_SYSTEM_ERROR(FAILED_OPERATION, 15), /* 271 Requested Operation failed */
744  MBED_DEFINE_SYSTEM_ERROR(OPERATION_PROHIBITED, 16), /* 272 Operation prohibited */
745  MBED_DEFINE_SYSTEM_ERROR(OPERATION_ABORTED, 17), /* 273 Operation failed */
746  MBED_DEFINE_SYSTEM_ERROR(WRITE_PROTECTED, 18), /* 274 Attempt to write to write-protected resource */
747  MBED_DEFINE_SYSTEM_ERROR(NO_RESPONSE, 19), /* 275 No response */
748  MBED_DEFINE_SYSTEM_ERROR(SEMAPHORE_LOCK_FAILED, 20), /* 276 Semaphore lock failed */
749  MBED_DEFINE_SYSTEM_ERROR(MUTEX_LOCK_FAILED, 21), /* 277 Mutex lock failed */
750  MBED_DEFINE_SYSTEM_ERROR(SEMAPHORE_UNLOCK_FAILED, 22), /* 278 Semaphore unlock failed */
751  MBED_DEFINE_SYSTEM_ERROR(MUTEX_UNLOCK_FAILED, 23), /* 279 Mutex unlock failed */
752  MBED_DEFINE_SYSTEM_ERROR(CRC_ERROR, 24), /* 280 CRC error or mismatch */
753  MBED_DEFINE_SYSTEM_ERROR(OPEN_FAILED, 25), /* 281 Open failed */
754  MBED_DEFINE_SYSTEM_ERROR(CLOSE_FAILED, 26), /* 282 Close failed */
755  MBED_DEFINE_SYSTEM_ERROR(READ_FAILED, 27), /* 283 Read failed */
756  MBED_DEFINE_SYSTEM_ERROR(WRITE_FAILED, 28), /* 284 Write failed */
757  MBED_DEFINE_SYSTEM_ERROR(INITIALIZATION_FAILED, 29), /* 285 Initialization failed */
758  MBED_DEFINE_SYSTEM_ERROR(BOOT_FAILURE, 30), /* 286 Boot failure */
759  MBED_DEFINE_SYSTEM_ERROR(OUT_OF_MEMORY, 31), /* 287 Out of memory */
760  MBED_DEFINE_SYSTEM_ERROR(OUT_OF_RESOURCES, 32), /* 288 Out of resources */
761  MBED_DEFINE_SYSTEM_ERROR(ALLOC_FAILED, 33), /* 289 Alloc failed */
762  MBED_DEFINE_SYSTEM_ERROR(FREE_FAILED, 34), /* 290 Free failed */
763  MBED_DEFINE_SYSTEM_ERROR(OVERFLOW, 35), /* 291 Overflow error */
764  MBED_DEFINE_SYSTEM_ERROR(UNDERFLOW, 36), /* 292 Underflow error */
765  MBED_DEFINE_SYSTEM_ERROR(STACK_OVERFLOW, 37), /* 293 Stack overflow error */
766  MBED_DEFINE_SYSTEM_ERROR(ISR_QUEUE_OVERFLOW, 38), /* 294 ISR queue overflow */
767  MBED_DEFINE_SYSTEM_ERROR(TIMER_QUEUE_OVERFLOW, 39), /* 295 Timer Queue overflow */
768  MBED_DEFINE_SYSTEM_ERROR(CLIB_SPACE_UNAVAILABLE, 40), /* 296 Standard library error - Space unavailable */
769  MBED_DEFINE_SYSTEM_ERROR(CLIB_EXCEPTION, 41), /* 297 Standard library error - Exception */
770  MBED_DEFINE_SYSTEM_ERROR(CLIB_MUTEX_INIT_FAILURE, 42), /* 298 Standard library error - Mutex Init failure */
771  MBED_DEFINE_SYSTEM_ERROR(CREATE_FAILED, 43), /* 299 Create failed */
772  MBED_DEFINE_SYSTEM_ERROR(DELETE_FAILED, 44), /* 300 Delete failed */
773  MBED_DEFINE_SYSTEM_ERROR(THREAD_CREATE_FAILED, 45), /* 301 Thread Create failed */
774  MBED_DEFINE_SYSTEM_ERROR(THREAD_DELETE_FAILED, 46), /* 302 Thread Delete failed */
775  MBED_DEFINE_SYSTEM_ERROR(PROHIBITED_IN_ISR_CONTEXT, 47), /* 303 Operation Prohibited in ISR context */
776  MBED_DEFINE_SYSTEM_ERROR(PINMAP_INVALID, 48), /* 304 Pinmap Invalid */
777  MBED_DEFINE_SYSTEM_ERROR(RTOS_EVENT, 49), /* 305 Unknown Rtos Error */
778  MBED_DEFINE_SYSTEM_ERROR(RTOS_THREAD_EVENT, 50), /* 306 Rtos Thread Error */
779  MBED_DEFINE_SYSTEM_ERROR(RTOS_MUTEX_EVENT, 51), /* 307 Rtos Mutex Error */
780  MBED_DEFINE_SYSTEM_ERROR(RTOS_SEMAPHORE_EVENT, 52), /* 308 Rtos Semaphore Error */
781  MBED_DEFINE_SYSTEM_ERROR(RTOS_MEMORY_POOL_EVENT, 53), /* 309 Rtos Memory Pool Error */
782  MBED_DEFINE_SYSTEM_ERROR(RTOS_TIMER_EVENT, 54), /* 310 Rtos Timer Error */
783  MBED_DEFINE_SYSTEM_ERROR(RTOS_EVENT_FLAGS_EVENT, 55), /* 311 Rtos Event flags Error */
784  MBED_DEFINE_SYSTEM_ERROR(RTOS_MESSAGE_QUEUE_EVENT, 56), /* 312 Rtos Message queue Error */
785  MBED_DEFINE_SYSTEM_ERROR(DEVICE_BUSY, 57), /* 313 Device Busy */
786  MBED_DEFINE_SYSTEM_ERROR(CONFIG_UNSUPPORTED, 58), /* 314 Configuration not supported */
787  MBED_DEFINE_SYSTEM_ERROR(CONFIG_MISMATCH, 59), /* 315 Configuration mismatch */
788  MBED_DEFINE_SYSTEM_ERROR(ALREADY_INITIALIZED, 60), /* 316 Already initialized */
789  MBED_DEFINE_SYSTEM_ERROR(HARDFAULT_EXCEPTION, 61), /* 317 HardFault exception */
790  MBED_DEFINE_SYSTEM_ERROR(MEMMANAGE_EXCEPTION, 62), /* 318 MemManage exception */
791  MBED_DEFINE_SYSTEM_ERROR(BUSFAULT_EXCEPTION, 63), /* 319 BusFault exception */
792  MBED_DEFINE_SYSTEM_ERROR(USAGEFAULT_EXCEPTION, 64), /* 320 UsageFault exception*/
793  MBED_DEFINE_SYSTEM_ERROR(BLE_NO_FRAME_INITIALIZED, 65), /* 321 BLE No frame initialized */
794  MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_CREATION_FAILED, 66), /* 322 BLE Backend creation failed */
795  MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_NOT_INITIALIZED, 67), /* 323 BLE Backend not initialized */
796  MBED_DEFINE_SYSTEM_ERROR(ASSERTION_FAILED, 68), /* 324 Assertion Failed */
797  MBED_DEFINE_SYSTEM_ERROR(AUTHENTICATION_FAILED, 69), /* 325 Authentication Failed */
798  MBED_DEFINE_SYSTEM_ERROR(RBP_AUTHENTICATION_FAILED, 70), /* 326 Rollback Protection Authentication Failed */
799  MBED_DEFINE_SYSTEM_ERROR(BLE_USE_INCOMPATIBLE_API, 71), /* 327 Concurrent use of incompatible versions of a BLE API */
800  MBED_DEFINE_SYSTEM_ERROR(BLE_ILLEGAL_STATE, 72), /* 328 BLE stack entered illegal state */
801 
802  //Everytime you add a new system error code, you must update
803  //Error documentation under Handbook to capture the info on
804  //the new error status/codes
805 
806  //MBED CUSTOM ERROR CODE definitions starts at offset MBED_CUSTOM_ERROR_BASE, see above.
807  /* Add More/Custom Error Codes here, See example below */
808  //DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR , 1 ),
809 
811 
812 /** mbed_error_ctx struct
813  *
814  * This struct captures the context information at the time of error.\n
815  * It primarily contains information about the thread where the error originated,\n
816  * filename/line number of the source file where the error occurred, a context specific error value(error_value)\n
817  * and the address where the error originated.\n
818  *
819  * @note
820  * Below are the members of mbed_error_ctx struct\n
821  * error_status mbed_error_status_t value for this error\n
822  * error_function_address Address where the error occurred\n
823  * thread_id ID of the thread which generated the error\n
824  * thread_entry_address Entry function of the thread which generated the error\n
825  * thread_stack_size Stack Size of the thread which generated the error\n
826  * thread_stack_mem Stack Top of the thread which generated the error\n
827  * thread_current_sp Current Stack Pointer of the thread which generated the error\n
828  * error_value A context/error specific value associated with this error\n
829  * error_filename Filename where the error originated\n
830  * error_line_number Line number in error_filename where the error originated\n
831  */
832 typedef struct _mbed_error_ctx {
833  mbed_error_status_t error_status;
834  uint32_t error_address;
835  uint32_t error_value;
836  uint32_t thread_id;
837  uint32_t thread_entry_address;
838  uint32_t thread_stack_size;
839  uint32_t thread_stack_mem;
840  uint32_t thread_current_sp;
841 #ifdef MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN
842  char error_filename[MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN];
843  uint32_t error_line_number;
844 #endif
845 #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
846  int32_t error_reboot_count;//everytime we write this struct we increment this value by 1, irrespective of time between reboots. Note that the data itself might change, but everytime we reboot due to error we update this count by 1
847  int32_t is_error_processed;//once this error is processed set this value to 1
848  uint32_t crc_error_ctx;//crc_error_ctx should always be the last member in this struct
849 #endif
851 
852 /** To generate a fatal compile-time error, you can use the pre-processor #error directive.
853  *
854  * @param format C string that contains data stream to be printed.
855  * Code snippets below show valid format.
856  *
857  * @code
858  * #error "That shouldn't have happened!"
859  * @endcode
860  *
861  * If the compiler evaluates this line, it will report the error and stop the compile.
862  *
863  * For example, you could use this to check some user-defined compile-time variables:
864  *
865  * @code
866  * #define NUM_PORTS 7
867  * #if (NUM_PORTS > 4)
868  * #error "NUM_PORTS must be less than 4"
869  * #endif
870  * @endcode
871  *
872  * Reporting Run-Time Errors:
873  * To generate a fatal run-time error, you can use the mbed error() function.
874  *
875  * @code
876  * error("That shouldn't have happened!");
877  * @endcode
878  *
879  * If the mbed running the program executes this function, it will print the
880  * message via the USB serial port, and then die with the blue lights of death!
881  *
882  * The message can use printf-style formatting, so you can report variables in the
883  * message too. For example, you could use this to check a run-time condition:
884  *
885  * @code
886  * if(x >= 5) {
887  * error("expected x to be less than 5, but got %d", x);
888  * }
889  * @endcode
890  *
891  *
892  */
893 
894 MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
895 
896 /**
897  * Call this Macro to generate a mbed_error_status_t value for a System error
898  * @param module Module generating the error code. If its unknown, pass MBED_MODULE_UNKNOWN. See mbed_module_type_t for module types.
899  * @param error_code The mbed_error_code_t code to be used in generating the mbed_error_status_t. See mbed_error_code_t for error codes.
900  *
901  * @code
902  *
903  * mbed_error_status_t driver_error = MBED_MAKE_SYSTEM_ERROR( MODULE_DRIVER_USB, MBED_ERROR_CODE_INITIALIZATION_FAILED )
904  *
905  * @endcode
906  * @note This macro generate mbed_error_status_t-es with error type set to MBED_ERROR_TYPE_SYSTEM
907  *
908  */
909 #define MBED_MAKE_SYSTEM_ERROR(module, error_code) MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, module, error_code)
910 
911 /**
912  * Call this Macro to generate a mbed_error_status_t value for a Custom error
913  * @param module Module generating the error code. If its unknown, pass MBED_MODULE_UNKNOWN. See mbed_module_type_t for module types.
914  * @param error_code The mbed_error_code_t code to be used in generating the mbed_error_status_t. See mbed_error_code_t for error codes.
915  *
916  * @code
917  *
918  * mbed_error_status_t custom_error = MBED_MAKE_CUSTOM_ERROR( MBED_MODULE_APPLICATION, 0xDEAD//16-bit custom error code )
919  *
920  * @endcode
921  * @note This macro generate mbed_error_status_t-es with error type set to MBED_ERROR_TYPE_CUSTOM
922  *
923  */
924 #define MBED_MAKE_CUSTOM_ERROR(module, error_code) MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, module, error_code)
925 
926 /**
927  * Call this Macro to generate a mbed_error_status_t value for a System error
928  * @param module Module generating the error code. If its unknown, pass MBED_MODULE_UNKNOWN. See mbed_module_type_t for module types.
929  * @param error_code The mbed_error_code_t code to be used in generating the mbed_error_status_t. See mbed_error_code_t for error codes.
930  *
931  * @code
932  *
933  * mbed_error_status_t new_error = MBED_MAKE_ERROR( MODULE_DRIVER_USB, MBED_ERROR_INITIALIZATION_FAILED )
934  *
935  * @endcode
936  * @note This macro generate mbed_error_status_t-es with error type set to MBED_ERROR_TYPE_SYSTEM
937  *
938  */
939 #define MBED_MAKE_ERROR(module, error_code) MBED_MAKE_SYSTEM_ERROR(module, error_code)
940 
941 /**
942  * Callback/Error hook function prototype. Applications needing a callback when an error is reported can use mbed_set_error_hook function
943  * to register a callback/error hook function using the following prototype. When an error happens in the system error handling
944  * implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.
945  * @param error_ctx Error context structure associated with this error.
946  * @return void
947  *
948  */
949 typedef void (*mbed_error_hook_t)(const mbed_error_ctx *error_ctx);
950 
951 
952 /**
953  * Callback function for reporting error context during boot up. When MbedOS error handling system detects a fatal error
954  * it will auto-reboot the system(if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled) after capturing the
955  * error info in special crash data RAM region. Once rebooted, MbedOS initialization routines will call this function with a pointer to
956  * the captured mbed_error_ctx structure. If application implementation needs to receive this callback, mbed_error_reboot_callback
957  * function should be overridden with custom implementation. By default it's defined as a WEAK function in mbed_error.c.
958  * Note that this callback will be invoked before the system starts executing main() function. So the implementation of
959  * the callback should be aware any resource limitations/availability of resources which are yet to be initialized by application main().
960  *
961  * @param error_ctx Error context structure associated with this error.
962  * @return void
963  *
964  */
965 void mbed_error_reboot_callback(mbed_error_ctx *error_context);
966 
967 /**
968  * Initialize error handling system, this is called by the mbed-os boot sequence. This is not required to be called by Application unless the boot sequence is overridden by the system implementation.
969  * NOTE: If MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled and if the current reboot count exceeds MBED_CONF_PLATFORM_ERROR_REBOOT_MAX the system will halt when this function is called,
970  * and in such cases the caller will not get the control back. Also note that calling this function may trigger mbed_error_reboot_callback() if application side overides mbed_error_reboot_callback().
971  * @return MBED_SUCCESS on success.
972  *
973  */
974 
975 mbed_error_status_t mbed_error_initialize(void);
976 
977 /**
978  * Call this function to retrieve the error context after a fatal error which triggered a system reboot. The function retrieves the error context stored in crash-report ram area which is preserved over reboot.
979  * @param error_info Pointer to mbed_error_ctx struct allocated by the caller. This is the mbed_error_ctx info captured as part of the fatal error which triggered the reboot.
980  * @return 0 or MBED_SUCCESS on success.
981  * MBED_ERROR_INVALID_ARGUMENT in case of invalid error_info pointer
982  * MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system
983  *
984  */
985 mbed_error_status_t mbed_get_reboot_error_info(mbed_error_ctx *error_info);
986 
987 /**
988  * Calling this function resets the current reboot context captured by the system(stored in special crash data RAM region).
989  * @return MBED_SUCCESS on success.
990  * MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system
991  */
992 mbed_error_status_t mbed_reset_reboot_error_info(void);
993 
994 /**
995  * Calling this function resets the current reboot count stored as part of error context captured in special crash data RAM region.
996  * The function will also update the CRC value stored as part of error context accordingly.
997  * @return MBED_SUCCESS on success.
998  * MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system
999  */
1000 mbed_error_status_t mbed_reset_reboot_count(void);
1001 
1002 /**
1003  * Call this function to set a system error/warning. This function will log the error status with the context info and return to caller.
1004  *
1005  * @param error_status mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
1006  * @param error_msg The error message to be printed out to STDIO/Serial.
1007  * @param error_value Value associated with the error status. This would depend on error code/error scenario.
1008  * @param filename Name of the source file originating the error( Most callers can pass __FILE__ here ).
1009  * @param line_number The line number of the source file originating the error( Most callers can pass __LINE__ here ) .
1010  * @return 0 or MBED_SUCCESS.
1011  * MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
1012  *
1013  * @code
1014  *
1015  * mbed_error( ERROR_OUT_OF_MEMORY, "Out of memory error", 0, __FILE__, __LINE__ )
1016  *
1017  * @endcode
1018  *
1019  * @note See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API
1020  */
1021 mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
1022 
1023 /**
1024  * Returns the first system error reported.
1025  * @return mbed_error_status_t code logged for the first error or MBED_SUCCESS if no errors are logged.
1026  *
1027  */
1028 mbed_error_status_t mbed_get_first_error(void);
1029 
1030 /**
1031  * Returns the most recent system error reported.
1032  * @return mbed_error_status_t code logged for the last error or MBED_SUCCESS if no errors are logged.
1033  *
1034  */
1035 mbed_error_status_t mbed_get_last_error(void);
1036 
1037 /**
1038  * Returns the number of system errors reported after boot.
1039  * @return int Number of errors reported.
1040  *
1041  */
1042 int mbed_get_error_count(void);
1043 
1044 /**
1045  * Returns whether we are processing a fatal mbed error.
1046  * @return bool Whether a fatal error has occurred.
1047  *
1048  */
1049 bool mbed_get_error_in_progress(void);
1050 
1051 /**
1052  * Call this function to set a fatal system error and halt the system. This function will log the fatal error with the context info and prints the error report and halts the system.
1053  *
1054  * @param error_status mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
1055  * @param error_msg The error message to be printed out to STDIO/Serial.
1056  * @param error_value Value associated with the error status. This would depend on error code/error scenario.
1057  * @param filename Name of the source file originating the error( Most callers can pass __FILE__ here ).
1058  * @param line_number The line number of the source file originating the error( Most callers can pass __LINE__ here ) .
1059  * @return Does not return.
1060  *
1061  * @code
1062  *
1063  * mbed_error( MBED_ERROR_PROHIBITED_OPERATION, "Prohibited operation tried", 0, __FILE__, __LINE__ )
1064  *
1065  * @endcode
1066  *
1067  * @note See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API
1068  */
1069 MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
1070 
1071 /**
1072  * Registers an application defined error callback with the error handling system.
1073  * This function will be called with error context info whenever system handles a mbed_error/mbed_warning call
1074  * NOTE: This function should be implemented for re-entrancy as multiple threads may invoke mbed_error which may cause error hook to be called.
1075  * @param custom_error_hook mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
1076  * @return 0 or MBED_SUCCESS on success.
1077  * MBED_ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
1078  *
1079  * @code
1080  *
1081  * mbed_error_status_t my_custom_error_hook(mbed_error_status_t error_status, const mbed_error_ctx *error_ctx) {
1082  * //Do something with the error_status or error_ctx
1083  * }
1084  *
1085  * mbed_set_error_hook( my_custom_error_hook )
1086  *
1087  * @endcode
1088  * @note The erro hook function implementation should be re-entrant.
1089  *
1090  */
1091 mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t custom_error_hook);
1092 
1093 /**
1094  * Reads the first error context information captured.
1095  * @param error_info This is the mbed_error_context info captured as part of the first mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
1096  * @return 0 or MBED_SUCCESS on success.
1097  * MBED_ERROR_INVALID_ARGUMENT in case of invalid index
1098  *
1099  */
1100 mbed_error_status_t mbed_get_first_error_info(mbed_error_ctx *error_info);
1101 
1102 /**
1103  * Reads the last error context information captured.
1104  * @param error_info This is the mbed_error_context info captured as part of the last mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
1105  * @return 0 or MBED_ERROR_SUCCESS on success.
1106  * MBED_ERROR_INVALID_ARGUMENT in case of invalid index
1107  *
1108  */
1109 mbed_error_status_t mbed_get_last_error_info(mbed_error_ctx *error_info);
1110 
1111 /**
1112  * Clears the last error, first error, error count and all entries in the error history.
1113  * @return 0 or MBED_SUCCESS on success.
1114  *
1115  */
1116 mbed_error_status_t mbed_clear_all_errors(void);
1117 
1118 /**
1119  * Generates a mbed_error_status_t value based on passed in values for type, module and error code.
1120  * @param error_type Error type based on mbed_error_type_t enum.
1121  * @param module Module type based on mbed_module_type_t enum.
1122  * @param error_code Error codes defined by mbed_error_code_t enum
1123  * @return 0 or MBED_ERROR_SUCCESS on success.
1124  *
1125  */
1126 mbed_error_status_t mbed_make_error(mbed_error_type_t error_type, mbed_module_type_t module, mbed_error_code_t error_code);
1127 
1128 /**
1129  * Returns the current number of entries in the error history, if there has been more than max number of errors logged the number returned will be max depth of error history.
1130  * @return Current number of entries in the error history.
1131  *
1132  */
1133 int mbed_get_error_hist_count(void);
1134 
1135 /**
1136  * Reads the error context information for a specific error from error history, specified by the index.
1137  *
1138  * @param index index of the error context entry in the history to be retrieved.\n
1139  * The number of entries in the error history is configured during build and the max index depends on max depth of error history.\n
1140  * index = 0 points to the oldest entry in the history, and index = (max history depth - 1) points to the latest entry in the error history.\n
1141  * @param error_info This is the mbed_error_context info captured as part of the error history. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
1142  * @return 0 or MBED_SUCCESS on success.
1143  * MBED_ERROR_INVALID_ARGUMENT in case of invalid index
1144  *
1145  */
1146 mbed_error_status_t mbed_get_error_hist_info(int index, mbed_error_ctx *error_info);
1147 
1148 /**
1149  * Saves the error history information to a file
1150  *
1151  * @param path path to the file in the filesystem
1152  * @return 0 or MBED_ERROR_SUCCESS on success.
1153  * MBED_ERROR_WRITE_FAILED if writing to file failed
1154  * MBED_ERROR_INVALID_ARGUMENT if path is not valid
1155  *
1156  * @note Filesystem support is required in order for this function to work.
1157  *
1158  */
1159 mbed_error_status_t mbed_save_error_hist(const char *path);
1160 
1161 #ifdef __cplusplus
1162 }
1163 #endif
1164 
1165 #endif
1166 
1167 /** @}*/
1168 /** @}*/
1169 
1170 
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t custom_error_hook)
Registers an application defined error callback with the error handling system.
mbed_error_status_t mbed_error_initialize(void)
Initialize error handling system, this is called by the mbed-os boot sequence.
void mbed_error_reboot_callback(mbed_error_ctx *error_context)
Callback function for reporting error context during boot up.
MBED_NORETURN void error(const char *format,...) MBED_PRINTF(1
To generate a fatal compile-time error, you can use the pre-processor error directive.
_mbed_module_type
mbed_module_type_t definition
Definition: mbed_error.h:268
enum _mbed_error_type_t mbed_error_type_t
mbed_error_type_t definition
#define MBED_DEFINE_POSIX_ERROR(error_name, error_code)
Macro for defining a POSIX error status.
Definition: mbed_error.h:116
mbed_error_status_t mbed_make_error(mbed_error_type_t error_type, mbed_module_type_t module, mbed_error_code_t error_code)
Generates a mbed_error_status_t value based on passed in values for type, module and error code...
int mbed_get_error_count(void)
Returns the number of system errors reported after boot.
mbed_error_status_t mbed_get_last_error(void)
Returns the most recent system error reported.
mbed_error_status_t mbed_get_last_error_info(mbed_error_ctx *error_info)
Reads the last error context information captured.
int mbed_get_error_hist_count(void)
Returns the current number of entries in the error history, if there has been more than max number of...
enum _mbed_error_code mbed_error_code_t
mbed_error_code_t definition
MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
Call this function to set a fatal system error and halt the system.
mbed_error_status_t mbed_get_error_hist_info(int index, mbed_error_ctx *error_info)
Reads the error context information for a specific error from error history, specified by the index...
enum _mbed_module_type mbed_module_type_t
mbed_module_type_t definition
mbed_error_status_t mbed_clear_all_errors(void)
Clears the last error, first error, error count and all entries in the error history.
mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
Call this function to set a system error/warning.
#define MBED_DEFINE_SYSTEM_ERROR(error_name, error_code)
Macro for defining a System error status.
Definition: mbed_error.h:126
struct _mbed_error_ctx mbed_error_ctx
mbed_error_ctx struct
bool mbed_get_error_in_progress(void)
Returns whether we are processing a fatal mbed error.
mbed_error_status_t mbed_reset_reboot_count(void)
Calling this function resets the current reboot count stored as part of error context captured in spe...
int mbed_error_status_t
mbed_error_status_t description
Definition: mbed_error.h:108
_mbed_error_type_t
mbed_error_type_t definition
Definition: mbed_error.h:212
_mbed_error_code
mbed_error_code_t definition
Definition: mbed_error.h:588
mbed_error_status_t mbed_get_first_error_info(mbed_error_ctx *error_info)
Reads the first error context information captured.
mbed_error_status_t mbed_get_first_error(void)
Returns the first system error reported.
#define MBED_NORETURN
MBED_NORETURN Declare a function that will never return.
mbed_error_status_t mbed_save_error_hist(const char *path)
Saves the error history information to a file.
void(* mbed_error_hook_t)(const mbed_error_ctx *error_ctx)
Callback/Error hook function prototype.
Definition: mbed_error.h:949
mbed_error_status_t mbed_reset_reboot_error_info(void)
Calling this function resets the current reboot context captured by the system(stored in special cras...
mbed_error_status_t mbed_get_reboot_error_info(mbed_error_ctx *error_info)
Call this function to retrieve the error context after a fatal error which triggered a system reboot...
mbed_error_ctx struct
Definition: mbed_error.h:832
#define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN
Define this macro to include filenames in error context.
Definition: mbed_error.h:43
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.