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

Subversion Repositories pcie_vera_tb

[/] [pcie_vera_tb/] [trunk/] [ti_phy_top.vr] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cmagleby
// ===========================================================================
2
// File    : ti_phy_top.vr
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
// Please contact www.gutzlogic.com for details.
10
// cmagleby@gutzlogic.com; cwinward@gutzlogic.com
11
// ===========================================================================
12
//
13
// $Id: ti_phy_top.vr,v 1.1.1.1 2007-12-05 18:37:07 cmagleby Exp $
14
//
15
// ===========================================================================
16
//
17
// $Log: not supported by cvs2svn $
18
//
19
// ===========================================================================
20
// Function : This is the top level VERA file.  It call all tasks and brings
21
// up the PHY.
22
// ===========================================================================
23
// ===========================================================================
24
 
25
#define OUTPUT_EDGE  PHOLD
26
#define OUTPUT_SKEW  #1
27
#define INPUT_SKEW   #-1
28
#define INPUT_EDGE   PSAMPLE
29
#include 
30
 
31
// define interfaces, and verilog_node here if necessary
32
 
33
#include "ti_phy_top.if.vrh"
34
#include "receive_packet.vri"
35
#include "send_packet.vri"
36
#include "pcie_phy_packet.vri"
37
#include "link_training.vri"
38
#include "skip_order_set.vri"
39
#include "pcie_dllp_packet.vri"
40
#include "InitFC1.vri"
41
#include "pcie_tlp_packet.vri"
42
#include "tlp_gen.vri"
43
 
44
//kcode symbols
45
#define COM_s 8'hbc
46
#define SKP_s 8'h1c
47
#define IDLE_s 8'h7c
48
#define FTS_s 8'h3c
49
#define STP_s 8'hfb
50
#define SDP_s 8'h5c
51
#define EDB   8'hfe
52
#define END_s 8'hfd
53
program ti_phy_top_test {
54
 
55
  pcie_phy_packet training_set;
56
  pcie_phy_packet skip_set;
57
  //********************************
58
  //link training gobal variables
59
  integer send_ts1 = 1;
60
  integer send_ts2 = 0;
61
  bit [11:0] sequence_id;
62
  bit [31:0] packet_array [1040];
63
  bit [7:0] link = 8'hf7;
64
  bit [7:0] lane = 8'hf7;
65
  integer ts1_cycle_cnt = 1;
66
  integer ts2_cycle_cnt = 1;
67
  integer LINK_UP = 0;
68
  bit [7:0]  ph_cl   = 8'b0;
69
  bit [11:0] pd_cl   = 12'b0;
70
  bit [7:0]  cplh_cl = 8'b0;
71
  bit [11:0] cpld_cl = 12'b0;
72
  bit [7:0]  nph_cl  = 8'b0;
73
  bit [11:0] npd_cl  = 12'b0;
74
  bit        INITFC_DONE = 1'b0;
75
  //********************************
76
  pcie_dllp_packet flowcntrl_1;
77
  pcie_dllp_packet ack_seq_num;
78
  pcie_tlp_packet tlp_packet;
79
  integer phy_rdy = 0;
80
  integer my_semaphore;
81
  bit [8:0]  tx_data_mailbox;
82
  bit [15:0] tlp_header_mailbox;
83
  bit [31:0] tlp_data_mailbox;
84
  bit [47:0] dllp_mailbox;
85
  bit [127:0] phy_mailbox;
86
  bit [17:0]  rx_data_mailbox;
87
 
88
  //create mailboxes for transmit and receive packets
89
  tx_data_mailbox     = alloc(MAILBOX,0,1);
90
  rx_data_mailbox     = alloc(MAILBOX,0,1);
91
 
92
  tlp_header_mailbox  = alloc(MAILBOX,0,1);
93
  tlp_data_mailbox    = alloc(MAILBOX,0,1);
94
  dllp_mailbox        = alloc(MAILBOX,0,1);
95
  phy_mailbox         = alloc(MAILBOX,0,1);
96
 
97
  //create a packet arbiter for packet going out on the rx line.
98
  my_semaphore = alloc(SEMAPHORE, 0, 1, 1);
99
  if (!my_semaphore) error ("Semaphore could not be allocated\n");
100
 
101
  fork
102
    clk_50mhz_gen();
103
    phy_status();
104
    skip_order_set();
105
    receive_packet();
106
    send_packet();
107
    wait_var(phy_rdy);
108
    link_training();
109
  join none
110
 
111
  init_ports ();
112
  reset_sequence();
113
  wait_var(LINK_UP);
114
  fork
115
    zero_fill();
116
  join none
117
  InitFC1(ph_cl,pd_cl,cplh_cl,cpld_cl,nph_cl,npd_cl,INITFC_DONE);
118
 
119
  printf("Posted Header credit %h\n",ph_cl);
120
  printf("Posted Data credit %h\n",pd_cl);
121
 
122
  printf("NonPosted Header credit %h\n",nph_cl);
123
  printf("NonPosted Data credit %h\n",npd_cl);
124
 
125
  printf("Completion Header credit %h\n",cplh_cl);
126
  printf("Completion Data credit %h\n",cpld_cl);
127
 
128
  printf("INITFC_DONE=%d\n.",INITFC_DONE);
129
  tlp_gen();
130
  repeat (10000) @(posedge CLOCK);
131
}  // end of program ti_phy_top_test
132
 
