From 6b21c3fdd6aaee3266b1ac69017e6c1ffaa2c99b Mon Sep 17 00:00:00 2001 From: danicampora Date: Fri, 20 Feb 2015 16:31:30 +0100 Subject: cc3200: Refactor UART and I2C object creation. I2C objects can be freed by the GC and a __del__ method is provided in order to de-init the peripheral prior to being garbage collected. UART objects are now added to a local list and this list is now part of the VM_STATE. --- cc3200/hal/cc3200_hal.c | 20 +++++++++++++------- cc3200/hal/cc3200_hal.h | 5 +++++ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'cc3200/hal') diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 75b0dca03..7932d9e06 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -70,10 +70,15 @@ static void hal_EnableSdCard (void); #endif /****************************************************************************** - DECLARE LOCAL VARIABLES + DECLARE LOCAL DATA ******************************************************************************/ static volatile uint32_t HAL_tickCount; +/****************************************************************************** + DECLARE PUBLIC DATA + ******************************************************************************/ +struct _pyb_uart_obj_t *pyb_stdio_uart; + /****************************************************************************** DECLARE IMPORTED DATA ******************************************************************************/ @@ -134,8 +139,9 @@ void mp_hal_stdout_tx_str(const char *str) { } void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { - if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { - uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len); + // send stdout to UART + if (pyb_stdio_uart != NULL) { + uart_tx_strn(pyb_stdio_uart, str, len); } // and also to telnet if (telnet_is_active()) { @@ -145,8 +151,8 @@ void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_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); + if (pyb_stdio_uart != NULL) { + uart_tx_strn_cooked(pyb_stdio_uart, str, len); } // and also to telnet if (telnet_is_active()) { @@ -159,8 +165,8 @@ int mp_hal_stdin_rx_chr(void) { 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)); + else if (pyb_stdio_uart != NULL && uart_rx_any(pyb_stdio_uart)) { + return uart_rx_char(pyb_stdio_uart); } HAL_Delay(1); } diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h index ecf500b63..71b644239 100644 --- a/cc3200/hal/cc3200_hal.h +++ b/cc3200/hal/cc3200_hal.h @@ -52,6 +52,11 @@ " isb \n"); \ } +/****************************************************************************** + DECLARE PUBLIC DATA + ******************************************************************************/ +extern struct _pyb_uart_obj_t *pyb_stdio_uart; + /****************************************************************************** DECLARE PUBLIC FUNCTIONS ******************************************************************************/ -- cgit v1.2.3