summaryrefslogtreecommitdiffstatshomepage
path: root/lib/utils
Commit message (Collapse)AuthorAge
* shared: Introduce new top-level dir and move 1st party lib code there.Damien George2021-07-12
| | | | | | | | | | | | | | | | | | | | | | This commit moves all first-party code developed for this project from lib/ to shared/, so that lib/ now only contains third-party code. The following directories are moved as-is from lib to shared: lib/libc -> shared/libc lib/memzip -> shared/memzip lib/netutils -> shared/netutils lib/timeutils -> shared/timeutils lib/upytesthelper -> shared/upytesthelper All files in lib/embed/ have been moved to shared/libc/. lib/mp-readline has been moved to shared/readline. lib/utils has been moved to shared/runtime, with the exception of lib/utils/printf.c which has been moved to shared/libc/printf.c. Signed-off-by: Damien George <damien@micropython.org>
* lib/utils/stdout_helpers: Make mp_hal_stdout_tx_strn_cooked efficient.Damien George2021-07-08
| | | | | | | | To reduce the number of calls to mp_hal_stdout_tx_strn and improve the overall throughput of printing data. This implementation is taken from ports/stm32/mphalport.c. Signed-off-by: Damien George <damien@micropython.org>
* lib/utils: Add ARM semihosting utility functions.Ayke van Laethem2021-05-11
| | | | This can be a replacement for a UART in custom ports.
* py/gc: Make gc_lock_depth have a count per thread.Damien George2021-05-10
| | | | | | | | | | | | | | | | | | | | | | | This commit makes gc_lock_depth have one counter per thread, instead of one global counter. This makes threads properly independent with respect to the GC, in particular threads can now independently lock the GC for themselves without locking it for other threads. It also means a given thread can run a hard IRQ without temporarily locking the GC for all other threads and potentially making them have MemoryError exceptions at random locations (this really only occurs on MCUs with multiple cores and no GIL, eg on the rp2 port). The commit also removes protection of the GC lock/unlock functions, which is no longer needed when the counter is per thread (and this also fixes the cas where a hard IRQ calling gc_lock() may stall waiting for the mutex). It also puts the check for `gc_lock_depth > 0` outside the GC mutex in gc_alloc, gc_realloc and gc_free, to potentially prevent a hard IRQ from waiting on a mutex if it does attempt to allocate heap memory (and putting the check outside the GC mutex is now safe now that there is a gc_lock_depth per thread). Signed-off-by: Damien George <damien@micropython.org>
* lib/utils: Remove unused PYEXEC_SWITCH_MODE from pyexec.h.Damien George2021-04-24
| | | | | | It was made obsolete by commit c98c128fe885e539ecd73843756340f8950115c8. Signed-off-by: Damien George <damien@micropython.org>
* lib/utils/gchelper_generic: Implement AArch64 support.Yonatan Goldschmidt2021-03-11
|
* lib/utils/pyexec: Remove obsolete LCD initialization.stijn2021-01-30
| | | | | | | | This was added a long time ago in 75abee206d1a575aa98a486d043c94d64df432c1 when USB host support was added to the stm (now stm32) port, and when this pyexec code was actually part of the stm port. It's unlikely to work as intended anymore. If it is needed in the future then generic hook macros can be added in pyexec.
* lib/utils/pyexec: Add stdin-reader on raw REPL with flow control.Damien George2020-11-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Background: the friendly/normal REPL is intended for human use whereas the raw REPL is for computer use/automation. Raw REPL is used for things like pyboard.py script_to_run.py. The normal REPL has built-in flow control because it echos back the characters. That's not so with raw REPL and flow control is just implemented by rate limiting the amount of data that goes in. Currently it's fixed at 256 byte chunks every 10ms. This is sometimes too fast for slow MCUs or systems with small stdin buffers. It's also too slow for a lot of higher-end MCUs, ie it could be a lot faster. This commit adds a new raw REPL mode which includes flow control: the device will echo back a character after a certain number of bytes are sent to the host, and the host can use this to regulate the data going out to the device. The amount of characters is controlled by the device and sent to the host before communication starts. This flow control allows getting the maximum speed out of a serial link, regardless of the link or the device at the other end. Also, this new raw REPL mode parses and compiles the incoming data as it comes in. It does this by creating a "stdin reader" object which is then passed to the lexer. The lexer requests bytes from this "stdin reader" which retrieves bytes from the host, and does flow control. What this means is that no memory is used to store the script (in the existing raw REPL mode the device needs a big buffer to read in the script before it can pass it on to the lexer/parser/compiler). The only memory needed on the device is enough to parse and compile. Finally, it would be possible to extend this new raw REPL to allow bytecode (.mpy files) to be sent as well as text mode scripts (but that's not done in this commit). Some results follow. The test was to send a large 33k script that contains mostly comments and then prints out the heap, run via pyboard.py large.py. On PYBD-SF6, prior to this PR: $ ./pyboard.py large.py stack: 524 out of 23552 GC: total: 392192, used: 34464, free: 357728 No. of 1-blocks: 12, 2-blocks: 2, max blk sz: 2075, max free sz: 22345 GC memory layout; from 2001a3f0: 00000: h=hhhh=======================================hhBShShh==h=======h 00400: =====hh=B........h==h=========================================== 00800: ================================================================ 00c00: ================================================================ 01000: ================================================================ 01400: ================================================================ 01800: ================================================================ 01c00: ================================================================ 02000: ================================================================ 02400: ================================================================ 02800: ================================================================ 02c00: ================================================================ 03000: ================================================================ 03400: ================================================================ 03800: ================================================================ 03c00: ================================================================ 04000: ================================================================ 04400: ================================================================ 04800: ================================================================ 04c00: ================================================================ 05000: ================================================================ 05400: ================================================================ 05800: ================================================================ 05c00: ================================================================ 06000: ================================================================ 06400: ================================================================ 06800: ================================================================ 06c00: ================================================================ 07000: ================================================================ 07400: ================================================================ 07800: ================================================================ 07c00: ================================================================ 08000: ================================================================ 08400: ===============================================.....h==......... (349 lines all free) (the big blob of used memory is the large script). Same but with this PR: $ ./pyboard.py large.py stack: 524 out of 23552 GC: total: 392192, used: 1296, free: 390896 No. of 1-blocks: 12, 2-blocks: 3, max blk sz: 40, max free sz: 24420 GC memory layout; from 2001a3f0: 00000: h=hhhh=======================================hhBShShh==h=======h 00400: =====hh=h=B......h==.....h==.................................... (381 lines all free) The only thing in RAM is the compiled script (and some other unrelated items). Time to download before this PR: 1438ms, data rate: 230,799 bits/sec. Time to download with this PR: 119ms, data rate: 2,788,991 bits/sec. So it's more than 10 times faster, and uses significantly less RAM. Results are similar on other boards. On an stm32 board that connects via UART only at 115200 baud, the data rate goes from 80kbit/sec to 113kbit/sec, so gets close to saturating the UART link without loss of data. The new raw REPL mode also supports a single ctrl-C to break out of this flow-control mode, so that a ctrl-C can always get back to a known state. It's also backwards compatible with the original raw REPL mode, which is still supported with the same sequence of commands. The new raw REPL mode is activated by ctrl-E, which gives an error on devices that do not support the new mode. Signed-off-by: Damien George <damien@micropython.org>
* lib/utils/pyexec: Add MICROPY_BOARD hooks before/after executing code.Damien George2020-11-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* stm32/uart: Allow static IRQ handler registration.Jim Mussared2020-09-08
| | | | | This will allow the HCI UART to use a non-heap mp_irq_obj_t, which avoids needing to make a root pointer for it.
* lib/utils/mpirq: Add mp_irq_init func, and clean up unused init method.Damien George2020-09-04
| | | | | | | | mp_irq_init() is useful when the IRQ object is allocated by the caller. The mp_irq_methods_t.init method is not used anywhere so has been removed. Signed-off-by: Damien George <damien@micropython.org>
* lib/utils: Protect all of mpirq.c with MICROPY_ENABLE_SCHEDULER.Damien George2020-06-30
| | | | | | | | So it can be unconditionally included in a port's build even if certain configurations in that port do not use its features, to simplify the Makefile. Signed-off-by: Damien George <damien@micropython.org>
* tools/uncrustify: Enable more opts to remove space between func and '('.David Lechner2020-06-19
| | | | | | With only `sp_func_proto_paren = remove` set there are some cases where uncrustify misses removing a space between the function name and the opening '('. This sets all of the related options to `force` as well.
* lib/utils/pyexec: Add missing MP_ERROR_TEXT when compiler disabled.Damien George2020-06-02
|
* lib/utils: Lock the scheduler when executing hard callback functions.Damien George2020-05-27
| | | | | Otherwise scheduled functions may execute during the hard callback and then fail if they try to allocate heap memory.
* all: Factor gchelper code to one place and use it for unix & ARM ports.Jim Mussared2020-04-29
| | | | | | | | | | | | | | | | | No functionality change is intended with this commit, it just consolidates the separate implementations of GC helper code to the lib/utils/ directory as a general set of helper functions useful for any port. This reduces duplication of code, and makes it easier for future ports or embedders to get the GC implementation correct. Ports should now link against gchelper_native.c and either gchelper_m0.s or gchelper_m3.s (currently only Cortex-M is supported but other architectures can follow), or use the fallback gchelper_generic.c which will work on x86/x64/ARM. The gc_helper_get_sp function from gchelper_m3.s is not really GC related and was only used by cc3200, so it has been moved to that port and renamed to cortex_m3_get_sp.
* all: Format code to add space after C++-style comment start.stijn2020-04-23
| | | | | | Note: the uncrustify configuration is explicitly set to 'add' instead of 'force' in order not to alter the comments which use extra spaces after // as a means of indenting text for clarity.
* all: Reformat C and Python source code with tools/codeformat.py.Damien George2020-02-28
| | | | This is run with uncrustify 0.70.1, and black 19.10b0.
* py/scheduler: Move clearing of kbd traceback to mp_keyboard_interrupt.Damien George2020-02-07
| | | | | | This is a more logical place to clear the KeyboardInterrupt traceback, right before it is set as a pending exception. The clearing is also optimised from a function call to a simple store of NULL.
* py/scheduler: Move mp_keyboard_interrupt from lib/utils to py core.Damien George2020-02-07
| | | | | | This function is tightly coupled to the state and behaviour of the scheduler, and is a core part of the runtime: to schedule a pending exception. So move it there.
* lib/utils/pyexec: Handle pending exceptions after disabling kbd intrs.Damien George2020-02-07
| | | | | | | | | Pending exceptions would otherwise be handled later on where there may not be an NLR handler in place. A similar fix is also made to the unix port's REPL handler. Fixes issues #4921 and #5488.
* lib/utils: Change default value of pyexec_mode_kind to 0 to put in bss.odewdney2020-02-04
| | | | | | | | | By simply reordering the enums for pyexec_mode_kind_t it eliminates a data variable which costs ROM to initialise it. And the minimal build now has nothing in the data section. It seems the compiler is smart enough so that the generated code for if-logic which tests these enum values is unchanged.
* lib/utils/pyexec: Introduce MICROPY_REPL_INFO, wrap debug prints in it.Yonatan Goldschmidt2019-12-28
| | | | | | | | | | For the 3 ports that already make use of this feature (stm32, nrf and teensy) this doesn't make any difference, it just allows to disable it from now on. For other ports that use pyexec, this decreases code size because the debug printing code is dead (it can't be enabled) but the compiler can't deduce that, so code is still emitted.
* py: Introduce MP_ROM_NONE macro for ROM to refer to None object.Damien George2019-12-27
| | | | | This helps to prevent mistakes, and allows easily changing the ROM value of None if needed.
* py: Add global default_emit_opt variable to make emit kind persistent.Damien George2019-08-28
| | | | | | | | | | | | | mp_compile no longer takes an emit_opt argument, rather this setting is now provided by the global default_emit_opt variable. Now, when -X emit=native is passed as a command-line option, the emitter will be set for all compiled modules (included imports), not just the top-level script. In the future there could be a way to also set this variable from a script. Fixes issue #4267.
* lib/utils/sys_stdio_mphal: Add support to poll sys.stdin and sys.stdout.Damien George2019-07-01
| | | | | | A port must provide the following function for this to work: uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
* lib/utils/interrupt_char: Invalidate interrupt char at start up.Damien George2019-05-01
| | | | | | | Otherwise mp_interrupt_char will have a value of zero on start up (because it's in the BSS) and a KeyboardInterrupt may be raised during start up. For example this can occur if there is a UART attached to the REPL which sends spurious null bytes when the device turns on.
* lib/utils: Make pyexec_file_if_exists run frozen scripts if they exist.Andrew Leech2019-05-01
| | | | | | So that boot.py and/or main.py can be frozen (either as STR or MPY) in the same way that other scripts are frozen. Frozen scripts have preference to scripts in the VFS.
* lib/utils/pyexec: Add pyexec_file_if_exists() helper function.Damien George2019-04-26
| | | | It will only execute the script if it can be stat'd and is a file.
* all: Change PYB message prefix to MPY.Mike Causer2019-02-12
| | | | | | | | Replaces "PYB: soft reboot" with "MPY: soft reboot", etc. Having a consistent prefix across ports reduces the difference between ports, which is a general goal. And this change won't break pyboard.py because that tool only looks for "soft reboot".
* lib/utils/gchelper: Add gchelper.h header file for assembler functions.Damien George2019-02-12
|
* lib/utils/gchelper_m3: Add gc_helper_get_sp() function.Damien George2019-02-12
|
* lib/utils/gchelper_m3: Add license header and clean up code.Damien George2019-02-12
| | | | | This file generates the same code with the cortex-m3 and cortex-m4 assembler directive, so use cortex-m3 to support more CPUs.
* stm32: Move gchelper assembler code to lib/utils for use by other ports.Damien George2019-02-12
|
* lib/utils/printf: Exclude __GI_vsnprintf alias for gcc 9 and above.Damien George2019-02-06
| | | | See issue #4457.
* lib/utils/pyexec: Implement paste mode with event driven REPL.Damien George2019-01-28
|
* lib/utils: Add generic MicroPython IRQ helper functions.Tobias Badertscher2018-12-29
| | | | Initial implementation of this is taken from the cc3200 port.
* lib/utils/pyexec: Forcefully unlock the heap if locked and REPL active.Damien George2018-10-13
| | | | | | | Otherwise there is really nothing that can be done, it can't be unlocked by the user because there is no way to allocate memory to execute the unlock. See issue #4205 and #4209.
* py/mpconfig.h: Introduce MICROPY_DEBUG_PRINTER for debugging output.Damien George2018-08-02
| | | | | | | | | | | This patch in effect renames MICROPY_DEBUG_PRINTER_DEST to MICROPY_DEBUG_PRINTER, moving its default definition from lib/utils/printf.c to py/mpconfig.h to make it official and documented, and makes this macro a pointer rather than the actual mp_print_t struct. This is done to get consistency with MICROPY_ERROR_PRINTER, and provide this macro for use outside just lib/utils/printf.c. Ports are updated to use the new macro name.
* lib/utils: Expose pyb_set_repl_info function publicGlenn Ruben Bakke2018-07-18
| | | | | | | The patch enables the possibility to disable or initialize the repl info from outside of the module. Can also be used to initialize the repl_display_debugging_info in pyexec.c if not startup file is clearing .bss segment.
* lib/utils: Fix to support compiling with object representation D.Damien George2018-07-08
|
* lib/utils/printf: Make DEBUG_printf implementation more accessible.stijn2018-07-05
| | | | | | | | The definition of DEBUG_printf doesn't depend on MICROPY_USE_INTERNAL_PRINTF so move it out of that preprocessor block and compile it conditionally just depending on the MICROPY_DEBUG_PRINTERS macro. This allows a port to use DEBUG_printf while providing it's own printf definition.
* lib/utils/pyexec: Update to work with new MICROPY_HW_ENABLE_USB option.Damien George2018-02-13
|
* lib/utils/pyexec.h: Include py/obj.h because its decls are needed.Damien George2018-01-31
|
* all: Remove inclusion of internal py header files.Damien George2017-10-04
| | | | | | | | | | | | | | | | Header files that are considered internal to the py core and should not normally be included directly are: py/nlr.h - internal nlr configuration and declarations py/bc0.h - contains bytecode macro definitions py/runtime0.h - contains basic runtime enums Instead, the top-level header files to include are one of: py/obj.h - includes runtime0.h and defines everything to use the mp_obj_t type py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h, and defines everything to use the general runtime support functions Additional, specific headers (eg py/objlist.h) can be included if needed.
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* all: Unify header guard usage.Alexander Steffen2017-07-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code conventions suggest using header guards, but do not define how those should look like and instead point to existing files. However, not all existing files follow the same scheme, sometimes omitting header guards altogether, sometimes using non-standard names, making it easy to accidentally pick a "wrong" example. This commit ensures that all header files of the MicroPython project (that were not simply copied from somewhere else) follow the same pattern, that was already present in the majority of files, especially in the py folder. The rules are as follows. Naming convention: * start with the words MICROPY_INCLUDED * contain the full path to the file * replace special characters with _ In addition, there are no empty lines before #ifndef, between #ifndef and one empty line before #endif. #endif is followed by a comment containing the name of the guard macro. py/grammar.h cannot use header guards by design, since it has to be included multiple times in a single C file. Several other files also do not need header guards as they are only used internally and guaranteed to be included only once: * MICROPY_MPHALPORT_H * mpconfigboard.h * mpconfigport.h * mpthreadport.h * pin_defs_*.h * qstrdefs*.h
* stmhal: Move pybstdio.c to lib/utils/sys_stdio_mphal.c for common use.Damien George2017-06-15
| | | | | It provides sys.stdin, sys.stdout, sys.stderr for bare-metal targets based on mp_hal functions.
* lib/utils/interrupt_char: Remove support for KBD_EXCEPTION disabled.Damien George2017-06-02
| | | | | If a port is using interrupt_char.c then it must enable MICROPY_KBD_EXCEPTION. This is the case for all official ports.
* various: Spelling fixesVille Skyttä2017-05-29
|