Skip to content

Commit

Permalink
cc3200: Convert dupterm to use common extmod implementation.
Browse files Browse the repository at this point in the history
Tested on a WIPY.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Nov 30, 2023
1 parent 22d9116 commit 1c0e464
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 124 deletions.
1 change: 0 additions & 1 deletion ports/cc3200/ftp/ftp.c
Expand Up @@ -48,7 +48,6 @@
#include "fifo.h"
#include "socketfifo.h"
#include "updater.h"
#include "modos.h"

/******************************************************************************
DEFINE PRIVATE CONSTANTS
Expand Down
33 changes: 9 additions & 24 deletions ports/cc3200/hal/cc3200_hal.c
Expand Up @@ -36,6 +36,7 @@
#include "py/mphal.h"
#include "py/runtime.h"
#include "py/objstr.h"
#include "extmod/misc.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_nvic.h"
Expand All @@ -49,7 +50,6 @@
#include "pybuart.h"
#include "utils.h"
#include "irq.h"
#include "modos.h"

#ifdef USE_FREERTOS
#include "FreeRTOS.h"
Expand Down Expand Up @@ -142,14 +142,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
}

void mp_hal_stdout_tx_strn(const char *str, size_t len) {
if (MP_STATE_PORT(os_term_dup_obj)) {
if (mp_obj_is_type(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) {
uart_tx_strn(MP_STATE_PORT(os_term_dup_obj)->stream_o, str, len);
} else {
MP_STATE_PORT(os_term_dup_obj)->write[2] = mp_obj_new_str_of_type(&mp_type_str, (const byte *)str, len);
mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->write);
}
}
mp_os_dupterm_tx_strn(str, len);
// and also to telnet
telnet_tx_strn(str, len);
}
Expand All @@ -159,22 +152,14 @@ int mp_hal_stdin_rx_chr(void) {
// read telnet first
if (telnet_rx_any()) {
return telnet_rx_char();
} else if (MP_STATE_PORT(os_term_dup_obj)) { // then the stdio_dup
if (mp_obj_is_type(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) {
if (uart_rx_any(MP_STATE_PORT(os_term_dup_obj)->stream_o)) {
return uart_rx_char(MP_STATE_PORT(os_term_dup_obj)->stream_o);
}
} else {
MP_STATE_PORT(os_term_dup_obj)->read[2] = mp_obj_new_int(1);
mp_obj_t data = mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->read);
// data len is > 0
if (mp_obj_is_true(data)) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
return ((int *)(bufinfo.buf))[0];
}
}
}

// then dupterm
int dupterm_c = mp_os_dupterm_rx_chr();
if (dupterm_c >= 0) {
return dupterm_c;
}

mp_hal_delay_ms(1);
}
}
Expand Down
48 changes: 2 additions & 46 deletions ports/cc3200/mods/modos.c
Expand Up @@ -35,8 +35,8 @@
#include "lib/oofatfs/ff.h"
#include "lib/oofatfs/diskio.h"
#include "genhdr/mpversion.h"
#include "modos.h"
#include "sflash_diskio.h"
#include "extmod/misc.h"
#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
#include "random.h"
Expand All @@ -55,25 +55,6 @@
///
/// On boot up, the current directory is `/flash`.

/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
STATIC os_term_dup_obj_t os_term_dup_obj;

/******************************************************************************
DEFINE PUBLIC FUNCTIONS
******************************************************************************/

void osmount_unmount_all (void) {
//TODO
/*
for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
unmount(mount_obj);
}
*/
}

/******************************************************************************/
// MicroPython bindings
//
Expand Down Expand Up @@ -120,31 +101,6 @@ STATIC mp_obj_t os_urandom(mp_obj_t num) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);

STATIC mp_obj_t os_dupterm(uint n_args, const mp_obj_t *args) {
if (n_args == 0) {
if (MP_STATE_PORT(os_term_dup_obj) == MP_OBJ_NULL) {
return mp_const_none;
} else {
return MP_STATE_PORT(os_term_dup_obj)->stream_o;
}
} else {
mp_obj_t stream_o = args[0];
if (stream_o == mp_const_none) {
MP_STATE_PORT(os_term_dup_obj) = MP_OBJ_NULL;
} else {
if (!mp_obj_is_type(stream_o, &pyb_uart_type)) {
// must be a stream-like object providing at least read and write methods
mp_load_method(stream_o, MP_QSTR_read, os_term_dup_obj.read);
mp_load_method(stream_o, MP_QSTR_write, os_term_dup_obj.write);
}
os_term_dup_obj.stream_o = stream_o;
MP_STATE_PORT(os_term_dup_obj) = &os_term_dup_obj;
}
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_dupterm_obj, 0, 1, os_dupterm);

STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },

Expand All @@ -170,7 +126,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&os_dupterm_obj) },
{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_os_dupterm_obj) },
};

STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
Expand Down
47 changes: 0 additions & 47 deletions ports/cc3200/mods/modos.h

This file was deleted.

3 changes: 1 addition & 2 deletions ports/cc3200/mods/pybuart.c
Expand Up @@ -50,7 +50,6 @@
#include "pin.h"
#include "pybpin.h"
#include "pins.h"
#include "modos.h"

/// \moduleref pyb
/// \class UART - duplex serial communication bus
Expand Down Expand Up @@ -249,7 +248,7 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) {
MAP_UARTIntClear(self->reg, UART_INT_RX | UART_INT_RT);
while (UARTCharsAvail(self->reg)) {
int data = MAP_UARTCharGetNonBlocking(self->reg);
if (MP_STATE_PORT(os_term_dup_obj) && MP_STATE_PORT(os_term_dup_obj)->stream_o == self && data == mp_interrupt_char) {
if (MP_STATE_VM(dupterm_objs[0]) == MP_OBJ_FROM_PTR(self) && data == mp_interrupt_char) {
// raise an exception when interrupts are finished
mp_sched_keyboard_interrupt();
} else { // there's always a read buffer available
Expand Down
1 change: 1 addition & 0 deletions ports/cc3200/mpconfigport.h
Expand Up @@ -115,6 +115,7 @@
#define MICROPY_PY_RE (1)
#define MICROPY_PY_HEAPQ (0)
#define MICROPY_PY_HASHLIB (0)
#define MICROPY_PY_OS_DUPTERM (1)
#define MICROPY_PY_SELECT (1)
#define MICROPY_PY_TIME (1)
#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1)
Expand Down
4 changes: 0 additions & 4 deletions ports/cc3200/mptask.c
Expand Up @@ -70,7 +70,6 @@
#include "cryptohash.h"
#include "mpirq.h"
#include "updater.h"
#include "modos.h"
#include "antenna.h"
#include "task.h"

Expand Down Expand Up @@ -247,9 +246,6 @@ void TASK_MicroPython(void *pvParameters) {
// clean-up the user socket space
modusocket_close_all_user_sockets();

// unmount all user file systems
osmount_unmount_all();

// wait for pending transactions to complete
mp_hal_delay_ms(20);

Expand Down

0 comments on commit 1c0e464

Please sign in to comment.