Commit Graph

208 Commits

Author SHA1 Message Date
Damien George 6d2e9e70b3 extmod/modlwip: Check for state change during recv busy-wait loop.
For example, the peer may close the connection while recv is waiting for
incoming data.
2016-03-09 12:29:40 +07:00
Paul Sokolovsky 6185dc5f3d extmod/modlwip: Add stream .read() and .readline() methods. 2016-03-09 09:20:22 +07:00
Paul Sokolovsky f1919b7c98 extmod/modlwip: Add dummy .makefile() method. 2016-03-09 09:14:45 +07:00
Paul Sokolovsky c7fb87caff extmod/modlwip: Add stream protocol read method. 2016-03-09 09:12:32 +07:00
Paul Sokolovsky ed593780bf extmod/modlwip: Implement dummy setsockopt(). 2016-03-08 14:24:49 +07:00
Paul Sokolovsky f8d42da104 extmod/modlwip: Add .print() method. 2016-03-08 11:37:15 +07:00
Paul Sokolovsky 04a9ac7f38 extmod/modlwip: Update make_new() arguments for recent refactor. 2016-03-08 10:31:21 +07:00
Paul Sokolovsky 65405247a0 extmod/vfs_fat_lexer: Add func prototype for pedantic warnings. 2016-03-03 14:53:36 +02:00
Paul Sokolovsky 3aa0f2eed3 extmod/vfs_fat_lexer: Make conditional on FatFs support enabled. 2016-03-03 14:08:27 +02:00
Paul Sokolovsky 453a2a3d7c extmod/vfs_fat: Add lexer, move from stmhal port for reuse. 2016-03-03 13:25:44 +02:00
Paul Sokolovsky e0821830b0 extmod/vfs_fat: Add .rename() method. 2016-02-29 01:23:53 +02:00
Paul Sokolovsky 09e363316f extmod/vfs_fat_misc: Fix cc3200 port build. 2016-02-29 01:15:19 +02:00
Paul Sokolovsky 08fed6992f extmod/vfs_fat_misc: Add func prototype for pedantic warnings. 2016-02-29 00:48:45 +02:00
Paul Sokolovsky 6ef65e70af extmod/vfs_fat: Add fat_vfs_import_stat(), reusable import stat routine.
Moved from stmhal.
2016-02-29 00:44:32 +02:00
Paul Sokolovsky bbe832a0b2 extmod/vfs_fat: Add .mkdir() method. 2016-02-29 00:03:20 +02:00
Paul Sokolovsky 6f469209e9 extmod/vfs_fat: Fix unused param warning/error. 2016-02-28 20:45:51 +02:00
Paul Sokolovsky 19749db7bf extmod/vfs_fat: Add .remove() method.
Based on stmhal implementation - rather small, so just duplicating.
2016-02-28 20:30:07 +02:00
Paul Sokolovsky cd6d189f48 extmod/vfs_fat: Move listdir() method from stmhal for reuse. 2016-02-28 17:17:24 +02:00
Paul Sokolovsky 4cd45f48b1 cc3200: Fix breakage after VfsFat refactor. 2016-02-15 10:39:56 +02:00
Paul Sokolovsky 46a0ac02c5 extmod/vfs_fat_ffconf: Reusable FatFs module, move from stmhal/ffconf.
TODO: Probably merge into vfs_fat_diskio.
2016-02-15 00:19:27 +02:00
Paul Sokolovsky 6b0c88256b extmod/vfs_fat_file: Reusable FatFs module, move from stmhal/file. 2016-02-15 00:16:46 +02:00
Paul Sokolovsky 8cb78e0e53 extmod/vfs_fat_diskio: Reusable FatFs module, move from stmhal/diskio. 2016-02-15 00:08:37 +02:00
Paul Sokolovsky 1bb15ca427 extmod/fsusermount,vfs_fat: Nanbox cleanness. 2016-02-14 19:15:22 +02:00
Paul Sokolovsky e9be6a378c extmod/vfs_fat: Object-oriented encapsulation of FatFs VFS.
This implements OO interface based on existing fsusermount code and with
minimal changes to it, to serve as a proof of concept of OO interface.

Examle of usage:

