8000 unix/unix_mphal: Implement HAL_Delay() and HAL_GetTick(). · micropython/micropython@949c5c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 949c5c9

Browse files
author
Paul Sokolovsky
committed
unix/unix_mphal: Implement HAL_Delay() and HAL_GetTick().
1 parent 7799410 commit 949c5c9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

unix/unix_mphal.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <unistd.h>
2828
#include <stdlib.h>
2929
#include <string.h>
30+
#include <sys/time.h>
3031

3132
#include "py/mpstate.h"
3233
#include MICROPY_HAL_H
@@ -117,3 +118,9 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
117118
void mp_hal_stdout_tx_str(const char *str) {
118119
mp_hal_stdout_tx_strn(str, strlen(str));
119120
}
121+
122+
uint32_t HAL_GetTick(void) {
123+
struct timeval tv;
124+
gettimeofday(&tv, NULL);
125+
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
126+
}

unix/unix_mphal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ int mp_hal_stdin_rx_chr(void);
3737
void mp_hal_stdout_tx_str(const char *str);
3838
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
3939
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
40+
41+
#define HAL_Delay(ms) usleep((ms) * 1000)
42+
uint32_t HAL_GetTick(void);

0 commit comments

Comments
 (0)
0