aboutsummaryrefslogtreecommitdiff
path: root/cc3200/mods
diff options
context:
space:
mode:
authorDaniel Campora2015-09-25 15:20:07 +0200
committerDaniel Campora2015-09-27 11:27:24 +0200
commitef369249cb406758ec1caa9a212478ef69fd7ff0 (patch)
tree3b8e4b4358417693179b488dd79cb3b232538a6b /cc3200/mods
parenta7261ae059f171e9677a86c59c7f7ed9e24b7ace (diff)
cc3200: Implement support for os.dupterm().
Diffstat (limited to 'cc3200/mods')
-rw-r--r--cc3200/mods/modpyb.c23
-rw-r--r--cc3200/mods/moduos.c31
-rw-r--r--cc3200/mods/moduos.h14
-rw-r--r--cc3200/mods/pybuart.c16
-rw-r--r--cc3200/mods/pybuart.h1
5 files changed, 46 insertions, 39 deletions
diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c
index c32ea6c90..45fa56569 100644
--- a/cc3200/mods/modpyb.c
+++ b/cc3200/mods/modpyb.c
@@ -141,28 +141,6 @@ STATIC mp_obj_t pyb_unique_id(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_unique_id_obj, pyb_unique_id);
-/// \function repl_uart(uart)
-/// Get or set the UART object that the REPL is repeated on.
-STATIC mp_obj_t pyb_repl_uart(uint n_args, const mp_obj_t *args) {
- if (n_args == 0) {
- if (pyb_stdio_uart == NULL) {
- return mp_const_none;
- } else {
- return pyb_stdio_uart;
- }
- } else {
- if (args[0] == mp_const_none) {
- pyb_stdio_uart = NULL;
- } else if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
- pyb_stdio_uart = args[0];
- } else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
- }
- return mp_const_none;
- }
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart);
-
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
@@ -174,7 +152,6 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_repl_uart), (mp_obj_t)&pyb_repl_uart_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_irq), (mp_obj_t)&pyb_disable_irq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_irq), (mp_obj_t)&pyb_enable_irq_obj },
diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c
index 8dc7716b5..096e9c393 100644
--- a/cc3200/mods/moduos.c
+++ b/cc3200/mods/moduos.c
@@ -34,7 +34,7 @@
#include "py/objstr.h"
#include "py/runtime.h"
#include "genhdr/mpversion.h"
-#include "ff.h"
+#include "moduos.h"
#include "diskio.h"
#include "sflash_diskio.h"
#include "file.h"
@@ -42,8 +42,8 @@
#include "mpexception.h"
#include "version.h"
#include "timeutils.h"
-#include "moduos.h"
#include "pybsd.h"
+#include "pybuart.h"
/// \module os - basic "operating system" services
///
@@ -60,6 +60,7 @@
DECLARE PRIVATE DATA
******************************************************************************/
STATIC uint32_t os_num_mounted_devices;
+STATIC os_term_dup_obj_t os_term_dup_obj;
/******************************************************************************
DEFINE PUBLIC FUNCTIONS
@@ -536,6 +537,31 @@ STATIC mp_obj_t os_mkfs(mp_obj_t device) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkfs_obj, os_mkfs);
+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_map_elem_t os_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) },
@@ -554,6 +580,7 @@ STATIC const mp_map_elem_t os_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&os_mount_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unmount), (mp_obj_t)&os_unmount_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkfs), (mp_obj_t)&os_mkfs_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_dupterm), (mp_obj_t)&os_dupterm_obj },
/// \constant sep - separation character used in paths
{ MP_OBJ_NEW_QSTR(MP_QSTR_sep), MP_OBJ_NEW_QSTR(MP_QSTR__slash_) },
diff --git a/cc3200/mods/moduos.h b/cc3200/mods/moduos.h
index 99172b706..fa5907125 100644
--- a/cc3200/mods/moduos.h
+++ b/cc3200/mods/moduos.h
@@ -28,6 +28,11 @@
#ifndef MODUOS_H_
#define MODUOS_H_
+#include "ff.h"
+
+/******************************************************************************
+ DEFINE PUBLIC TYPES
+ ******************************************************************************/
typedef struct _os_fs_mount_t {
mp_obj_t device;
const char *path;
@@ -40,6 +45,15 @@ typedef struct _os_fs_mount_t {
uint8_t vol;
} os_fs_mount_t;
+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 moduos_init0 (void);
os_fs_mount_t *osmount_find_by_path (const char *path);
os_fs_mount_t *osmount_find_by_volume (uint8_t vol);
diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c
index 213000975..41819d4f5 100644
--- a/cc3200/mods/pybuart.c
+++ b/cc3200/mods/pybuart.c
@@ -55,6 +55,7 @@
#include "pin.h"
#include "pybpin.h"
#include "pins.h"
+#include "moduos.h"
/// \moduleref pyb
/// \class UART - duplex serial communication bus
@@ -168,15 +169,6 @@ bool uart_tx_strn(pyb_uart_obj_t *self, const char *str, uint len) {
return true;
}
-void uart_tx_strn_cooked(pyb_uart_obj_t *self, const char *str, uint len) {
- for (const char *top = str + len; str < top; str++) {
- if (*str == '\n') {
- uart_tx_char(self, '\r');
- }
- uart_tx_char(self, *str);
- }
-}
-
/******************************************************************************
DEFINE PRIVATE FUNCTIONS
******************************************************************************/
@@ -261,12 +253,10 @@ 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 (pyb_stdio_uart == self && data == user_interrupt_char) {
+ if (MP_STATE_PORT(os_term_dup_obj) && MP_STATE_PORT(os_term_dup_obj)->stream_o == self && data == user_interrupt_char) {
// raise an exception when interrupts are finished
mpexception_keyboard_nlr_jump();
- }
- // there's always a read buffer available
- else {
+ } else { // there's always a read buffer available
uint16_t next_head = (self->read_buf_head + 1) % PYBUART_RX_BUFFER_LEN;
if (next_head != self->read_buf_tail) {
// only store data if room in buf
diff --git a/cc3200/mods/pybuart.h b/cc3200/mods/pybuart.h
index 74871cbab..19bc93607 100644
--- a/cc3200/mods/pybuart.h
+++ b/cc3200/mods/pybuart.h
@@ -42,6 +42,5 @@ uint32_t uart_rx_any(pyb_uart_obj_t *uart_obj);
int uart_rx_char(pyb_uart_obj_t *uart_obj);
bool uart_tx_char(pyb_uart_obj_t *self, int c);
bool uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
-void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
#endif // PYBUART_H_