bdev = RAMFS(48)
uos.VfsFat.mkfs(bdev)
vfs = uos.VfsFat(bdev, "/ramdisk")
f = vfs.open("foo", "w")
f.write("hello!")
f.close()
2016-02-14 19:15:21 +02:00
Paul Sokolovsky bf904b238d extmod/fsusermount: umount: Add NULL pointer checks. 2016-02-13 22:55:35 +02:00
Damien George e372e83b30 extmod/fsusermount: Move BP_IOCTL_xxx constants to fsusermount.h. 2016-02-10 23:40:35 +00:00
Damien George b33a770596 extmod/fsusermount: Support mounting of multiple block devices.
This patch adds support to fsusermount for multiple block devices
(instead of just one).  The maximum allowed is fixed at compile time by
the size of the fs_user_mount array accessed via MP_STATE_PORT, which
in turn is set by MICROPY_FATFS_VOLUMES.

With this patch, stmhal (which is still tightly coupled to fsusermount)
is also modified to support mounting multiple devices   And the flash and
SD card are now just two block devices that are mounted at start up if
they exist (and they have special native code to make them more
efficient).
2016-02-10 23:40:10 +00:00
Damien George 0e0ce47e65 extmod/fsusermount: Expose umount as a public function. 2016-02-10 23:40:10 +00:00
Damien George 3a042fb921 extmod/modmachine: Truncate integers that are to be stored using mem*.
Addresses issue #1835.
2016-02-10 17:05:03 +00:00
Damien George c33ad60a67 extmod/fsusermount: Change block protocol to support ioctl method.
The new block protocol is:
- readblocks(self, n, buf)
- writeblocks(self, n, buf)
- ioctl(self, cmd, arg)

The new ioctl method handles the old sync and count methods, as well as
a new "get sector size" method.

The old protocol is still supported, and used if the device doesn't have
the ioctl method.
2016-02-10 08:59:31 +00:00
Paul Sokolovsky 3846fd56c1 extmod/fsusermount: Implement separate umount() function. 2016-02-10 00:51:47 +02:00
Paul Sokolovsky 5b85a86ce3 extmod/fsusermount: Introduce separate mkfs() function.
Per the previously discussed plan. mount() still stays backward-compatible,
and new mkfs() is rought and takes more args than needed. But is a step
in a forward direction.
2016-02-10 00:50:07 +02:00
Paul Sokolovsky 103fbaaf27 extmod/fsusermount: Common subexpression elimination.
Don't repeat MP_STATE_PORT(fs_user_mount), use local var.
2016-02-06 22:26:34 +02:00
Paul Sokolovsky 67e8108345 extmod: Update uzlib to 1.2.2.
Fixes use of uninitialized structure field by tinf_uncompress().
2016-02-01 23:05:45 +02:00
Damien George a53af6c875 extmod/modurandom: Add some extra random functions.
Functions added are:
- randint
- randrange
- choice
- random
- uniform

They are enabled with configuration variable
MICROPY_PY_URANDOM_EXTRA_FUNCS, which is disabled by default.  It is
enabled for unix coverage build and stmhal.
2016-01-26 15:27:00 +00:00
Paul Sokolovsky f5c42dd9d1 extmod/moduhashlib: Use MICROPY_PY_UHASHLIB_SHA1 config define. 2016-01-25 00:49:00 +02:00
Paul Sokolovsky ee1656e148 extmod/moduhashlib: Add support for SHA1 (based on axTLS).
SHA1 is used in a number of protocols and algorithm originated 5 years ago
or so, in other words, it's in "wide use", and only newer protocols use
SHA2.

The implementation depends on axTLS enabled. TODO: Make separate config
option specifically for sha1().
2016-01-24 20:55:09 +02:00
Paul Sokolovsky ea495d6aa6 extmod/modurandom: Make yasmarang() function static. 2016-01-17 14:12:33 +02:00
Paul Sokolovsky a58a91eb04 extmod/modurandom: Add "urandom" module.
Seedable and reproducible pseudo-random number generator. Implemented
functions are getrandbits(n) (n <= 32) and seed().

