Commit Graph

467 Commits

Author SHA1 Message Date
Scott Shawcroft 778e975936 Split uos module into os and storage.
os is a subset of CPython's os. storage contains additional
file system mounting functionality based on UNIX's mount
management.

Fixes #140
2017-06-27 15:17:30 -07:00
Scott Shawcroft 30ee7019ca Merge tag 'v1.9.1'
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
2017-06-20 10:56:05 -07:00
Paul Sokolovsky 0a7735f1a6 extmod/modframebuf: Fix signed/unsigned comparison pendantic warning.
Happened with 32-bit gcc 4.8.4.
2017-06-10 20:34:38 +03:00
Damien George 7ecfbb8267 extmod/vfs: Allow "buffering" and "encoding" args to VFS's open().
These args are currently ignored but are parsed to make it easier to
write portable scripts between CPython and MicroPython.
2017-06-07 15:29:53 +10:00
Damien George f6ef8e3f17 extmod/vfs: Allow to statvfs the root directory. 2017-06-07 15:17:45 +10:00
Paul Sokolovsky 50de6d2fab extmod/modlwip: accept: Fix error code for non-blocking mode.
In non-blocking mode, if no pending connection available, should return
EAGAIN, not ETIMEDOUT.
2017-06-04 13:45:37 +03:00
Paul Sokolovsky 5da8de2b66 extmod/modlwip: Fix error codes for duplicate calls to connect().
If socket is already connected, POSIX requires returning EISCONN. If
connection was requested, but not yet complete (for non-blocking
socket), error code is EALREADY.

http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
2017-06-04 12:30:41 +03:00
Paul Sokolovsky a0dbbbebb8 extmod/modlwip: connect: For non-blocking mode, return EINPROGRESS.
Instead of ETIMEDOUT. This is consistent with POSIX:
http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
2017-06-03 22:48:31 +03:00
Ville Skyttä ca16c38210 various: Spelling fixes 2017-05-29 11:36:05 +03:00
Damien George f95e4e7782 extmod/vfs_fat_misc: Remove dot-dirs filter since FatFS already does it. 2017-05-13 18:58:46 +10:00
Scott Shawcroft 790c38e18c atmel-samd: Rework boot, main and REPL order.
Boot will only run once now before USB is started. Its output goes to
boot_out.txt. After main and REPL will run with VM and hardware resets
between each.
2017-05-12 18:26:14 -07:00
Damien George d70f688f25 extmod/vfs: Use MP_S_IFDIR, MP_S_IFREG consts instead of magic numbers. 2017-05-10 12:30:34 +10:00
Damien George d4cd4831b0 extmod/vfs_fat: Replace listdir() with implementation of ilistdir().
VfsFat no longer has the listdir() method.  Rather, if listdir()
functionality is needed then one should use uos.listdir() which will call
VfsFat.ilistdir().
2017-05-10 11:39:28 +10:00
Damien George 87283c1974 extmod/vfs: Implement mp_vfs_ilistdir().
uos.ilistdir() is the core function, returning an iterator that yields
3-tuples.  uos.listdir() is implemented in terms of ilistdir().
2017-05-10 11:39:28 +10:00
Damien George c9a3a68a49 extmod/vfs: Allow a VFS to be mounted at the root dir.
This patch allows mounting of VFS objects right at the root directory, eg
os.mount(vfs, '/').  It still allows VFS's to be mounted at a path within
the root, eg os.mount(vfs, '/flash'), and such mount points will override
any paths within a VFS that is mounted at the root.
2017-05-05 20:15:10 +10:00
Scott Shawcroft 58b9789d0c atmel-samd: Introduce audio sample playback via audioio.AudioOut. 2017-05-01 13:10:03 -07:00
Paul Sokolovsky 5db55e63f3 extmod/modlwip: ioctl POLL: Fix handling of peer closed socket.
Peer-closed socket is both readable and writable: read will return EOF,
write - error. Without this poll will hang on such socket.

