11// SPDX-License-Identifier: MIT
22// Copyright (c) 2013, 2014 Damien P. George
3+ // Copyright (c) 2018-2020 The Pybricks Authors
34
45// Pybricks brick specific definitions
56#include "brickconfig.h"
@@ -64,7 +65,9 @@ static const char pybricks_ev3dev_help_text[] =
6465#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
6566#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (1)
6667#endif
68+ #define MICROPY_MODULE_WEAK_LINKS (1)
6769#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
70+ #define MICROPY_VFS_POSIX_FILE (1)
6871#define MICROPY_PY_FUNCTION_ATTRS (1)
6972#define MICROPY_PY_DESCRIPTORS (1)
7073#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
@@ -86,13 +89,21 @@ static const char pybricks_ev3dev_help_text[] =
8689#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
8790#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
8891#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
92+ #define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
8993#define MICROPY_PY_INSTANCE_ATTRS (1)
9094#define MICROPY_PY_SYS_EXIT (1)
95+ #define MICROPY_PY_SYS_ATEXIT (1)
96+ #if MICROPY_PY_SYS_SETTRACE
97+ #define MICROPY_PERSISTENT_CODE_SAVE (1)
98+ #define MICROPY_COMP_CONST (0)
99+ #endif
100+ #ifndef MICROPY_PY_SYS_PLATFORM
91101#if defined(__APPLE__ ) && defined(__MACH__ )
92102 #define MICROPY_PY_SYS_PLATFORM "darwin"
93103#else
94104 #define MICROPY_PY_SYS_PLATFORM "linux"
95105#endif
106+ #endif
96107#define MICROPY_PY_SYS_MAXSIZE (1)
97108#define MICROPY_PY_SYS_STDFILES (1)
98109#define MICROPY_PY_SYS_EXC_INFO (0)
@@ -105,7 +116,6 @@ static const char pybricks_ev3dev_help_text[] =
105116#define MICROPY_PY_IO_IOBASE (1)
106117#define MICROPY_PY_IO_FILEIO (1)
107118#define MICROPY_PY_GC_COLLECT_RETVAL (1)
108- #define MICROPY_MODULE_FROZEN_STR (1)
109119#define MICROPY_MODULE_BUILTIN_INIT (1)
110120
111121#define MICROPY_PY_THREAD (1)
@@ -200,6 +210,7 @@ static const char pybricks_ev3dev_help_text[] =
200210#define MICROPY_PY_UTIMEQ (1)
201211#define MICROPY_PY_UHASHLIB (1)
202212#if MICROPY_PY_USSL
213+ #define MICROPY_PY_UHASHLIB_MD5 (1)
203214#define MICROPY_PY_UHASHLIB_SHA1 (1)
204215#define MICROPY_PY_UCRYPTOLIB (1)
205216#endif
@@ -233,23 +244,20 @@ static const char pybricks_ev3dev_help_text[] =
233244
234245extern const struct _mp_print_t mp_stderr_print ;
235246
236- // Define to 1 to use undertested inefficient GC helper implementation
237- // (if more efficient arch-specific one is not available).
238- #ifndef MICROPY_GCREGS_SETJMP
239- #ifdef __mips__
240- #define MICROPY_GCREGS_SETJMP (1)
241- #else
242- #define MICROPY_GCREGS_SETJMP (0)
243- #endif
247+ #if !(defined(MICROPY_GCREGS_SETJMP ) || defined(__x86_64__ ) || defined(__i386__ ) || defined(__thumb2__ ) || defined(__thumb__ ) || defined(__arm__ ))
248+ // Fall back to setjmp() implementation for discovery of GC pointers in registers.
249+ #define MICROPY_GCREGS_SETJMP (1)
244250#endif
245251
246252#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
247253#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
248254#define MICROPY_KBD_EXCEPTION (1)
249255#define MICROPY_ASYNC_KBD_INTR (0)
250256
257+ #define mp_type_fileio mp_type_vfs_posix_fileio
258+ #define mp_type_textio mp_type_vfs_posix_textio
259+
251260extern const struct _mp_obj_module_t mp_module_machine ;
252- extern const struct _mp_obj_module_t mp_module_mmap ;
253261extern const struct _mp_obj_module_t mp_module_os ;
254262extern const struct _mp_obj_module_t mp_module_uos_vfs ;
255263extern const struct _mp_obj_module_t mp_module_uselect ;
@@ -259,6 +267,7 @@ extern const struct _mp_obj_module_t mp_module_socket;
259267extern const struct _mp_obj_module_t mp_module_ffi ;
260268extern const struct _mp_obj_module_t mp_module_jni ;
261269extern const struct _mp_obj_module_t mp_module_ufcntl ;
270+ extern const struct _mp_obj_module_t mp_module_ummap ;
262271
263272#if MICROPY_PY_UOS_VFS
264273#define MICROPY_PY_UOS_DEF { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos_vfs) },
@@ -306,8 +315,8 @@ extern const struct _mp_obj_module_t mp_module_ufcntl;
306315 MICROPY_PY_UOS_DEF \
307316 MICROPY_PY_USELECT_DEF \
308317 MICROPY_PY_TERMIOS_DEF \
309- { MP_ROM_QSTR(MP_QSTR_mmap), MP_ROM_PTR(&mp_module_mmap) }, \
310318 { MP_ROM_QSTR(MP_QSTR_ufcntl), MP_ROM_PTR(&mp_module_ufcntl) }, \
319+ { MP_ROM_QSTR(MP_QSTR_ummap), MP_ROM_PTR(&mp_module_ummap) }, \
311320
312321// type definitions for the specific machine
313322
@@ -345,17 +354,6 @@ void mp_unix_mark_exec(void);
345354#define MICROPY_FORCE_PLAT_ALLOC_EXEC (1)
346355#endif
347356
348- #if MICROPY_PY_OS_DUPTERM
349- #define MP_PLAT_PRINT_STRN (str , len ) mp_hal_stdout_tx_strn_cooked(str, len)
350- #else
351- #define MP_PLAT_PRINT_STRN (str , len ) do { \
352- MP_THREAD_GIL_EXIT(); \
353- ssize_t ret = write(1, str, len); \
354- MP_THREAD_GIL_ENTER(); \
355- (void)ret; \
356- } while (0)
357- #endif
358-
359357#ifdef __linux__
360358// Can access physical memory using /dev/mem
361359#define MICROPY_PLAT_DEV_MEM (1)
@@ -380,9 +378,17 @@ void mp_unix_mark_exec(void);
380378
381379#define MP_STATE_PORT MP_STATE_VM
382380
381+ #if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK
382+ struct _mp_bluetooth_btstack_root_pointers_t ;
383+ #define MICROPY_BLUETOOTH_ROOT_POINTERS struct _mp_bluetooth_btstack_root_pointers_t *bluetooth_btstack_root_pointers;
384+ #else
385+ #define MICROPY_BLUETOOTH_ROOT_POINTERS
386+ #endif
387+
383388#define MICROPY_PORT_ROOT_POINTERS \
384389 const char *readline_hist[50]; \
385390 void *mmap_region_head; \
391+ MICROPY_BLUETOOTH_ROOT_POINTERS \
386392
387393// We need to provide a declaration/definition of alloca()
388394// unless support for it is disabled.
@@ -413,4 +419,30 @@ void mp_unix_mark_exec(void);
413419#include <stdio.h>
414420#endif
415421
422+ #if MICROPY_PY_THREAD
423+ #define MICROPY_BEGIN_ATOMIC_SECTION () (mp_thread_unix_begin_atomic_section(), 0)
424+ #define MICROPY_END_ATOMIC_SECTION (x ) (void)x; mp_thread_unix_end_atomic_section()
425+ #endif
426+
427+ #define MICROPY_VM_HOOK_LOOP do { \
428+ extern int pbio_do_one_event(void); \
429+ pbio_do_one_event(); \
430+ } while (0);
431+
432+ #include <glib.h>
433+
434+ #define MICROPY_EVENT_POLL_HOOK do { \
435+ extern void mp_handle_pending(bool); \
436+ mp_handle_pending(true); \
437+ extern int pbio_do_one_event(void); \
438+ while (pbio_do_one_event()) { } \
439+ MP_THREAD_GIL_EXIT(); \
440+ g_main_context_iteration(g_main_context_get_thread_default(), TRUE); \
441+ MP_THREAD_GIL_ENTER(); \
442+ } while (0);
443+
444+
445+ #include <sched.h>
446+ #define MICROPY_UNIX_MACHINE_IDLE sched_yield();
447+
416448#include "../pybricks_config.h"
0 commit comments