Skip to content

Commit 919ff07

Browse files
committed
mp
1 parent 079430c commit 919ff07

File tree

7 files changed

+117
-129
lines changed

7 files changed

+117
-129
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ source_group("third_party\\micropython\\extmod" FILES ${src_third_party_micropyt
533533

534534
set(src_third_party_micropython_ports_bb3
535535
src/third_party/micropython/ports/bb3/main.c
536-
src/third_party/micropython/ports/bb3/gccollect.c
536+
src/third_party/micropython/ports/bb3/gccollect.cpp
537537
src/third_party/micropython/ports/bb3/mphalport.cpp
538538
)
539539
list (APPEND src_files ${src_third_party_micropython_ports_bb3})

scripts/test.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
U_STEP = 0.1
66
U_MAX = 40.0
7-
TIME_STEP_MS = 10
8-
MEASURE_DELAY_MS = 5
7+
#TIME_STEP_MS = 10
8+
#MEASURE_DELAY_MS = 5
99
I_SET = 0.001
1010

1111
scpi("inst ch1")
@@ -14,7 +14,7 @@
1414

1515
print("start")
1616

17-
#i_list = []
17+
i_list = []
1818
#t = ticks_ms()
1919
i = 0
2020
while True:
@@ -23,6 +23,14 @@
2323
break
2424

2525
scpi("volt " + str(u_set))
26+
curr = scpi("curr?")
27+
mode = scpi("outp:mode?")
28+
29+
i_list.append(float(curr))
30+
31+
#print(u_set)
32+
#print(curr)
33+
#print(mode)
2634

2735
i = i + 1
2836

@@ -34,6 +42,8 @@
3442

3543
#i_list.add(scpi("curr?"))
3644

45+
print(i_list)
46+
3747
#t = ticks_add(t, (TIME_STEP_MS - MEASURE_DELAY_MS) * 1000)
3848
#sleep_ms(ticks_diff(t, ticks_ms()))
3949

src/eez/mp.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ osThreadId g_mpTaskHandle;
111111
#pragma GCC diagnostic ignored "-Wwrite-strings"
112112
#endif
113113

114-
osThreadDef(g_mpTask, mainLoop, osPriorityNormal, 0, 2048);
114+
osThreadDef(g_mpTask, mainLoop, osPriorityNormal, 0, 4096);
115115

116116
#if defined(EEZ_PLATFORM_STM32)
117117
#pragma GCC diagnostic pop
@@ -233,34 +233,31 @@ void oneIter() {
233233
if (event.status == osEventMessage) {
234234
switch (event.value.v) {
235235
case QUEUE_MESSAGE_START_SCRIPT:
236-
237-
// Initialized stack limit
238-
//mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
239-
240-
// Initialize heap
241-
242-
// volatile int stackTop;
243-
// mp_stack_set_top((void *)(&stackTop));
244-
// mp_stack_set_limit(1024);
245-
246-
gc_init(g_scriptSource + g_scriptSourceLength, MP_BUFFER + MP_BUFFER_SIZE);
247-
248-
mp_init();
236+
static bool g_initialized = false;
237+
if (!g_initialized) {
238+
volatile char dummy;
239+
g_initialized = true;
240+
mp_stack_set_top((void *)&dummy);
241+
gc_init(g_scriptSource + g_scriptSourceLength, MP_BUFFER + MP_BUFFER_SIZE - 32768 - 1024);
242+
mp_init();
243+
}
249244

250245
nlr_buf_t nlr;
251246
if (nlr_push(&nlr) == 0) {
252247
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, g_scriptSource, g_scriptSourceLength, 0);
253248
qstr source_name = lex->source_name;
254249
mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT);
255-
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, true);
250+
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
256251
mp_call_function_0(module_fun);
257252
nlr_pop();
258253
} else {
259254
// uncaught exception
260255
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
261256
}
262257

263-
mp_deinit();
258+
// gc_sweep_all();
259+
260+
// mp_deinit();
264261

265262
break;
266263
}
@@ -328,29 +325,33 @@ void onQueueMessage(uint32_t type, uint32_t param) {
328325
}
329326

330327
bool scpi(const char *commandOrQueryText, const char **resultText, size_t *resultTextLen) {
331-
g_commandOrQueryText = commandOrQueryText;
332328
g_scpiDataLen = 0;
333329

334-
osMessagePut(scpi::g_scpiMessageQueueId, SCPI_QUEUE_MP_MESSAGE(EXECUTE_SCPI, 0), osWaitForever);
335-
336-
while (true) {
337-
osEvent event = osMessageGet(g_mpMessageQueueId, osWaitForever);
338-
if (event.status == osEventMessage) {
339-
switch (event.value.v) {
340-
case QUEUE_MESSAGE_SCPI_RESULT:
341-
*resultText = g_scpiData;
342-
*resultTextLen = g_scpiDataLen;
343-
return true;
344-
}
345-
}
346-
}
330+
// g_commandOrQueryText = commandOrQueryText;
331+
// osMessagePut(scpi::g_scpiMessageQueueId, SCPI_QUEUE_MP_MESSAGE(EXECUTE_SCPI, 0), osWaitForever);
332+
333+
// while (true) {
334+
// osEvent event = osMessageGet(g_mpMessageQueueId, osWaitForever);
335+
// if (event.status == osEventMessage) {
336+
// switch (event.value.v) {
337+
// case QUEUE_MESSAGE_SCPI_RESULT:
338+
// *resultText = g_scpiData;
339+
// *resultTextLen = g_scpiDataLen;
340+
// return true;
341+
// }
342+
// }
343+
// }
347344

348-
// input(g_scpiContext, (const char *)commandOrQueryText, strlen(commandOrQueryText));
349-
// input(g_scpiContext, "\r\n", 2);
345+
input(g_scpiContext, (const char *)commandOrQueryText, strlen(commandOrQueryText));
346+
input(g_scpiContext, "\r\n", 2);
350347

351-
// *resultText = g_scpiData;
352-
// *resultTextLen = g_scpiDataLen;
353-
// return true;
348+
if (g_scpiDataLen >= 2 && g_scpiData[g_scpiDataLen - 2] == '\r' && g_scpiData[g_scpiDataLen - 1] == '\n') {
349+
g_scpiDataLen -= 2;
350+
}
351+
352+
*resultText = g_scpiData;
353+
*resultTextLen = g_scpiDataLen;
354+
return true;
354355
}
355356

356357
} // mp

