diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-04-05 18:32:08 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-04-05 18:32:08 +0100 |
| commit | ea13f407a392593e7746131952a57bad222ee882 (patch) | |
| tree | 240fb586f678808bb5039a22e06a6214408adfc3 /stmhal | |
| parent | 2a037408af77d4c9e9cc98f5f12ea77fab93cc0e (diff) | |
py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off.
To address issue #420.
Diffstat (limited to 'stmhal')
| -rw-r--r-- | stmhal/adc.c | 8 | ||||
| -rw-r--r-- | stmhal/dac.c | 4 | ||||
| -rw-r--r-- | stmhal/exti.c | 10 | ||||
| -rw-r--r-- | stmhal/i2c.c | 8 | ||||
| -rw-r--r-- | stmhal/input.c | 2 | ||||
| -rw-r--r-- | stmhal/led.c | 2 | ||||
| -rw-r--r-- | stmhal/modos.c | 10 | ||||
| -rw-r--r-- | stmhal/pin_map.c | 4 | ||||
| -rw-r--r-- | stmhal/servo.c | 2 | ||||
| -rw-r--r-- | stmhal/timer.c | 2 | ||||
| -rw-r--r-- | stmhal/usart.c | 2 |
11 files changed, 27 insertions, 27 deletions
diff --git a/stmhal/adc.c b/stmhal/adc.c index 0b4f3e23e..8a1c23c4f 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -131,16 +131,16 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ const pin_obj_t *pin = pin_map_user_obj(pin_obj); if ((pin->adc_num & PIN_ADC1) == 0) { // No ADC1 function on that pin - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not have ADC capabilities", pin->name)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not have ADC capabilities", pin->name)); } channel = pin->adc_channel; } if (!IS_ADC_CHANNEL(channel)) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Not a valid ADC Channel: %d", channel)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Not a valid ADC Channel: %d", channel)); } if (pin_adc1[channel] == NULL) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Channel %d not available on this board", channel)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Channel %d not available on this board", channel)); } pyb_obj_adc_t *o = m_new_obj(pyb_obj_adc_t); @@ -192,7 +192,7 @@ void adc_init_all(pyb_obj_adc_all_t *adc_all, uint32_t resolution) { case 10: resolution = ADC_RESOLUTION10b; break; case 12: resolution = ADC_RESOLUTION12b; break; default: - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "resolution %d not supported", resolution)); } diff --git a/stmhal/dac.c b/stmhal/dac.c index 4dbf70022..22622d474 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -77,7 +77,7 @@ STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const pin = GPIO_PIN_5; dac_obj = &pyb_dac_channel_2; } else { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Dac %d does not exist", dac_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Dac %d does not exist", dac_id)); } // GPIO configuration @@ -182,7 +182,7 @@ mp_obj_t pyb_dac_dma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_obj_type_t *type = mp_obj_get_type(args[1]); if (type->buffer_p.get_buffer == NULL) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "buffer argument must support buffer protocol")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "buffer argument must support buffer protocol")); } buffer_info_t bufinfo; type->buffer_p.get_buffer(args[1], &bufinfo, BUFFER_READ); diff --git a/stmhal/exti.c b/stmhal/exti.c index a9b05644c..afb8c8e13 100644 --- a/stmhal/exti.c +++ b/stmhal/exti.c @@ -116,10 +116,10 @@ uint exti_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_ob // get both the port number and line number. v_line = mp_obj_get_int(pin_obj); if (v_line < 16) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d < 16, use a Pin object", v_line)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d < 16, use a Pin object", v_line)); } if (v_line >= EXTI_NUM_VECTORS) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d >= max of %d", v_line, EXTI_NUM_VECTORS)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d >= max of %d", v_line, EXTI_NUM_VECTORS)); } } else { pin = pin_map_user_obj(pin_obj); @@ -132,18 +132,18 @@ uint exti_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_ob mode != GPIO_MODE_EVT_RISING && mode != GPIO_MODE_EVT_FALLING && mode != GPIO_MODE_EVT_RISING_FALLING) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Mode: %d", mode)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Mode: %d", mode)); } int pull = mp_obj_get_int(pull_obj); if (pull != GPIO_NOPULL && pull != GPIO_PULLUP && pull != GPIO_PULLDOWN) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Pull: %d", pull)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Pull: %d", pull)); } exti_vector_t *v = &exti_vector[v_line]; if (v->callback_obj != mp_const_none && callback_obj != mp_const_none) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d is already in use", v_line)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d is already in use", v_line)); } // We need to update callback and param atomically, so we disable the line diff --git a/stmhal/i2c.c b/stmhal/i2c.c index f35d00b54..e998d5941 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -86,7 +86,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const // check i2c number if (!(0 <= i2c_id && i2c_id < PYB_NUM_I2C)) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C bus %d does not exist", i2c_id + 1)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C bus %d does not exist", i2c_id + 1)); } // get i2c object @@ -130,7 +130,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args) { if (status != HAL_OK) { // TODO really need a HardwareError object, or something - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Read failed with code %d", status)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Read failed with code %d", status)); } return mp_obj_str_builder_end(o); @@ -152,14 +152,14 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args) { uint8_t data[1] = {mp_obj_get_int(args[3])}; status = HAL_I2C_Mem_Write(self->i2c_handle, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, data, 1, 200); } else { - nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "data argument must be an integer or support the buffer protocol")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "data argument must be an integer or support the buffer protocol")); } //printf("Write got %d\n", status); if (status != HAL_OK) { // TODO really need a HardwareError object, or something - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Write failed with code %d", status)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Write failed with code %d", status)); } return mp_const_none; diff --git a/stmhal/input.c b/stmhal/input.c index d704c2cf7..0ded89866 100644 --- a/stmhal/input.c +++ b/stmhal/input.c @@ -14,7 +14,7 @@ STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) { vstr_init(&line, 16); int ret = readline(&line, ""); if (line.len == 0 && ret == VCP_CHAR_CTRL_D) { - nlr_jump(mp_obj_new_exception(&mp_type_EOFError)); + nlr_raise(mp_obj_new_exception(&mp_type_EOFError)); } mp_obj_t o = mp_obj_new_str((const byte*)line.buf, line.len, false); vstr_clear(&line); diff --git a/stmhal/led.c b/stmhal/led.c index 3108ee779..5c2d2c60a 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -204,7 +204,7 @@ STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const // check led number if (!(0 <= led_id && led_id < NUM_LEDS)) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Led %d does not exist", led_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Led %d does not exist", led_id)); } // return static led object diff --git a/stmhal/modos.c b/stmhal/modos.c index 5684d1105..6103b1b4f 100644 --- a/stmhal/modos.c +++ b/stmhal/modos.c @@ -38,7 +38,7 @@ STATIC mp_obj_t os_listdir(uint n_args, const mp_obj_t *args) { res = f_opendir(&dir, path); /* Open the directory */ if (res != FR_OK) { // TODO should be mp_type_FileNotFoundError - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "No such file or directory: '%s'", path)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "No such file or directory: '%s'", path)); } mp_obj_t dir_list = mp_obj_new_list(0, NULL); @@ -91,9 +91,9 @@ STATIC mp_obj_t os_mkdir(mp_obj_t path_o) { return mp_const_none; case FR_EXIST: // TODO should be FileExistsError - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "File exists: '%s'", path)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "File exists: '%s'", path)); default: - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error creating directory '%s'", path)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error creating directory '%s'", path)); } } @@ -107,7 +107,7 @@ STATIC mp_obj_t os_remove(mp_obj_t path_o) { case FR_OK: return mp_const_none; default: - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing file '%s'", path)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing file '%s'", path)); } } @@ -121,7 +121,7 @@ STATIC mp_obj_t os_rmdir(mp_obj_t path_o) { case FR_OK: return mp_const_none; default: - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing directory '%s'", path)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing directory '%s'", path)); } } diff --git a/stmhal/pin_map.c b/stmhal/pin_map.c index 2313540a3..c0c6910b2 100644 --- a/stmhal/pin_map.c +++ b/stmhal/pin_map.c @@ -164,7 +164,7 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) { pin_obj = mp_call_function_1(pin_map_obj.mapper, user_obj); if (pin_obj != mp_const_none) { if (!MP_OBJ_IS_TYPE(pin_obj, &pin_obj_type)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object")); } if (pin_map_obj.debug) { printf("Pin.mapper maps "); @@ -222,5 +222,5 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) { return pin_obj; } - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", pin_name)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", pin_name)); } diff --git a/stmhal/servo.c b/stmhal/servo.c index 893fb11bd..79a6843b7 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -147,7 +147,7 @@ STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con // check servo number if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1)); } // get and init servo object diff --git a/stmhal/timer.c b/stmhal/timer.c index cfdb93587..1e77f0fea 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -174,7 +174,7 @@ void timer_interrupt(void) { mp_obj_t pyb_Timer(mp_obj_t timx_in) { TIM_TypeDef *TIMx = (TIM_TypeDef*)mp_obj_get_int(timx_in); if (!IS_TIM_INSTANCE(TIMx)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "argument 1 is not a TIM instance")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "argument 1 is not a TIM instance")); } pyb_hal_tim_t *tim = m_new_obj(pyb_hal_tim_t); tim->htim.Instance = TIMx; diff --git a/stmhal/usart.c b/stmhal/usart.c index 9bcc6be28..3cf8da6de 100644 --- a/stmhal/usart.c +++ b/stmhal/usart.c @@ -145,7 +145,7 @@ STATIC void usart_obj_print(void (*print)(void *env, const char *fmt, ...), void STATIC mp_obj_t usart_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments if (!(n_args == 2 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Usart accepts 2 arguments")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Usart accepts 2 arguments")); } if (mp_obj_get_int(args[0]) > PYB_USART_MAX) { |
