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

Subversion Repositories pcie_vera_tb

[/] [pcie_vera_tb/] [trunk/] [link_training.vri] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cmagleby
// ===========================================================================
2
// File    : link_training.vri
3
// Author  : cmagleby
4
// Date    : Mon Dec 3 11:03:46 MST 2007
5
// Project : TI PHY design
6
//
7
// Copyright (c) notice
8
// This code adheres to the GNU public license
9
//
10
// ===========================================================================
11
//
12
// $Id: link_training.vri,v 1.1.1.1 2007-12-05 18:37:06 cmagleby Exp $
13
//
14
// ===========================================================================
15
//
16
// $Log: not supported by cvs2svn $
17
//
18
// ===========================================================================
19
// Function :This file performs the link training and link and lane negotiation
20
//
21
// ===========================================================================
22
// ===========================================================================
23
#include 
24
#define COM_s 8'hbc
25
#define SKP_s 8'h1c
26
#define IDLE_s 8'h7c
27
#define FTS_s 8'h3c
28
#define STP_s 8'hfb
29
#define SDP_s 8'h5c
30
#define EDB   8'hfe
31
#define END_s 8'hfd
32
 
33
task link_training () {
34
 
35
  fork
36
    send_ts();
37
    receive_ts();
38
  join none
39
}
40
 
41
 
