OpenCores

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [top/] [ptp_drv_bfm/] [ptp_drv_bfm.c] - Blame information for rev 24

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 edn_walter
#include <stdio.h>
2
 
3
#include "svdpi.h"
4
#include "../dpiheader.h"
5
int ptp_drv_bfm_c(double fw_delay)
6
{
7
  int cpu_addr_i;
8
  int cpu_data_i;
9
  int cpu_data_o;
10
 
11 22 edn_walter
  // LOAD RTC PERIOD AND ACC_MODULO
12
  cpu_addr_i = 0x00000020;
13
  cpu_data_i = 0x8;
14
  cpu_wr(cpu_addr_i, cpu_data_i);
15
  cpu_addr_i = 0x00000024;
16
  cpu_data_i = 0x0;
17
  cpu_wr(cpu_addr_i, cpu_data_i);
18
  cpu_addr_i = 0x00000028;
19
  cpu_data_i = 0x3B9ACA00;
20
  cpu_wr(cpu_addr_i, cpu_data_i);
21
  cpu_addr_i = 0x0000002C;
22
  cpu_data_i = 0x0;
23
  cpu_wr(cpu_addr_i, cpu_data_i);
24
  cpu_addr_i = 0x00000000;
25 23 edn_walter
  cpu_data_i = 0x0;
26
  cpu_wr(cpu_addr_i, cpu_data_i);
27
  cpu_addr_i = 0x00000000;
28 22 edn_walter
  cpu_data_i = 0x4;
29
  cpu_wr(cpu_addr_i, cpu_data_i);
30 23 edn_walter
  // RESET RTC
31 22 edn_walter
  cpu_addr_i = 0x00000000;
32
  cpu_data_i = 0x0;
33
  cpu_wr(cpu_addr_i, cpu_data_i);
34
  cpu_addr_i = 0x00000000;
35 24 edn_walter
  cpu_data_i = 0xA10;
36 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
37
  // LOAD RTC SEC AND NS
38
  cpu_addr_i = 0x00000010;
39
  cpu_data_i = 0x0;
40
  cpu_wr(cpu_addr_i, cpu_data_i);
41
  cpu_addr_i = 0x00000014;
42
  cpu_data_i = 0x1;
43
  cpu_wr(cpu_addr_i, cpu_data_i);
44
  cpu_addr_i = 0x00000018;
45
  cpu_data_i = 0x3B9AC9F6;
46
  cpu_wr(cpu_addr_i, cpu_data_i);
47
  cpu_addr_i = 0x0000001C;
48
  cpu_data_i = 0x0;
49
  cpu_wr(cpu_addr_i, cpu_data_i);
50
  cpu_addr_i = 0x00000000;
51 23 edn_walter
  cpu_data_i = 0x0;
52 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
53
  cpu_addr_i = 0x00000000;
54 23 edn_walter
  cpu_data_i = 0x8;
55 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
56
  // LOAD RTC ADJ
57
  cpu_addr_i = 0x00000030;
58
  cpu_data_i = 0x100;
59
  cpu_wr(cpu_addr_i, cpu_data_i);
60
  cpu_addr_i = 0x00000038;
61
  cpu_data_i = 0x1;
62
  cpu_wr(cpu_addr_i, cpu_data_i);
63
  cpu_addr_i = 0x0000003C;
64
  cpu_data_i = 0x20;
65
  cpu_wr(cpu_addr_i, cpu_data_i);
66
  cpu_addr_i = 0x00000000;
67 23 edn_walter
  cpu_data_i = 0x0;
68
  cpu_wr(cpu_addr_i, cpu_data_i);
69
  cpu_addr_i = 0x00000000;
70 22 edn_walter
  cpu_data_i = 0x2;
71
  cpu_wr(cpu_addr_i, cpu_data_i);
72 23 edn_walter
  // READ RTC SEC AND NS
73 22 edn_walter
  cpu_addr_i = 0x00000000;
74
  cpu_data_i = 0x0;
75
  cpu_wr(cpu_addr_i, cpu_data_i);
76
  cpu_addr_i = 0x00000000;
77
  cpu_data_i = 0x1;
78
  cpu_wr(cpu_addr_i, cpu_data_i);
79 24 edn_walter
  do {
80
    cpu_addr_i = 0x00000000;
81
    cpu_rd(cpu_addr_i, &cpu_data_o);
82
    //printf("%08x\n", (cpu_data_o & 0x1));
83
  } while ((cpu_data_o & 0x1) == 0x0);
84 23 edn_walter
  cpu_addr_i = 0X00000040;
85
  cpu_rd(cpu_addr_i, &cpu_data_o);
86
  cpu_addr_i = 0X00000044;
87
  cpu_rd(cpu_addr_i, &cpu_data_o);
88
  cpu_addr_i = 0X00000048;
89
  cpu_rd(cpu_addr_i, &cpu_data_o);
90
  cpu_addr_i = 0X0000004C;
91
  cpu_rd(cpu_addr_i, &cpu_data_o);
92
  // READ RTC SEC AND NS
93 22 edn_walter
  cpu_addr_i = 0x00000000;
94
  cpu_data_i = 0x0;
95
  cpu_wr(cpu_addr_i, cpu_data_i);
96 23 edn_walter
  cpu_addr_i = 0x00000000;
97
  cpu_data_i = 0x1;
98
  cpu_wr(cpu_addr_i, cpu_data_i);
99 24 edn_walter
  do {
100
    cpu_addr_i = 0x00000000;
101
    cpu_rd(cpu_addr_i, &cpu_data_o);
102
    //printf("%08x\n", (cpu_data_o & 0x1));
103
  } while ((cpu_data_o & 0x1) == 0x0);
104 22 edn_walter
  cpu_addr_i = 0X00000040;
105
  cpu_rd(cpu_addr_i, &cpu_data_o);
106
  cpu_addr_i = 0X00000044;
107
  cpu_rd(cpu_addr_i, &cpu_data_o);
108
  cpu_addr_i = 0X00000048;
109
  cpu_rd(cpu_addr_i, &cpu_data_o);
110
  cpu_addr_i = 0X0000004C;
111
  cpu_rd(cpu_addr_i, &cpu_data_o);
112
 
113 24 edn_walter
  int i;
114
  // POLL TSU RX STATUS
115
  int rx_queue_num;
116
  do {
117
    cpu_addr_i = 0x00000004;
118
    cpu_rd(cpu_addr_i, &cpu_data_o);
119
    rx_queue_num = cpu_data_o;
120
    //printf("%08x\n", rx_queue_num);
121
  } while (!(rx_queue_num > 0x2));
122
  // READ TSU RX FIFO
123
  for (i=rx_queue_num; i>=0; i--) {
124
      cpu_addr_i = 0x00000000;
125
      cpu_data_i = 0x0;
126
      cpu_wr(cpu_addr_i, cpu_data_i);
127
      cpu_addr_i = 0x00000000;
128
      cpu_data_i = 0x400;
129
      cpu_wr(cpu_addr_i, cpu_data_i);
130
      cpu_addr_i = 0x00000050;
131
      cpu_rd(cpu_addr_i, &cpu_data_o);
132
      cpu_addr_i = 0x00000054;
133
      cpu_rd(cpu_addr_i, &cpu_data_o);
134
  }
135
  // POLL TSU TX STATUS
136
  int tx_queue_num;
137
  do {
138
    cpu_addr_i = 0x00000008;
139
    cpu_rd(cpu_addr_i, &cpu_data_o);
140
    tx_queue_num = cpu_data_o;
141
    //printf("%08x\n", tx_queue_num);
142
  } while (!(tx_queue_num > 0x2));
143
  // READ TSU TX FIFO
144
  for (i=tx_queue_num; i>=0; i--) {
145
      cpu_addr_i = 0x00000000;
146
      cpu_data_i = 0x0;
147
      cpu_wr(cpu_addr_i, cpu_data_i);
148
      cpu_addr_i = 0x00000000;
149
      cpu_data_i = 0x100;
150
      cpu_wr(cpu_addr_i, cpu_data_i);
151
      cpu_addr_i = 0x00000058;
152
      cpu_rd(cpu_addr_i, &cpu_data_o);
153
      cpu_addr_i = 0x0000005C;
154
      cpu_rd(cpu_addr_i, &cpu_data_o);
155
  }
156
 
157 22 edn_walter
  // READ BACK ALL REGISTERS
158
  for (;;)
159 21 edn_walter
  {
160 22 edn_walter
    int t;
161
    for (t=0; t<=0x5c; t=t+4)
162
    {
163 24 edn_walter
      cpu_hd(10);
164
 
165 22 edn_walter
      cpu_addr_i = t;
166 21 edn_walter
      cpu_rd(cpu_addr_i, &cpu_data_o);
167 22 edn_walter
    }
168 21 edn_walter
  }
169
 
170
  return(0); /* Return success (required by tasks) */
171
}

powered by: WebSVN 2.1.0

© copyright 1999-2014 OpenCores.org, equivalent to ORSoC AB, all rights reserved. OpenCores®, registered trademark.