summaryrefslogtreecommitdiffstatshomepage
path: root/extmod
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-10-27 23:31:42 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-10-27 23:31:42 +0300
commit404dae80a9d5cb6315071fe6206b2a6026be0a09 (patch)
tree1673c104f54427386044a0e739cc1adf8b6f0569 /extmod
parent9011815d862683711a6d79bb76a553d84b6e4556 (diff)
downloadmicropython-404dae80a9d5cb6315071fe6206b2a6026be0a09.tar.gz
micropython-404dae80a9d5cb6315071fe6206b2a6026be0a09.zip
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.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/lwip-include/lwipopts.h6
-rw-r--r--extmod/modlwip.c21
2 files changed, 14 insertions, 13 deletions
diff --git a/extmod/lwip-include/lwipopts.h b/extmod/lwip-include/lwipopts.h
index ddb4348900..a11bac935a 100644
--- a/extmod/lwip-include/lwipopts.h
+++ b/extmod/lwip-include/lwipopts.h
@@ -1,6 +1,10 @@
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
+#include <py/mpconfig.h>
+#include <py/misc.h>
+#include MICROPY_HAL_H
+
// We're running without an OS for this port. We don't provide any services except light protection.
#define NO_SYS 1
@@ -26,7 +30,7 @@ typedef uint32_t sys_prot_t;
// For now, we can simply define this as a macro for the timer code. But this function isn't
// universal and other ports will need to do something else. It may be necessary to move
// things like this into a port-provided header file.
-#define sys_now HAL_GetTick
+#define sys_now mp_hal_ticks_ms
#endif
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index 7711db1a94..ced9c06a1b 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -48,9 +48,6 @@
#include "lwip/sio.h"
#endif
-// FIXME FIXME FIXME
-#define LWIP_DELAY HAL_Delay
-
#ifdef MICROPY_PY_LWIP_SLIP
/******************************************************************************/
// Slip object for modlwip. Requires a serial driver for the port that supports
@@ -324,7 +321,7 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
if (socket->incoming == NULL) {
if (socket->timeout != -1) {
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
if (socket->incoming != NULL) break;
}
if (socket->incoming == NULL) {
@@ -333,7 +330,7 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
}
} else {
while (socket->incoming == NULL) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
}
}
}
@@ -378,7 +375,7 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
if (socket->incoming == NULL) {
if (socket->timeout != -1) {
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
if (socket->incoming != NULL) break;
}
if (socket->incoming == NULL) {
@@ -387,7 +384,7 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
}
} else {
while (socket->incoming == NULL) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
}
}
}
@@ -572,7 +569,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
if (socket->incoming == NULL) {
if (socket->timeout != -1) {
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
if (socket->incoming != NULL) break;
}
if (socket->incoming == NULL) {
@@ -580,7 +577,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
}
} else {
while (socket->incoming == NULL) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
}
}
}
@@ -656,7 +653,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
// And now we wait...
if (socket->timeout != -1) {
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
if (socket->connected != 1) break;
}
if (socket->connected == 1) {
@@ -664,7 +661,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
}
} else {
while (socket->connected == 1) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
}
}
if (socket->connected == 2) {
@@ -946,7 +943,7 @@ STATIC mp_obj_t lwip_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
}
case ERR_INPROGRESS: {
while(!lwip_dns_returned) {
- LWIP_DELAY(100);
+ mp_hal_delay_ms(100);
}
if (lwip_dns_returned == 2) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));