Skip to content

Commit 0b32e50

Browse files
committed
stmhal: Make pybstdio usable by other ports, and use it.
Now all ports can use pybstdio.c to provide sys.stdin/stdout/stderr, so long as they implement mp_hal_stdin_* and mp_hal_stdout_* functions.
1 parent c385a63 commit 0b32e50

33 files changed

Lines changed: 222 additions & 545 deletions

cc3200/application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ APP_MODS_SRC_C = $(addprefix mods/,\
9191
pybextint.c \
9292
pybpin.c \
9393
pybrtc.c \
94-
pybstdio.c \
9594
pybsystick.c \
9695
pybuart.c \
9796
)
@@ -144,6 +143,7 @@ APP_STM_SRC_C = $(addprefix stmhal/,\
144143
moduselect.c \
145144
printf.c \
146145
pyexec.c \
146+
pybstdio.c \
147147
string0.c \
148148
)
149149

cc3200/hal/cc3200_hal.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
******************************************************************************/
3131
#include <stdio.h>
3232
#include <stdint.h>
33+
#include <string.h>
3334
#include "inc/hw_types.h"
3435
#include "inc/hw_ints.h"
3536
#include "inc/hw_nvic.h"
3637
#include "hw_memmap.h"
37-
#include "mpconfig.h"
38+
#include "py/mpstate.h"
3839
#include MICROPY_HAL_H
3940
#include "rom_map.h"
4041
#include "interrupt.h"
@@ -43,6 +44,8 @@
4344
#include "sdhost.h"
4445
#include "pin.h"
4546
#include "mpexception.h"
47+
#include "telnet.h"
48+
#include "pybuart.h"
4649

4750
#ifdef USE_FREERTOS
4851
#include "FreeRTOS.h"
@@ -126,6 +129,43 @@ void mp_hal_set_interrupt_char (int c) {
126129
mpexception_set_interrupt_char (c);
127130
}
128131

132+
void mp_hal_stdout_tx_str(const char *str) {
133+
mp_hal_stdout_tx_strn(str, strlen(str));
134+
}
135+
136+
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
137+
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
138+
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
139+
}
140+
// and also to telnet
141+
if (telnet_is_active()) {
142+
telnet_tx_strn(str, len);
143+
}
144+
}
145+
146+
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
147+
// send stdout to UART
148+
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
149+
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
150+
}
151+
// and also to telnet
152+
if (telnet_is_active()) {
153+
telnet_tx_strn_cooked(str, len);
154+
}
155+
}
156+
157+
int mp_hal_stdin_rx_chr(void) {
158+
for ( ;; ) {
159+
if (telnet_rx_any()) {
160+
return telnet_rx_char();
161+
}
162+
else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
163+
return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
164+
}
165+
HAL_Delay(1);
166+
}
167+
}
168+
129169
/******************************************************************************
130170
DEFINE PRIVATE FUNCTIONS
131171
******************************************************************************/

cc3200/hal/cc3200_hal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ extern uint32_t HAL_GetTick(void);
6363
extern void HAL_Delay(uint32_t delay);
6464
extern void mp_hal_set_interrupt_char (int c);
6565

66+
int mp_hal_stdin_rx_chr(void);
67+
void mp_hal_stdout_tx_str(const char *str);
68+
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
69+
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
70+
6671
#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */

cc3200/misc/FreeRTOSHooks.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "obj.h"
3636
#include "inc/hw_memmap.h"
3737
#include "pybuart.h"
38-
#include "pybstdio.h"
3938
#include "osi.h"
4039

4140

cc3200/misc/mperror.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,16 @@
3737
#include "obj.h"
3838
#include "inc/hw_memmap.h"
3939
#include "pybuart.h"
40-
#include "pybstdio.h"
4140
#include "utils.h"
4241

4342

4443
void NORETURN __fatal_error(const char *msg) {
4544
if (msg != NULL) {
4645
// wait for 20ms
4746
UtilsDelay(UTILS_DELAY_US_TO_COUNT(20000));
48-
stdout_tx_str("\r\nFATAL ERROR:");
49-
stdout_tx_str(msg);
50-
stdout_tx_str("\r\n");
47+
mp_hal_stdout_tx_str("\r\nFATAL ERROR:");
48+
mp_hal_stdout_tx_str(msg);
49+
mp_hal_stdout_tx_str("\r\n");
5150
}
5251
for ( ;; ) {__WFI();}
5352
}

cc3200/mods/modpyb.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "pyexec.h"
4949
#include "pybuart.h"
5050
#include "pybpin.h"
51-
#include "pybstdio.h"
5251
#include "pybrtc.h"
5352
#include "pybsystick.h"
5453
#include "simplelink.h"

cc3200/mods/modwlan.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "modwlan.h"
4343
#include "pybioctl.h"
4444
#include "pybuart.h"
45-
#include "pybstdio.h"
4645
#include "osi.h"
4746
#include "debug.h"
4847
#include "serverstask.h"

cc3200/mods/pybstdio.c

Lines changed: 0 additions & 174 deletions
This file was deleted.

cc3200/mods/pybstdio.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

cc3200/mods/pybuart.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#include "pin.h"
5454
#include "pybuart.h"
5555
#include "pybioctl.h"
56-
#include "pybstdio.h"
5756
#include "mpexception.h"
5857
#include "osi.h"
5958

0 commit comments

Comments
 (0)