mbed_error.h 67 KB

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