-
Notifications
You must be signed in to change notification settings - Fork 2
/
TEK-DSO-IFC-6.ino
464 lines (357 loc) · 12.7 KB
/
TEK-DSO-IFC-6.ino
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#include <avr/pgmspace.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdbool.h>
#include "GPIB.h"
#include "Tek_Interface.h"
#include "SVG.h"
#include "Arduino.h"
#include "RTC.h"
#include "EEP.h"
#include <SD.h>
#include <SPI.h>
/*This code will interface to the scope and wait for a SRQ. It assumes it is ONLY connected to one scope and
* nothing else. It does not poll "EVT?" It simply uses a loop reading the SRQ signal and when it is asserted (LOW)
* it will read the event and take appropriate action.
*
* There are 5 buttons that are able to be used: event code 450-454 inclusive
* 1: Save displayed waveforms to SVG
* 2: unused: Maybe something like FFT
* 3: unused: Maybe to save the front panel setup
* 4: unused: Maybe something like recall the front panel setup
* 5: unused: Use it for a hard reboot of the arduino
*
* This will not use the switches on the modified SONY-TEKTRONIX unit: the box is passive
* This allows essentially ANY ARDUINO to be used for the GPIB interface as long as it can also use an SD card somehow.
* I think that NANO types don't have enough IO pins for full GPIB interface plus SD
*/
/* Assumes the scope is at address #1! */
// TODO: have errors printed to the scope screen instead of to the serial port
//extern char data_buffer[]; //defined in Tek_Interface module
extern RTC_PCF8523 rtc;
void setup() {
bool wait_for_scope_boot = false;
Serial.begin(115200);
Serial.print(F("checking bus"));
while (!GPIBCheck()) { //check the GPIB Bus
//TODO: send message to 7-segments "SCOP" to indicate no scope present. OR scroll "NO SCOPE" on the display
delay(1000);
Serial.print(F("."));
wait_for_scope_boot = true;
}
Serial.println(F(" Bus OK"));
//if the bus was not on-line when first tested, then the scope is booting up
// and we need to it for the scope to complete its own initialization
if (wait_for_scope_boot)
{
Serial.println(F("Scope Boot Delay...30 sec"));
for (int i=0; i<30;i++) //perform N loops of a 1 second delay
{
delay(1000); //delay 1 second
}
}
EEP_Init();
RTC_setup();
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.println(now.day(), DEC);
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
tek_Setup();
checkID(); //TODO: use this check to stop further processing?
introScreen();
tek_Menu(1);
//testDataPins();
//testSPI();
}
//******************************************************************************
void loop() {
uint16_t event;
event = 0;
#ifdef USE_SRQ
// Serial.println(F("wait for SRQ"));
while (WaitForSRQ(0, 0xFFFE)); //returns a 1 if timeout occurs. Keep polling SRQ until it is asserted (LOW): returns before timeout with a value of zero.
// if (SRQ_PIN & SRQ_BIT) Serial.print(F("SRQ NOT ASSERTED (high)"));
// else Serial.print(F("SRQ IS ASSERTED (low)"));
event = GetEvent_SRQ();
if (event)
{
Serial.print(F("Event occurred:"));
Serial.println(event);
processEvent(event);
}
//no delays: process SRQs as fastr as possible
#else //use polling method
event = GetEvent();
if (event)
{
Serial.print(F("Event occurred:"));
Serial.println(event);
processEvent(event);
}
else delay(1000); //if there is an event read, then don't delay reading the next one in case they are stacked up
#endif
} //end of loop
//*********************************************************
//*
//* Handle an incoming event
//* Most will just get ignored!
//*
//*********************************************************
void processEvent(uint16_t evnt)
{
// main menu [0] = save svg/hide/x/settings/reset cpu
// settings menu [1] = date/time/x/x/back
static uint8_t MenuState = 0;
switch (MenuState)
{
case 0: //main menu
switch (evnt)
{
case 652: //hide display button pressed
tek_Menu(MenuState, 1); //show the menu and force it to be displayed
break;
case 450: //Left hand-most button pressed: save SVG
processSVG();
break;
case 451: //hide or unhide the menubar
tek_Menu(MenuState); //toggle the displayed state of the menu
break;
case 452:
break;
case 453:
MenuState = 1;
tek_Menu(MenuState,1); //show the new menu and force it to be displayed
break;
case 454: //maybe use this to hard reset the arduino
//hideMenu();
resetCPU();
break;
} //end switch evnt
break;
case 1: //settings menu
switch (evnt)
{
case 652: //hide display button pressed
tek_Menu(MenuState, 1); //show the menu and force it to be displayed
break;
case 450: //set date
//call date setting function
RTC_Date();
tek_Menu(MenuState, 1); //show the menu and force it to be displayed
break;
case 451: //set time
RTC_Time();
tek_Menu(MenuState, 1); //show the menu and force it to be displayed
break;
case 452: //set file name
tek_SetFileName();
tek_Menu(MenuState, 1); //show the menu and force it to be display
break;
case 453:
break;
case 454: //move up one menu state
MenuState--;
if (MenuState == 0xFF) MenuState = 0; //prevent undershooting menustate accidentally: shouldn't ever be possible
tek_Menu(MenuState,1); //show the new menu and force it to be displayed
break;
} //end switch evnt
break;
} //end switch MenuState
}
void resetCPU(void)
{
//This does a software-only reset without resetting ALL the hardware
//void(* resetFunc) (void) = 0;//declare reset function at address 0
//resetFunc(); //call reset
//This does a hardware reset like a power-up reset: All registers ad pins are cleared
noInterrupts();
__asm("wdr");
WDTCSR = (1<<WDCE) | (1<<WDE);
WDTCSR = (1<<WDE);
while (1);
}
void testDataPins(void)
{
Serial.println(F("testing pins: data0, gpib PIN 1"));
//test the data pins
while (Serial.available()) Serial.read(); //flush the serial channel
while (!Serial.available()) {
GPIBRelease( &DATA0_PORT,&DATA0_DDR, DATA0_BIT);
delay(10);
GPIBAssert( &DATA0_PORT,&DATA0_DDR, DATA0_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data1, GPIB PIN 2"));
while (!Serial.available()) {
GPIBRelease( &DATA1_PORT,&DATA1_DDR, DATA1_BIT);
delay(10);
GPIBAssert( &DATA1_PORT,&DATA1_DDR, DATA1_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data2, GPIB PIN 3"));
while (!Serial.available()) {
GPIBRelease( &DATA2_PORT,&DATA2_DDR, DATA2_BIT);
delay(10);
GPIBAssert( &DATA2_PORT,&DATA2_DDR, DATA2_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data3, GPIB PIN 4"));
while (!Serial.available()) {
GPIBRelease( &DATA3_PORT,&DATA3_DDR, DATA3_BIT);
delay(10);
GPIBAssert( &DATA3_PORT,&DATA3_DDR, DATA3_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data4, GPIB PIN 13"));
while (!Serial.available()) {
GPIBRelease( &DATA4_PORT,&DATA4_DDR, DATA4_BIT);
delay(10);
GPIBAssert( &DATA4_PORT,&DATA4_DDR, DATA4_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data5, GPIB PIN 14"));
while (!Serial.available()) {
GPIBRelease( &DATA5_PORT,&DATA5_DDR, DATA5_BIT);
delay(10);
GPIBAssert( &DATA5_PORT,&DATA5_DDR, DATA5_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data6, GPIB PIN 15"));
while (!Serial.available()) {
GPIBRelease( &DATA6_PORT,&DATA6_DDR, DATA6_BIT);
delay(10);
GPIBAssert( &DATA6_PORT,&DATA6_DDR, DATA6_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: data7, GPIB PIN 16"));
while (!Serial.available()) {
GPIBRelease( &DATA7_PORT,&DATA7_DDR, DATA7_BIT);
delay(10);
GPIBAssert( &DATA7_PORT,&DATA7_DDR, DATA7_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: EOI, GPIB PIN 5"));
while (!Serial.available()) {
GPIBRelease( &EOI_PORT,&EOI_DDR, EOI_BIT);
delay(10);
GPIBAssert( &EOI_PORT,&EOI_DDR, EOI_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: DAV, GPIB PIN 6"));
while (!Serial.available()) {
GPIBRelease( &DAV_PORT,&DAV_DDR, DAV_BIT);
delay(10);
GPIBAssert( &DAV_PORT,&DAV_DDR, DAV_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: NRFD, GPIB PIN 7"));
while (!Serial.available()) {
GPIBRelease( &NRFD_PORT,&NRFD_DDR, NRFD_BIT);
delay(10);
GPIBAssert( &NRFD_PORT,&NRFD_DDR, NRFD_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: NDAC, GPIB PIN 8"));
while (!Serial.available()) {
GPIBRelease( &NDAC_PORT,&NDAC_DDR, NDAC_BIT);
delay(10);
GPIBAssert( &NDAC_PORT,&NDAC_DDR, NDAC_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: IFC, GPIB PIN 9"));
while (!Serial.available()) {
GPIBRelease( &IFC_PORT,&IFC_DDR, IFC_BIT);
delay(10);
GPIBAssert( &IFC_PORT,&IFC_DDR, IFC_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: SRQ, GPIB PIN 10"));
while (!Serial.available()) {
GPIBRelease( &SRQ_PORT,&SRQ_DDR, SRQ_BIT);
delay(10);
GPIBAssert( &SRQ_PORT,&SRQ_DDR, SRQ_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: ATN, GPIB PIN 11"));
while (!Serial.available()) {
GPIBRelease( &ATN_PORT,&ATN_DDR, ATN_BIT);
delay(10);
GPIBAssert( &ATN_PORT,&ATN_DDR, ATN_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("testing pins: REN, GPIB PIN 17"));
while (!Serial.available()) {
GPIBRelease( &REN_PORT,&REN_DDR, REN_BIT);
delay(10);
GPIBAssert( &REN_PORT,&REN_DDR, REN_BIT);
delay(10);
}
while (Serial.available()) Serial.read(); //flush the serial channel
}
void testSPI(void)
{
Serial.println(F("Testing SPI MOSI"));
pinMode(PIN_SPI_MOSI,OUTPUT);
while (!Serial.available()) {
digitalWrite(PIN_SPI_MOSI, 1);
delay(10);
digitalWrite(PIN_SPI_MOSI, 0);
delay(10);
}
pinMode(PIN_SPI_MOSI,INPUT);
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("Testing SPI MISO"));
pinMode(PIN_SPI_MISO,OUTPUT);
while (!Serial.available()) {
digitalWrite(PIN_SPI_MISO, 1);
delay(10);
digitalWrite(PIN_SPI_MISO, 0);
delay(10);
}
pinMode(PIN_SPI_MISO,INPUT);
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("Testing SPI SCK"));
pinMode(PIN_SPI_SCK,OUTPUT);
while (!Serial.available()) {
digitalWrite(PIN_SPI_SCK, 1);
delay(10);
digitalWrite(PIN_SPI_SCK, 0);
delay(10);
}
pinMode(PIN_SPI_SCK,INPUT);
while (Serial.available()) Serial.read(); //flush the serial channel
Serial.println(F("Testing SPI /CS"));
pinMode(CS_PIN,OUTPUT);
while (!Serial.available()) {
digitalWrite(CS_PIN, 1);
delay(10);
digitalWrite(CS_PIN, 0);
delay(10);
}
pinMode(CS_PIN,INPUT);
while (Serial.available()) Serial.read(); //flush the serial channel
}