Note that we don't return POLLHUP, based on argumentation in
http://www.greenend.org.uk/rjk/tech/poll.html that it should apply to
deeper disconnects, for example for networking, that would be link layer
disconnect (e.g. WiFi went down).
2017-05-01 18:20:09 +03:00
Paul Sokolovsky 4c2402e41e extmod/modlwip: getaddrinfo: Allow to accept all 6 standard params.
But warn if anything else but host/port is passed.
2017-04-29 18:56:39 +03:00
Paul Sokolovsky de3a96ba17 extmod/moduselect: Implement ipoll() method for alloc-free polling.
Similar to the implementation added to unix port module previously.
2017-04-29 13:05:44 +03:00
Paul Sokolovsky edc0dcb55c extmod/moduselect: Refactor towards introduction of poll.ipoll().
This follows previous refactor made to unix/moduselect.
2017-04-29 13:05:20 +03:00
Paul Sokolovsky b08286948a extmod/moduselect: Convert to MP_ROM_QSTR and friends. 2017-04-29 11:06:05 +03:00
Paul Sokolovsky 8109cd5f23 extmod/crypto-algorithms/sha256: Remove non-standard memory.h header. 2017-04-27 15:01:01 +03:00
Paul Sokolovsky 9e8f316392 extmod/moductypes: Fix bigint handling for 32-bit ports. 2017-04-21 16:43:21 +03:00
Damien George 61616e84ce extmod/machine_signal: Rename "inverted" arg to "invert", it's shorter.
A shorter name takes less code size, less room in scripts and is faster to
type at the REPL.

Tests and HW-API examples are updated to reflect the change.
2017-04-15 21:01:47 +03:00
Paul Sokolovsky 605ff91efd extmod/machine_signal: Support all Pin's arguments to the constructor.
This implements the orginal idea is that Signal is a subclass of Pin, and
thus can accept all the same argument as Pin, and additionally, "inverted"
param. On the practical side, it allows to avoid many enclosed parenses for
a typical declararion, e.g. for Zephyr:

Signal(Pin(("GPIO_0", 1))).

Of course, passing a Pin to Signal constructor is still supported and is the
most generic form (e.g. Unix port will only support such form, as it doesn't
have "builtin" Pins), what's introduces here is just practical readability
optimization.

"value" kwarg is treated as applying to a Signal (i.e. accounts for possible
inversion).
2017-04-11 00:12:20 +03:00
Peter Hinch 468c6f9da1 extmod/modframebuf: Make monochrome bitmap formats start with MONO_.
MONO_xxx is much easier to read if you're not familiar with the code.
MVLSB is deprecated but kept for backwards compatibility, for the time
being.

This patch also updates the associated docs and tests.
2017-04-04 17:38:33 +10:00
Damien George b6c7e4b143 all: Use full path name when including mp-readline/timeutils/netutils.
This follows the pattern of how all other headers are now included, and
makes it explicit where the header file comes from.  This patch also
removes -I options from Makefile's that specify the mp-readline/timeutils/
netutils directories, which are no longer needed.
2017-03-31 22:29:39 +11:00
Jan Pochyla e9d7c3ea0e modutimeq: Add peektime() function (provisional).
Allows to get event time for a head item in the queue. The usecase
if waiting for the next event *OR* I/O completion. I/O completion may
happen before event triggers, and then wait should continue for the
remaining event time (or I/O completion may schedule another earlier
event altogether).

The new function has a strongly provisional status - it may be converted
to e.g. peek() function returning all of the event fields, not just time.
2017-03-29 18:18:35 +03:00
Damien George 204ded848e extmod: Update for changes to mp_obj_str_get_data. 2017-03-29 12:56:45 +11:00
Damien George a8a3ab48da extmod/moduselect: Update to use size_t for array accessor. 2017-03-29 12:56:17 +11:00
Damien George f7816188b7 extmod/vfs_fat: Fix calculation of total blocks in statvfs. 2017-03-29 12:53:35 +11:00
Damien George b568448306 extmod/modlwip: Use mp_obj_str_get_str instead of mp_obj_str_get_data. 2017-03-26 19:19:35 +11:00
Damien George 2e3fc77809 extmod/utime_mphal: Don't exit/enter the GIL in generic sleep functions.
GIL behaviour should be handled by the port.  And ports probably want to
define sleep_us so that it doesn't release the GIL, to improve timing
accuracy.
2017-03-22 12:49:21 +11:00
Peter Hinch 231cfc84a7 extmod/modframebuf: Add support for monochrome horizontal format.
MHLSB and MHMSB formats are added to the framebuf module, which have 8
adjacent horizontal pixels represented in a single byte.
2017-03-20 16:21:47 +11:00
Damien George 1831034be1 py: Allow lexer to raise exceptions during construction.
This patch refactors the error handling in the lexer, to simplify it (ie
reduce code size).

A long time ago, when the lexer/parser/compiler were first written, the
lexer and parser were designed so they didn't use exceptions (ie nlr) to
report errors but rather returned an error code.  Over time that has
gradually changed, the parser in particular has more and more ways of
raising exceptions.  Also, the lexer never really handled all errors without
raising, eg there were some memory errors which could raise an exception
(and in these rare cases one would get a fatal nlr-not-handled fault).

This patch accepts the fact that the lexer can raise exceptions in some
cases and allows it to raise exceptions to handle all its errors, which are
for the most part just out-of-memory errors during construction of the
lexer.  This makes the lexer a bit simpler, and also the persistent code
stuff is simplified.