src/third_party/micropython/ports/bb3/gccollect.c

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013, 2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdio.h>
28+
#include <setjmp.h>
29+
30+
#ifdef _MSC_VER
31+
#pragma warning( push )
32+
#pragma warning( disable : 4200)
33+
#endif
34+
35+
extern "C" {
36+
#include "py/mpstate.h"
37+
#include "py/gc.h"
38+
}
39+
40+
#ifdef _MSC_VER
41+
#pragma warning( pop )
42+
#endif
43+
44+
#if MICROPY_ENABLE_GC
45+
46+
#include <eez/debug.h>
47+
48+
typedef jmp_buf regs_t;
49+
static void gc_helper_get_regs(regs_t arr) {
50+
setjmp(arr);
51+
}
52+
53+
extern "C" void gc_collect(void) {
54+
DebugTrace("gc_collect\n");
55+
56+
gc_collect_start();
57+
regs_t regs;
58+
gc_helper_get_regs(regs);
59+
// GC stack (and regs because we captured them)
60+
void **regs_ptr = (void**)(void*)&regs;
61+
gc_collect_root(regs_ptr, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)&regs) / sizeof(mp_uint_t));
62+
gc_collect_end();
63+
}
64+
65+
#endif //MICROPY_ENABLE_GC

src/third_party/micropython/ports/bb3/mpconfigport.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949

5050
#define MICROPY_PY_UTIME_MP_HAL (1)
5151

52-
#define MICROPY_STACKLESS (0)
53-
5452
// type definitions for the specific machine
5553

5654
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))

src/third_party/micropython/ports/bb3/mphalport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include <stdio.h>
2929
#endif
3030

31-
#include <eez/debug.h>
32-
3331
#ifdef _MSC_VER
3432
#pragma warning( push )
3533
#pragma warning( disable : 4200)
@@ -45,6 +43,8 @@ extern "C" {
4543

4644
#include "cmsis_os.h"
4745

46+
#include <eez/debug.h>
47+
4848
extern"C" void mp_hal_stdout_tx_strn(const char *str, size_t len) {
4949
DebugTrace("%.*s", len, str);
5050
}

0 commit comments

Comments
 (0)