133
// define tasks/classes/functions here if necessary
134
 
135
task clk_50mhz_gen () {
136
  ti_phy_top.clk_50mhz = 0;
137
  @(posedge ti_phy_top.rxclk);
138
  while(1) {
139
    @10 ti_phy_top.clk_50mhz = 1;
140
    @10 ti_phy_top.clk_50mhz = 0;
141
  }
142
}
143
 
144
task init_ports () {
145
  printf("Task init_ports\n");
146
  @(posedge ti_phy_top.rxclk);
147
  ti_phy_top.FPGA_RESET_n = 1'b0;
148
  ti_phy_top.rxdata16     = 16'b0;
149
  ti_phy_top.rxdatak16    = 2'b0;
150
  ti_phy_top.rxvalid16    = 1'b0;
151
  ti_phy_top.rxidle16     = 1'b0;
152
  ti_phy_top.rxstatus     = 1'b1;
153
  ti_phy_top.phystatus    = 1'b1;
154
}
155
 
156
task reset_sequence() {
157
  printf("Task phy bring up\n");
158
 
159
  @5 ti_phy_top.FPGA_RESET_n = 1'b0;
160
  @1 ti_phy_top.FPGA_RESET_n = 1'b1;
161
}
162
 
163
 
164
task phy_status () {
165
  bit [1:0] prev_pwrdwn = 0;
166
  integer loop_back_high;
167
  integer phy_status_arb;
168
  phy_status_arb = alloc(SEMAPHORE,0,1,1);
169
  if (!phy_status_arb) error ("Semaphore could not be allocated\n");
170
  printf("Look for power changes\n");
171
  @50 ti_phy_top.rxidle16    = 1'b0;
172
  @100 ti_phy_top.phystatus  = 1'b0;
173
    while (1){
174
      prev_pwrdwn = ti_phy_top.pwrdwn;
175
      @(posedge CLOCK);
176
      //receiver detect
177
      if (ti_phy_top.rxdet_loopb == 1'b1 && ti_phy_top.pwrdwn == 2'b10) {
178
        loop_back_high = 1;
179
        if (!semaphore_get(WAIT,phy_status_arb,1))
180
          error ("Semaphore_get returned 0\n");
181
        //printf("GOT PHY ARB1 /n");
182
        @10 ti_phy_top.rxstatus = 3'b11;
183
        @10 ti_phy_top.phystatus = 1'b1;
184
        while(loop_back_high) {
185
          @(posedge CLOCK);
186
          if (ti_phy_top.rxdet_loopb == 1'b0) {
187
            loop_back_high = 1'b0;
188
          }
189
        }
190
        @4 ti_phy_top.phystatus = 1'b0;
191
        ti_phy_top.rxstatus = 3'b0;
192
        semaphore_put (phy_status_arb, 1);
193
      }
194
      if (ti_phy_top.pwrdwn != prev_pwrdwn){
195
        if (!semaphore_get(WAIT,phy_status_arb,1))
196
          error ("Semaphore_get returned 0\n");
197
        //printf("GOT PHY ARB2 /n");
198
        @1 ti_phy_top.rxstatus = 3'b100;
199
        ti_phy_top.phystatus = 1'b1;
200
        @1 ti_phy_top.phystatus = 1'b0;
201
        if (ti_phy_top.pwrdwn == 2'b00) phy_rdy = 1;
202
        semaphore_put (phy_status_arb, 1);
203
 
204
      }
205
    }
206
}
207
 
208
 
209
 

powered by: WebSVN 2.1.0

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