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

Subversion Repositories ha1588

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

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

Line No. Rev Author Line
1 34 edn_walter
/*
2
 * $ptp_drv_bfm.c
3
 *
4 37 edn_walter
 * Copyright (c) 2012, BABY&HW. All rights reserved.
5 34 edn_walter
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301  USA
20
 */
21
 
22 21 edn_walter
#include <stdio.h>
23
 
24
#include "svdpi.h"
25
#include "../dpiheader.h"
26 33 edn_walter
 
27
// define RTC address values
28
#define RTC_CTRL            0x00000000
29
#define RTC_NULL_0x4        0x00000004
30
#define RTC_NULL_0x8        0x00000008
31
#define RTC_NULL_0xC        0x0000000C
32
#define RTC_TIME_SEC_H_LOAD 0x00000010
33
#define RTC_TIME_SEC_L_LOAD 0x00000014
34
#define RTC_TIME_NSC_H_LOAD 0x00000018
35
#define RTC_TIME_NSC_L_LOAD 0x0000001C
36
#define RTC_PERIOD_H_LOAD   0x00000020
37
#define RTC_PERIOD_L_LOAD   0x00000024
38
#define RTC_ACCMOD_H_LOAD   0x00000028
39
#define RTC_ACCMOD_L_LOAD   0x0000002C
40
#define RTC_ADJNUM_LOAD     0x00000030
41
#define RTC_NULL_0x34       0x00000034
42
#define RTC_ADJPER_H_LOAD   0x00000038
43
#define RTC_ADJPER_L_LOAD   0x0000003C
44
#define RTC_TIME_SEC_H_READ 0x00000040
45
#define RTC_TIME_SEC_L_READ 0x00000044
46
#define RTC_TIME_NSC_H_READ 0x00000048
47
#define RTC_TIME_NSC_L_READ 0x0000004C
48
// define RTC data values
49
#define RTC_SET_CTRL_0 0x0
50
#define RTC_GET_TIME   0x1
51
#define RTC_SET_ADJ    0x2
52
#define RTC_SET_PERIOD 0x4
53
#define RTC_SET_TIME   0x8
54
#define RTC_SET_RESET  0x10
55
#define RTC_ACCMOD_H   0x3B9ACA00  // 1,000,000,000 for 30bit
56
#define RTC_ACCMOD_L   0x0         // 256 for 8bit
57 37 edn_walter
#define RTC_PERIOD_H   0x8         // 8ns for 125MHz rtc_clk
58 33 edn_walter
#define RTC_PERIOD_L   0x0
59
 
60
// define TSU address values
61 37 edn_walter
#define TSU_CTRL          0x00000050
62
#define TSU_RXQUE_STATUS  0x00000054
63
#define TSU_TXQUE_STATUS  0x00000058
64
#define TSU_NULL_0x5C     0x0000005C
65
#define TSU_RXQUE_DATA_HH 0x00000060
66
#define TSU_RXQUE_DATA_HL 0x00000064
67
#define TSU_RXQUE_DATA_LH 0x00000068
68
#define TSU_RXQUE_DATA_LL 0x0000006C
69
#define TSU_TXQUE_DATA_HH 0x00000070
70
#define TSU_TXQUE_DATA_HL 0x00000074
71
#define TSU_TXQUE_DATA_LH 0x00000078
72
#define TSU_TXQUE_DATA_LL 0x0000007C
73 33 edn_walter
// define TSU data values
74
#define TSU_SET_CTRL_0 0x0
75
#define TSU_GET_TXQUE  0x1
76
#define TSU_GET_RXQUE  0x4
77 37 edn_walter
#define TSU_SET_RXRST  0x8
78
#define TSU_SET_TXRST  0x2
79 33 edn_walter
 
