cc3200: Convert dupterm to use common extmod implementation.

Tested on a WIPY.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2023-11-29 13:19:28 +11:00
parent 22d9116c8c
commit 1c0e4644c7
7 changed files with 13 additions and 124 deletions

View File

@ -48,7 +48,6 @@
#include "fifo.h"
#include "socketfifo.h"
#include "updater.h"
#include "modos.h"
/******************************************************************************
DEFINE PRIVATE CONSTANTS

View File

@ -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"
@ -49,7 +50,6 @@
#include "pybuart.h"
#include "utils.h"
#include "irq.h"
#include "modos.h"
#ifdef USE_FREERTOS
#include "FreeRTOS.h"
@ -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);
}
@ -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);
}
}

View File

@ -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"
@ -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
//
@ -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) },
@ -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);

View File

@ -1,47 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Daniel Campora
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_CC3200_MODS_MODOS_H
#define MICROPY_INCLUDED_CC3200_MODS_MODOS_H
#include "py/obj.h"
/******************************************************************************
DEFINE PUBLIC TYPES
******************************************************************************/
typedef struct _os_term_dup_obj_t {
mp_obj_t stream_o;
mp_obj_t read[3];
mp_obj_t write[3];
} os_term_dup_obj_t;
/******************************************************************************
DECLARE PUBLIC FUNCTIONS
******************************************************************************/
void osmount_unmount_all (void);
#endif // MICROPY_INCLUDED_CC3200_MODS_MODOS_H

View File

@ -50,7 +50,6 @@
#include "pin.h"
#include "pybpin.h"
#include "pins.h"
#include "modos.h"
/// \moduleref pyb
/// \class UART - duplex serial communication bus
@ -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

View File

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

View File

@ -70,7 +70,6 @@
#include "cryptohash.h"
#include "mpirq.h"
#include "updater.h"
#include "modos.h"
#include "antenna.h"
#include "task.h"
@ -247,9 +246,6 @@ soft_reset_exit:
// 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);