OpenCores
URL https://opencores.org/ocsvn/spacewiresystemc/spacewiresystemc/trunk

Subversion Repositories spacewiresystemc

[/] [spacewiresystemc/] [trunk/] [systemC/] [rx_spw.h] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 redbear
#ifndef SPW_RX_H
2
#define SPW_RX_H
3
 
4
#define STATE_RESET     0
5
#define STATE_ENABLED   1
6
#define STATE_GOT_BIT   2
7
#define STATE_GOT_NULL  3
8
 
9
#define ESC       0
10
#define FCT       1
11
#define EOP       2
12
#define EEP       3
13
#define DATA      4
14
#define TIME_CODE 5
15
 
16
class SPW_RX_SC;
17
 
18
SC_MODULE(SPW_RX_SC)
19
{
20
 
21
        sc_in<bool> RX_CLOCK;
22
        sc_in<uint>  DIN;
23
        sc_in<uint>  SIN;
24
 
25
        sc_in<bool> CLOCK_SYS;
26
 
27
        sc_in<bool> ENABLE_RX;
28
        sc_in<bool> RESET_RX;
29
 
30
        sc_out<bool> RX_ERROR;
31
        sc_out<bool> RX_CREDIT_ERROR;
32
        sc_out<bool> GOT_BIT;
33
        sc_out<bool> GOT_NULL;
34
        sc_out<bool> GOT_NCHAR;
35
        sc_out<bool> GOT_TIME_CODE;
36
        sc_out<bool> GOT_FCT;
37
 
38
        sc_out<bool> SEND_FCT_NOW_RX;
39
 
40
        sc_in<bool> BUFFER_READY;
41
        sc_out<sc_uint<9> > DATARX_FLAG;
42
        sc_out<bool> BUFFER_WRITE;
43
 
44
        sc_out<sc_uint<8> > TIME_OUT;
45
        sc_out<bool>    TICK_OUT;
46
        sc_out<bool>    CONTROL_FLAG_OUT;
47
 
48
        //INTERNAL 
49
        sc_uint<4> state_rx;
50
 
51
        sc_uint<4> control;
52
        sc_uint<10> data;
53
        sc_uint<10> timecode;
54
 
55
        sc_uint<4> control_sys =4;
56
        sc_uint<4> last_control_sys =4;
57
 
58
        sc_uint<10> data_sys;
59
        sc_uint<10> last_data;
60
 
61
        sc_uint<10> timecode_sys;
62
        sc_uint<10> last_timecode;
63
 
64
        sc_signal<bool> tag_found;
65
 
66
        unsigned int counter = 0;
67
        unsigned int counter_fct = 0;
68
        unsigned int counter_received_data = 0;
69
        bool enable_bit;
70
        bool first_time;
71
 
72
        bool connected = false;
73
 
74
        int cycles=0;
75
 
76
        bool control_found;
77
        bool data_found;
78
        bool time_code_found;
79
 
80
 
81 40 redbear
        bool last_is_control;
82
        bool last_is_data;
83
 
84
 
85 29 redbear
        bool NULL_FOUND;
86
        bool FCT_FOUND;
87
        bool DATA_FOUND;
88
        bool TIMECODE_FOUND;
89
 
90
        bool control_parity_error;
91
        bool data_parity_error;
92
        bool time_code_parity_error;
93
        bool invalid_combination;
94
 
95
        vector<sc_uint<9> > data_store;
96
        vector<sc_uint<9> > time_code;
97
 
98
        unsigned int last_char;
99
 
100
        void CalcPARITY()
101
        {
102
                control_parity_error = false;
103
                data_parity_error = false;
104
                time_code_parity_error = false;
105 40 redbear
 
106
 
107
                if(last_is_control)
108 29 redbear
                {
109
                        if(control_found)
110
                        {
111
                                if(!(control_sys[2]^last_control_sys[0]^last_control_sys[1]) != control_sys[3])
112
                                {
113
                                        control_parity_error = true;
114
                                }
115
                        }else if(data_found)
116
                        {
117
                                if(!(data_sys[8]^last_control_sys[0]^last_control_sys[1])  != data_sys[9])
118
                                {
119
                                        data_parity_error = true;
120
                                }
121
                        }
122 40 redbear
 
123
                }else if(last_is_data)
124 29 redbear
                {
125
                        if(control_found)
126
                        {
127
                                if(!(data_sys[8]^last_control_sys[0]^last_control_sys[1])  != data_sys[9])
128
                                {
129
                                        control_parity_error = true;
130
                                }
131
                        }else if(data_found)
132
                        {
133
                                if(!(data_sys[8]^last_data[0]^last_data[1]^last_data[2]^last_data[3]^last_data[4]^last_data[5]^last_data[6]^last_data[7]) != data_sys[9])
134
                                {
135
                                        data_parity_error = true;
136
                                }
137
                        }
138
                }
139 40 redbear
 
140 29 redbear
        }
141
 
142
        void gotFCT()
143
        {
144
                while(1)
145
                {
146
                        if(!ENABLE_RX)
147
                        {
148
                                RX_CREDIT_ERROR = false;
149
                                counter_fct = 1;
150
                        }else
151
                        {
152
                                if(counter_fct*8 > 56)
153
                                {
154
                                        RX_CREDIT_ERROR = true;
155
                                        wait(1);
156
                                        RX_CREDIT_ERROR = false;
157
                                }
158
                        }
159
                        wait(1);
160
                }
161
        }
162
 
163
        void UPDATE_FCT()
164
        {
165
                while(1)
166
                {
167
                        if(!ENABLE_RX)
168
                        {
169
                                SEND_FCT_NOW_RX = false;
170
                                counter_received_data = 0;
171
                        }else if(counter_received_data >= 64)
172
                        {
173
                                SEND_FCT_NOW_RX = true;
174
                                counter_received_data = 0;
175
                        }else { SEND_FCT_NOW_RX = false;}
176
                        wait(1);
177
                }
178
        }
179
 
180
 
181
        void TIMER_ADTER850()
182
        {
183
                if(GOT_BIT)
184
                {
185
                        cycles=0;
186
                }
187
        }
188
 
189
        void TIMER_850COUNTER()
190
        {
191
                if(!ENABLE_RX)
192
                {
193
                        RX_ERROR = false;
194
                        control_parity_error = false;
195
                        data_parity_error = false;
196
                        time_code_parity_error = false;
197
                        invalid_combination = false;
198
                        cycles = 0;
199
                }
200
                else
201
                {
202
                        //if(GOT_BIT)
203
                        //{
204
                                if(cycles == 43 || control_parity_error || data_parity_error || time_code_parity_error || invalid_combination)
205
                                {
206
                                        //RX_ERROR = true;
207
                                        #ifdef RX_ERROR_ENABLE
208
                                        cout << "ERROR RX ENABLE" << endl;
209
                                        cout << control_parity_error << endl;
210
                                        cout << data_parity_error << endl;
211
                                        cout << time_code_parity_error << endl;
212
                                        cout << invalid_combination << endl;
213
                                        #endif
214
                                }
215
                                else
216
                                {
217
                                        RX_ERROR = false;
218
                                        cycles++;
219
                                }
220
                        //}
221
                }
222
        }
223
 
224
 
225
        void RX_GET_SIGNAL()
226
        {
227
 
228
                if( NULL_FOUND )
229
                {
230
                        GOT_NULL   = true;
231
                        GOT_FCT    = false;
232
                        GOT_NCHAR  = false;
233
                }else if( FCT_FOUND )
234
                {
235
                        GOT_FCT    = true;
236
                        GOT_NULL   = false;
237
                        GOT_NCHAR  = false;
238
                }else if( DATA_FOUND )
239
                {
240
                        GOT_NCHAR  = true;
241
                        GOT_FCT    = false;
242
                        GOT_NULL   = false;
243
                }else if( TIMECODE_FOUND )
244
                {
245
                        GOT_TIME_CODE = true;
246
                        GOT_NCHAR  = false;
247
                        GOT_FCT    = false;
248
                        GOT_NULL   = false;
249
                }
250
 
251
        }
252
 
253
        void RX_RECEIVER()
254
        {
255
                GOT_BIT        = true;
256
                NULL_FOUND     = false;
257
                FCT_FOUND      = false;
258
                DATA_FOUND     = false;
259
                TIMECODE_FOUND = false;
260 40 redbear
 
261
                last_is_control = false;
262
                last_is_data    = false;
263
 
264 29 redbear
                data_col_store.clear();
265
 
266
                if(!connected)
267
                {
268
                        if(counter == 0)
269
                        {
270
                                timecode(0,0) = data(9,9) = control(3,3) = DIN;
271
                                counter++;
272
                        }
273
                        else if(counter == 1)
274
                        {
275
                                timecode(1,1) = data(8,8) = control(2,2) = DIN;
276
                                counter++;
277
                        }
278
                        else if(counter == 2)
279
                        {
280
                                timecode(2,2) = data(0,0) = control(1,1) = DIN;
281
                                counter++;
282
                        }else if(counter == 3)
283
                        {
284
                                data_col_store.clear();
285
 
286
                                timecode(3,3) = data(1,1) = control(0,0) = DIN;
287
 
288
                                counter = 0;
289
 
290
                                if(last_control_sys(2,0) == 7 && control(2,0) == 4)
291
                                {
292
                                        control_found = true;
293
                                        NULL_FOUND = true;
294
                                        FCT_FOUND = false;
295
                                        DATA_FOUND = false;
296 40 redbear
 
297 29 redbear
                                        last_char = ESC;
298
 
299 40 redbear
                                        data_rx_sc_o(0,control,last_control_sys,data,timecode_sys);
300 29 redbear
 
301
                                        if(counter_fct > 0)
302
                                        {
303
                                                counter_fct = counter_fct -1;
304
                                        }
305
 
306
 
307
                                }else if(last_control_sys(2,0) != 7 && control(2,0) == 4)
308
                                {
309
                                        last_char = FCT;
310
                                        counter_fct++;
311
                                        FCT_FOUND = true;
312
                                        connected = true;
313
                                        NULL_FOUND = false;
314
 
315 40 redbear
                                        data_rx_sc_o(1,control,last_control_sys,data,timecode_sys);
316 29 redbear
 
317
                                }else if(last_control_sys(2,0) == 4 && control(2,0) == 7)
318
                                {
319
                                        last_char = ESC;
320
                                        if(counter_fct > 0)
321
                                        {
322
                                                counter_fct = counter_fct -1;
323
                                        }
324
                                }else
325
                                {
326
                                        invalid_combination = true;
327
                                        connected = false;
328
                                        //cout << last_control_sys(2,0) <<  control_sys(2,0) << endl;
329 40 redbear
 
330
                                        data_rx_sc_o(4,control,last_control_sys,data,timecode_sys);
331 29 redbear
                                }
332
                                last_control_sys = control;
333
                        }
334
                }
335
                else
336
                {
337
                        if(counter == 0)
338
                        {
339
                                timecode(9,9) = data(9,9) = control(3,3) = DIN;
340
                                counter++;
341
                        }
342
                        else if(counter == 1)
343
                        {
344
                                timecode(8,8) = data(8,8) = control(2,2) = DIN;
345
                                counter++;
346
                        }
347
                        else if(counter == 2)
348
                        {
349
                                timecode(0,0) = data(0,0) = control(1,1) = DIN;
350
                                counter++;
351
                        }else if(counter == 3)
352
                        {
353
                                timecode(1,1) = data(1,1) = control(0,0) = DIN;
354
 
355
                                if(control(2,2) == 1)
356
                                {
357 40 redbear
 
358
                                        last_is_control = control_found;
359
                                        last_is_data    = data_found;
360
 
361 29 redbear
                                        control_found = true;
362 40 redbear
                                        data_found    = false;
363 29 redbear
                                        counter = 0;
364
 
365
                                        if(last_control_sys(2,0) == 7 && control(2,0) == 4)
366
                                        {
367
                                                control_found = true;
368
                                                NULL_FOUND = true;
369
                                                FCT_FOUND  = false;
370
                                                DATA_FOUND = false;
371
                                                last_char = ESC;
372 40 redbear
 
373
                                                data_rx_sc_o(0,control,last_control_sys,data,timecode_sys);
374 29 redbear
 
375
                                                if(counter_fct > 0)
376
                                                {
377
                                                        counter_fct = counter_fct -1;
378
                                                }
379
 
380
 
381
                                        }else if(last_control_sys(2,0) != 7 && control(2,0) == 4)
382
                                        {
383
                                                last_char = FCT;
384
                                                counter_fct++;
385
 
386
                                                FCT_FOUND  = true;
387
                                                NULL_FOUND = false;
388
                                                DATA_FOUND = false;
389
 
390 40 redbear
                                                data_rx_sc_o(1,control,last_control_sys,data,timecode_sys);
391 29 redbear
 
392
                                        }else if(last_control_sys(2,0) != 7 && control(2,0) == 5)
393
                                        {
394
 
395
                                                last_char = EOP;
396
 
397
                                                FCT_FOUND  = false;
398
                                                NULL_FOUND = false;
399
                                                DATA_FOUND = true;
400 40 redbear
 
401
                                                data_rx_sc_o(2,control,last_control_sys,data,timecode_sys);
402 29 redbear
 
403
                                                if(counter_fct > 0)
404
                                                {
405
                                                        counter_fct = counter_fct - 1;
406
                                                }
407
 
408
                                                counter_received_data = counter_received_data + 8;
409
                                        }else if(last_control_sys(2,0) != 7 && control(2,0) == 6)
410
                                        {
411
 
412 40 redbear
                                                //data_col_store.clear();
413 29 redbear
 
414
                                                last_char = EEP;
415
 
416
                                                FCT_FOUND  = false;
417
                                                NULL_FOUND = false;
418
                                                DATA_FOUND = true;
419 40 redbear
 
420
                                                data_rx_sc_o(3,control,last_control_sys,data,timecode_sys);
421 29 redbear
 
422
                                                if(counter_fct > 0)
423
                                                {
424
                                                        counter_fct = counter_fct -1;
425
                                                }
426
 
427
                                                counter_received_data = counter_received_data + 8;
428
                                        }else if((last_control_sys(2,0) == 0 || last_control_sys(2,0) == 6) && control(2,0) == 7)
429
                                        {
430
                                                last_char = ESC;
431
                                                if(counter_fct > 0)
432
                                                {
433
                                                        counter_fct = counter_fct -1;
434
                                                }
435
                                        }else if(last_control_sys(2,0) == 4 && control(2,0) == 7)
436
                                        {
437
                                                last_char = ESC;
438
                                                if(counter_fct > 0)
439
                                                {
440
                                                        counter_fct = counter_fct -1;
441
                                                }
442
                                        }else if(last_control_sys(2,0) == 5 && control(2,0) == 7)
443
                                        {
444
                                                last_char = ESC;
445
                                                if(counter_fct > 0)
446
                                                {
447
                                                        counter_fct = counter_fct -1;
448
                                                }
449
                                        }else
450
                                        {
451 40 redbear
                                                //data_col_store.clear();
452 29 redbear
 
453
                                                invalid_combination = true;
454
                                                connected = false;
455 40 redbear
 
456
                                                data_rx_sc_o(4,control,last_control_sys,data,timecode_sys);
457 29 redbear
                                        }
458
                                        last_control_sys = control;
459
 
460
 
461
                                }
462
                                else
463
                                {
464
                                        counter++;
465
                                }
466
 
467
                                //cout << control.to_string(SC_HEX) << endl;
468
                        }else if(counter == 4)
469
                        {
470
                                timecode(2,2) = data(2,2) = DIN;
471
                                counter++;
472
                        }else if(counter == 5)
473
                        {
474
                                timecode(3,3) = data(3,3) = DIN;
475
                                counter++;
476
                        }else if(counter == 6)
477
                        {
478
                                timecode(4,4) = data(4,4) = DIN;
479
                                counter++;
480
                        }else if(counter == 7)
481
                        {
482
                                timecode(5,5) = data(5,5) = DIN;
483
                                counter++;
484
                        }else if(counter == 8)
485
                        {
486
                                timecode(6,6) = data(6,6) = DIN;
487
                                counter++;
488
                        }else if(counter == 9)
489
                        {
490
                                timecode(7,7) = data(7,7) = DIN;
491
 
492 40 redbear
                                last_is_control = control_found;
493
                                last_is_data    = data_found;
494
 
495
                                control_found = false;
496
                                data_found    = true;
497
 
498 29 redbear
                                if(data(8,8) == 0 && last_control_sys(2,0) != 7)
499
                                {
500
                                        data_col_store.clear();
501
 
502
                                        FCT_FOUND = false;
503
                                        NULL_FOUND = false;
504
                                        DATA_FOUND = true;
505
                                        //data_store.push_back(data);
506
                                        last_char = DATA;
507
 
508
                                        control_sys = 0;
509
                                        last_control_sys =0;
510
 
511 40 redbear
                                        data_rx_sc_o(5,control,last_control_sys,data,timecode_sys);
512 29 redbear
 
513
                                        counter_received_data = counter_received_data + 8;
514
 
515 40 redbear
                                        //data_iteration++;
516 29 redbear
                                        last_data = data;
517
 
518
                                        if(counter_fct > 0)
519
                                        {
520
                                                counter_fct = counter_fct -1;
521
                                        }
522
 
523
 
524
                                }else if(data(8,8) == 0 && last_control_sys(2,0) == 7)
525
                                {
526
                                        FCT_FOUND  = false;
527
                                        NULL_FOUND = false;
528
                                        DATA_FOUND = false;
529
                                        TIMECODE_FOUND = true;
530
 
531
                                        timecode_sys = timecode;
532
 
533
                                        last_char = TIME_CODE;
534
                                        control_sys = 0;
535
                                        last_control_sys =0;
536
 
537 40 redbear
                                        data_rx_sc_o(6,control,last_control_sys,data,timecode_sys);
538
 
539 29 redbear
                                        if(counter_fct > 0)
540
                                        {
541
                                                counter_fct = counter_fct -1;
542
                                        }
543
                                }
544
                                counter = 0;
545
                        }
546
                }
547
 
548
        }
549
 
550
        SC_CTOR(SPW_RX_SC)
551
        {
552
                SC_CTHREAD(gotFCT,CLOCK_SYS.pos());
553
 
554
                SC_CTHREAD(UPDATE_FCT,CLOCK_SYS.pos());
555
 
556
                SC_METHOD(TIMER_ADTER850);
557
                sensitive << RX_CLOCK.pos() << RX_CLOCK.neg();
558
                dont_initialize();
559
 
560
                SC_METHOD(TIMER_850COUNTER);
561
                sensitive << CLOCK_SYS.pos();
562
                dont_initialize();
563
 
564
                SC_METHOD(CalcPARITY);
565
                sensitive << RX_CLOCK.pos() << RX_CLOCK.neg();
566
                dont_initialize();
567
 
568
                SC_METHOD(RX_RECEIVER);
569
                sensitive << RX_CLOCK.pos() << RX_CLOCK.neg();
570
                dont_initialize();
571
 
572
                SC_METHOD(RX_GET_SIGNAL);
573
                sensitive << RX_CLOCK.pos() << RX_CLOCK.neg();
574
                dont_initialize();
575
 
576
        }
577
};
578
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.