diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-04-05 13:34:37 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-04-05 13:39:16 +0300 |
commit | faf333c04f3dddb9ca1a6b7fc5ff74eabcfe51b0 (patch) | |
tree | c00f3fbd88dfb2e713cf25e1ee3aa8f95e32273f | |
parent | 390d5a3bf101eba5952c3f757f27b82ff0bdfed1 (diff) | |
download | micropython-faf333c04f3dddb9ca1a6b7fc5ff74eabcfe51b0.tar.gz micropython-faf333c04f3dddb9ca1a6b7fc5ff74eabcfe51b0.zip |
zephyr/modusocket: Factor out "extended k_fifo API".
Internal structure of k_fifo changed between 1.7 and 1.8, so we need
to abstract it away. This adds more functions than currently used, for
future work.
-rw-r--r-- | zephyr/modusocket.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/zephyr/modusocket.c b/zephyr/modusocket.c index 155ed69b80..0bcbbce604 100644 --- a/zephyr/modusocket.c +++ b/zephyr/modusocket.c @@ -31,6 +31,8 @@ #include <stdio.h> #include <zephyr.h> +// Zephyr's generated version header +#include <version.h> #include <net/net_context.h> #include <net/nbuf.h> @@ -55,6 +57,36 @@ typedef struct _socket_obj_t { STATIC const mp_obj_type_t socket_type; +// k_fifo extended API + +static inline void *_k_fifo_peek_head(struct k_fifo *fifo) +{ +#if KERNEL_VERSION_NUMBER < 0x010763 /* 1.7.99 */ + return sys_slist_peek_head(&fifo->data_q); +#else + return sys_slist_peek_head(&fifo->_queue.data_q); +#endif +} + +static inline void *_k_fifo_peek_tail(struct k_fifo *fifo) +{ +#if KERNEL_VERSION_NUMBER < 0x010763 /* 1.7.99 */ + return sys_slist_peek_tail(&fifo->data_q); +#else + return sys_slist_peek_tail(&fifo->_queue.data_q); +#endif +} + +static inline void _k_fifo_wait_non_empty(struct k_fifo *fifo, int32_t timeout) +{ + struct k_poll_event events[] = { + K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, fifo), + }; + + k_poll(events, MP_ARRAY_SIZE(events), timeout); + DEBUG_printf("poll res: %d\n", events[0].state); +} + // Helper functions #define RAISE_ERRNO(x) { int _err = x; if (_err < 0) mp_raise_OSError(-_err); } @@ -112,8 +144,7 @@ static void sock_received_cb(struct net_context *context, struct net_buf *net_bu // if net_buf == NULL, EOF if (net_buf == NULL) { - // TODO: k_fifo accessor for this? - struct net_buf *last_buf = (struct net_buf*)sys_slist_peek_tail(&socket->recv_q.data_q); + struct net_buf *last_buf = _k_fifo_peek_tail(&socket->recv_q); // We abuse "buf_sent" flag to store EOF flag net_nbuf_set_buf_sent(last_buf, true); DEBUG_printf("Set EOF flag on %p\n", last_buf); |