forked from orbcode/orbuculum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbtrace.c
790 lines (653 loc) · 26.5 KB
/
orbtrace.c
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Orbtrace Interface
* ==================
*
*/
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <getopt.h>
#include "git_version_info.h"
#include "generics.h"
#include "orbtraceIf.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
/* Record for options, either defaults or from command line */
struct Options
{
/* Probe config */
char *sn; /* Any part of serial number to differentiate probe */
char *nick; /* Nickname for device */
int brightness; /* Brightness of OP LEDs */
/* Trace settings */
int traceWidth; /* Width to be used for communication */
bool swoMANCH; /* SWO Manchester output */
bool swoUART; /* SWO UART output */
bool opJSON; /* Set output to JSON */
bool mono; /* Supress colour in output */
uint32_t serial_speed; /* Speed of serial communication via SWO */
/* Power settings */
bool forceVoltage; /* Force application of voltage */
int TPwrmv; /* Target power setting in mv */
int TRefmv; /* Target voltage setting in mv */
bool TPwrEN; /* If to enable/disable TPwr */
bool TRefEN; /* If to enable/disable TRef */
} _options;
enum Actions { ACTION_BRIGHTNESS, ACTION_ENCHANGE_VTREF, ACTION_ENCHANGE_VTPWR, ACTION_LIST_DEVICES,
ACTION_LOCKDEVICE, ACTION_SETNICK, ACTION_VCHANGE_VTREF, ACTION_VCHANGE_VTPWR, ACTION_SN,
ACTION_UNLOCK, ACTION_WRITE_PARAMS, ACTION_READ_PARAMS, ACTION_RESET_PARAMS, ACTION_SET_TRACE,
ACTION_SERIAL_SPEED,
ACTION_ENCHANGE_ALL
};
struct RunTime
{
struct OrbtraceIf *dev; /* Link to the connected Orbtrace device */
bool ending; /* Flag indicating app is terminating */
int ndevices; /* Number of devices found connected that match search spec */
uint64_t actions; /* Actions to be performed */
struct Options *options; /* Runtime command line options */
} _r =
{
.options = &_options
};
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// Private routines
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
static void _set_action( struct RunTime *r, int x )
/* Set up an action flag */
{
r->actions |= ( 1 << x );
}
// ====================================================================================================
static void _clr_action( struct RunTime *r, int x )
/* Clear an action flag */
{
r->actions &= ~( 1 << x );
}
// ====================================================================================================
static bool _tst_action( struct RunTime *r, int x )
/* Query an action flag */
{
return ( 0 != ( r->actions & ( 1 << x ) ) );
}
// ====================================================================================================
static bool _tcl_action( struct RunTime *r, int x )
/* Query and then clear an action flag */
{
if ( !_tst_action( r, x ) )
{
return false;
}
else
{
_clr_action( r, x );
return true;
}
}
// ====================================================================================================
static int _num_actions( struct RunTime *r )
/* Return how many actions flags are set */
{
return ( __builtin_popcount( r->actions ) );
}
// ====================================================================================================
static void _intHandler( int sig )
/* Signal handler for CTRL-C */
{
/* CTRL-C exit is not an error... */
exit( 0 );
}
// ====================================================================================================
static void _printHelp( const char *const progName )
{
genericsPrintf( "Usage: %s [options]" EOL, progName );
genericsPrintf( " -a, --serial-speed: <serialSpeed> to use (when SWO UART is selected)" EOL );
genericsPrintf( " -e, --power: <Ch>,<On> Enable or Disable power. Ch is vtref, vtpwr or all" EOL );
genericsPrintf( " -h, --help:: This help" EOL );
genericsPrintf( " -l, --list: Show all OrbTrace devices attached to system" EOL );
genericsPrintf( " -M, --no-colour: Supress colour in output" EOL );
genericsPrintf( " -T, --trace-format: <x> Trace format; 1,2 or 4 bit parallel, m for Manchester SWO, u=UART SWO" EOL );
genericsPrintf( " -n, --serial-number: <Serial> any part of serial number to differentiate specific OrbTrace device" EOL );
genericsPrintf( " -p, --voltage: <Ch>,<Voltage> Set voltage in V, Ch is vtref or vtpwr" EOL );
genericsPrintf( " -v, --verbose: <level> Verbose mode 0(errors)..3(debug)" EOL );
genericsPrintf( " -V, --version: Print version and exit" EOL );
// genericsPrintf( " *-b: <Brightness> Set default brightness of output leds" EOL );
// genericsPrintf( " *-F: Force voltage setting" EOL );
// genericsPrintf( " *-j: Format output in JSON" EOL );
// genericsPrintf( " *-L: Lock device (prevent further changes)" EOL );
// genericsPrintf( " *-N: <Nick> Specify nickname for adaptor (8 chars max)" EOL );
// genericsPrintf( " *-q: Query all data from connected device" EOL );
// genericsPrintf( " *-Q: Query specified data from connected device (pPrR VPwr/IPwr/VRef/IRef)" EOL );
// genericsPrintf( " *-U: Unlock device (allow changes, default state)" EOL );
// genericsPrintf( " *-w: Write parameters specified on command line to NVRAM" EOL );
// genericsPrintf( " *-W: Reset all NVRAM parameters to default values" EOL );
}
// ====================================================================================================
void _printVersion( void )
{
genericsPrintf( "Orbtrace version " GIT_DESCRIBE );
}
// ====================================================================================================
static struct option _longOptions[] =
{
{"serial-speed", required_argument, NULL, 'a'},
{"power", required_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"list", no_argument, NULL, 'l'},
{"monitor", required_argument, NULL, 'm'},
{"no-colour", no_argument, NULL, 'M'},
{"no-color", no_argument, NULL, 'M'},
{"trace-format", required_argument, NULL, 'T'},
{"serial-number", required_argument, NULL, 'n'},
{"voltage", required_argument, NULL, 'p'},
{"verbose", required_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
{NULL, no_argument, NULL, 0}
};
// ====================================================================================================
static bool _checkVoltages( struct RunTime *r )
/* Check that voltages, if requested, are sensible */
{
if ( _tst_action( r, ACTION_VCHANGE_VTREF ) && ( 0 == OrbtraceIfValidateVoltage( r->dev, r->options->TRefmv ) ) )
{
genericsReport( V_ERROR, "Illegal voltage specified for TRef (%d.%03dV)" EOL, r->options->TRefmv / 1000, r->options->TRefmv % 1000 );
return false;
}
if ( _tst_action( r, ACTION_VCHANGE_VTPWR ) && ( 0 == OrbtraceIfValidateVoltage( r->dev, r->options->TPwrmv ) ) )
{
genericsReport( V_ERROR, "Illegal voltage specified for TPwr (%d.%03dV)" EOL, r->options->TPwrmv / 1000, r->options->TPwrmv % 1000 );
return false;
}
return true;
}
// ====================================================================================================
static int _processOptions( struct RunTime *r, int argc, char *argv[] )
/* Process command line options into options and actions records */
{
int c;
int optionIndex = 0;
float voltage;
int channel;
bool action;
char *a;
while ( ( c = getopt_long ( argc, argv, "a:e:hlp:Mn:T:v:V", _longOptions, &optionIndex ) ) != -1 )
switch ( c )
{
// ------------------------------------
case 'a': /* Serial Speed */
r->options->serial_speed = atoi( optarg );
_set_action( r, ACTION_SERIAL_SPEED );
break;
// ------------------------------------
case 'b': /* Brightness */
r->options->brightness = atoi( optarg );
_set_action( r, ACTION_BRIGHTNESS );
break;
// ------------------------------------
case 'e':
channel = OrbtraceIfNameToChannel( optarg );
a = optarg;
while ( ( *a ) && ( *a != ',' ) )
{
a++;
}
if ( ( *a == ',' ) || ( channel != CH_NONE ) )
{
a++;
action = ( ( *a == '1' ) || ( !strcasecmp( "on", a ) ) );
if ( action || ( *a == '0' ) || ( !strcasecmp( "off", a ) ) )
{
if ( channel == CH_VTREF )
{
r->options->TRefEN = action;
_set_action( r, ACTION_ENCHANGE_VTREF );
break;
}
if ( channel == CH_VTPWR )
{
r->options->TPwrEN = action;
_set_action( r, ACTION_ENCHANGE_VTPWR );
break;
}
if ( channel == CH_ALL )
{
r->options->TPwrEN = r->options->TRefEN = action;
_set_action( r, ACTION_ENCHANGE_ALL );
break;
}
}
}
genericsReport( V_ERROR, "Badly formatted enable" EOL );
return false;
// ------------------------------------
case 'F': /* Force voltage */
r->options->forceVoltage = true;
break;
// ------------------------------------
case 'h':
_printHelp( argv[0] );
return false;
// ------------------------------------
case 'j': /* Force output in JSON */
r->options->opJSON = true;
break;
// ------------------------------------
case 'l': /* List connected devices */
_set_action( r, ACTION_LIST_DEVICES );
break;
// ------------------------------------
case 'L': /* Lock device */
_set_action( r, ACTION_LOCKDEVICE );
break;
// ------------------------------------
case 'M':
r->options->mono = true;
break;
// ------------------------------------
case 'N': /* Set nickname */
r->options->nick = optarg;
_set_action( r, ACTION_SETNICK );
break;
// ------------------------------------
case 'T': /* Set tracewidth */
r->options->traceWidth = 0;
if ( ( *optarg == 'u' ) && ( !*( optarg + 1 ) ) )
{
r->options->swoUART = true;
}
else if ( ( *optarg == 'm' ) && ( !*( optarg + 1 ) ) )
{
r->options->swoMANCH = true;
}
else
{
r->options->traceWidth = atoi( optarg );
}
_set_action( r, ACTION_SET_TRACE );
break;
// ------------------------------------
case 'p': /* Set power */
channel = OrbtraceIfNameToChannel( optarg );
a = optarg;
while ( ( *a ) && ( *a != ',' ) )
{
a++;
}
if ( ( *a == ',' ) && ( channel != CH_NONE ) )
{
a++;
voltage = atof( a );
if ( channel == CH_VTREF )
{
r->options->TRefmv = ( int )( ( voltage + 0.0005F ) * 1000 );
_set_action( r, ACTION_VCHANGE_VTREF );
break;
}
if ( channel == CH_VTPWR )
{
r->options->TPwrmv = ( int )( ( voltage + 0.0005F ) * 1000 );
_set_action( r, ACTION_VCHANGE_VTPWR );
break;
}
}
genericsReport( V_ERROR, "Badly formatted power statement" EOL );
return false;
// ------------------------------------
case 'n': /* Set serial number */
r->options->sn = optarg;
_set_action( r, ACTION_SN );
break;
// ------------------------------------
case 'U': /* Unlock device */
_set_action( r, ACTION_UNLOCK );
break;
// ------------------------------------
case 'v':
if ( !isdigit( *optarg ) )
{
genericsReport( V_ERROR, "-v requires a numeric argument." EOL );
return false;
}
genericsSetReportLevel( atoi( optarg ) );
break;
// ------------------------------------
case 'V':
_printVersion();
return false;
// ------------------------------------
case 'w': /* Write parameters to NVRAM */
_set_action( r, ACTION_WRITE_PARAMS );
break;
// ------------------------------------
case 'W': /* Reset parameters in NVRAM */
_set_action( r, ACTION_RESET_PARAMS );
break;
// ------------------------------------
case '?':
if ( optopt == 'b' )
{
genericsReport( V_ERROR, "Option '%c' requires an argument." EOL, optopt );
}
else if ( !isprint ( optopt ) )
{
genericsReport( V_ERROR, "Unknown option character `\\x%x'." EOL, optopt );
}
return false;
// ------------------------------------
default:
genericsReport( V_ERROR, "Unrecognised option '%c'" EOL, c );
return false;
// ------------------------------------
}
/* Test parameters for sanity */
if ( _tst_action( r, ACTION_RESET_PARAMS ) && ( _num_actions( r ) > 1 ) )
{
genericsReport( V_ERROR, "Resetting parameters is an exclusive operation" EOL );
return false;
}
if ( ( ( r->options->serial_speed ) && ( !r->options->swoUART ) ) &&
( ( !r->options->serial_speed ) && ( r->options->swoUART ) ) )
{
genericsReport( V_ERROR, "For SWO/UART both baudrate and mode need to be set" EOL );
return false;
}
if ( ( _tst_action( r, ACTION_SET_TRACE ) ) &&
( ( ( r->options->traceWidth ) && ( ( r->options->swoUART ) || ( r->options->swoMANCH ) ) ) ||
( ( r->options->swoUART ) && ( r->options->swoMANCH ) ) ) )
{
genericsReport( V_ERROR, "Only one trace configuration can be set at the same time" EOL );
return false;
}
if ( _tst_action( r, ACTION_LIST_DEVICES ) && ( _num_actions( r ) > 1 ) )
{
genericsReport( V_ERROR, "Listing devices is an exclusive operation" EOL );
return false;
}
if ( ( r->options->traceWidth != 0 ) &&
( r->options->traceWidth != 1 ) &&
( r->options->traceWidth != 2 ) &&
( r->options->traceWidth != 4 ) )
{
genericsReport( V_ERROR, "Orbtrace interface illegal port width" EOL );
return false;
}
if ( _tst_action( r, ACTION_BRIGHTNESS ) && ( ( r->options->brightness < 0 ) || ( r->options->brightness > 255 ) ) )
{
genericsReport( V_ERROR, "Brightness setting out of range" EOL );
return false;
}
/* ... and dump the config if we're being verbose */
genericsReport( V_INFO, "orbtrace version " GIT_DESCRIBE EOL );
return true;
}
// ====================================================================================================
static void _doExit( void )
{
_r.ending = true;
}
// ====================================================================================================
static int _selectDevice( struct RunTime *r, bool listOnly )
{
int descWidth = 0;
int selection = 0;
if ( ( !listOnly ) && ( r->ndevices == 1 ) )
{
return r->ndevices - 1;
}
for ( int i = 0; i < r->ndevices; i++ )
{
int l = MAX( 11, strlen( OrbtraceIfGetManufacturer( r->dev, i ) ) + strlen( OrbtraceIfGetProduct( r->dev, i ) ) ) + MAX( 6, strlen( OrbtraceIfGetSN( r->dev, i ) ) );
if ( l > descWidth )
{
descWidth = l;
}
}
descWidth += 1;
fprintf( stdout, "Id | " );
for ( int i = 0; i < ( ( descWidth + 1 ) / 2 - 6 ); i++ )
{
fprintf( stdout, " " );
}
fprintf( stdout, "Description" );
for ( int i = 0; i < ( descWidth / 2 - 6 ); i++ )
{
fprintf( stdout, " " );
}
fprintf( stdout, " | Serial" EOL );
for ( int i = 0; i < ( descWidth + 5 + 10 ); i++ )
{
fprintf( stdout, "-" );
}
fprintf( stdout, EOL );
for ( int i = 0; i < r->ndevices; i++ )
{
int thisWidth = strlen( OrbtraceIfGetManufacturer( r->dev, i ) ) + strlen( OrbtraceIfGetProduct( r->dev, i ) ) + 1;
printf( "%2i | %s %s", i + 1, OrbtraceIfGetManufacturer( r->dev, i ), OrbtraceIfGetProduct( r->dev, i ) );
for ( int j = thisWidth; j < descWidth; j++ )
{
fprintf( stdout, " " );
}
fprintf( stdout, "| %s" EOL, OrbtraceIfGetSN( r->dev, i ) );
}
if ( !listOnly )
while ( ( selection < 1 ) || ( selection > r->ndevices ) )
{
fprintf( stdout, EOL "Selection>" );
scanf( "%d", &selection );
}
return selection - 1;
}
// ====================================================================================================
static int _performActions( struct RunTime *r )
/* Whatever we were asked to do, do it */
{
int retVal = 0;
/* Beware, there is a logic to the order of actions...think before you change them or insert new ones */
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_UNLOCK ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_RESET_PARAMS ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_VCHANGE_VTREF ) )
{
genericsReport( V_INFO, "Setting VTRef %d.%03dV : ", r->options->TRefmv / 1000, r->options->TRefmv % 1000 );
if ( OrbtraceIfVoltage( r->dev, CH_VTREF, r->options->TRefmv ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Setting VTRef failed" EOL );
retVal |= -1;
}
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_VCHANGE_VTPWR ) )
{
genericsReport( V_INFO, "Setting VTPwr %d.%03dV : ", r->options->TPwrmv / 1000, r->options->TPwrmv % 1000 );
if ( OrbtraceIfVoltage( r->dev, CH_VTPWR, r->options->TPwrmv ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Setting VTPwr failed" EOL );
retVal |= -1;
}
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_ENCHANGE_VTREF ) )
{
genericsReport( V_INFO, "VTRef %s : ", r->options->TRefEN ? "On" : "Off" );
if ( OrbtraceIfSetVoltageEn( r->dev, CH_VTREF, r->options->TRefEN ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Changing VTRef state failed" EOL );
retVal |= -1;
}
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_ENCHANGE_ALL ) )
{
genericsReport( V_INFO, "All Channels %s : ", r->options->TRefEN ? "On" : "Off" );
if ( OrbtraceIfSetVoltageEn( r->dev, CH_ALL, r->options->TRefEN ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Changing all power channel states failed" EOL );
retVal |= -1;
}
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_ENCHANGE_VTPWR ) )
{
genericsReport( V_INFO, "VTPwr %s : ", r->options->TPwrEN ? "On" : "Off" );
if ( OrbtraceIfSetVoltageEn( r->dev, CH_VTPWR, r->options->TPwrEN ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Changing VTPwr state failed" EOL );
retVal |= -1;
}
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_BRIGHTNESS ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_SN ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_READ_PARAMS ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_SETNICK ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_SERIAL_SPEED ) )
{
genericsReport( V_INFO, "Setting baudrate to %d bps" EOL, r->options->serial_speed );
if ( OrbtraceIfSetSWOBaudrate( r->dev, r->options->serial_speed ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Setting serial speed failed" EOL );
retVal |= -1;
}
}
// -----------------------------------------------------------------------------------
if ( _tcl_action( r, ACTION_SET_TRACE ) )
{
if ( r->options->traceWidth )
{
genericsReport( V_INFO, "Setting port width to %d" EOL, r->options->traceWidth );
if ( OrbtraceIfSetTraceWidth( r->dev, r->options->traceWidth ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Setting port width failed" EOL );
retVal |= -1;
}
}
else if ( ( r->options->swoMANCH ) || ( r->options->swoUART ) )
{
genericsReport( V_INFO, "Setting SWO with %s encoding" EOL, r->options->swoMANCH ? "Manchester" : "UART" );
if ( OrbtraceIfSetTraceSWO( r->dev, r->options->swoMANCH ) )
{
genericsReport( V_INFO, "OK" EOL );
}
else
{
genericsReport( V_ERROR, "Setting SWO encoding failed" EOL );
retVal |= -1;
}
}
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_WRITE_PARAMS ) )
{
}
// -----------------------------------------------------------------------------------
if ( _tst_action( r, ACTION_LOCKDEVICE ) )
{
}
return retVal;
}
// ====================================================================================================
int main( int argc, char *argv[] )
{
int selection = 0;
int retVal = 0;
if ( !_processOptions( &_r, argc, argv ) )
{
/* processOptions generates its own error messages */
genericsExit( -1, "" EOL );
}
genericsScreenHandling( !_r.options->mono );
/* Make sure everything gets removed at the end */
atexit( _doExit );
/* This ensures the atexit gets called */
if ( SIG_ERR == signal( SIGINT, _intHandler ) )
{
genericsExit( -1, "Failed to establish Int handler" EOL );
}
_r.dev = OrbtraceIfCreateContext();
assert( _r.dev );
_r.ndevices = OrbtraceIfGetDeviceList( _r.dev, _r.options->sn );
if ( !_r.ndevices )
{
genericsReport( V_ERROR, "No devices found" EOL );
}
else
{
/* Allow option to choose between devices if there's more than one found */
int seldevice = _selectDevice( &_r, _tcl_action ( &_r, ACTION_LIST_DEVICES ) );
if ( _num_actions( &_r ) )
{
genericsReport( V_INFO, "Got device [%s %s, S/N %s]" EOL,
OrbtraceIfGetManufacturer( _r.dev, selection ),
OrbtraceIfGetProduct( _r.dev, selection ),
OrbtraceIfGetSN( _r.dev, selection ) );
if ( !OrbtraceIfOpenDevice( _r.dev, seldevice ) )
{
genericsExit( -1, "Couldn't open device" EOL );
}
/* Check voltages now we know what interface we're connected to */
if ( !_checkVoltages( &_r ) )
{
genericsExit( -2, "Specified interface voltage check failed" EOL );
}
retVal = _performActions( &_r );
}
OrbtraceIfCloseDevice( _r.dev );
}
return retVal;
}
// ====================================================================================================