What this means for users of the lexer is that calls to it must be wrapped
in a nlr handler.  But all uses of the lexer already have such an nlr
handler for the parser (and compiler) so that doesn't put any extra burden
on the callers.
2017-03-14 11:52:05 +11:00
Damien George 0a3ac07ec7 extmod/vfs: Rewrite path lookup algo to support relative paths from root.
For example, if the current directory is the root dir then this patch
allows one to do uos.listdir('mnt'), where 'mnt' is a valid mount point.
Previous to this patch such a thing would not work, on needed to do
uos.listdir('/mnt') instead.
2017-03-13 21:37:21 +11:00
Damien George 643876fb77 extmod/vfs_fat: Allow to compile with MICROPY_VFS_FAT disabled.
Some ports may want to compile with generic MICROPY_VFS support but without
the VfsFat class.  This patch allows such a thing.
2017-03-13 21:23:31 +11:00
Damien George 12d0731b91 extmod/vfs_fat: Remove obsolete and unused str/len members. 2017-03-10 19:09:42 +11:00
Paul Sokolovsky 830ce74f32 extmod/modutimeq: Make scheduling fair (round-robin).
By adding back monotonically increasing field in addition to time field.
As heapsort is not stable, without this, among entried added and readded
at the same time instant, some might be always selected, and some might
never be selected, leading to scheduling starvation.
2017-03-07 09:34:09 +01:00
Scott Shawcroft 75d6abe3bb Correct name of mp_raise_NotImplementedError to make error name. 2017-02-24 16:46:38 +01:00
Paul Sokolovsky 0982884655 extmod/modurandom: Use mp_raise_ValueError().
For the standard unix x86_64 build, this saves 11 bytes on object file
level, but no difference in executable size due to (bloaty) code alignment.
2017-02-24 10:04:23 -05:00
Scott Shawcroft 12fa5b3a66 Switch exception throwing to mp_raise helpers. It saves a little code space each time to share the call. 2017-02-24 15:13:07 +01:00
Damien George ae8d867586 py: Add iter_buf to getiter type method.
Allows to iterate over the following without allocating on the heap:
- tuple
- list
- string, bytes
- bytearray, array
- dict (not dict.keys, dict.values, dict.items)
- set, frozenset

Allows to call the following without heap memory:
- all, any, min, max, sum

TODO: still need to allocate stack memory in bytecode for iter_buf.
2017-02-16 18:38:06 +11:00
Paul Sokolovsky a937750ceb extmod/modlwip: Add my copyright.
Per:

$ git log modlwip.c |grep ^Auth | sort | uniq -c
      9 Author: Damien George
      2 Author: Galen Hazelwood
     43 Author: Paul Sokolovsky
2017-02-15 19:20:46 +03:00
Scott Shawcroft 18c299b13d Make mp_float_t conversions explicit to silence warnings of converting floats to doubles. 2017-02-14 10:55:54 +01:00
Damien George 3625afa173 extmod/vfs: Allow to stat the root directory.
os.stat('/') now works and returns a mostly-empty tuple.  Really all that
is useful is the mode which tells that it's a directory.
2017-02-13 12:25:43 +11:00
Damien George 8f1c6d952a extmod/vfs: Raise OSError(EEXIST) on attempt to mkdir a mount point. 2017-02-09 15:51:34 +11:00
Damien George ec7dc7f8d7 extmod/vfs: Allow to mount a block device, not just a VFS object.
If the mounted object doesn't have a "mount" method then assume it's a
block device and try to detect the filesystem.  Since we currently only
support FAT filesystems, the behaviour is to just try and create a VfsFat
object automatically, using the given block device.
2017-02-09 12:03:12 +11:00
Paul Sokolovsky 181f7d1450 extmod/machine_signal: Implement Signal .on() and .off() methods.
Each method asserts and deasserts signal respectively. They are equivalent
to .value(1) and .value(0) but conceptually simpler (and may help to avoid
confusion with inverted signals, where "asserted" state means logical 0
output).
2017-02-08 11:14:23 +03:00
Damien George dee47949cc extmod/machine_spi: Remove EVENT_POLL_HOOK from soft-SPI transfer func.
SPI needs to be fast, and calling the EVENT_POLL_HOOK every byte makes it
unusable for ports that need to do non-trivial work in the EVENT_POLL_HOOK
call.  And individual SPI transfers should be short enough in time that
EVENT_POLL_HOOK doesn't need to be called.

If something like this proves to be needed in practice then we will need
to introduce separate event hook macros, one for "slow" loops (eg
select/poll) and one for "fast" loops (eg software I2C, SPI).
2017-02-06 14:38:33 +11:00