summaryrefslogtreecommitdiff
path: root/docs/library/micropython.rst
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-06-20 10:56:05 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-06-20 10:56:05 -0700
commit30ee7019ca651bce1fe966c1089fe977d51dc92b (patch)
tree0114b6f744dd175b7722dd8edcbe24f4ee84bb45 /docs/library/micropython.rst
parent97fcdfbd08c922efd7470d6482d7c7c703ffc0ae (diff)
parent869cdcfdfc860b1177baf9b0f8818915ba54f3f5 (diff)
Merge tag 'v1.9.1'2.0.0-alpha.0
Fixes for stmhal USB mass storage, lwIP bindings and VFS regressions This release provides an important fix for the USB mass storage device in the stmhal port by implementing the SCSI SYNCHRONIZE_CACHE command, which is now require by some Operating Systems. There are also fixes for the lwIP bindings to improve non-blocking sockets and error codes. The VFS has some regressions fixed including the ability to statvfs the root. All changes are listed below. py core: - modbuiltins: add core-provided version of input() function - objstr: catch case of negative "maxsplit" arg to str.rsplit() - persistentcode: allow to compile with complex numbers disabled - objstr: allow to compile with obj-repr D, and unicode disabled - modsys: allow to compile with obj-repr D and PY_ATTRTUPLE disabled - provide mp_decode_uint_skip() to help reduce stack usage - makeqstrdefs.py: make script run correctly with Python 2.6 - objstringio: if created from immutable object, follow copy on write policy extmod: - modlwip: connect: for non-blocking mode, return EINPROGRESS - modlwip: fix error codes for duplicate calls to connect() - modlwip: accept: fix error code for non-blocking mode - vfs: allow to statvfs the root directory - vfs: allow "buffering" and "encoding" args to VFS's open() - modframebuf: fix signed/unsigned comparison pendantic warning lib: - libm: use isfinite instead of finitef, for C99 compatibility - utils/interrupt_char: remove support for KBD_EXCEPTION disabled tests: - basics/string_rsplit: add tests for negative "maxsplit" argument - float: convert "sys.exit()" to "raise SystemExit" - float/builtin_float_minmax: PEP8 fixes - basics: convert "sys.exit()" to "raise SystemExit" - convert remaining "sys.exit()" to "raise SystemExit" unix port: - convert to use core-provided version of built-in import() - Makefile: replace references to make with $(MAKE) windows port: - convert to use core-provided version of built-in import() qemu-arm port: - Makefile: adjust object-file lists to get correct dependencies - enable micropython.mem_*() functions to allow more tests stmhal port: - boards: enable DAC for NUCLEO_F767ZI board - add support for NUCLEO_F446RE board - pass USB handler as parameter to allow more than one USB handler - usb: use local USB handler variable in Start-of-Frame handler - usb: make state for USB device private to top-level USB driver - usbdev: for MSC implement SCSI SYNCHRONIZE_CACHE command - convert from using stmhal's input() to core provided version cc3200 port: - convert from using stmhal's input() to core provided version teensy port: - convert from using stmhal's input() to core provided version esp8266 port: - Makefile: replace references to make with $(MAKE) - Makefile: add clean-modules target - convert from using stmhal's input() to core provided version zephyr port: - modusocket: getaddrinfo: Fix mp_obj_len() usage - define MICROPY_PY_SYS_PLATFORM (to "zephyr") - machine_pin: use native Zephyr types for Zephyr API calls docs: - machine.Pin: remove out_value() method - machine.Pin: add on() and off() methods - esp8266: consistently replace Pin.high/low methods with .on/off - esp8266/quickref: polish Pin.on()/off() examples - network: move confusingly-named cc3200 Server class to its reference - uos: deconditionalize, remove minor port-specific details - uos: move cc3200 port legacy VFS mounting functions to its ref doc - machine: sort machine classes in logical order, not alphabetically - network: first step to describe standard network class interface examples: - embedding: use core-provided KeyboardInterrupt object
Diffstat (limited to 'docs/library/micropython.rst')
-rw-r--r--docs/library/micropython.rst115
1 files changed, 96 insertions, 19 deletions
diff --git a/docs/library/micropython.rst b/docs/library/micropython.rst
index 14e4c917e..7f4002856 100644
--- a/docs/library/micropython.rst
+++ b/docs/library/micropython.rst
@@ -7,25 +7,31 @@
Functions
---------
-.. only:: port_pyboard or port_unix
-
- .. function:: mem_info([verbose])
-
- Print information about currently used memory. If the ``verbose`` argument
- is given then extra information is printed.
-
- The information that is printed is implementation dependent, but currently
- includes the amount of stack and heap used. In verbose mode it prints out
- the entire heap indicating which blocks are used and which are free.
-
- .. function:: qstr_info([verbose])
-
- Print information about currently interned strings. If the ``verbose``
- argument is given then extra information is printed.
-
- The information that is printed is implementation dependent, but currently
- includes the number of interned strings and the amount of RAM they use. In
- verbose mode it prints out the names of all RAM-interned strings.
+.. function:: const(expr)
+
+ Used to declare that the expression is a constant so that the compile can
+ optimise it. The use of this function should be as follows::
+
+ from micropython import const
+
+ CONST_X = const(123)
+ CONST_Y = const(2 * CONST_X + 1)
+
+ Constants declared this way are still accessible as global variables from
+ outside the module they are declared in. On the other hand, if a constant
+ begins with an underscore then it is hidden, it is not available as a global
+ variable, and does not take up any memory during execution.
+
+ This `const` function is recognised directly by the MicroPython parser and is
+ provided as part of the `micropython` module mainly so that scripts can be
+ written which run under both CPython and MicroPython, by following the above
+ pattern.
+
+.. function:: opt_level([level])
+
+ If `level` is given then this function sets the optimisation level for subsequent
+ compilation of scripts, and returns `None`. Otherwise it returns the current
+ optimisation level.
.. function:: alloc_emergency_exception_buf(size)
@@ -37,3 +43,74 @@ Functions
A good way to use this function is to put it at the start of your main script
(eg boot.py or main.py) and then the emergency exception buffer will be active
for all the code following it.
+
+.. function:: mem_info([verbose])
+
+ Print information about currently used memory. If the ``verbose`` argument
+ is given then extra information is printed.
+
+ The information that is printed is implementation dependent, but currently
+ includes the amount of stack and heap used. In verbose mode it prints out
+ the entire heap indicating which blocks are used and which are free.
+
+.. function:: qstr_info([verbose])
+
+ Print information about currently interned strings. If the ``verbose``
+ argument is given then extra information is printed.
+
+ The information that is printed is implementation dependent, but currently
+ includes the number of interned strings and the amount of RAM they use. In
+ verbose mode it prints out the names of all RAM-interned strings.
+
+.. function:: stack_use()
+
+ Return an integer representing the current amount of stack that is being
+ used. The absolute value of this is not particularly useful, rather it
+ should be used to compute differences in stack usage at different points.
+
+.. function:: heap_lock()
+.. function:: heap_unlock()
+
+ Lock or unlock the heap. When locked no memory allocation can occur and a
+ `MemoryError` will be raised if any heap allocation is attempted.
+
+ These functions can be nested, ie `heap_lock()` can be called multiple times
+ in a row and the lock-depth will increase, and then `heap_unlock()` must be
+ called the same number of times to make the heap available again.
+
+.. function:: kbd_intr(chr)
+
+ Set the character that will raise a `KeyboardInterrupt` exception. By
+ default this is set to 3 during script execution, corresponding to Ctrl-C.
+ Passing -1 to this function will disable capture of Ctrl-C, and passing 3
+ will restore it.
+
+ This function can be used to prevent the capturing of Ctrl-C on the
+ incoming stream of characters that is usually used for the REPL, in case
+ that stream is used for other purposes.
+
+.. function:: schedule(fun, arg)
+
+ Schedule the function `fun` to be executed "very soon". The function
+ is passed the value `arg` as its single argument. "very soon" means that
+ the MicroPython runtime will do its best to execute the function at the
+ earliest possible time, given that it is also trying to be efficient, and
+ that the following conditions hold:
+
+ - A scheduled function will never preempt another scheduled function.
+ - Scheduled functions are always executed "between opcodes" which means
+ that all fundamental Python operations (such as appending to a list)
+ are guaranteed to be atomic.
+ - A given port may define "critical regions" within which scheduled
+ functions will never be executed. Functions may be scheduled within
+ a critical region but they will not be executed until that region
+ is exited. An example of a critical region is a preempting interrupt
+ handler (an IRQ).
+
+ A use for this function is to schedule a callback from a preempting IRQ.
+ Such an IRQ puts restrictions on the code that runs in the IRQ (for example
+ the heap may be locked) and scheduling a function to call later will lift
+ those restrictions.
+
+ There is a finite stack to hold the scheduled functions and `schedule`
+ will raise a `RuntimeError` if the stack is full.