Skip to content

Commit 83d5c05

Browse files
committed
esp32/mphalport: Add FUNC info to check_esp_err().
esp32/mphalport: Add __FUNCTION__, __LINE__, __FILE__ info to check_esp_err(). Signed-off-by: Ihor Nehrutsa <IhorNehrutsa@gmail.com>
1 parent bf35eef commit 83d5c05

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ports/esp32/mphalport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@
4747
#include "usb_serial_jtag.h"
4848
#include "uart.h"
4949

50+
#include "py/mpprint.h"
51+
52+
#define DEBUG 0
53+
5054
TaskHandle_t mp_main_task_handle;
5155

5256
STATIC uint8_t stdin_ringbuf_array[260];
5357
ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0};
5458

5559
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
56-
void check_esp_err(esp_err_t code) {
60+
void check_esp_err_(esp_err_t code, const char *func, const int line, const char *file) {
5761
if (code != ESP_OK) {
5862
// map esp-idf error code to posix error code
5963
uint32_t pcode = -code;
@@ -78,6 +82,9 @@ void check_esp_err(esp_err_t code) {
7882
o_str->data = (const byte *)esp_err_to_name(code); // esp_err_to_name ret's ptr to const str
7983
o_str->len = strlen((char *)o_str->data);
8084
o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
85+
#if DEBUG
86+
mp_printf(MP_PYTHON_PRINTER, "Exception in function '%s' at line %d in file '%s'", func, line, file);
87+
#endif
8188
// raise
8289
mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(pcode), MP_OBJ_FROM_PTR(o_str)};
8390
nlr_raise(mp_obj_exception_make_new(&mp_type_OSError, 2, 0, args));

ports/esp32/mphalport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ extern TaskHandle_t mp_main_task_handle;
5555
extern ringbuf_t stdin_ringbuf;
5656

5757
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
58-
void check_esp_err(esp_err_t code);
58+
#define check_esp_err(code) check_esp_err_(code, __FUNCTION__, __LINE__, __FILE__)
59+
void check_esp_err_(esp_err_t code, const char *func, const int line, const char *file);
5960

6061
uint32_t mp_hal_ticks_us(void);
6162
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy