Commit Graph

257 Commits

Author SHA1 Message Date
Paul Sokolovsky
1c6d91d968 extmod/modlwip: Add print_pcbs() debug function.
This requires lwIP built with LWIP_DEBUG (or it will be no-op).
2016-04-26 16:30:13 +03:00
Damien George
45ac5a85d5 extmod/modlwip: Workaround esp8266 sendto issue where 1 is returned. 2016-04-26 13:19:08 +01:00
Damien George
a63542387d extmod, stmhal: Fix typo of macro that detects if float is enabled. 2016-04-26 12:47:24 +01:00
Paul Sokolovsky
7a012f4793 extmod/modlwip: Protect recv/accept Python callback against exceptions.
Using usual call_function_*_protected() helper, to avoid NLR jump crashes.
2016-04-25 21:27:55 +03:00
Damien George
624738ca64 extmod/machine_i2c: Allow mp_hal_pin_obj_t to be any type, not a ptr. 2016-04-22 09:56:02 +01:00
Paul Sokolovsky
7d57037906 extmod/modlwip: Add ability to run callback on "recv" and "accept" events.
To use: .setsockopt(SOL_SOCKET, 20, lambda sock: print(sock)). There's a
single underlying callback slot. For normal sockets, it serves as data
received callback, for listening sockets - connection arrived callback.
2016-04-17 18:06:45 +03:00
Paul Sokolovsky
8007f84cca extmod/modlwip: lwip_tcp_receive(): Full error handling. 2016-04-17 02:22:26 +03:00
Paul Sokolovsky
b830f4c610 extmod/modlwip: lwip_tcp_send(): Full error handling. 2016-04-17 02:20:05 +03:00
Damien George
bcd719ea3a extmod/fsusermount: In mount/mkfs, deregister VFS object on error.
Should fix issue #1947.
2016-04-14 23:36:25 +01:00
Paul Sokolovsky
5c1af60e19 extmod/modlwip: More debug messages for various edge conditions. 2016-04-15 00:37:12 +03:00
Paul Sokolovsky
44ab5c3ef1 extmod/modlwip: Start adding debug output. 2016-04-14 01:15:52 +03:00
Paul Sokolovsky
fef0d9818a extmod/modlwip: lwip_tcp_receive(): Properly handle EOF for non-blocking sock. 2016-04-14 00:59:09 +03:00
Paul Sokolovsky
59a4fee516 extmod/modwebsocket: Another case to propagate EOF. 2016-04-13 22:17:09 +03:00
Paul Sokolovsky
54ea253f56 extmod/moduos_dupterm: Don't swallow exceptions in dupterm's read()/write().
The idea is that if dupterm object can handle exceptions, it will handle
them itself. Otherwise, object state can be compromised and it's better
to terminate dupterm session. For example, disconnected socket will keep
throwing exceptions and dump messages about that.
2016-04-13 16:34:11 +03:00
Damien George
eec8a94f04 extmod/machine_i2c: Implement I2C memory reading/writing. 2016-04-12 15:52:17 +01:00
Damien George
9314b2df4f extmod/machine_i2c: Fix I2C reading by sending ack/nack at end of byte. 2016-04-12 15:46:13 +01:00
Damien George
d083712224 extmod: Add generic machine.I2C class, with bit-bang I2C.
Should work on any machine that provides the correct pin functions.
2016-04-12 14:06:54 +01:00
Damien George
53ad681ed1 extmod: Add initial framebuf module. 2016-04-12 14:06:53 +01:00
Paul Sokolovsky
f8fb4470a0 extmod/modwebsocket: write(): Support write size beyond 125 bytes. 2016-04-11 14:07:57 +03:00
Paul Sokolovsky
7063210014 extmod/modlwip: Fix for loss of data in unaccepted incoming sockets.
When lwIP creates a incoming connection socket of a listen socket, it
sets its recv callback to one which discards incoming data. We set
proper callback only in accept() call, when we allocate Python-level
socket where we can queue incoming data. So, in lwIP accept callback
be sure to set recv callback to one which tells lwIP to not discard
incoming data.
2016-04-11 01:21:34 +03:00
Paul Sokolovsky
b69f798c92 extmod/modwebsocket.h: Split websocket-related defines for reuse. 2016-04-10 13:42:51 +03:00
Paul Sokolovsky
d6236e85c2 extmod/modwebsocket: Implement MP_STREAM_SET_DATA_OPTS ioctl.
Allows to set fragment type (txt/bin/etc.) for output records.
2016-04-10 13:19:26 +03:00
Paul Sokolovsky
6837dba6b8 extmod/modwebsocket: Allow to get type of last read data using ioctl(). 2016-04-10 12:50:46 +03:00
Paul Sokolovsky
f38e8f5217 extmod/modwebsocket: Record current fragment type (binary/text/etc.)
Also, handle continuation frames (untested).
2016-04-09 16:14:47 +03:00
Paul Sokolovsky
5b1c221785 extmod/modwebsocket: Add option for blocking writes to non-blk sockets.
This is strange asymmetry which is sometimes needed, e.g. for WebREPL: we
want to process only available input and no more; but for output, we want
to get rid of all of it, because there's no other place to buffer/store
it. This asymmetry is akin to CPython's asyncio asymmetry, where reads are
asynchronous, but writes are synchronous (asyncio doesn't expect them to
block, instead expects there to be (unlimited) buffering for any sync write
to completely immediately).
2016-04-09 16:03:38 +03:00
Paul Sokolovsky
397b705647 extmod/modwebsocket: Reset mask between packets. 2016-04-09 12:29:18 +03:00
Paul Sokolovsky
7e9182f3aa extmod/modwebsocket: Make sure to propagate EOF. 2016-04-08 20:26:54 +03:00
Tom Sparks
20d9bc2d76 extmod/modure: re_exec() renamed to ure_exec() due to collison in 4.3BSD.
Addresses issue #1972.
2016-04-08 20:12:03 +03:00
Paul Sokolovsky
05ba2433f6 extmod/modwebsocket: Properly check number of args to constructor. 2016-04-08 16:05:48 +03:00
Paul Sokolovsky
651a188299 extmod/vfs_fat_diskio: Actually support sectors != 512 with Python blockdevs. 2016-03-27 14:21:06 +03:00
Paul Sokolovsky
91031a75a1 extmod/modlwip: lwip_socket_setsockopt: Handle option value properly. 2016-03-25 20:53:52 +02:00
Paul Sokolovsky
4332d72fd8 extmod/modlwip: Add lwip->POSIX error map for lwIP 1.4.0.
Between 1.4.0 and 1.4.1, lwIP errors were renumbered.
2016-03-25 20:32:01 +02:00
Paul Sokolovsky
de0c84ebf1 extmod/modlwip: lwip_tcp_send: Handle properly send buffer full condition.
Per POSIX http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html :
"If space is not available at the sending socket to hold the message to be
transmitted, and the socket file descriptor does not have O_NONBLOCK set,
send() shall block until space is available. If space is not available at the
sending socket to hold the message to be transmitted, and the socket file
descriptor does have O_NONBLOCK set, send() shall fail [with EAGAIN]."
2016-03-25 18:38:13 +02:00
Paul Sokolovsky
5e75f335e6 extmod/modlwip: Implement setsocketopt(SO_REUSEADDR). 2016-03-25 17:44:24 +02:00
Paul Sokolovsky
8f1854ad2d extmod/modlwip: Add SOL_SOCKET and SO_REUSEADDR constants for setsockopt(). 2016-03-25 15:06:12 +02:00
Paul Sokolovsky
3dbd2ee926 extmod/modwebsocket: Implement read support. 2016-03-25 00:51:51 +02:00
Paul Sokolovsky
24342dd65e extmod/modwebsocket: Start module for WebSocket helper functions.
Currently, only write support is implemented (of limited buffer size).
2016-03-24 19:16:00 +02:00
Damien George
b894551772 extmod/uctypes: Change param type from void* to byte*. 2016-03-19 22:13:17 +00:00
Damien George
da161fd9f0 extmod/uctypes: Finish support for FLOAT32 and FLOAT64 types. 2016-03-19 21:59:42 +00:00
Damien George
12154b1774 extmod/uctypes: Use mp_binary_get_val helper when extracting value.
It handles more cases than mp_binary_get_int.
2016-03-19 21:41:01 +00:00
Damien George
0be6359f39 py: When printf'ing an object as a pointer, pass the concrete pointer. 2016-03-14 22:41:14 +00:00
Paul Sokolovsky
0779409d0d extmod/modlwip: lwip_tcp_receive: Properly map lwIP error to POSIX errno. 2016-03-12 11:42:15 +07:00
Paul Sokolovsky
ba8f7d5171 extmod/modlwip: Add socket.setblocking() method. 2016-03-12 10:52:50 +07:00
Paul Sokolovsky
09ed5bcbbb extmod/modlwip: Rework getaddrinfo() data passing.
The code is based on Damien George's implementation for esp8266 port,
avoids use of global variables and associated re-entrancy issues, and
fixes returning stale data in some cases.
2016-03-12 10:50:51 +07:00
Paul Sokolovsky
e5b047369b extmod/modlwip: Use MICROPY_EVENT_POLL_HOOK for event polling if defined.
Instead of just delaying 100ms if event isn't yet ready.

So far applies only to default, "infinite" socket timeout.
2016-03-11 09:32:07 +07:00
Paul Sokolovsky
43d497592f extmod/modlwip: Factor out "socket connected" check to a function.
Same code repeated for each send*() and recv*() function.
2016-03-09 12:43:09 +07:00
Paul Sokolovsky
fda874e406 extmod/modlwip: Support non-blocking recv(). 2016-03-09 12:39:33 +07:00
Paul Sokolovsky
7379be3673 extmod/modlwip: Add .write() stream method. 2016-03-09 12:35:43 +07:00
Damien George
4f64f6bfd3 extmod/modlwip: Still process remaining incoming data of a closed socket.
It can happen that a socket gets closed while the pbuf is not completely
drained by the application.  It can also happen that a new pbuf comes in
via the recv callback, and then a "peer closed" event comes via the same
callback (pbuf=NULL) before the previous event has been handled.  In both
cases the socket is closed but there is remaining data.  This patch makes
sure such data is passed to the application.
2016-03-09 12:31:25 +07:00
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