1
|
/**
|
2
|
* \file main.cpp
|
3
|
*
|
4
|
* \brief DSP side main routine for DSP Hello World application.
|
5
|
* The DSP simply sets itself up, and then waits for a
|
6
|
* message from the ARM, to which it replies.
|
7
|
*
|
8
|
* o 0
|
9
|
* | / Copyright (c) 2005-2010
|
10
|
* (CL)---o Critical Link, LLC
|
11
|
* \
|
12
|
* O
|
13
|
*/
|
14
|
|
15
|
#include <std.h>
|
16
|
#include <tsk.h>
|
17
|
#include <stdio.h>
|
18
|
#include <string.h>
|
19
|
#include <sem.h>
|
20
|
|
21
|
#include "core/cl_ipc_inbound.h"
|
22
|
#include "core/cl_ipc_outbound.h"
|
23
|
|
24
|
enum MsgCommand {
|
25
|
eReadFromARM,
|
26
|
eWriteToARM,
|
27
|
eReadFromDSP,
|
28
|
eWriteToDSP
|
29
|
};
|
30
|
|
31
|
enum MsgTypes {
|
32
|
eGlobalFixture,
|
33
|
eLibrary,
|
34
|
eGlobalUser,
|
35
|
eGlobalSerialPort,
|
36
|
eGlobalScannerJog,
|
37
|
eFeature,
|
38
|
eFeatureData,
|
39
|
eFeatureDataSource,
|
40
|
eFeatureExpressions,
|
41
|
eFeatureFixture,
|
42
|
eFeatureMeasurement,
|
43
|
eFeatureSegmentList,
|
44
|
eGlobalDigitalInputs,
|
45
|
eGlobalDigitalOutputs,
|
46
|
eGlobalFactory,
|
47
|
eDebugText
|
48
|
};
|
49
|
|
50
|
typedef struct {
|
51
|
MsgTypes type;
|
52
|
MsgCommand command;
|
53
|
} Header;
|
54
|
|
55
|
typedef struct {
|
56
|
Header header;
|
57
|
char textMessage[100]; // 100 bytes for now
|
58
|
} DebugText;
|
59
|
|
60
|
typedef struct {
|
61
|
Header header;
|
62
|
char fixtureName[33];
|
63
|
int fixtureID;
|
64
|
int fixtureTencoderpe;
|
65
|
int fixtureURR;
|
66
|
int fixtureHomeMethod;
|
67
|
int fixtureZeroMethod;
|
68
|
int fixtureMotion;
|
69
|
int fixtureDirection;
|
70
|
int fixtureOrientation;
|
71
|
double fixtureLinearTravel;
|
72
|
double fixtureRotaryTravel;
|
73
|
int motorPresent;
|
74
|
int motorPort;
|
75
|
int motorRotation;
|
76
|
double motorGearRatioIn;
|
77
|
double motorGearRationOut;
|
78
|
int motorType;
|
79
|
int motorMaxSpeed;
|
80
|
int motorStepsPerRevolution;
|
81
|
char motorAcceleration[16]; // todo
|
82
|
int encoderPresent;
|
83
|
int encoderPort;
|
84
|
int encoderRotation;
|
85
|
double encoderGearRatioIn;
|
86
|
double encoderGearRationOut;
|
87
|
int encoderResolution;
|
88
|
int encoderIndexPresent;
|
89
|
int encoderIndexInput;
|
90
|
int encoderIndexIsHome;
|
91
|
int encoderIndexIsEndOfTravel;
|
92
|
int encoderQuadratureMode;
|
93
|
int homeSensorPresent;
|
94
|
int homeSensorInput;
|
95
|
int homeSensorType;
|
96
|
int homeSensorDirection;
|
97
|
int endOfTravelSensorPresent;
|
98
|
int endOfTravelSensorInput;
|
99
|
int endOfTravelSensorType;
|
100
|
int endOfTravelSensorDirection;
|
101
|
char inputMapping[5]; // todo
|
102
|
char outputMapping[8]; // todo
|
103
|
double pulleyDiam;
|
104
|
int pulleyUnits;
|
105
|
} GlobalFixture_str ;
|
106
|
|
107
|
typedef struct {
|
108
|
Header header;
|
109
|
int SerialNumber;
|
110
|
double AnalogCalMinValue;
|
111
|
double AnalogCalMaxValue;
|
112
|
double AnalogCalGain;
|
113
|
double AnalogOffset;
|
114
|
int LowPowerScannerType;
|
115
|
int LowPowerValue;
|
116
|
int CalibrationUnits;
|
117
|
double CalibrationSmallPart;
|
118
|
double CalibrationLargePart;
|
119
|
double CalibrationmValue;
|
120
|
double CalibrationbValue;
|
121
|
char CalibrationDate[20];
|
122
|
} GlobalFactory_str ;
|
123
|
|
124
|
typedef struct {
|
125
|
Header header;
|
126
|
int DigInputID;
|
127
|
int ActivationType;
|
128
|
int FunctionID;
|
129
|
} GlobalDigitalInputs_str ;
|
130
|
|
131
|
typedef struct {
|
132
|
Header header;
|
133
|
int DigOutputID;
|
134
|
int Polarity;
|
135
|
int Latched;
|
136
|
int ServerID;
|
137
|
} GlobalDigitalOutputs_str ;
|
138
|
|
139
|
typedef struct {
|
140
|
Header header;
|
141
|
int SerialPortID;
|
142
|
int BaudRate;
|
143
|
int ParityBits;
|
144
|
int DataBits;
|
145
|
int StopBits;
|
146
|
int FlowControl;
|
147
|
int ProtocolFlag;
|
148
|
int DataFlag;
|
149
|
} GlobalSerialPort_str ;
|
150
|
|
151
|
typedef struct {
|
152
|
Header header;
|
153
|
int FeatureID;
|
154
|
int LibraryToFeatureKey;
|
155
|
char Name[16];
|
156
|
int AdvanceMode;
|
157
|
int AdvanceDelay;
|
158
|
double SizeOffset;
|
159
|
double PositionOffset;
|
160
|
int URRUnits;
|
161
|
int URRResolution;
|
162
|
int URRRounding;
|
163
|
int DataSourceExpressionType;
|
164
|
int DataSource_op;
|
165
|
int Sequence;
|
166
|
double ToleranceRejectPlus;
|
167
|
double ToleranceRejectMinus;
|
168
|
double ToleranceWarningPlus;
|
169
|
double ToleranceWarningMinus;
|
170
|
double ToleranceNominal;
|
171
|
bool ToleranceRejectEnablePlus;
|
172
|
bool ToleranceRejectEnableMinus;
|
173
|
bool ToleranceWarningEnablePlus;
|
174
|
bool ToleranceWarningEnableMinus;
|
175
|
int UseFixtureToCollectData;
|
176
|
int UseFixtureForAutoPositioning;
|
177
|
double UserSingleMasterSize;
|
178
|
} Feature_str ;
|
179
|
|
180
|
typedef struct {
|
181
|
Header header;
|
182
|
int FeatureToDataKey;
|
183
|
int LibraryToDataKey;
|
184
|
char Label[16];
|
185
|
int DisplayLine;
|
186
|
int SerialPortSelected;
|
187
|
int UseAsLimits;
|
188
|
} FeatureData_str ;
|
189
|
|
190
|
typedef struct {
|
191
|
Header header;
|
192
|
int FeatureToDataKey;
|
193
|
int LibraryToDataKey;
|
194
|
int TermType;
|
195
|
double TermConstanst;
|
196
|
int TermFeatureID;
|
197
|
int TermID;
|
198
|
} FeatureDataSource_str ;
|
199
|
|
200
|
typedef struct {
|
201
|
Header header;
|
202
|
int FeatureToDataKey;
|
203
|
int LibraryToDataKey;
|
204
|
int Segment ;
|
205
|
} FeatureSegmentList_str ;
|
206
|
|
207
|
typedef struct {
|
208
|
Header header;
|
209
|
int FeatureToDataKey;
|
210
|
int LibraryToDataKey;
|
211
|
int Type;
|
212
|
int EdgeCount;
|
213
|
int GlassMode;
|
214
|
int InternalRefFlag;
|
215
|
int LowerRefFlag;
|
216
|
int UpperRefFlag;
|
217
|
int PartSegmentIndex;
|
218
|
int PartModeFlag;
|
219
|
int SamplingMode;
|
220
|
int AveragingMode;
|
221
|
int AveragingPeriod;
|
222
|
int GoodScans;
|
223
|
int EnterDelayMode;
|
224
|
int EnterDelayPeriod;
|
225
|
char FormatString[34];
|
226
|
int PolledFlag;
|
227
|
} FeatureMeasurement_str ;
|
228
|
|
229
|
typedef struct {
|
230
|
Header header;
|
231
|
int FeatureToDataKey;
|
232
|
int LibraryToDataKey;
|
233
|
int LineOrder;
|
234
|
char ExpressionText[50];
|
235
|
} FeatureExpressions_str ;
|
236
|
|
237
|
typedef struct {
|
238
|
Header header;
|
239
|
int FeatureToDataKey;
|
240
|
int LibraryToDataKey;
|
241
|
int FixtureID;
|
242
|
int DisableMotorAfterMove;
|
243
|
int IDODWALLComputeWall;
|
244
|
int MeasurementMode;
|
245
|
int UsageMode;
|
246
|
int AutomaticShankDiamFlag;
|
247
|
double Speed;
|
248
|
int StepMode;
|
249
|
int ReturnPosition;
|
250
|
int NumberOfMeasurementPositions;
|
251
|
double TotalDistance;
|
252
|
double StartPosition;
|
253
|
double ShankDiameter;
|
254
|
} FeatureFixture_str ;
|
255
|
|
256
|
typedef struct {
|
257
|
Header header;
|
258
|
int ScannerJogID;
|
259
|
double mOffset;
|
260
|
double bOffset;
|
261
|
double LowSize;
|
262
|
double HighSize;
|
263
|
} GlobalScannerJog_str ;
|
264
|
|
265
|
typedef struct {
|
266
|
Header header;
|
267
|
char LanguageName[20];
|
268
|
char LanguagePrefix[5];
|
269
|
char Password[8];
|
270
|
int PowerUpLocked;
|
271
|
int AllowNominalChanges;
|
272
|
int AllowRemastering;
|
273
|
int AllowLibraryChanges;
|
274
|
int AdvancedScreenOperation;
|
275
|
int AutoScrollEnable;
|
276
|
int AudibleAlarm;
|
277
|
int FlipScreen180;
|
278
|
int ScannerDoubleDiff;
|
279
|
int LatchScanErrors;
|
280
|
int IgnoreScanErrors;
|
281
|
char IPAddress[20];
|
282
|
int ButtonsDefined;
|
283
|
int ButtonID_1;
|
284
|
int ButtonID_2;
|
285
|
int ButtonID_3;
|
286
|
} GlobalUser_str ;
|
287
|
|
288
|
typedef struct {
|
289
|
Header header;
|
290
|
int LibraryID;
|
291
|
char LibraryName[16];
|
292
|
double UserDualPointMasterSize1;
|
293
|
double UserDualPointMasterSize2;
|
294
|
double AlarmDuration;
|
295
|
int AlarmEnable;
|
296
|
int SQCBatchSize;
|
297
|
int SQCBatchClearAtEndOfBatch;
|
298
|
int SQCBatchPrintAtEndOfBatch;
|
299
|
int FeatureCount;
|
300
|
int SerialDOFAutoSendFlag;
|
301
|
int SerialDOFAutoSendDelay;
|
302
|
int SerialDOFDateTimeFlag;
|
303
|
int SerialDOFLabelFlag;
|
304
|
int SerialDOFHeaderType;
|
305
|
int SerialDOFRequestorType;
|
306
|
char SerialDOFRequestorString[5];
|
307
|
int SerialDOFSeparatorType;
|
308
|
char SerialDOFSeparatorString[5];
|
309
|
int SerialDOFTerminatorType;
|
310
|
char SerialDOFTerminatorString[5];
|
311
|
int SerialDOFDecimalFlag;
|
312
|
int SerialDOFSignFlag;
|
313
|
double LegacySlideCounterPerInch;
|
314
|
int ReportSelected1;
|
315
|
int ReportSelected2;
|
316
|
int ReportSelected3;
|
317
|
int ReportSelected4;
|
318
|
char ReportUserTitle[33];
|
319
|
int ReportPrinterPort;
|
320
|
int ReportDisableHeaderAndFooter;
|
321
|
int ReportDisableFormFeed;
|
322
|
int URRUnits;
|
323
|
int URRResolution;
|
324
|
int URRRounding;
|
325
|
} Library_str ;
|
326
|
|
327
|
typedef union {
|
328
|
Header header;
|
329
|
DebugText debugMsg;
|
330
|
Library_str library;
|
331
|
GlobalFixture_str globalFixture;
|
332
|
GlobalUser_str globalUser;
|
333
|
GlobalScannerJog_str globalScannerJog;
|
334
|
FeatureFixture_str featureFixture;
|
335
|
FeatureExpressions_str featureExpressions;
|
336
|
FeatureMeasurement_str featureMeasurement;
|
337
|
FeatureSegmentList_str featureSegmentList;
|
338
|
FeatureDataSource_str featureDataSource;
|
339
|
FeatureData_str featureData;
|
340
|
Feature_str feature;
|
341
|
GlobalFactory_str globalFactory;
|
342
|
GlobalDigitalInputs_str globalDigitalInputs;
|
343
|
GlobalDigitalOutputs_str globalDigitalOutputs;
|
344
|
GlobalSerialPort_str globalSerialPort;
|
345
|
} allTypes;
|
346
|
|
347
|
allTypes messageA2D; // message data between DSP and ARM
|
348
|
|
349
|
using namespace MityDSP;
|
350
|
|
351
|
// Forward declarations
|
352
|
void init();
|
353
|
void debugPrint(char *buffer);
|
354
|
int handleInboundMessage(void *apBuffer, uint32_t anLength, void *apUserArg) ;
|
355
|
int handleInboundMessageBM(void *apBuffer, uint32_t anLength, void *apUserArg) ;
|
356
|
|
357
|
// Object for sending debug messages (these are received and printed to stdout by tcDspApp)
|
358
|
tcCL_IPCOutbound* gpDebug;
|
359
|
// Object for sending GPPMSGQ1 messages that the ARM will receive
|
360
|
tcCL_IPCOutbound* gpOutbound;
|
361
|
// Object for receiving DSPMSGQ0 messages that the DSP will receive
|
362
|
tcCL_IPCInbound* gpInbound;
|
363
|
// semaphore for waiting on messages
|
364
|
SEM_Handle msgRecvd;
|
365
|
|
366
|
#include "core/DspSerial.h"
|
367
|
#include "core/DspFpgaSerial.h"
|
368
|
#define RS232_SERIAL_BASE 0x66000080
|
369
|
|
370
|
|
371
|
/* *********************
|
372
|
void trySerialPort() {
|
373
|
int bytes, rv;
|
374
|
unsigned int my_base_addr = RS232_SERIAL_BASE; // was 0xE000001C;
|
375
|
unsigned int my_vector = 6;
|
376
|
char input[32], output[32];
|
377
|
tcDspFpgaSerial *my_port;
|
378
|
|
379
|
// create a serial interface
|
380
|
my_port = new tcDspFpgaSerial((void *)my_base_addr, my_vector,
|
381
|
38400, 8, 1, tcDspFpgaSerial::gnUART_NOPARITY);
|
382
|
// start using the port
|
383
|
my_port->enable(true);
|
384
|
|
385
|
// send something...
|
386
|
sprintf(output, "Testing..1..2..3..");
|
387
|
bytes = strlen(output);
|
388
|
rv = my_port->put((void *)output, bytes);
|
389
|
if (rv != bytes)
|
390
|
{
|
391
|
printf("Failed, only sent %1d of %1d bytes\n", rv, bytes);
|
392
|
}
|
393
|
|
394
|
// receive something...
|
395
|
bytes = sizeof(input);
|
396
|
rv = my_port->get((void *)input, bytes);
|
397
|
printf("Received %1d bytes of data\n", rv);
|
398
|
|
399
|
} ****************** */
|
400
|
extern "C" {
|
401
|
typedef unsigned int u_8 ;
|
402
|
MityDSP::tcDspFpgaSerial *Com1;
|
403
|
MityDSP::tcDspSerial *Com2;
|
404
|
bool Com1_initialized=false;
|
405
|
bool Com2_initialized=false;
|
406
|
|
407
|
typedef struct serialPort_str {
|
408
|
MityDSP::tcSerial *Com;
|
409
|
bool initialized;
|
410
|
void (*rx_func)(u_8 c, u_8 stat);
|
411
|
} serialPort;
|
412
|
|
413
|
void (*rx_func1)(u_8 c, u_8 stat) = NULL;
|
414
|
void (*rx_func2)(u_8 c, u_8 stat) = NULL;
|
415
|
extern "C" int StartMonitorTask1(void);
|
416
|
extern "C" int StartMonitorTask2(void);
|
417
|
}
|
418
|
|
419
|
serialPort spCom[2];
|
420
|
|
421
|
char gBuffer[200];
|
422
|
|
423
|
#define Sec2tick(x) (1000*x)
|
424
|
#define GGE_PRIO 9
|
425
|
|
426
|
void ser1_task() {
|
427
|
int count=0;
|
428
|
int idx=0;
|
429
|
static char buf[64];
|
430
|
|
431
|
while (!Com1_initialized)
|
432
|
TSK_sleep(Sec2tick(1));
|
433
|
|
434
|
while (1) {
|
435
|
//if (count == 0) {
|
436
|
count = strlen(gBuffer); //sprintf(buf,"%s %d\n", gBuffer, idx++);
|
437
|
int j=0, k=0;
|
438
|
for (int i=0; i < count; i++){
|
439
|
if ((int)gBuffer[i] < 32) {
|
440
|
k=sprintf(&buf[j], "*%2x!", (unsigned char)gBuffer[i]);
|
441
|
j = j+k;
|
442
|
} else {
|
443
|
buf[j] = gBuffer[i];
|
444
|
j++;
|
445
|
}
|
446
|
}
|
447
|
buf[j]=0;
|
448
|
count = j;
|
449
|
//}
|
450
|
Com1->put(buf, count, 0, 0);
|
451
|
TSK_sleep(1250);
|
452
|
/*count = Com1->get(buf, 60, 1000);
|
453
|
if (count && Com1_initialized && (rx_func1 != NULL)) {
|
454
|
idx = 0;
|
455
|
while(idx < count)
|
456
|
rx_func1(buf[idx++],0);
|
457
|
} else {
|
458
|
TSK_sleep(5);
|
459
|
}*/
|
460
|
}
|
461
|
}
|
462
|
|
463
|
extern "C" int StartMonitorTask1(void)
|
464
|
{
|
465
|
TSK_Handle task;
|
466
|
TSK_Attrs attrs;
|
467
|
|
468
|
attrs = TSK_ATTRS;
|
469
|
attrs.priority = GGE_PRIO;
|
470
|
attrs.name = "ser1_task";
|
471
|
task = TSK_create((Fxn)ser1_task, &attrs);
|
472
|
if(task)
|
473
|
return 1;
|
474
|
else
|
475
|
return 0;
|
476
|
}
|
477
|
|
478
|
void ser2_task() {
|
479
|
int count;
|
480
|
int idx=0;
|
481
|
static int flipper;
|
482
|
static char buf[64];
|
483
|
char workingBuffer[100]; // just some junk
|
484
|
|
485
|
while (!Com2_initialized)
|
486
|
TSK_sleep(Sec2tick(1));
|
487
|
|
488
|
while (1) {
|
489
|
/*count = sprintf(buf, "hello world #2 %d\n", idx++);
|
490
|
Com2->put(buf, count, 0, 0);
|
491
|
TSK_sleep(1250);*/
|
492
|
/**/
|
493
|
count = Com2->get(buf, 64, 500);
|
494
|
if (count && Com2_initialized && Com1_initialized ) {
|
495
|
// copy the data to a global buffer and...
|
496
|
sprintf(gBuffer, "%s", buf);
|
497
|
unsigned char command = gBuffer[0];
|
498
|
if (command == 208 && gBuffer[1] == '0' && gBuffer[2] == '2') { // was a byte request..for 02
|
499
|
// send back some sort of string
|
500
|
flipper++;
|
501
|
count = sprintf(workingBuffer, "%c02%02d",0xe0, flipper);
|
502
|
if (flipper > 5) flipper = 0;
|
503
|
sprintf(gBuffer, "%s!!!!", workingBuffer);
|
504
|
Com2->put(workingBuffer,count,0,0);
|
505
|
} else {
|
506
|
command = command + 0x10;
|
507
|
count = sprintf(workingBuffer, "%c%c%c%02d",command, gBuffer[1], gBuffer[2], flipper);
|
508
|
Com2->put(workingBuffer,count,0,0);
|
509
|
}
|
510
|
//} else {
|
511
|
gBuffer[count] = NULL;
|
512
|
} else if (count == 0) {
|
513
|
sprintf(gBuffer, "empty string %d ", idx++);
|
514
|
}
|
515
|
if (count && Com2_initialized && (rx_func2 != NULL)) {
|
516
|
idx = 0;
|
517
|
while(idx < count)
|
518
|
rx_func2(buf[idx++],0);
|
519
|
} else {
|
520
|
TSK_sleep(5);
|
521
|
}
|
522
|
/* */
|
523
|
}
|
524
|
}
|
525
|
|
526
|
extern "C" int StartMonitorTask2(void)
|
527
|
{
|
528
|
TSK_Handle task;
|
529
|
TSK_Attrs attrs;
|
530
|
|
531
|
attrs = TSK_ATTRS;
|
532
|
attrs.priority = GGE_PRIO;
|
533
|
attrs.name = "ser1_task";
|
534
|
task = TSK_create((Fxn)ser2_task, &attrs);
|
535
|
if(task)
|
536
|
return 1;
|
537
|
else
|
538
|
return 0;
|
539
|
}
|
540
|
|
541
|
///////////////////////////////////////////////////////////////////////////////
|
542
|
///////////////////////////////////////////////////////////////////////////////
|
543
|
// This routine actually creates the comm port. It is not to be called
|
544
|
// directly by users.
|
545
|
///////////////////////////////////////////////////////////////////////////////
|
546
|
|
547
|
extern "C" void InitSerPort(serialPort *xPort, int style, int baud, u_8 dbits, u_8 parity,
|
548
|
u_8 sbits, u_8 hnd_shk,
|
549
|
void (*rx_func)(u_8 c, u_8 stat))
|
550
|
{
|
551
|
// PORT tmp;
|
552
|
|
553
|
MityDSP::tcDspSerial::tsConfig Cfg;
|
554
|
|
555
|
int DBitsCfg,SbitsCfg,PrtyCfg;
|
556
|
|
557
|
DBitsCfg = dbits;
|
558
|
|
559
|
switch(parity)
|
560
|
{
|
561
|
case 'e':
|
562
|
case 'E':
|
563
|
PrtyCfg = MityDSP::tcDspFpgaSerial::gnUART_EVENPARITY;
|
564
|
Cfg.parity = MityDSP::tcDspSerial::tsConfig::even;
|
565
|
break;
|
566
|
case 'o':
|
567
|
case 'O':
|
568
|
PrtyCfg = MityDSP::tcDspFpgaSerial::gnUART_ODDPARITY;
|
569
|
Cfg.parity = MityDSP::tcDspSerial::tsConfig::odd;
|
570
|
break;
|
571
|
case 'n':
|
572
|
case 'N':
|
573
|
PrtyCfg = MityDSP::tcDspFpgaSerial::gnUART_NOPARITY;
|
574
|
Cfg.parity = MityDSP::tcDspSerial::tsConfig::none;
|
575
|
|
576
|
break;
|
577
|
}
|
578
|
|
579
|
SbitsCfg = sbits;
|
580
|
|
581
|
if(style == 1)
|
582
|
{
|
583
|
xPort->Com = new MityDSP::tcDspFpgaSerial((void *)RS232_SERIAL_BASE,
|
584
|
baud,
|
585
|
DBitsCfg,
|
586
|
SbitsCfg,
|
587
|
PrtyCfg,
|
588
|
false);
|
589
|
|
590
|
xPort->rx_func = rx_func;
|
591
|
}
|
592
|
else
|
593
|
{
|
594
|
xPort->Com = MityDSP::tcDspSerial::GetInstance(MityDSP::tcDspSerial::UART0);
|
595
|
Cfg.baud = baud;
|
596
|
Cfg.databits = DBitsCfg;
|
597
|
Cfg.stopbits = SbitsCfg;
|
598
|
Cfg.hw_flowcontrol = false;
|
599
|
Com2->configure(&Cfg);
|
600
|
|
601
|
xPort->rx_func = rx_func;
|
602
|
StartMonitorTask2();
|
603
|
}
|
604
|
}
|
605
|
|
606
|
///////////////////////////////////////////////////////////////////////////////
|
607
|
///////////////////////////////////////////////////////////////////////////////
|
608
|
// This is the main initialization call to create the comm ports. It should
|
609
|
// be called before interrupts are enabled
|
610
|
///////////////////////////////////////////////////////////////////////////////
|
611
|
|
612
|
extern "C" void InitSerPortX(serialPort *xPort, int style, int baud)
|
613
|
{
|
614
|
xPort->Com = 0;
|
615
|
xPort->initialized = false;
|
616
|
InitSerPort(xPort, style, baud, 8, 'n', 1, 0, 0);
|
617
|
xPort->initialized = true;
|
618
|
}
|
619
|
|
620
|
|
621
|
|
622
|
extern "C" void InitSerPortndc(u_8 port, u_8 io, int baud, u_8 dbits, u_8 parity,
|
623
|
u_8 sbits, u_8 hnd_shk,
|
624
|
void (*rx_func)(u_8 c, u_8 stat))
|
625
|
{
|
626
|
// PORT tmp;
|
627
|
|
628
|
MityDSP::tcDspSerial::tsConfig Cfg;
|
629
|
|
630
|
int DBitsCfg,SbitsCfg,PrtyCfg;
|
631
|
|
632
|
DBitsCfg = dbits;
|
633
|
|
634
|
switch(parity)
|
635
|
{
|
636
|
case 'e':
|
637
|
case 'E':
|
638
|
PrtyCfg = MityDSP::tcDspFpgaSerial::gnUART_EVENPARITY;
|
639
|
Cfg.parity = MityDSP::tcDspSerial::tsConfig::even;
|
640
|
break;
|
641
|
case 'o':
|
642
|
case 'O':
|
643
|
PrtyCfg = MityDSP::tcDspFpgaSerial::gnUART_ODDPARITY;
|
644
|
Cfg.parity = MityDSP::tcDspSerial::tsConfig::odd;
|
645
|
break;
|
646
|
case 'n':
|
647
|
case 'N':
|
648
|
PrtyCfg = MityDSP::tcDspFpgaSerial::gnUART_NOPARITY;
|
649
|
Cfg.parity = MityDSP::tcDspSerial::tsConfig::none;
|
650
|
|
651
|
break;
|
652
|
}
|
653
|
|
654
|
SbitsCfg = sbits;
|
655
|
|
656
|
if(port == 1)
|
657
|
{
|
658
|
Com1 = new MityDSP::tcDspFpgaSerial((void *)RS232_SERIAL_BASE,
|
659
|
baud,
|
660
|
DBitsCfg,
|
661
|
SbitsCfg,
|
662
|
PrtyCfg,
|
663
|
false);
|
664
|
|
665
|
rx_func1 = rx_func;
|
666
|
StartMonitorTask1();
|
667
|
}
|
668
|
else
|
669
|
{
|
670
|
Com2 = MityDSP::tcDspSerial::GetInstance(MityDSP::tcDspSerial::UART0);
|
671
|
Cfg.baud = baud;
|
672
|
Cfg.databits = DBitsCfg;
|
673
|
Cfg.stopbits = SbitsCfg;
|
674
|
Cfg.hw_flowcontrol = false;
|
675
|
Com2->configure(&Cfg);
|
676
|
|
677
|
rx_func2 = rx_func;
|
678
|
StartMonitorTask2();
|
679
|
}
|
680
|
}
|
681
|
|
682
|
///////////////////////////////////////////////////////////////////////////////
|
683
|
///////////////////////////////////////////////////////////////////////////////
|
684
|
// This is the main initialization call to create the comm ports. It should
|
685
|
// be called before interrupts are enabled
|
686
|
///////////////////////////////////////////////////////////////////////////////
|
687
|
|
688
|
extern "C" void InitSerPorts(int baud1, int baud2)
|
689
|
{
|
690
|
Com1 = 0;
|
691
|
Com2 = 0;
|
692
|
|
693
|
Com1_initialized = false;
|
694
|
Com2_initialized = false;
|
695
|
InitSerPortndc(1, 0, baud1, 8, 'n', 1, 0, 0);
|
696
|
InitSerPortndc(2, 0, baud2, 8, 'n', 1, 0, 0);
|
697
|
Com1_initialized = true;
|
698
|
Com2_initialized = true;
|
699
|
|
700
|
}
|
701
|
|
702
|
/**
|
703
|
* Main routine.
|
704
|
*/
|
705
|
int main(int argc, char* argv[])
|
706
|
{
|
707
|
|
708
|
int bWaitForMe = argc;
|
709
|
int iCounter = 0;
|
710
|
int iCounter2 = 0;
|
711
|
while (bWaitForMe) {
|
712
|
iCounter++; // wait for the debugger here....
|
713
|
if (iCounter > 10000) {
|
714
|
iCounter2++;
|
715
|
iCounter = 0;
|
716
|
}
|
717
|
}
|
718
|
|
719
|
// initialize the DSPLink system
|
720
|
tcCL_IPCInit::GetInstance();
|
721
|
|
722
|
msgRecvd = SEM_create(0, NULL);
|
723
|
|
724
|
// Launch an initialization task
|
725
|
TSK_Attrs* lpAttrs = new TSK_Attrs;
|
726
|
*lpAttrs = TSK_ATTRS;
|
727
|
lpAttrs->name = "Initialize";
|
728
|
lpAttrs->stacksize = 8192*2;
|
729
|
lpAttrs->priority = 5;
|
730
|
TSK_create((Fxn)init,lpAttrs);
|
731
|
|
732
|
// according to loc_init.c:loc_init it appears the first port is the 232 and the second one is the 422
|
733
|
// InitSerPorts(baud232, baud422);
|
734
|
// This will create a task for each serial port.
|
735
|
/*
|
736
|
* InitSerPortX(&spCom[0], 1, 38400); //. TBD use enum for style of serial port either FPGA or plain DSP
|
737
|
StartMonitorTask1();
|
738
|
InitSerPortX(&spCom[1], 2, 38400);
|
739
|
StartMonitorTask2();*/
|
740
|
|
741
|
// we're done exit and leave the tasks going...
|
742
|
return 0;
|
743
|
}
|
744
|
|
745
|
/**
|
746
|
* Initialize the inbound and outbound IPC objects.
|
747
|
*
|
748
|
* \return None.
|
749
|
*/
|
750
|
void init()
|
751
|
{
|
752
|
// Message to ARM core.
|
753
|
char lpReturnMessage[] = "DSP Initialization finished.";
|
754
|
// Buffer for return message
|
755
|
char* lpMessageBuffer = NULL;
|
756
|
|
757
|
// Create the outbound debug link
|
758
|
gpDebug = new tcCL_IPCOutbound("debug");
|
759
|
|
760
|
// Create the inbound link for messages to the DSP
|
761
|
gpInbound = new tcCL_IPCInbound();
|
762
|
|
763
|
gpInbound->Open("DSPMSGQ0", 8);
|
764
|
|
765
|
// Create the outbound controller for sending messages to the ARM
|
766
|
gpOutbound = new tcCL_IPCOutbound("GPPMSGQ1");
|
767
|
|
768
|
if (NULL != gpInbound)
|
769
|
{
|
770
|
// Register a callback function to handle messages from the ARM
|
771
|
gpInbound->RegisterCallback(handleInboundMessageBM, (void*)NULL);
|
772
|
}
|
773
|
|
774
|
// Now that initialization is complete, let the ARM know with a message
|
775
|
|
776
|
// Obtain a dsplink buffer for the return message
|
777
|
lpMessageBuffer = (char*)gpOutbound->GetBuffer(sizeof(messageA2D) + 1);
|
778
|
|
779
|
// Make sure we received a valid buffer
|
780
|
if (NULL != lpMessageBuffer)
|
781
|
{
|
782
|
|
783
|
// create a debug message for the first one...
|
784
|
sprintf(messageA2D.debugMsg.textMessage, "%s", lpReturnMessage);
|
785
|
messageA2D.debugMsg.header.type = eDebugText;
|
786
|
// Copy our message to the buffer
|
787
|
memcpy(lpMessageBuffer, &messageA2D, sizeof(messageA2D));
|
788
|
|
789
|
// Send first message to the ARM
|
790
|
gpOutbound->SendMessage(lpMessageBuffer);
|
791
|
}
|
792
|
|
793
|
// now wait on msgs from the ARM
|
794
|
bool keepGoing=true;
|
795
|
while (keepGoing) {
|
796
|
SEM_pend(msgRecvd, SYS_FOREVER);
|
797
|
// msg rcv'd... now what...
|
798
|
}
|
799
|
}
|
800
|
|
801
|
/**
|
802
|
* Callback function that handles messages from the ARM.
|
803
|
*
|
804
|
* \param apBuffer Pointer to message buffer.
|
805
|
* \param anLength Length of message.
|
806
|
* \param apUserArg Pointer to user defined argument
|
807
|
*
|
808
|
* \return 0 on sucess.
|
809
|
*/
|
810
|
int handleInboundMessage(void* apBuffer, uint32_t anLength, void* apUserArg)
|
811
|
{
|
812
|
int retval = 0;
|
813
|
// The return message to the ARM
|
814
|
char lpReturnMessage[] = "Hello World. DSP Received Message = \'";
|
815
|
// Buffer for return message
|
816
|
char* lpMessageBuffer = NULL;
|
817
|
|
818
|
// Obtain a dsplink buffer for the return message
|
819
|
lpMessageBuffer = (char*)gpOutbound->GetBuffer(strlen(lpReturnMessage) + strlen((const char*)apBuffer) + 2);
|
820
|
|
821
|
// Make sure we received a valid buffer
|
822
|
if (NULL != lpMessageBuffer)
|
823
|
{
|
824
|
// Copy our message to the buffer
|
825
|
strcpy(lpMessageBuffer, lpReturnMessage);
|
826
|
// Append the received message to the buffer
|
827
|
strcpy((char*)&lpMessageBuffer[strlen(lpReturnMessage)], (const char *)apBuffer);
|
828
|
// Null terminate the string
|
829
|
lpMessageBuffer[strlen(lpMessageBuffer)+1] = 0;
|
830
|
// Append the closing quotation
|
831
|
lpMessageBuffer[strlen(lpMessageBuffer)] = '\'';
|
832
|
|
833
|
// Send the message back to the ARM
|
834
|
retval = gpOutbound->SendMessage(lpMessageBuffer);
|
835
|
}
|
836
|
else
|
837
|
{
|
838
|
retval = -1;
|
839
|
}
|
840
|
|
841
|
return retval;
|
842
|
}
|
843
|
|
844
|
/**
|
845
|
* Callback function that handles messages from the ARM.
|
846
|
*
|
847
|
* \param apBuffer Pointer to message buffer.
|
848
|
* \param anLength Length of message.
|
849
|
* \param apUserArg Pointer to user defined argument
|
850
|
*
|
851
|
* \return 0 on sucess.
|
852
|
*/
|
853
|
int handleInboundMessageBM(void* apBuffer, uint32_t anLength, void* apUserArg)
|
854
|
{
|
855
|
int retval = 0;
|
856
|
// Buffer for return message
|
857
|
char* lpMessageBuffer = NULL;
|
858
|
|
859
|
// Obtain a dsplink buffer for the return message
|
860
|
lpMessageBuffer = (char*)gpOutbound->GetBuffer(sizeof(messageA2D));
|
861
|
|
862
|
// Make sure we received a valid buffer
|
863
|
if (NULL != lpMessageBuffer)
|
864
|
{
|
865
|
// Process message from ARM here...
|
866
|
// extract msg type from message
|
867
|
memcpy(&messageA2D, apBuffer, anLength);
|
868
|
switch (messageA2D.header.type) {
|
869
|
case eLibrary:
|
870
|
// for fun just increment some values and send back to ARM
|
871
|
messageA2D.library.FeatureCount++;
|
872
|
messageA2D.library.SQCBatchSize++;
|
873
|
messageA2D.library.header.command = eWriteToARM;
|
874
|
break;
|
875
|
};
|
876
|
// Copy our message to the buffer
|
877
|
memcpy(lpMessageBuffer, &messageA2D, sizeof(messageA2D));
|
878
|
|
879
|
// Send the message back to the ARM
|
880
|
retval = gpOutbound->SendMessage(lpMessageBuffer);
|
881
|
SEM_post(msgRecvd); // trigger that we have recv'd and responded to the ARM Message.
|
882
|
gpOutbound->ReturnBuffer(apBuffer);
|
883
|
}
|
884
|
else
|
885
|
{
|
886
|
retval = -1;
|
887
|
}
|
888
|
|
889
|
return retval;
|
890
|
}
|
891
|
|
892
|
/**
|
893
|
* Function for sending debug messages to the ARM.
|
894
|
*
|
895
|
* \param buffer Null terminated string to be printed.
|
896
|
*
|
897
|
* \return None.
|
898
|
*/
|
899
|
void debugPrint(char* pMsg)
|
900
|
{
|
901
|
// The length of the message to be sent
|
902
|
int len = strlen(pMsg);
|
903
|
// Pointer to dsplink buffer where to write the message
|
904
|
char* pBuffer;
|
905
|
|
906
|
// Make sure the debug IPC outbound object has been initialized
|
907
|
if (gpDebug == NULL)
|
908
|
return;
|
909
|
|
910
|
// Get a buffer for the message
|
911
|
pBuffer = (char *)gpDebug->GetBuffer(len+1);
|
912
|
|
913
|
// Check that the buffer is valid
|
914
|
if (pBuffer)
|
915
|
{
|
916
|
// Copy the message to the buffer
|
917
|
strcpy(pBuffer, pMsg);
|
918
|
// Send the message
|
919
|
gpDebug->SendMessage(pBuffer);
|
920
|
}
|
921
|
}
|
922
|
|