Commit 404dae80 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

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.
parent 9011815d
#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
......@@ -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)));
......
......@@ -23,3 +23,6 @@ int mp_hal_stdin_rx_chr(void);
void mp_hal_stdout_tx_str(const char *str);
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define mp_hal_delay_ms HAL_Delay
#define mp_hal_ticks_ms HAL_GetTick
......@@ -119,7 +119,7 @@ void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str));
}
uint32_t HAL_GetTick(void) {
uint32_t mp_hal_ticks_ms(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
......
......@@ -38,5 +38,5 @@ void mp_hal_stdout_tx_str(const char *str);
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define HAL_Delay(ms) usleep((ms) * 1000)
uint32_t HAL_GetTick(void);
#define mp_hal_delay_ms(ms) usleep((ms) * 1000)
uint32_t mp_hal_ticks_ms(void);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment