mpconfigport.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. * Copyright (c) 2015 Daniel Campora
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #include <stdint.h>
  28. #ifndef BOOTLOADER
  29. #include "FreeRTOS.h"
  30. #include "semphr.h"
  31. #endif
  32. // options to control how MicroPython is built
  33. #define MICROPY_ALLOC_PATH_MAX (128)
  34. #define MICROPY_PERSISTENT_CODE_LOAD (1)
  35. #define MICROPY_EMIT_THUMB (0)
  36. #define MICROPY_EMIT_INLINE_THUMB (0)
  37. #define MICROPY_COMP_MODULE_CONST (1)
  38. #define MICROPY_ENABLE_GC (1)
  39. #define MICROPY_ENABLE_FINALISER (1)
  40. #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
  41. #define MICROPY_STACK_CHECK (0)
  42. #define MICROPY_HELPER_REPL (1)
  43. #define MICROPY_ENABLE_SOURCE_LINE (1)
  44. #define MICROPY_ENABLE_DOC_STRING (0)
  45. #define MICROPY_REPL_AUTO_INDENT (1)
  46. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
  47. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
  48. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
  49. #define MICROPY_OPT_COMPUTED_GOTO (0)
  50. #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
  51. #define MICROPY_READER_VFS (1)
  52. #ifndef DEBUG // we need ram on the launchxl while debugging
  53. #define MICROPY_CPYTHON_COMPAT (1)
  54. #else
  55. #define MICROPY_CPYTHON_COMPAT (0)
  56. #endif
  57. #define MICROPY_QSTR_BYTES_IN_HASH (1)
  58. // fatfs configuration used in ffconf.h
  59. #define MICROPY_FATFS_ENABLE_LFN (2)
  60. #define MICROPY_FATFS_MAX_LFN (MICROPY_ALLOC_PATH_MAX)
  61. #define MICROPY_FATFS_LFN_CODE_PAGE (437) // 1=SFN/ANSI 437=LFN/U.S.(OEM)
  62. #define MICROPY_FATFS_RPATH (2)
  63. #define MICROPY_FATFS_REENTRANT (1)
  64. #define MICROPY_FATFS_TIMEOUT (2500)
  65. #define MICROPY_FATFS_SYNC_T SemaphoreHandle_t
  66. #define MICROPY_STREAMS_NON_BLOCK (1)
  67. #define MICROPY_MODULE_WEAK_LINKS (1)
  68. #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
  69. #define MICROPY_USE_INTERNAL_ERRNO (1)
  70. #define MICROPY_VFS (1)
  71. #define MICROPY_VFS_FAT (1)
  72. #define MICROPY_PY_ASYNC_AWAIT (0)
  73. #define MICROPY_PY_ALL_SPECIAL_METHODS (1)
  74. #define MICROPY_PY_BUILTINS_INPUT (1)
  75. #define MICROPY_PY_BUILTINS_HELP (1)
  76. #define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text
  77. #ifndef DEBUG
  78. #define MICROPY_PY_BUILTINS_STR_UNICODE (1)
  79. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
  80. #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
  81. #define MICROPY_PY_BUILTINS_FROZENSET (1)
  82. #define MICROPY_PY_BUILTINS_EXECFILE (1)
  83. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
  84. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
  85. #else
  86. #define MICROPY_PY_BUILTINS_STR_UNICODE (0)
  87. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
  88. #define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
  89. #define MICROPY_PY_BUILTINS_FROZENSET (0)
  90. #define MICROPY_PY_BUILTINS_EXECFILE (0)
  91. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
  92. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
  93. #endif
  94. #define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
  95. #define MICROPY_PY_SYS_MAXSIZE (1)
  96. #define MICROPY_PY_SYS_EXIT (1)
  97. #define MICROPY_PY_SYS_STDFILES (1)
  98. #define MICROPY_PY_CMATH (0)
  99. #define MICROPY_PY_IO (1)
  100. #define MICROPY_PY_IO_FILEIO (1)
  101. #define MICROPY_PY_UERRNO (1)
  102. #define MICROPY_PY_UERRNO_ERRORCODE (0)
  103. #define MICROPY_PY_THREAD (1)
  104. #define MICROPY_PY_THREAD_GIL (1)
  105. #define MICROPY_PY_UBINASCII (0)
  106. #define MICROPY_PY_UCTYPES (0)
  107. #define MICROPY_PY_UZLIB (0)
  108. #define MICROPY_PY_UJSON (1)
  109. #define MICROPY_PY_URE (1)
  110. #define MICROPY_PY_UHEAPQ (0)
  111. #define MICROPY_PY_UHASHLIB (0)
  112. #define MICROPY_PY_USELECT (1)
  113. #define MICROPY_PY_UTIME_MP_HAL (1)
  114. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
  115. #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
  116. #define MICROPY_KBD_EXCEPTION (1)
  117. // We define our own list of errno constants to include in uerrno module
  118. #define MICROPY_PY_UERRNO_LIST \
  119. X(EPERM) \
  120. X(EIO) \
  121. X(ENODEV) \
  122. X(EINVAL) \
  123. X(ETIMEDOUT) \
  124. // TODO these should be generic, not bound to fatfs
  125. #define mp_type_fileio mp_type_vfs_fat_fileio
  126. #define mp_type_textio mp_type_vfs_fat_textio
  127. // use vfs's functions for import stat and builtin open
  128. #define mp_import_stat mp_vfs_import_stat
  129. #define mp_builtin_open mp_vfs_open
  130. #define mp_builtin_open_obj mp_vfs_open_obj
  131. // extra built in names to add to the global namespace
  132. #define MICROPY_PORT_BUILTINS \
  133. { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
  134. // extra built in modules to add to the list of known ones
  135. extern const struct _mp_obj_module_t machine_module;
  136. extern const struct _mp_obj_module_t wipy_module;
  137. extern const struct _mp_obj_module_t mp_module_ure;
  138. extern const struct _mp_obj_module_t mp_module_ujson;
  139. extern const struct _mp_obj_module_t mp_module_uos;
  140. extern const struct _mp_obj_module_t mp_module_utime;
  141. extern const struct _mp_obj_module_t mp_module_uselect;
  142. extern const struct _mp_obj_module_t mp_module_usocket;
  143. extern const struct _mp_obj_module_t mp_module_network;
  144. extern const struct _mp_obj_module_t mp_module_ubinascii;
  145. extern const struct _mp_obj_module_t mp_module_ussl;
  146. #define MICROPY_PORT_BUILTIN_MODULES \
  147. { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
  148. { MP_ROM_QSTR(MP_QSTR_wipy), MP_ROM_PTR(&wipy_module) }, \
  149. { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
  150. { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
  151. { MP_ROM_QSTR(MP_QSTR_uselect), MP_ROM_PTR(&mp_module_uselect) }, \
  152. { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) }, \
  153. { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&mp_module_network) }, \
  154. { MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) }, \
  155. { MP_ROM_QSTR(MP_QSTR_ussl), MP_ROM_PTR(&mp_module_ussl) }, \
  156. #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
  157. { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
  158. { MP_ROM_QSTR(MP_QSTR_struct), MP_ROM_PTR(&mp_module_ustruct) }, \
  159. { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) }, \
  160. { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, \
  161. { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&mp_module_uos) }, \
  162. { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \
  163. { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_module_uselect) }, \
  164. { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_usocket) }, \
  165. { MP_ROM_QSTR(MP_QSTR_binascii), MP_ROM_PTR(&mp_module_ubinascii) }, \
  166. { MP_ROM_QSTR(MP_QSTR_ssl), MP_ROM_PTR(&mp_module_ussl) }, \
  167. { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
  168. // extra constants
  169. #define MICROPY_PORT_CONSTANTS \
  170. { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
  171. // vm state and root pointers for the gc
  172. #define MP_STATE_PORT MP_STATE_VM
  173. #define MICROPY_PORT_ROOT_POINTERS \
  174. const char *readline_hist[8]; \
  175. mp_obj_t mp_const_user_interrupt; \
  176. mp_obj_t machine_config_main; \
  177. mp_obj_list_t pyb_sleep_obj_list; \
  178. mp_obj_list_t mp_irq_obj_list; \
  179. mp_obj_list_t pyb_timer_channel_obj_list; \
  180. struct _pyb_uart_obj_t *pyb_uart_objs[2]; \
  181. struct _os_term_dup_obj_t *os_term_dup_obj; \
  182. // type definitions for the specific machine
  183. #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
  184. #define MP_SSIZE_MAX (0x7FFFFFFF)
  185. #define UINT_FMT "%u"
  186. #define INT_FMT "%d"
  187. typedef int32_t mp_int_t; // must be pointer size
  188. typedef unsigned int mp_uint_t; // must be pointer size
  189. typedef long mp_off_t;
  190. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  191. #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
  192. #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)
  193. #define MICROPY_EVENT_POLL_HOOK __WFI();
  194. // assembly functions to handle critical sections, interrupt
  195. // disabling/enabling and sleep mode enter/exit
  196. #include "cc3200_asm.h"
  197. // We need to provide a declaration/definition of alloca()
  198. #include <alloca.h>
  199. // Include board specific configuration
  200. #include "mpconfigboard.h"
  201. #define MICROPY_MPHALPORT_H "cc3200_hal.h"
  202. #define MICROPY_PORT_HAS_TELNET (1)
  203. #define MICROPY_PORT_HAS_FTP (1)
  204. #define MICROPY_PY_SYS_PLATFORM "WiPy"
  205. #define MICROPY_PORT_WLAN_AP_SSID "wipy-wlan"
  206. #define MICROPY_PORT_WLAN_AP_KEY "www.wipy.io"
  207. #define MICROPY_PORT_WLAN_AP_SECURITY SL_SEC_TYPE_WPA_WPA2
  208. #define MICROPY_PORT_WLAN_AP_CHANNEL 5