The algorithm used is Yasmarang by Ilya Levin:
http://www.literatecode.com/yasmarang
2016-01-17 12:13:01 +02:00
Damien George 5b3f0b7f39 py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
The first argument to the type.make_new method is naturally a uPy type,
and all uses of this argument cast it directly to a pointer to a type
structure.  So it makes sense to just have it a pointer to a type from
the very beginning (and a const pointer at that).  This patch makes
such a change, and removes all unnecessary casting to/from mp_obj_t.
2016-01-11 00:49:27 +00:00
Damien George 4b72b3a133 py: Change type signature of builtin funs that take variable or kw args.
With this patch the n_args parameter is changed type from mp_uint_t to
size_t.
2016-01-11 00:49:27 +00:00
Damien George a0c97814df py: Change type of .make_new and .call args: mp_uint_t becomes size_t.
This patch changes the type signature of .make_new and .call object method
slots to use size_t for n_args and n_kw (was mp_uint_t.  Makes code more
efficient when mp_uint_t is larger than a machine word.  Doesn't affect
ports when size_t and mp_uint_t have the same size.
2016-01-11 00:48:41 +00:00
Dave Hylands 66d0c1052a extmod: Fix uctypes size calculation for bitfields 2016-01-10 23:31:26 +02:00
Antonin ENFRUN 26ed00118b uctypes: Implement assignment for scalar array 2016-01-03 20:23:20 +02:00
Paul Sokolovsky 467504da01 extmod/moduos_dupterm: Handle exceptions in call to dupterm's .write() 2016-01-01 22:06:38 +02:00
Paul Sokolovsky 30b7344eb0 extmod/moduos_dupterm: Make mp_uos_dupterm_tx_strn() function reusable.
Function to actually spool output terminal data to dupterm object.
2016-01-01 16:43:35 +02:00
Paul Sokolovsky ddea7cb702 extmod/moduos_dupterm: Make uos.dupterm() implementation reusable.
That's just function which sets/gets dup terminal object, and can be
easily reused across ports.
2016-01-01 13:04:32 +02:00
Paul Sokolovsky fb7b715b7b extmod/modlwip: Use _ERR_BADF instead of magic number. 2015-12-30 16:43:35 +02:00
Paul Sokolovsky bc25545fbb extmod/modlwip: Avoid magic numeric values in memcpy(). 2015-12-30 16:40:23 +02:00
Paul Sokolovsky 722fb2d251 extmod/modlwip: User proper field name and value names for socket state. 2015-12-30 16:26:23 +02:00
Paul Sokolovsky fff2dd2627 extmod/modlwip: Mark some lwip_socket_obj_t's fields as volatile.
Any fields changed by asynchronous callbacks must be volatile.
2015-12-29 21:02:02 +02:00
Paul Sokolovsky a63d4a6cc2 extmod/modlwip: tcp_recv: Use more regular and responsive poll pattern.
Polling once in 100ms means dismal performance.

TODO: Propagate this pattern to other polling places.
2015-12-29 20:37:22 +02:00
Paul Sokolovsky 7203b58e87 extmod/modubinascii: Add "separator" argument to hexlify().
This is extension to CPython, it allows to easily produce human-readable
hex dump:

>>> ubinascii.hexlify(b"\xaa\x55\xaa\x55", b" ")
b'aa 55 aa 55'
2015-12-26 02:15:56 +02:00
Paul Sokolovsky 1b7f622410 extmod/moduhashlib: Add namespace prefix for crypto-algorithms/sha256.h.
Everyone loves to names similar things the same, then there're conflicts
between different libraries. The namespace prefix used is "CRYAL_", which
is weird, and that's good, as that minimizes chance of another conflict.
2015-12-20 23:14:47 +02:00
Dave Hylands 755b01439b unix: machine_mem improvements
This basically introduces the MICROPY_MACHINE_MEM_GET_READ_ADDR
and MICROPY_MACHINE_MEM_GET_WRITE_ADDR macros. If one of them is
not defined, then a default identity function is provided.
2015-12-18 22:01:03 +02:00
Dave Hylands f925165942 unix: Move modmachine into unix directory
This leaves behind the common functionality in extmod/machine_mem.c
which can be used by all ports.
2015-12-13 01:21:36 +02:00
Paul Sokolovsky d4a874b81e extmod/moductypes: sizeof operation depends on layout type of structure.
Previously, sizeof() blindly assumed LAYOUT_NATIVE and tried to align
size even for packed LAYOUT_LITTLE_ENDIAN & LAYOUT_BIG_ENDIAN. As sizeof()
is implemented on a strucuture descriptor dictionary (not an structure
object), resolving this required passing layout type around.
2015-12-09 21:43:28 +02:00
Paul Sokolovsky add6f4556e extmod/moductypes: set_aligned(): Handle INT64/UINT64. 2015-12-04 00:59:08 +02:00
Damien George 999cedb90f py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
This allows the mp_obj_t type to be configured to something other than a
pointer-sized primitive type.

This patch also includes additional changes to allow the code to compile
when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of
mp_uint_t, and various casts.
2015-11-29 14:25:35 +00:00
Damien George cbf7674025 py: Add MP_ROM_* macros and mp_rom_* types and use them. 2015-11-29 14:25:04 +00:00
Damien George 278f3592d4 extmod/modmachine: Use uintptr_t instead of mp_uint_t for address type. 2015-11-29 14:25:04 +00:00
Paul Sokolovsky f0fbab7ca7 extmod/fsusermount: Make configurable with MICROPY_FSUSERMOUNT. 2015-11-25 13:19:36 +02:00
Paul Sokolovsky 3a1bbcc2ef extmod: Move fsusermount.c from stmhal for cross-port reuse. 2015-11-25 13:19:36 +02:00
Damien George a8aa1998ce extmod/modure: Use correct integer type for n_args argument. 2015-11-23 15:05:58 +00:00
Galen Hazelwood af3e45419c extmod/lwip: Change void pointers to unions, include new mphal.h file 2015-11-04 23:24:04 +03:00
Paul Sokolovsky d0601b0a1f extmod/re1.5: Workaround issue with mingw32-gcc 4.2.1. 2015-11-01 02:39:01 +03:00
Paul Sokolovsky aee704ebe1 extmod/modure: Make sure that errors in regexps are caught early. 2015-11-01 00:38:22 +03:00
Paul Sokolovsky 7cce2f664c extmod/re1.5: Update to 0.8.
Contains implementation of ?: (non-capturing groups), ?? (non-greedy ?),
as well as much improved robustness, and edge cases and error handling by
Amir Plivatsky (@ampli).
2015-11-01 00:38:00 +03:00
Paul Sokolovsky 4deb4936d5 extmod/modlwip: socket->incoming changed by async callbacks, must be volatile.
Otherwise for code like:

while (socket->incoming == NULL) {
    LWIP_DELAY(100);
}

a compiler may cache it in a register and it will be an infinite loop.
2015-10-31 19:51:23 +03:00
Paul Sokolovsky 20f85feecc extmod/moductypes: When dealing with UINT64, use mp_obj_new_int_from_ull().
Since we now have it.
2015-10-28 00:21:42 +03:00
Paul Sokolovsky 404dae80a9 unix, stmhal: Introduce mp_hal_delay_ms(), mp_hal_ticks_ms().
These MPHAL functions are intended to replace previously used HAL_Delay(),
HAL_GetTick() to provide better naming and MPHAL separation (they are
fully equivalent otherwise).

Also, refactor extmod/modlwip to use them.
2015-10-27 23:31:42 +03:00
Paul Sokolovsky 858ed6d2f7 extmod/modlwip: Codestyle: no need for () when taking address of primary expr.
Like foo.bar or foo->bar.
2015-10-27 01:39:57 +03:00
Paul Sokolovsky fa87e90cfa extmod/modlwip: lwip_tcp_send(): Common subexpression elimination, use MIN(). 2015-10-27 01:39:57 +03:00
Paul Sokolovsky 76217064ac extmod/modlwip.c: Codestyle whitespace changes.
With MicroPython codestyle, with pointer casts, "*" packs with primary type
without space. Few other similar changes too (git diff -b -w is null).
2015-10-27 01:39:57 +03:00
Paul Sokolovsky e0d7740a22 extmod/modlwip: slip: Use stream protocol and be port-independent.
Based on the original patch by Galen Hazelwood:
https://github.com/micropython/micropython/pull/1517 .
2015-10-27 00:04:59 +03:00
Paul Sokolovsky 393d0c1679 extmod/moductypes: Implement buffer protocol.
This is required to write structures to files, pass to FFI functions,
etc.
2015-10-26 01:03:24 +03:00
Galen Hazelwood 805c6534f8 extmod/modlwip: Initial commit of the lwip network stack module 2015-10-23 19:30:02 +03:00
Paul Sokolovsky d19e4f0ba4 extmod/modussl: Remove unused header. 2015-10-20 17:41:59 +03:00
Paul Sokolovsky aaa8867d4a modussl: SSL socket wrapper module based on axTLS. 2015-10-06 18:10:39 +03:00
Paul Sokolovsky 2a6660ba59 extmod/modmachine: Avoid conflicts with system PAGE_SIZE define, if any. 2015-08-18 00:31:31 +03:00
Paul Sokolovsky 354d17523f modmachine: Implement physical memory access using /dev/mem (Linux, etc).
This requires root access. And on recent Linux kernels, with
CONFIG_STRICT_DEVMEM option enabled, only address ranges listed in
/proc/iomem can be accessed. The above compiled-time option can be
however overriden with boot-time option "iomem=relaxed".

This also removed separate read/write paths - there unlikely would
be a case when they're different.
2015-07-08 11:37:23 +03:00
Damien George 722d4842df extmod/modubinascii: Re-use error string to reduce code size.
Drops Thumb2 arch size by 24 bytes.
2015-07-06 11:34:29 +00:00
Paul Sokolovsky 7370fd5560 ubinascii: Fix a shadowed variable case. 2015-07-04 13:13:10 +03:00
Paul Sokolovsky e284a95cc3 ubinascii: b2a_base64: Optimize away a modulo operation. 2015-07-04 12:36:46 +03:00
Galen Hazelwood 616986a5f3 extmod: Add a2b_base64 and b2a_base64 functions to ubinascii. 2015-07-04 12:26:52 +03:00
Paul Sokolovsky 1679696612 moductypes: Swap address and descriptor args in constructor.
Now address comes first, and args related to struct type are groupped next.
Besides clear groupping, should help catch errors eagerly (e.g. forgetting
to pass address will error out).

Also, improve args number checking/reporting overall.
2015-06-06 22:57:54 +03:00
Daniel Campora 7bd273b818 extmod: Actually expose the ubinascii python methods. 2015-05-22 09:56:09 +02:00
Paul Sokolovsky 2fddc68fdf moduhashlib: Remove not implemented .hexdigest().
Effect can be easily achieved by ubinsacii.hexlify(hash.digest()).
2015-05-21 17:20:26 +03:00
Daniel Campora 0f716aced7 extmod: Expose mod_binascii_hexlify() and mod_binascii_unhexlify(). 2015-05-21 17:19:41 +03:00
Dave Hylands 3ad94d6072 extmod: Add ubinascii.unhexlify
This also pulls out hex_digit from py/lexer.c and makes unichar_hex_digit
2015-05-20 09:29:22 +01:00
Damien George c50772d19f py: Add mp_obj_get_int_truncated and use it where appropriate.
mp_obj_get_int_truncated will raise a TypeError if the argument is not
an integral type.  Use mp_obj_int_get_truncated only when you know the
argument is a small or big int.
2015-05-12 23:05:53 +01:00
Paul Sokolovsky 0116218fa8 modmachine: Add new module to access hardware, starting with physical memory.
Refactored from "stm" module, provides mem8, mem16, mem32 objects with
array subscript syntax.
2015-05-04 13:05:12 +03:00
Damien George 7f9d1d6ab9 py: Overhaul and simplify printf/pfenv mechanism.
Previous to this patch the printing mechanism was a bit of a tangled
mess.  This patch attempts to consolidate printing into one interface.

All (non-debug) printing now uses the mp_print* family of functions,
mainly mp_printf.  All these functions take an mp_print_t structure as
their first argument, and this structure defines the printing backend
through the "print_strn" function of said structure.

Printing from the uPy core can reach the platform-defined print code via
two paths: either through mp_sys_stdout_obj (defined pert port) in
conjunction with mp_stream_write; or through the mp_plat_print structure
which uses the MP_PLAT_PRINT_STRN macro to define how string are printed
on the platform.  The former is only used when MICROPY_PY_IO is defined.

With this new scheme printing is generally more efficient (less layers
to go through, less arguments to pass), and, given an mp_print_t*
structure, one can call mp_print_str for efficiency instead of
mp_printf("%s", ...).  Code size is also reduced by around 200 bytes on
Thumb2 archs.
2015-04-16 14:30:16 +00:00
Damien George b1bbe966c4 py: Combine load_attr and store_attr type methods into one (attr).
This simplifies the API for objects and reduces code size (by around 400
bytes on Thumb2, and around 2k on x86).  Performance impact was measured
with Pystone score, but change was barely noticeable.
2015-04-11 16:54:37 +01:00
Damien George 6b07a6132f extmod/crypto: Add static keyword where it should be. 2015-03-19 00:25:33 +00:00
Paul Sokolovsky 02894b51f4 extmod: Update uzlib to 1.2.1.
Fixes for compiler warnings in pedantic mode.
2015-03-19 00:04:12 +02:00
Paul Sokolovsky d7194f1b8e extmod: Update re1.5 to 0.7.
Includes static function fix and all the previous improvements and fixes
by @dpgeorge.
2015-03-18 23:42:17 +02:00
stijn f43e03ee4f extmod/ure: Fix msvc warning resulting from memset on const char ** pointer 2015-03-17 15:41:42 +01:00
Damien George 1ef26b35c1 py, extmod: Remove include of unnecessary system headers. 2015-03-14 23:11:25 +00:00
Damien George 8dead2a6c6 extmod: Pull in upstream changes to re1.5; fixes bugs with regex errors. 2015-03-10 17:47:13 +00:00