mpconfigport.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2017 Armink (armink.ztl@gmail.com)
  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. #include <rtthread.h>
  27. #include <stdint.h>
  28. #include <libc/libc_errno.h>
  29. // options to control how MicroPython is built
  30. // You can disable the built-in MicroPython compiler by setting the following
  31. // config option to 0. If you do this then you won't get a REPL prompt, but you
  32. // will still be able to execute pre-compiled scripts, compiled with mpy-cross.
  33. #define MICROPY_ENABLE_COMPILER (1)
  34. #if defined(PKG_MICROPYTHON_HEAP_SIZE)
  35. #define MICROPY_HEAP_SIZE PKG_MICROPYTHON_HEAP_SIZE
  36. #else
  37. #define MICROPY_HEAP_SIZE (8 * 1024)
  38. #endif
  39. #define MICROPY_STACK_CHECK (1)
  40. #define MICROPY_QSTR_BYTES_IN_HASH (1)
  41. #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
  42. #define MICROPY_ALLOC_PATH_MAX (256)
  43. #define MICROPY_ALLOC_PARSE_CHUNK_INIT (16)
  44. #define MICROPY_EMIT_X64 (0)
  45. #define MICROPY_EMIT_THUMB (0)
  46. #define MICROPY_EMIT_INLINE_THUMB (0)
  47. #define MICROPY_COMP_MODULE_CONST (0)
  48. #define MICROPY_COMP_CONST (0)
  49. #define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0)
  50. #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
  51. #define MICROPY_MEM_STATS (0)
  52. #define MICROPY_DEBUG_PRINTERS (0)
  53. #define MICROPY_ENABLE_GC (1)
  54. #define MICROPY_ENABLE_FINALISER (1)
  55. #define MICROPY_GC_ALLOC_THRESHOLD (0)
  56. #define MICROPY_REPL_EVENT_DRIVEN (0)
  57. #define MICROPY_REPL_AUTO_INDENT (1)
  58. #define MICROPY_KBD_EXCEPTION (1)
  59. #define MICROPY_HELPER_REPL (1)
  60. #define MICROPY_HELPER_LEXER_UNIX (0)
  61. #define MICROPY_ENABLE_SOURCE_LINE (0)
  62. #define MICROPY_ENABLE_DOC_STRING (0)
  63. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
  64. #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0)
  65. #define MICROPY_PY_ASYNC_AWAIT (0)
  66. // control over Python builtins
  67. #define MICROPY_PY_FUNCTION_ATTRS (1)
  68. #define MICROPY_PY_BUILTINS_STR_UNICODE (1)
  69. #define MICROPY_PY_BUILTINS_STR_CENTER (1)
  70. #define MICROPY_PY_BUILTINS_STR_PARTITION (1)
  71. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
  72. #define MICROPY_PY_BUILTINS_BYTEARRAY (1)
  73. #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
  74. #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
  75. #define MICROPY_PY_ALL_SPECIAL_METHODS (1)
  76. #define MICROPY_PY_BUILTINS_COMPILE (1)
  77. #define MICROPY_PY_BUILTINS_EXECFILE (1)
  78. #define MICROPY_PY_BUILTINS_INPUT (1)
  79. #define MICROPY_PY_BUILTINS_POW3 (1)
  80. #define MICROPY_PY_BUILTINS_ENUMERATE (1)
  81. #define MICROPY_PY_BUILTINS_FILTER (1)
  82. #define MICROPY_PY_BUILTINS_FROZENSET (1)
  83. #define MICROPY_PY_BUILTINS_REVERSED (1)
  84. #define MICROPY_PY_BUILTINS_SET (1)
  85. #define MICROPY_PY_BUILTINS_HELP (1)
  86. #define MICROPY_PY_BUILTINS_HELP_TEXT rtthread_help_text
  87. #define MICROPY_PY_BUILTINS_HELP_MODULES (1)
  88. #define MICROPY_PY_BUILTINS_SLICE (1)
  89. #define MICROPY_PY_BUILTINS_PROPERTY (1)
  90. #define MICROPY_PY_BUILTINS_MIN_MAX (1)
  91. #define MICROPY_PY___FILE__ (1)
  92. #define MICROPY_PY_GC (1)
  93. #define MICROPY_PY_ARRAY (1)
  94. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
  95. #define MICROPY_PY_ATTRTUPLE (1)
  96. #define MICROPY_PY_COLLECTIONS (1)
  97. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
  98. #define MICROPY_PY_MATH (1)
  99. #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
  100. #define MICROPY_PY_CMATH (1)
  101. #define MICROPY_PY_IO (1)
  102. #define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
  103. #define MICROPY_STREAMS_NON_BLOCK (1)
  104. #define MICROPY_MODULE_WEAK_LINKS (1)
  105. #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
  106. #define MICROPY_USE_INTERNAL_ERRNO (1)
  107. #define MICROPY_PY_STRUCT (0)
  108. #define MICROPY_PY_RTTHREAD (1)
  109. #define MICROPY_PY_SYS (0)
  110. #define MICROPY_MODULE_FROZEN_MPY (1)
  111. #define MICROPY_CPYTHON_COMPAT (0)
  112. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
  113. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
  114. // extended modules
  115. #define MICROPY_PY_UCTYPES (1)
  116. #define MICROPY_PY_UZLIB (0)
  117. #define MICROPY_PY_UJSON (1)
  118. #define MICROPY_PY_URE (0)
  119. #define MICROPY_PY_UHEAPQ (1)
  120. #define MICROPY_PY_UHASHLIB (0)
  121. #define MICROPY_PY_UBINASCII (1)
  122. #define MICROPY_PY_UTIME (1)
  123. #define MICROPY_PY_UTIME_MP_HAL (1)
  124. #define MICROPY_PY_UTIMEQ (1)
  125. #define MICROPY_PY_URANDOM (1)
  126. #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
  127. #define MICROPY_PY_MACHINE (1)
  128. #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
  129. #if defined(__CC_ARM)
  130. //TODO
  131. #elif defined(__ICCARM__)
  132. //#include <sys/types.h>
  133. #define MICROPY_NO_ALLOCA 1
  134. #define NORETURN __noreturn
  135. #define MP_WEAK __weak
  136. #define MP_NOINLINE
  137. #define MP_ALWAYSINLINE
  138. #define MP_LIKELY(x) x
  139. #define MP_UNLIKELY(x) x
  140. #elif defined(__GNUC__)
  141. // We need to provide a declaration/definition of alloca()
  142. #include <alloca.h>
  143. #else
  144. #error "not supported compiler"
  145. #endif /* defined(__CC_ARM) */
  146. // type definitions for the specific machine
  147. #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
  148. // This port is intended to be 32-bit, but unfortunately, int32_t for
  149. // different targets may be defined in different ways - either as int
  150. // or as long. This requires different printf formatting specifiers
  151. // to print such value. So, we avoid int32_t and use int directly.
  152. #define UINT_FMT "%u"
  153. #define INT_FMT "%d"
  154. typedef int mp_int_t; // must be pointer size
  155. typedef unsigned mp_uint_t; // must be pointer size
  156. typedef long mp_off_t;
  157. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  158. // extra built in names to add to the global namespace
  159. #define MICROPY_PORT_BUILTINS \
  160. { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
  161. #define MICROPY_HW_BOARD_NAME "RT-Thread Board"
  162. #define MICROPY_HW_MCU_NAME "stm32f4"
  163. #ifdef __linux__
  164. #define MICROPY_MIN_USE_STDOUT (1)
  165. #endif
  166. #ifdef __thumb__
  167. #define MICROPY_MIN_USE_CORTEX_CPU (1)
  168. #define MICROPY_MIN_USE_STM32_MCU (1)
  169. #endif
  170. #define MP_STATE_PORT MP_STATE_VM
  171. #define MICROPY_PORT_ROOT_POINTERS const char *readline_hist[8];
  172. extern const struct _mp_obj_module_t pyb_module;
  173. extern const struct _mp_obj_module_t mp_module_rtthread;
  174. extern const struct _mp_obj_module_t mp_module_time;
  175. extern const struct _mp_obj_module_t mp_module_machine;
  176. #if MICROPY_PY_RTTHREAD
  177. #define MICROPY_PY_RTTHREAD_DEF { MP_ROM_QSTR(MP_QSTR_rtthread), MP_ROM_PTR(&mp_module_rtthread) },
  178. #else
  179. #define MICROPY_PY_RTTHREAD_DEF
  180. #endif
  181. #define MICROPY_PORT_BUILTIN_MODULES \
  182. { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
  183. { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
  184. MICROPY_PY_RTTHREAD_DEF \
  185. #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
  186. { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_time) }, \
  187. #define MP_RTT_NOT_IMPL_PRINT rt_kprintf("Not implement on %s:%ld, Please add for your board!\n", __FILE__, __FUNCTION__)