42
task send_ts( ) {
43
  integer index;
44
  string pkt_type;
45
  pkt_type = "ts";
46
  //ti_phy_top.t1_count == 9'hff;
47
  ti_phy_top.rxvalid16 = 1'b1;
48
  wait_var(phy_rdy);
49
 
50
  printf ("send_ts1 =  %d \n",send_ts1);
51
  while (LINK_UP == 0) {
52
    if (send_ts1 == 1) {
53
      ts2_cycle_cnt = 1;
54
      //printf ("number of ts dut sent %d \n",ti_phy_top.t1_count);
55
      printf ("ts #%0d ts 1's ",ts1_cycle_cnt++);
56
      pkt_type = "ts";
57
      training_set = new(link,lane,*,*,*,*);
58
      training_set.build_packet(pkt_type);
59
      if (!semaphore_get(WAIT,my_semaphore,1))
60
        error ("Semaphore_get returned 0\n");
61
      for (index = 0; index < training_set.length; index ++) {
62
        @ (posedge CLOCK);
63
        //ti_phy_top.rxdatak16 = training_set.temp_packet[index][17:16];
64
        //ti_phy_top.rxdata16  = training_set.temp_packet[index][15:0];
65
        //adding mailbox
66
        mailbox_put (rx_data_mailbox, {training_set.temp_packet[index][17:16],training_set.temp_packet[index][15:0]});
67
      }
68
      semaphore_put (my_semaphore, 1);
69
    }
70
    else if (send_ts2 == 1){
71
      ts1_cycle_cnt = 1;
72
      printf ("ts #%0d ts 2's ",ts2_cycle_cnt++);
73
      pkt_type = "ts";
74
      training_set = new(lane,link,*,*,*,'h45);
75
      training_set.build_packet(pkt_type);
76
      for (index = 0; index < training_set.length; index ++) {
77
        @ (posedge CLOCK);
78
        //ti_phy_top.rxdatak16 = training_set.temp_packet[index][17:16];
79
        //ti_phy_top.rxdata16  = training_set.temp_packet[index][15:0];
80
        //adding mailbox
81
        mailbox_put (rx_data_mailbox, {training_set.temp_packet[index][17:16],training_set.temp_packet[index][15:0]});
82
      }
83
    }
84
  }
85
 
86
  printf ("LINK UP(%0d) !!!!!!!!!!!\n",LINK_UP);
87
  //ti_phy_top.rxdatak16 = 2'b00;
88
  //ti_phy_top.rxdata16  = 1'b0;
89
}
90
 
91
task receive_ts () {
92
  integer ret;
93
  integer ts1_count=0;
94
  integer ts2_count=0;
95
  integer ts1_link_count = 0;
96
  integer ts1_lane_count = 0;
97
  integer ts2_lane_link_count = 0;
98
  integer send_ts1_with_link, send_ts1_with_link_lane, send_ts2_with_link_lane;
99
  bit [127:0] receive_phy_packet;
100
 
101
  send_ts1  = 1;
102
  send_ts2  = 0;
103
  send_ts1_with_link = 0;
104
  send_ts1_with_link_lane = 0;
105
  send_ts2_with_link_lane = 0;
106
  while (1) {
107
    ret = mailbox_get (WAIT,phy_mailbox,receive_phy_packet,CHECK);
108
    //printf ("Recieved PHY PACKET (%0h) added to phy mailbox\n",receive_phy_packet);
109
    if (receive_phy_packet == 127'h454545454545454545450002f0f7f7bc) {
110
      printf ("Recieved TS 2 PHY PACKET\n");
111
      ts2_count++;
112
    }
113
    if (receive_phy_packet == 127'h4a4a4a4a4a4a4a4a4a4a0002f0f7f7bc){
114
      printf ("Recieved TS 1 PHY PACKET\n");
115
      ts1_count++;
116
    }
117
    if (receive_phy_packet == 127'h4a4a4a4a4a4a4a4a4a4a0002f0f701bc) {
118
      printf ("Recieved TS 1 link accept PHY PACKET\n");
119
      ts1_link_count++;
120
    }
121
    if (receive_phy_packet == 127'h4a4a4a4a4a4a4a4a4a4a0002f00101bc) {
122
      printf ("Recieved TS 1 lane and link accept PHY PACKET\n");
123
      ts1_lane_count++;
124
    }
125
    if (receive_phy_packet == 127'h454545454545454545450002f00101bc) {
126
      printf ("Recieved TS 1 lane and link accept PHY PACKET\n");
127
      ts2_lane_link_count++;
128
    }
129
 
130
    //printf ("send_ts2_with_link_lane(%0d)send_ts1_with_link_lane(%0d)send_ts1_with_link(%0d)send_ts2(%0d)send_ts1(%0d)\n",
131
    //        send_ts2_with_link_lane,send_ts1_with_link_lane,send_ts1_with_link,send_ts2,send_ts1 );
132
    //printf ("ts2_lane_link_count(%0d)ts1_lane_count(%0d)ts1_link_count(%0d)ts1_count(%0d)ts2_count(%0d)\n",
133
    //        ts2_lane_link_count,ts1_lane_count,ts1_link_count,ts1_count,ts2_count);
134
 
135
    if (send_ts2_with_link_lane && ts2_cycle_cnt > 16 && ts2_lane_link_count > 15) {
136
      //clear all signals if we get a ts1 with pad
137
      if (ts1_count > 0) {
138
        send_ts1 = 1;
139
        send_ts2 = 0;
140
        send_ts2_with_link_lane = 0;
141
        send_ts1_with_link_lane = 0;
142
        send_ts1_with_link = 0;
143
        LINK_UP = 0;
144
        ts2_lane_link_count = 0;
145
        ts1_lane_count = 0;
146
        ts1_link_count = 0;
147
        ts1_count = 0;
148
        ts2_count = 0;
149
      }
150
      else {
151
        send_ts1 = 0;
152
        send_ts2 = 0;
153
        LINK_UP  = 1;
154
        ts1_lane_count = 0;
155
        ts1_link_count = 0;
156
        ts1_count = 0;
157
        ts2_count = 0;
158
 
159
      }
160
 
161
    }
162
    else if (send_ts1_with_link_lane){
163
      if (ts1_cycle_cnt > 16 && ts1_lane_count >16 ) {
164
        send_ts1 = 0;
165
        send_ts2 = 1;
166
        link = 8'b1;
167
        lane = 8'b1;
168
        send_ts2_with_link_lane = 1;
169
        ts1_lane_count = 0;
170
        ts1_link_count = 0;
171
        ts1_count = 0;
172
        ts2_count = 0;
173
      }
174
    }
175
    else if (send_ts1_with_link) {
176
      if (ts1_cycle_cnt > 16 && ts1_link_count > 16) {
177
        send_ts1 = 1;
178
        send_ts2 = 0;
179
        link = 8'b1;
180
        lane = 8'b1;
181
        send_ts1_with_link_lane = 1;
182
      }
183
    }
184
    //send at least 16 ts 2
185
    else if (send_ts2) {
186
      if (ts2_count > 16 && ts2_cycle_cnt > 16) {
187
        send_ts1 = 1;
188
        send_ts2 = 0;
189
        send_ts1_with_link = 1;
190
        link = 8'b1;
191
        lane = 8'hf7;
192
      }
193
    }
194
    //send at least 100 ts 1's
195
    else if (ts2_count > 16 && ts1_cycle_cnt > 100) {
196
      send_ts1 = 0;
197
      send_ts2 = 1;
198
      link = 'hf7;
199
      lane = 'hf7;
200
    }
201
    else {
202
      send_ts1 = 1;
203
      send_ts2 = 0;
204
      link = 'hf7;
205
      lane = 'hf7;
206
    }
207
  }
208
}
209
 

powered by: WebSVN 2.1.0

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