|
30 | 30 | #include "gc.h" |
31 | 31 | #include "gccollect.h" |
32 | 32 | #include "systick.h" |
| 33 | +#include "pendsv.h" |
33 | 34 | #include "led.h" |
34 | 35 | #include "servo.h" |
35 | 36 | #include "lcd.h" |
@@ -327,7 +328,7 @@ int readline(vstr_t *line, const char *prompt) { |
327 | 328 | } |
328 | 329 | } |
329 | 330 | if (escape == 0) { |
330 | | - if (c == 4 && vstr_len(line) == len) { |
| 331 | + if (c == VCP_CHAR_CTRL_D && vstr_len(line) == len) { |
331 | 332 | return 0; |
332 | 333 | } else if (c == '\r') { |
333 | 334 | stdout_tx_str("\r\n"); |
@@ -435,10 +436,14 @@ void do_repl(void) { |
435 | 436 | nlr_buf_t nlr; |
436 | 437 | uint32_t start = sys_tick_counter; |
437 | 438 | if (nlr_push(&nlr) == 0) { |
| 439 | + usb_vcp_set_interrupt_char(VCP_CHAR_CTRL_C); // allow ctrl-C to interrupt us |
438 | 440 | rt_call_function_0(module_fun); |
| 441 | + usb_vcp_set_interrupt_char(VCP_CHAR_NONE); // disable interrupt |
439 | 442 | nlr_pop(); |
440 | 443 | } else { |
441 | 444 | // uncaught exception |
| 445 | + // FIXME it could be that an interrupt happens just before we disable it here |
| 446 | + usb_vcp_set_interrupt_char(VCP_CHAR_NONE); // disable interrupt |
442 | 447 | mp_obj_print_exception((mp_obj_t)nlr.ret_val); |
443 | 448 | } |
444 | 449 |
|
@@ -488,11 +493,15 @@ bool do_file(const char *filename) { |
488 | 493 |
|
489 | 494 | nlr_buf_t nlr; |
490 | 495 | if (nlr_push(&nlr) == 0) { |
| 496 | + usb_vcp_set_interrupt_char(VCP_CHAR_CTRL_C); // allow ctrl-C to interrupt us |
491 | 497 | rt_call_function_0(module_fun); |
| 498 | + usb_vcp_set_interrupt_char(VCP_CHAR_NONE); // disable interrupt |
492 | 499 | nlr_pop(); |
493 | 500 | return true; |
494 | 501 | } else { |
495 | 502 | // uncaught exception |
| 503 | + // FIXME it could be that an interrupt happens just before we disable it here |
| 504 | + usb_vcp_set_interrupt_char(VCP_CHAR_NONE); // disable interrupt |
496 | 505 | mp_obj_print_exception((mp_obj_t)nlr.ret_val); |
497 | 506 | return false; |
498 | 507 | } |
@@ -560,6 +569,10 @@ mp_obj_t pyb_rng_get(void) { |
560 | 569 | return mp_obj_new_int(RNG_GetRandomNumber() >> 16); |
561 | 570 | } |
562 | 571 |
|
| 572 | +mp_obj_t pyb_millis(void) { |
| 573 | + return mp_obj_new_int(sys_tick_counter); |
| 574 | +} |
| 575 | + |
563 | 576 | int main(void) { |
564 | 577 | // TODO disable JTAG |
565 | 578 |
|
@@ -592,6 +605,7 @@ int main(void) { |
592 | 605 |
|
593 | 606 | // basic sub-system init |
594 | 607 | sys_tick_init(); |
| 608 | + pendsv_init(); |
595 | 609 | led_init(); |
596 | 610 |
|
597 | 611 | #if MICROPY_HW_ENABLE_RTC |
@@ -693,6 +707,7 @@ int main(void) { |
693 | 707 | rt_store_attr(m, MP_QSTR_Usart, rt_make_function_n(2, pyb_Usart)); |
694 | 708 | rt_store_attr(m, qstr_from_str("ADC_all"), (mp_obj_t)&pyb_ADC_all_obj); |
695 | 709 | rt_store_attr(m, MP_QSTR_ADC, (mp_obj_t)&pyb_ADC_obj); |
| 710 | + rt_store_attr(m, qstr_from_str("millis"), rt_make_function_n(0, pyb_millis)); |
696 | 711 | rt_store_name(MP_QSTR_pyb, m); |
697 | 712 |
|
698 | 713 | rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open)); |
|
0 commit comments