1 #include <stdint.h>
2 
3 // options to control how MicroPython is built
4 
5 #define MICROPY_ALLOC_PATH_MAX      (128)
6 #define MICROPY_EMIT_THUMB          (1)
7 #define MICROPY_EMIT_INLINE_THUMB   (1)
8 #define MICROPY_ENABLE_GC           (1)
9 #define MICROPY_ENABLE_FINALISER    (1)
10 #define MICROPY_STACK_CHECK         (1)
11 #define MICROPY_HELPER_REPL         (1)
12 #define MICROPY_REPL_INFO           (1)
13 #define MICROPY_ENABLE_SOURCE_LINE  (1)
14 #define MICROPY_LONGINT_IMPL        (MICROPY_LONGINT_IMPL_MPZ)
15 #define MICROPY_FLOAT_IMPL          (MICROPY_FLOAT_IMPL_FLOAT)
16 #define MICROPY_OPT_COMPUTED_GOTO   (1)
17 
18 #define MICROPY_PY_BUILTINS_INPUT   (1)
19 #define MICROPY_PY_BUILTINS_HELP    (1)
20 #define MICROPY_PY_BUILTINS_HELP_TEXT teensy_help_text
21 
22 #define MICROPY_PY_IO               (0)
23 #define MICROPY_PY_FROZENSET        (1)
24 #define MICROPY_PY_SYS_EXIT         (1)
25 #define MICROPY_PY_SYS_STDFILES     (1)
26 #define MICROPY_PY_CMATH            (1)
27 
28 #define MICROPY_TIMER_REG           (0)
29 #define MICROPY_REG                 (MICROPY_TIMER_REG)
30 
31 #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF   (1)
32 #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE  (0)
33 
34 // extra built in names to add to the global namespace
35 #define MICROPY_PORT_BUILTINS \
36 
37 // extra built in modules to add to the list of known ones
38 extern const struct _mp_obj_module_t os_module;
39 extern const struct _mp_obj_module_t pyb_module;
40 extern const struct _mp_obj_module_t time_module;
41 #define MICROPY_PORT_BUILTIN_MODULES \
42     { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
43 
44 // extra constants
45 #define MICROPY_PORT_CONSTANTS \
46     { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
47 
48 #define MP_STATE_PORT MP_STATE_VM
49 
50 #define MICROPY_PORT_ROOT_POINTERS \
51     const char *readline_hist[8]; \
52     mp_obj_t pin_class_mapper; \
53     mp_obj_t pin_class_map_dict; \
54     struct _pyb_uart_obj_t *pyb_stdio_uart; \
55 
56 // type definitions for the specific machine
57 
58 #define UINT_FMT "%u"
59 #define INT_FMT "%d"
60 
61 typedef int32_t mp_int_t; // must be pointer size
62 typedef unsigned int mp_uint_t; // must be pointer size
63 typedef long mp_off_t;
64 
65 // We have inlined IRQ functions for efficiency (they are generally
66 // 1 machine instruction).
67 //
68 // Note on IRQ state: you should not need to know the specific
69 // value of the state variable, but rather just pass the return
70 // value from disable_irq back to enable_irq.  If you really need
71 // to know the machine-specific values, see irq.h.
72 
__get_PRIMASK(void)73 __attribute__((always_inline)) static inline uint32_t __get_PRIMASK(void) {
74     uint32_t result;
75     __asm volatile ("MRS %0, primask" : "=r" (result));
76     return result;
77 }
78 
__set_PRIMASK(uint32_t priMask)79 __attribute__((always_inline)) static inline void __set_PRIMASK(uint32_t priMask) {
80     __asm volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
81 }
82 
enable_irq(mp_uint_t state)83 __attribute__((always_inline)) static inline void enable_irq(mp_uint_t state) {
84     __set_PRIMASK(state);
85 }
86 
disable_irq(void)87 __attribute__((always_inline)) static inline mp_uint_t disable_irq(void) {
88     mp_uint_t state = __get_PRIMASK();
89     __asm__ volatile ("CPSID i");
90     return state;
91 }
92 
93 #define MICROPY_BEGIN_ATOMIC_SECTION()     disable_irq()
94 #define MICROPY_END_ATOMIC_SECTION(state)  enable_irq(state)
95 
96 // We need to provide a declaration/definition of alloca()
97 #include <alloca.h>
98 
99 // The following would be from a board specific file, if one existed
100 
101 #define MICROPY_HW_BOARD_NAME       "Teensy-3.1"
102 #define MICROPY_HW_MCU_NAME         "MK20DX256"
103 
104 #define MICROPY_HW_HAS_SWITCH       (0)
105 #define MICROPY_HW_HAS_SDCARD       (0)
106 #define MICROPY_HW_HAS_MMA7660      (0)
107 #define MICROPY_HW_HAS_LIS3DSH      (0)
108 #define MICROPY_HW_HAS_LCD          (0)
109 #define MICROPY_HW_ENABLE_RNG       (0)
110 #define MICROPY_HW_ENABLE_RTC       (0)
111 #define MICROPY_HW_ENABLE_TIMER     (0)
112 #define MICROPY_HW_ENABLE_SERVO     (0)
113 #define MICROPY_HW_ENABLE_DAC       (0)
114 #define MICROPY_HW_ENABLE_I2C1      (0)
115 #define MICROPY_HW_ENABLE_SPI1      (0)
116 #define MICROPY_HW_ENABLE_SPI3      (0)
117 #define MICROPY_HW_ENABLE_CC3K      (0)
118 
119 #define MICROPY_HW_LED1             (pin_C5)
120 #define MICROPY_HW_LED_OTYPE        (GPIO_MODE_OUTPUT_PP)
121 #define MICROPY_HW_LED_ON(pin)      (pin->gpio->PSOR = pin->pin_mask)
122 #define MICROPY_HW_LED_OFF(pin)     (pin->gpio->PCOR = pin->pin_mask)
123 
124 #if 0
125 // SD card detect switch
126 #define MICROPY_HW_SDCARD_DETECT_PIN        (pin_A8)
127 #define MICROPY_HW_SDCARD_DETECT_PULL       (GPIO_PULLUP)
128 #define MICROPY_HW_SDCARD_DETECT_PRESENT    (GPIO_PIN_RESET)
129 #endif
130 
131 #define MICROPY_MATH_SQRT_ASM     (1)
132 
133 #define MICROPY_MPHALPORT_H     "teensy_hal.h"
134 #define MICROPY_PIN_DEFS_PORT_H "pin_defs_teensy.h"
135