VSF Documented
mpconfigport.h
Go to the documentation of this file.
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// Options to control how MicroPython is built for this port, overriding
28// defaults in py/mpconfig.h. This file is mostly about configuring the
29// features to work on Unix-like systems, see mpconfigvariant.h (and
30// mpconfigvariant_common.h) for feature enabling.
31
32// For size_t and ssize_t
33#include <unistd.h>
34
35#ifdef __VSF__
36#undef _MSC_VER
37#undef _WIN32
38#undef _WIN64
39#define MICROPY_GCREGS_SETJMP 1
40#define MICROPY_NLR_SETJMP 1
41#ifndef __APPLET__
42#if __IS_COMPILER_IAR__
43#define MICROPY_NO_ALLOCA 1
44#endif
45#endif
46#endif
47
48// Variant-specific definitions.
49#include "mpconfigvariant.h"
50
51#ifndef MICROPY_CONFIG_ROM_LEVEL
52#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES)
53#endif
54
55#ifndef MICROPY_PY_SYS_PLATFORM
56#if defined(__APPLE__) && defined(__MACH__)
57 #define MICROPY_PY_SYS_PLATFORM "darwin"
58#else
59 #define MICROPY_PY_SYS_PLATFORM "linux"
60#endif
61#endif
62
63#ifndef MICROPY_PY_SYS_PATH_DEFAULT
64#ifdef __WIN__
65#define MICROPY_PY_SYS_PATH_DEFAULT "/usr/micropython/lib"
66#else
67#define MICROPY_PY_SYS_PATH_DEFAULT "/root/micropython/lib"
68#endif
69#endif
70
71#define MP_STATE_PORT MP_STATE_VM
72
73// Configure which emitter to use for this target.
74#if !defined(MICROPY_EMIT_X64) && defined(__x86_64__)
75 #define MICROPY_EMIT_X64 (1)
76#endif
77#if !defined(MICROPY_EMIT_X86) && defined(__i386__)
78 #define MICROPY_EMIT_X86 (1)
79#endif
80#if !defined(MICROPY_EMIT_THUMB) && defined(__thumb2__)
81 #define MICROPY_EMIT_THUMB (1)
82 #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
83#endif
84// Some compilers define __thumb2__ and __arm__ at the same time, let
85// autodetected thumb2 emitter have priority.
86#if !defined(MICROPY_EMIT_ARM) && defined(__arm__) && !defined(__thumb2__)
87 #define MICROPY_EMIT_ARM (1)
88#endif
89
90// Type definitions for the specific machine based on the word size.
91#ifndef MICROPY_OBJ_REPR
92typedef intptr_t mp_int_t; // must be pointer size
93typedef uintptr_t mp_uint_t; // must be pointer size
94#else
95// Assume that if we already defined the obj repr then we also defined types.
96#endif
97
98// Cannot include <sys/types.h>, as it may lead to symbol name clashes
99#if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
100typedef long long mp_off_t;
101#else
102typedef long mp_off_t;
103#endif
104
105// We need to provide a declaration/definition of alloca()
106// unless support for it is disabled.
107#if !defined(MICROPY_NO_ALLOCA) || MICROPY_NO_ALLOCA == 0
108#if defined(__FreeBSD__) || defined(__NetBSD__)
109#include <stdlib.h>
110#else
111//#include <alloca.h>
112#endif
113#endif
114
115// Always enable GC.
116#define MICROPY_ENABLE_GC (1)
117
118#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
119// Fall back to setjmp() implementation for discovery of GC pointers in registers.
120#define MICROPY_GCREGS_SETJMP (1)
121#endif
122
123// Enable the VFS, and enable the posix "filesystem".
124#define MICROPY_ENABLE_FINALISER (1)
125#define MICROPY_VFS (0)
126#define MICROPY_READER_VFS (0)
127#define MICROPY_HELPER_LEXER_UNIX (1)
128#define MICROPY_VFS_POSIX (0)
129#define MICROPY_READER_POSIX (1)
130#ifndef MICROPY_TRACKED_ALLOC
131#define MICROPY_TRACKED_ALLOC (MICROPY_BLUETOOTH_BTSTACK)
132#endif
133
134// VFS stat functions should return time values relative to 1970/1/1
135#define MICROPY_EPOCH_IS_1970 (1)
136
137// Assume that select() call, interrupted with a signal, and erroring
138// with EINTR, updates remaining timeout value.
139#define MICROPY_SELECT_REMAINING_TIME (1)
140
141// Disable stackless by default.
142#ifndef MICROPY_STACKLESS
143#define MICROPY_STACKLESS (0)
144#define MICROPY_STACKLESS_STRICT (0)
145#endif
146
147// If settrace is enabled then we need code saving.
148#if MICROPY_PY_SYS_SETTRACE
149#define MICROPY_PERSISTENT_CODE_SAVE (1)
150#define MICROPY_COMP_CONST (0)
151#endif
152
153// Unix-specific configuration of machine.mem*.
154#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
155#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
156
157#define MICROPY_FATFS_ENABLE_LFN (1)
158#define MICROPY_FATFS_RPATH (2)
159#define MICROPY_FATFS_MAX_SS (4096)
160#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
161
162#define MICROPY_ALLOC_PATH_MAX (PATH_MAX)
163
164// Ensure builtinimport.c works with -m.
165#define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (1)
166
167// Don't default sys.argv and sys.path because we do that in main.
168#define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0)
169
170// Enable sys.executable.
171#define MICROPY_PY_SYS_EXECUTABLE (1)
172
173#define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128)
174
175// Bare-metal ports don't have stderr. Printing debug to stderr may give tests
176// which check stdout a chance to pass, etc.
177extern const struct _mp_print_t mp_stderr_print;
178#define MICROPY_DEBUG_PRINTER (&mp_stderr_print)
179#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
180
181// For the native emitter configure how to mark a region as executable.
182void mp_unix_alloc_exec(size_t min_size, void **ptr, size_t *size);
183void mp_unix_free_exec(void *ptr, size_t size);
185#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size)
186#define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size)
187#ifndef MICROPY_FORCE_PLAT_ALLOC_EXEC
188// Use MP_PLAT_ALLOC_EXEC for any executable memory allocation, including for FFI
189// (overriding libffi own implementation)
190#define MICROPY_FORCE_PLAT_ALLOC_EXEC (1)
191#endif
192
193// If enabled, configure how to seed random on init.
194#ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC
195#include <stddef.h>
196void mp_hal_get_random(size_t n, void *buf);
197static inline unsigned long mp_random_seed_init(void) {
198 unsigned long r;
199 mp_hal_get_random(sizeof(r), &r);
200 return r;
201}
202#endif
203
204#ifdef __linux__
205// Can access physical memory using /dev/mem
206#define MICROPY_PLAT_DEV_MEM (1)
207#endif
208
209#ifdef __ANDROID__
210#include <android/api-level.h>
211#if __ANDROID_API__ < 4
212// Bionic libc in Android 1.5 misses these 2 functions
213#define MP_NEED_LOG2 (1)
214#define nan(x) NAN
215#endif
216#endif
217
218// From "man readdir": "Under glibc, programs can check for the availability
219// of the fields [in struct dirent] not defined in POSIX.1 by testing whether
220// the macros [...], _DIRENT_HAVE_D_TYPE are defined."
221// Other libc's don't define it, but proactively assume that dirent->d_type
222// is available on a modern *nix system.
223#ifndef _DIRENT_HAVE_D_TYPE
224#define _DIRENT_HAVE_D_TYPE (1)
225#endif
226// This macro is not provided by glibc but we need it so ports that don't have
227// dirent->d_ino can disable the use of this field.
228#ifndef _DIRENT_HAVE_D_INO
229#define _DIRENT_HAVE_D_INO (1)
230#endif
231
232#ifndef __APPLE__
233// For debugging purposes, make printf() available to any source file.
234#include <stdio.h>
235#endif
236
237// If threading is enabled, configure the atomic section.
238#if MICROPY_PY_THREAD
239#define MICROPY_BEGIN_ATOMIC_SECTION() (mp_thread_unix_begin_atomic_section(), 0xffffffff)
240#define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section()
241#endif
242
243// In lieu of a WFI(), slow down polling from being a tight loop.
244#ifndef MICROPY_EVENT_POLL_HOOK
245#define MICROPY_EVENT_POLL_HOOK \
246 do { \
247 extern void mp_handle_pending(bool); \
248 mp_handle_pending(true); \
249 usleep(500); /* equivalent to mp_hal_delay_us(500) */ \
250 } while (0);
251#endif
252
253// Configure the implementation of machine.idle().
254#include <sched.h>
255#define MICROPY_UNIX_MACHINE_IDLE sched_yield();
256
257#ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
258#define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
259#endif
260
261#ifndef MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS
262#define MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS (MICROPY_BLUETOOTH_NIMBLE)
263#endif
long mp_off_t
Definition mpconfigport.h:102
void mp_unix_alloc_exec(size_t min_size, void **ptr, size_t *size)
intptr_t mp_int_t
Definition mpconfigport.h:92
void mp_unix_free_exec(void *ptr, size_t size)
const struct _mp_print_t mp_stderr_print
uintptr_t mp_uint_t
Definition mpconfigport.h:93
void mp_unix_mark_exec(void)
uint32_t uintptr_t
Definition stdint.h:38
int32_t intptr_t
Definition stdint.h:39
uint32_t size
Definition vsf_memfs.h:50