80 21 edn_walter
int ptp_drv_bfm_c(double fw_delay)
81
{
82 26 edn_walter
  unsigned int cpu_addr_i;
83
  unsigned int cpu_data_i;
84
  unsigned int cpu_data_o;
85 21 edn_walter
 
86 22 edn_walter
  // LOAD RTC PERIOD AND ACC_MODULO
87 33 edn_walter
  cpu_addr_i = RTC_PERIOD_H_LOAD;
88
  cpu_data_i = RTC_PERIOD_H;
89 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
90 37 edn_walter
 
91 33 edn_walter
  cpu_addr_i = RTC_PERIOD_L_LOAD;
92
  cpu_data_i = RTC_PERIOD_L;
93 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
94 37 edn_walter
 
95 33 edn_walter
  cpu_addr_i = RTC_ACCMOD_H_LOAD;
96
  cpu_data_i = RTC_ACCMOD_H;
97 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
98 37 edn_walter
 
99 33 edn_walter
  cpu_addr_i = RTC_ACCMOD_L_LOAD;
100
  cpu_data_i = RTC_ACCMOD_L;
101 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
102 37 edn_walter
 
103 33 edn_walter
  cpu_addr_i = RTC_CTRL;
104
  cpu_data_i = RTC_SET_CTRL_0;
105 23 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
106 37 edn_walter
 
107 33 edn_walter
  cpu_addr_i = RTC_CTRL;
108
  cpu_data_i = RTC_SET_PERIOD;
109 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
110 37 edn_walter
 
111
  // RESET RTC
112 33 edn_walter
  cpu_addr_i = RTC_CTRL;
113
  cpu_data_i = RTC_SET_CTRL_0;
114 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
115 37 edn_walter
 
116 33 edn_walter
  cpu_addr_i = RTC_CTRL;
117
  cpu_data_i = RTC_SET_RESET;
118 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
119 37 edn_walter
 
120 26 edn_walter
  // READ RTC SEC AND NS
121 33 edn_walter
  cpu_addr_i = RTC_CTRL;
122
  cpu_data_i = RTC_SET_CTRL_0;
123 26 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
124 37 edn_walter
 
125 33 edn_walter
  cpu_addr_i = RTC_CTRL;
126
  cpu_data_i = RTC_GET_TIME;
127 26 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
128 37 edn_walter
 
129 26 edn_walter
  do {
130 33 edn_walter
    cpu_addr_i = RTC_CTRL;
131 26 edn_walter
    cpu_rd(cpu_addr_i, &cpu_data_o);
132
    //printf("%08x\n", (cpu_data_o & 0x1));
133 33 edn_walter
  } while ((cpu_data_o & RTC_GET_TIME) == 0x0);
134 37 edn_walter
 
135 33 edn_walter
  cpu_addr_i = RTC_TIME_SEC_H_READ;
136 26 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
137
  printf("\ntime: \n%08x\n", cpu_data_o);
138 37 edn_walter
 
139 33 edn_walter
  cpu_addr_i = RTC_TIME_SEC_L_READ;
140 26 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
141
  printf("%08x\n", cpu_data_o);
142 37 edn_walter
 
143 33 edn_walter
  cpu_addr_i = RTC_TIME_NSC_H_READ;
144 26 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
145
  printf("%08x\n", cpu_data_o);
146 37 edn_walter
 
147 33 edn_walter
  cpu_addr_i = RTC_TIME_NSC_L_READ;
148 26 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
149
  printf("%08x\n", cpu_data_o);
150 37 edn_walter
 
151 22 edn_walter
  // LOAD RTC SEC AND NS
152 33 edn_walter
  cpu_addr_i = RTC_TIME_SEC_H_LOAD;
153 22 edn_walter
  cpu_data_i = 0x0;
154
  cpu_wr(cpu_addr_i, cpu_data_i);
155 37 edn_walter
 
156 33 edn_walter
  cpu_addr_i = RTC_TIME_SEC_L_LOAD;
157 22 edn_walter
  cpu_data_i = 0x1;
158
  cpu_wr(cpu_addr_i, cpu_data_i);
159 37 edn_walter
 
160 33 edn_walter
  cpu_addr_i = RTC_TIME_NSC_H_LOAD;
161
  cpu_data_i = RTC_ACCMOD_H - 0xA;
162 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
163 37 edn_walter
 
164 33 edn_walter
  cpu_addr_i = RTC_TIME_NSC_L_LOAD;
165 22 edn_walter
  cpu_data_i = 0x0;
166
  cpu_wr(cpu_addr_i, cpu_data_i);
167 37 edn_walter
 
168 33 edn_walter
  cpu_addr_i = RTC_CTRL;
169
  cpu_data_i = RTC_SET_CTRL_0;
170 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
171 37 edn_walter
 
172 33 edn_walter
  cpu_addr_i = RTC_CTRL;
173
  cpu_data_i = RTC_SET_TIME;
174 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
175 37 edn_walter
 
176 22 edn_walter
  // LOAD RTC ADJ
177 33 edn_walter
  cpu_addr_i = RTC_ADJNUM_LOAD;
178 22 edn_walter
  cpu_data_i = 0x100;
179
  cpu_wr(cpu_addr_i, cpu_data_i);
180 37 edn_walter
 
181 33 edn_walter
  cpu_addr_i = RTC_ADJPER_H_LOAD;
182 22 edn_walter
  cpu_data_i = 0x1;
183
  cpu_wr(cpu_addr_i, cpu_data_i);
184 37 edn_walter
 
185 33 edn_walter
  cpu_addr_i = RTC_ADJPER_L_LOAD;
186 22 edn_walter
  cpu_data_i = 0x20;
187
  cpu_wr(cpu_addr_i, cpu_data_i);
188 37 edn_walter
 
189 33 edn_walter
  cpu_addr_i = RTC_CTRL;
190
  cpu_data_i = RTC_SET_CTRL_0;
191 23 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
192 37 edn_walter
 
193 33 edn_walter
  cpu_addr_i = RTC_CTRL;
194
  cpu_data_i = RTC_SET_ADJ;
195 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
196 37 edn_walter
 
197 23 edn_walter
  // READ RTC SEC AND NS
198 33 edn_walter
  cpu_addr_i = RTC_CTRL;
199
  cpu_data_i = RTC_SET_CTRL_0;
200 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
201 37 edn_walter
 
202 33 edn_walter
  cpu_addr_i = RTC_CTRL;
203
  cpu_data_i = RTC_GET_TIME;
204 22 edn_walter
  cpu_wr(cpu_addr_i, cpu_data_i);
205 37 edn_walter
 
206 24 edn_walter
  do {
207 33 edn_walter
    cpu_addr_i = RTC_CTRL;
208 24 edn_walter
    cpu_rd(cpu_addr_i, &cpu_data_o);
209
    //printf("%08x\n", (cpu_data_o & 0x1));
210 33 edn_walter
  } while ((cpu_data_o & RTC_GET_TIME) == 0x0);
211 37 edn_walter
 
212 33 edn_walter
  cpu_addr_i = RTC_TIME_SEC_H_READ;
213 23 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
214 26 edn_walter
  printf("\ntime: \n%08x\n", cpu_data_o);
215 37 edn_walter
 
216 33 edn_walter
  cpu_addr_i = RTC_TIME_SEC_L_READ;
217 23 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
218 26 edn_walter
  printf("%08x\n", cpu_data_o);
219 37 edn_walter
 
220 33 edn_walter
  cpu_addr_i = RTC_TIME_NSC_H_READ;
221 23 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
222 26 edn_walter
  printf("%08x\n", cpu_data_o);
223 37 edn_walter
 
224 33 edn_walter
  cpu_addr_i = RTC_TIME_NSC_L_READ;
225 23 edn_walter
  cpu_rd(cpu_addr_i, &cpu_data_o);
226 26 edn_walter
  printf("%08x\n", cpu_data_o);
227 22 edn_walter
 
228 24 edn_walter
  int i;
229 33 edn_walter
  int rx_queue_num;
230
  int tx_queue_num;
231 37 edn_walter
 
232
  // RESET TSU
233
  cpu_addr_i = TSU_CTRL;
234
  cpu_data_i = TSU_SET_CTRL_0;
235
  cpu_wr(cpu_addr_i, cpu_data_i);
236
 
237
  cpu_addr_i = TSU_CTRL;
238
  cpu_data_i = TSU_SET_RXRST + TSU_SET_TXRST;
239
  cpu_wr(cpu_addr_i, cpu_data_i);
240
 
241
  // READ TSU
242 33 edn_walter
  while (1) {
243 37 edn_walter
 
244
    // POLL TSU RX STATUS
245
    cpu_addr_i = TSU_RXQUE_STATUS;
246
    cpu_rd(cpu_addr_i, &cpu_data_o);
247
    rx_queue_num = cpu_data_o;
248
    //printf("%08x\n", rx_queue_num);
249
 
250
    if (rx_queue_num > 0x0) {
251
      for (i=rx_queue_num; i>0; i--) {
252
 
253
        // READ TSU RX FIFO
254 33 edn_walter
        cpu_addr_i = TSU_CTRL;
255 37 edn_walter
        cpu_data_i = TSU_SET_CTRL_0;
256
        cpu_wr(cpu_addr_i, cpu_data_i);
257
 
258
        cpu_addr_i = TSU_CTRL;
259
        cpu_data_i = TSU_GET_RXQUE;
260
        cpu_wr(cpu_addr_i, cpu_data_i);
261
 
262
        do {
263
          cpu_addr_i = TSU_CTRL;
264
          cpu_rd(cpu_addr_i, &cpu_data_o);
265
          //printf("%08x\n", (cpu_data_o & 0x1));
266
        } while ((cpu_data_o & TSU_GET_RXQUE) == 0x0);
267
 
268
        cpu_addr_i = TSU_RXQUE_DATA_HH;
269 31 edn_walter
        cpu_rd(cpu_addr_i, &cpu_data_o);
270 37 edn_walter
        printf("\nRx stamp: \n%08x\n", cpu_data_o);
271
 
272
        cpu_addr_i = TSU_RXQUE_DATA_HL;
273
        cpu_rd(cpu_addr_i, &cpu_data_o);
274
        printf("%08x\n", cpu_data_o);
275
 
276
        cpu_addr_i = TSU_RXQUE_DATA_LH;
277
        cpu_rd(cpu_addr_i, &cpu_data_o);
278
        printf("%08x\n", cpu_data_o);
279
 
280
        cpu_addr_i = TSU_RXQUE_DATA_LL;
281
        cpu_rd(cpu_addr_i, &cpu_data_o);
282
        printf("%08x\n", cpu_data_o);
283
 
284
        // READ RTC SEC AND NS
285
        cpu_addr_i = RTC_CTRL;
286
        cpu_data_i = RTC_SET_CTRL_0;
287
        cpu_wr(cpu_addr_i, cpu_data_i);
288
 
289
        cpu_addr_i = RTC_CTRL;
290
        cpu_data_i = RTC_GET_TIME;
291
        cpu_wr(cpu_addr_i, cpu_data_i);
292
 
293
        do {
294
          cpu_addr_i = RTC_CTRL;
295
          cpu_rd(cpu_addr_i, &cpu_data_o);
296
          //printf("%08x\n", (cpu_data_o & 0x1));
297
        } while ((cpu_data_o & RTC_GET_TIME) == 0x0);
298
 
299
        cpu_addr_i = RTC_TIME_SEC_H_READ;
300
        cpu_rd(cpu_addr_i, &cpu_data_o);
301
        printf("\ntime: \n%08x\n", cpu_data_o);
302
 
303
        cpu_addr_i = RTC_TIME_SEC_L_READ;
304
        cpu_rd(cpu_addr_i, &cpu_data_o);
305
        printf("%08x\n", cpu_data_o);
306
 
307
        cpu_addr_i = RTC_TIME_NSC_H_READ;
308
        cpu_rd(cpu_addr_i, &cpu_data_o);
309
        printf("%08x\n", cpu_data_o);
310
 
311
        cpu_addr_i = RTC_TIME_NSC_L_READ;
312
        cpu_rd(cpu_addr_i, &cpu_data_o);
313
        printf("%08x\n", cpu_data_o);
314
      }
315 33 edn_walter
    }
316 37 edn_walter
 
317
    // POLL TSU TX STATUS
318
    cpu_addr_i = TSU_TXQUE_STATUS;
319
    cpu_rd(cpu_addr_i, &cpu_data_o);
320
    tx_queue_num = cpu_data_o;
321
    //printf("%08x\n", tx_queue_num);
322
 
323
    if (tx_queue_num > 0x0) {
324
      for (i=tx_queue_num; i>0; i--) {
325
 
326
        // READ TSU TX FIFO
327 33 edn_walter
        cpu_addr_i = TSU_CTRL;
328 37 edn_walter
        cpu_data_i = TSU_SET_CTRL_0;
329
        cpu_wr(cpu_addr_i, cpu_data_i);
330
 
331
        cpu_addr_i = TSU_CTRL;
332
        cpu_data_i = TSU_GET_TXQUE;
333
        cpu_wr(cpu_addr_i, cpu_data_i);
334
 
335
        do {
336
          cpu_addr_i = TSU_CTRL;
337
          cpu_rd(cpu_addr_i, &cpu_data_o);
338
          //printf("%08x\n", (cpu_data_o & 0x1));
339
        } while ((cpu_data_o & TSU_GET_TXQUE) == 0x0);
340
 
341
        cpu_addr_i = TSU_TXQUE_DATA_HH;
342 31 edn_walter
        cpu_rd(cpu_addr_i, &cpu_data_o);
343 37 edn_walter
        printf("\nTx stamp: \n%08x\n", cpu_data_o);
344
 
345
        cpu_addr_i = TSU_TXQUE_DATA_HL;
346
        cpu_rd(cpu_addr_i, &cpu_data_o);
347
        printf("%08x\n", cpu_data_o);
348
 
349
        cpu_addr_i = TSU_TXQUE_DATA_LH;
350
        cpu_rd(cpu_addr_i, &cpu_data_o);
351
        printf("%08x\n", cpu_data_o);
352
 
353
         cpu_addr_i = TSU_TXQUE_DATA_LL;
354
        cpu_rd(cpu_addr_i, &cpu_data_o);
355
        printf("%08x\n", cpu_data_o);
356
 
357
        // READ RTC SEC AND NS
358
        cpu_addr_i = RTC_CTRL;
359
        cpu_data_i = RTC_SET_CTRL_0;
360
        cpu_wr(cpu_addr_i, cpu_data_i);
361
 
362
        cpu_addr_i = RTC_CTRL;
363
        cpu_data_i = RTC_GET_TIME;
364
        cpu_wr(cpu_addr_i, cpu_data_i);
365
 
366
        do {
367
          cpu_addr_i = RTC_CTRL;
368
          cpu_rd(cpu_addr_i, &cpu_data_o);
369
          //printf("%08x\n", (cpu_data_o & 0x1));
370
        } while ((cpu_data_o & RTC_GET_TIME) == 0x0);
371
 
372
        cpu_addr_i = RTC_TIME_SEC_H_READ;
373
        cpu_rd(cpu_addr_i, &cpu_data_o);
374
        printf("\ntime: \n%08x\n", cpu_data_o);
375
 
376
        cpu_addr_i = RTC_TIME_SEC_L_READ;
377
        cpu_rd(cpu_addr_i, &cpu_data_o);
378
        printf("%08x\n", cpu_data_o);
379
 
380
        cpu_addr_i = RTC_TIME_NSC_H_READ;
381
        cpu_rd(cpu_addr_i, &cpu_data_o);
382
        printf("%08x\n", cpu_data_o);
383
 
384
        cpu_addr_i = RTC_TIME_NSC_L_READ;
385
        cpu_rd(cpu_addr_i, &cpu_data_o);
386
        printf("%08x\n", cpu_data_o);
387
      }
388 33 edn_walter
    }
389 24 edn_walter
  }
390
 
391 22 edn_walter
  // READ BACK ALL REGISTERS
392
  for (;;)
393 21 edn_walter
  {
394 22 edn_walter
    int t;
395 37 edn_walter
    for (t=0; t<=0xff; t=t+4)
396 22 edn_walter
    {
397 24 edn_walter
      cpu_hd(10);
398
 
399 22 edn_walter
      cpu_addr_i = t;
400 21 edn_walter
      cpu_rd(cpu_addr_i, &cpu_data_o);
401 22 edn_walter
    }
402 21 edn_walter
  }
403
 
404
  return(0); /* Return success (required by tasks) */
405
}

powered by: WebSVN 2.1.0

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