Skip to content

Commit

Permalink
stmhal: Make pybstdio usable by other ports, and use it.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpgeorge committed Feb 13, 2015
1 parent c385a63 commit 0b32e50
Show file tree
Hide file tree
Showing 33 changed files with 222 additions and 545 deletions.
2 changes: 1 addition & 1 deletion cc3200/application.mk
Expand Up @@ -91,7 +91,6 @@ APP_MODS_SRC_C = $(addprefix mods/,\
pybextint.c \
pybpin.c \
pybrtc.c \
pybstdio.c \
pybsystick.c \
pybuart.c \
)
Expand Down Expand Up @@ -144,6 +143,7 @@ APP_STM_SRC_C = $(addprefix stmhal/,\
moduselect.c \
printf.c \
pyexec.c \
pybstdio.c \
string0.c \
)

Expand Down
42 changes: 41 additions & 1 deletion cc3200/hal/cc3200_hal.c
Expand Up @@ -30,11 +30,12 @@
******************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_nvic.h"
#include "hw_memmap.h"
#include "mpconfig.h"
#include "py/mpstate.h"
#include MICROPY_HAL_H
#include "rom_map.h"
#include "interrupt.h"
Expand All @@ -43,6 +44,8 @@
#include "sdhost.h"
#include "pin.h"
#include "mpexception.h"
#include "telnet.h"
#include "pybuart.h"

#ifdef USE_FREERTOS
#include "FreeRTOS.h"
Expand Down Expand Up @@ -126,6 +129,43 @@ void mp_hal_set_interrupt_char (int c) {
mpexception_set_interrupt_char (c);
}

void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str));
}

void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
}
// and also to telnet
if (telnet_is_active()) {
telnet_tx_strn(str, len);
}
}

void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
// send stdout to UART
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
}
// and also to telnet
if (telnet_is_active()) {
telnet_tx_strn_cooked(str, len);
}
}

int mp_hal_stdin_rx_chr(void) {
for ( ;; ) {
if (telnet_rx_any()) {
return telnet_rx_char();
}
else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
}
HAL_Delay(1);
}
}

/******************************************************************************
DEFINE PRIVATE FUNCTIONS
******************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions cc3200/hal/cc3200_hal.h
Expand Up @@ -63,4 +63,9 @@ extern uint32_t HAL_GetTick(void);
extern void HAL_Delay(uint32_t delay);
extern void mp_hal_set_interrupt_char (int c);

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);

#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */
1 change: 0 additions & 1 deletion cc3200/misc/FreeRTOSHooks.c
Expand Up @@ -35,7 +35,6 @@
#include "obj.h"
#include "inc/hw_memmap.h"
#include "pybuart.h"
#include "pybstdio.h"
#include "osi.h"


Expand Down
7 changes: 3 additions & 4 deletions cc3200/misc/mperror.c
Expand Up @@ -37,17 +37,16 @@
#include "obj.h"
#include "inc/hw_memmap.h"
#include "pybuart.h"
#include "pybstdio.h"
#include "utils.h"


void NORETURN __fatal_error(const char *msg) {
if (msg != NULL) {
// wait for 20ms
UtilsDelay(UTILS_DELAY_US_TO_COUNT(20000));
stdout_tx_str("\r\nFATAL ERROR:");
stdout_tx_str(msg);
stdout_tx_str("\r\n");
mp_hal_stdout_tx_str("\r\nFATAL ERROR:");
mp_hal_stdout_tx_str(msg);
mp_hal_stdout_tx_str("\r\n");
}
for ( ;; ) {__WFI();}
}
Expand Down
1 change: 0 additions & 1 deletion cc3200/mods/modpyb.c
Expand Up @@ -48,7 +48,6 @@
#include "pyexec.h"
#include "pybuart.h"
#include "pybpin.h"
#include "pybstdio.h"
#include "pybrtc.h"
#include "pybsystick.h"
#include "simplelink.h"
Expand Down
1 change: 0 additions & 1 deletion cc3200/mods/modwlan.c
Expand Up @@ -42,7 +42,6 @@
#include "modwlan.h"
#include "pybioctl.h"
#include "pybuart.h"
#include "pybstdio.h"
#include "osi.h"
#include "debug.h"
#include "serverstask.h"
Expand Down
174 changes: 0 additions & 174 deletions cc3200/mods/pybstdio.c

This file was deleted.

31 changes: 0 additions & 31 deletions cc3200/mods/pybstdio.h

This file was deleted.

1 change: 0 additions & 1 deletion cc3200/mods/pybuart.c
Expand Up @@ -53,7 +53,6 @@
#include "pin.h"
#include "pybuart.h"
#include "pybioctl.h"
#include "pybstdio.h"
#include "mpexception.h"
#include "osi.h"

Expand Down
1 change: 0 additions & 1 deletion cc3200/mptask.c
Expand Up @@ -44,7 +44,6 @@
#include "pybuart.h"
#include "pybpin.h"
#include "pybrtc.h"
#include "pybstdio.h"
#include "pyexec.h"
#include "gccollect.h"
#include "gchelper.h"
Expand Down
1 change: 0 additions & 1 deletion cc3200/telnet/telnet.c
Expand Up @@ -39,7 +39,6 @@
#include "debug.h"
#include "mpexception.h"
#include "serverstask.h"
#include "pybstdio.h"
#include "genhdr/py-version.h"


Expand Down
2 changes: 1 addition & 1 deletion esp8266/Makefile
Expand Up @@ -45,7 +45,6 @@ SRC_C = \
main.c \
esp_mphal.c \
gccollect.c \
pybstdio.c \
uart.c \
modpyb.c \
modesp.c \
Expand All @@ -54,6 +53,7 @@ STM_SRC_C = $(addprefix stmhal/,\
printf.c \
string0.c \
pyexec.c \
pybstdio.c \
)

LIB_SRC_C = $(addprefix lib/,\
Expand Down

3 comments on commit 0b32e50

@dpgeorge
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danicampora please make sure this did not break cc3200!

@danicampora
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgeorge looks pretty good!! will test it ASAP, I am now finishing the I2C for the CC3200...

@danicampora
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgeorge tested and works like a charm!
Thanks!!!

Please sign in to comment.