forked from Traumflug/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator.h
182 lines (154 loc) · 3.52 KB
/
simulator.h
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
#ifdef SIMULATOR
#undef X_STEP_PIN
#undef X_DIR_PIN
#undef X_MIN_PIN
#undef X_ENABLE_PIN
#undef Y_STEP_PIN
#undef Y_DIR_PIN
#undef Y_MIN_PIN
#undef Y_ENABLE_PIN
#undef Z_STEP_PIN
#undef Z_DIR_PIN
#undef Z_MIN_PIN
#undef Z_ENABLE_PIN
#undef E_STEP_PIN
#undef E_DIR_PIN
#undef E_ENABLE_PIN
#undef STEPPER_ENABLE_PIN
#undef PS_MOSFET_PIN
#undef PS_ON_PIN
#undef RX_ENABLE_PIN
#undef TX_ENABLE_PIN
#undef X_MAX_PIN
#undef Y_MAX_PIN
#undef Z_MAX_PIN
#undef READ
#undef WRITE
#undef TOGGLE
#undef SET_INPUT
#undef SET_OUTPUT
#undef GET_INPUT
#undef GET_OUTPUT
// Compiler appeasement
#undef disable_transmit
#undef enable_transmit
#define disable_transmit()
#define enable_transmit()
#undef USB_SERIAL
#undef BSS
#ifdef __MACH__ // Mac OS X
#define BSS __attribute__ ((__section__ ("__DATA,.bss")))
#else
#define BSS __attribute__ ((__section__ (".bss")))
#endif
#ifndef _SIMULATOR_H
#define _SIMULATOR_H
#include <stdint.h>
#include <stdbool.h>
#include "simulator/data_recorder.h"
#define PROGMEM
#define PGM_P const char *
#define PSTR(x) (x)
#define pgm_read_byte(x) (*((uint8_t *)(x)))
#define pgm_read_word(x) (*((uint16_t *)(x)))
#define MASK(PIN) (1 << PIN)
#define ACD 7
#define OCIE1A 1
// TODO: Implement simulated EEMEM persistence
#define EEMEM
#define eeprom_read_dword(ptr32) (*(ptr32))
#define eeprom_read_word(ptr16) (*(ptr16))
#define eeprom_write_dword(ptr32, i32) (*(ptr32)=i32)
#define eeprom_write_word(ptr16, i16) (*(ptr16)=i16)
typedef enum {
// Define pins used
X_STEP_PIN,
X_DIR_PIN,
X_MIN_PIN,
X_ENABLE_PIN,
Y_STEP_PIN,
Y_DIR_PIN,
Y_MIN_PIN,
Y_ENABLE_PIN,
Z_STEP_PIN,
Z_DIR_PIN,
Z_MIN_PIN,
Z_ENABLE_PIN,
E_STEP_PIN,
E_DIR_PIN,
E_ENABLE_PIN,
STEPPER_ENABLE_PIN,
SCK,
MOSI,
MISO,
SS,
RX_ENABLE_PIN,
TX_ENABLE_PIN,
/*
* Not used in the simulator. Add them to this list to enable them if needed.
PS_MOSFET_PIN,
PS_ON_PIN,
X_MAX_PIN,
Y_MAX_PIN,
Z_MAX_PIN,
*/
PIN_NB /* End of PINS marker; Put all new pins before this one */
} pin_t;
// AVR stand-ins
typedef enum {
WGM00 = 0,
WGM01,
WGM20,
WGM21,
CS00 = 0,
CS02,
CS20,
CS21,
CS22,
} masks_t;
#undef TEMP_PIN_CHANNEL
#define TEMP_PIN_CHANNEL 0
extern uint8_t ACSR;
extern uint8_t TIMSK1;
extern volatile bool sim_interrupts;
bool READ(pin_t pin);
void WRITE(pin_t pin, bool on);
void SET_OUTPUT(pin_t pin);
void SET_INPUT(pin_t pin);
// Simulate AVR interrupts.
#define ISR(fn) void fn (void)
void TIMER1_COMPA_vect(void);
void TIMER1_COMPB_vect(void);
// Compare-timers for next interrupts.
extern uint16_t OCR1A, OCR1B;
// Interrupt control registers.
extern uint16_t TCCR1A, TCCR1B;
enum { CS10 = 1 , OCIE1B = 3 };
#define TCNT1 (sim_tick_counter())
void cli(void);
void sei(void);
#ifdef USE_WATCHDOG
#define wd_init()
#define wd_reset()
#endif
void sim_start(int argc, char ** argv);
void sim_info(const char fmt[], ...);
void sim_debug(const char fmt[], ...);
void sim_error(const char msg[]);
void sim_assert(bool cond, const char msg[]);
void sim_gcode_ch(char ch);
void sim_gcode(const char msg[]);
/**
* Initialize simulator timer and set time scale.
*
* @param scale time slow-down factor; 0=warp-speed, 1=real-time, 2-half-time, etc.
*/
void sim_timer_init(uint8_t scale);
void sim_timer_stop(void);
void sim_setTimer(void);
uint16_t sim_tick_counter(void);
uint64_t sim_runtime_ns(void); ///< Simulated run-time in nanoseconds
void sim_time_warp(void); ///< skip ahead to next timer interrupt, when time_scale==0
#define DIO0_PIN "proof of life"
#endif /* _SIMULATOR_H */
#endif /* SIMULATOR */