-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.h
More file actions
230 lines (174 loc) · 4.34 KB
/
main.h
File metadata and controls
230 lines (174 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// *** main.h *********************************************************
#ifndef MAIN_INCLUDED
#define VERSION "2.27k"
//#define SODEBUG 1
#define DEBUGGING 1 // enable to use mplab x debugger
#define ZIGFLEA 1
#define UPGRADE 1
// Enable in-memory trace buffer for debugging with the trace() macro.
#define IN_MEMORY_TRACE 0
#if STICK_GUEST
#define __32MK0512GPK064__ 1
#else
#define NULL ((void*)0)
#endif
#if ! STICK_GUEST
#include <myplib.h>
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
#define MCU_CORE_BITS 32
typedef int intptr;
typedef unsigned int uintptr;
#define asm_halt() asm("SDBBP 0");
#else // STICK_GUEST
#if WIN32
// _DEBUG/NDEBUG win
#if _DEBUG
#define SODEBUG 1
#else
#if NDEBUG
#define SODEBUG 0
#else
#error _DEBUG/NDEBUG?
#endif
#endif // _DEBUG
#else // WIN32
// SODEBUG wins
#if SODEBUG
#define _DEBUG
#undef NDEBUG
#else
#define NDEBUG
#undef _DEBUG
#endif // SODEBUG
#endif // WIN32
#if GCC
#include <inttypes.h>
#include <bits/wordsize.h>
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef uintptr_t uintptr;
typedef intptr_t intptr;
typedef uint32 size_t;
#else // GCC
#define _WIN32_WINNT 0x0601
#include <windows.h>
extern int isatty(int);
#if ! NO_UINT_TYPEDEFS
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
typedef int intptr;
typedef unsigned int uintptr;
#endif
#define NO_UINT_TYPEDEFS 1
#endif // ! GCC
#include <assert.h>
#define ASSERT(x) assert(x)
#define assert_ram(x) assert(x)
extern void write(int, const void *, size_t);
extern char *gets(char *);
#define inline
#undef MAX_PATH
#endif // ! STICK_GUEST
typedef unsigned char bool;
typedef unsigned char byte;
typedef unsigned int uint;
enum {
false,
true
};
#define IN
#define OUT
#define OPTIONAL
#define VARIABLE 1
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ROUNDUP(n, s) (((n)+(s)-1)&~((s)-1)) // N.B. s must be power of 2!
#define ROUNDDOWN(n, s) ((n)&~((s)-1)) // N.B. s must be power of 2!
#define LENGTHOF(a) (sizeof(a)/sizeof(a[0]))
#define OFFSETOF(t, f) ((int)(intptr)(&((t *)0)->f))
#define IS_POWER_OF_2(x) ((((x)-1)&(x))==0)
#define BASIC_OUTPUT_LINE_SIZE 79
#define BASIC_INPUT_LINE_SIZE 72
#define vsnprintf myvsnprintf
#define snprintf mysnprintf
#define sprintf mysprintf
#define vsprintf myvsprintf
#define printf myprintf
#define sprintf_s mysprintf_s
#define snprintf_s mysnprintf_s
#include <stdarg.h>
#include "flash.h"
#include "pin.h"
#include "printf.h"
#include "qspi.h"
#include "i2c.h"
#include "zigflea.h"
#include "terminal.h"
#include "text.h"
#include "timer.h"
#include "util.h"
#include "adc.h"
#include "led.h"
#include "serial.h"
#include "config.h"
#if ! STICK_GUEST
#include "cdcacm.h"
#include "usb.h"
#endif // ! STICK_GUEST
#include "cpustick.h"
#include "basic.h"
#include "code.h"
#include "parse.h"
#include "run.h"
#include "vars.h"
#include "basic0.h"
#include "parse2.h"
#include "run2.h"
#include "scope.h"
#define os_yield() // NULL
int
vprintf(const char *format, va_list ap);
#if ! STICK_GUEST
#define CASSERT(predicate) _impl_CASSERT_LINE(predicate,__LINE__)
#define _impl_PASTE(a,b) a##b
#define _impl_CASSERT_LINE(predicate, line) \
typedef char _impl_PASTE(cassert_failed_line##_,line)[2*!!(predicate)-1];
// usable in function body
#define cassert(predicate) do { CASSERT(predicate); } while (0)
#if SODEBUG
#define assert(x) do { if (! (x)) { led_line(__LINE__); } } while (0)
#else
#define assert(x)
#endif
#define assert_ram(x) do { if (! (x)) { asm_halt(); } } while (0)
#define ASSERT(x) do { if (! (x)) { led_line(__LINE__); } } while (0)
#define ASSERT_RAM(x) do { if (! (x)) { asm_halt(); } } while (0)
#else // STICK_GUEST
extern byte big_buffer[768];
#endif // ! STICK_GUEST
extern bool disable_autorun;
extern uint16 flash_checksum;
extern byte *end_of_static;
extern uint32 cpu_frequency;
extern uint32 bus_frequency;
extern uint32 oscillator_frequency;
extern bool debugger_attached;
extern byte big_buffer[768];
typedef void (*flash_upgrade_ram_begin_f)(void);
void
#if ! _WIN32
__longramfunc__
__attribute__((nomips16))
#endif
flash_upgrade_ram_begin(void);
void
flash_upgrade_ram_end(void);
#define MAIN_INCLUDED 1
#endif // MAIN_INCLUDED