diff options
Diffstat (limited to 'stmhal/mphal.c')
-rw-r--r-- | stmhal/mphal.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/stmhal/mphal.c b/stmhal/mphal.c new file mode 100644 index 000000000..e8f242051 --- /dev/null +++ b/stmhal/mphal.c @@ -0,0 +1,20 @@ +#include <errno.h> + +#include "mpconfig.h" +#include "nlr.h" +#include "misc.h" +#include "qstr.h" +#include "obj.h" +#include "mphal.h" + +// this table converts from HAL_StatusTypeDef to POSIX errno +const byte mp_hal_status_to_errno_table[4] = { + [HAL_OK] = 0, + [HAL_ERROR] = EIO, + [HAL_BUSY] = EBUSY, + [HAL_TIMEOUT] = ETIMEDOUT, +}; + +NORETURN void mp_hal_raise(HAL_StatusTypeDef status) { + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, (mp_obj_t)(mp_uint_t)mp_hal_status_to_errno_table[status])); +} |