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

Subversion Repositories i2cslave

[/] [i2cslave/] [trunk/] [bench/] [multiByteReadWrite.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
// ------------------ multiByteReadWrite.v ----------------------
2
`include "timescale.v"
3
`include "i2cSlaveTB_defines.v"
4
 
5
 
6
module multiByteReadWrite();
7
reg ack;
8
reg [31:0] readData;
9
reg [7:0] dataByteRead;
10
//reg [7:0] dataMSB;
11
 
12
// ------------------ write ----------------------
13
task write;
14
input [7:0] i2cAddr;
15
input [7:0] regAddr;
16
input [31:0] data;
17
input stop;
18
 
19
begin
20
  $write("I2C Write: At [0x%0x] = 0x%0x\n", regAddr, data);
21
 
22
  //i2c address
23
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, i2cAddr);
24
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h90); //STA, WR
25
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
26
  while (dataByteRead[1] == 1'b1) //while trans in progress
27
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
28
  //$write("I2C device address sent, SR = 0x%x\n", dataByteRead );
29
 
30
  //slave reg address
31
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, regAddr);
32
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h10); //WR
33
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
34
  while (dataByteRead[1] == 1'b1) //while trans in progress
35
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
36
  //$write("Slave reg address sent, SR = 0x%x\n", dataByteRead );
37
 
38
  //data[31:24]
39
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, data[31:24]);
40
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h10); //WR
41
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
42
  while (dataByteRead[1] == 1'b1) //while trans in progress
43
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
44
  //$write("Data[31:24] sent, SR = 0x%x\n", dataByteRead );
45
 
46
  //data[23:16]
47
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, data[23:16]);
48
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h10); //WR
49
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
50
  while (dataByteRead[1] == 1'b1) //while trans in progress
51
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
52
  //$write("Data[23:16] sent, SR = 0x%x\n", dataByteRead );
53
 
54
  //data[15:8]
55
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, data[15:8]);
56
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h10); //WR
57
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
58
  while (dataByteRead[1] == 1'b1) //while trans in progress
59
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
60
  //$write("Data[15:8] sent, SR = 0x%x\n", dataByteRead );
61
 
62
  //data[7:0]
63
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, data[7:0]);
64
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , {1'b0, stop, 6'b010000}); //STO?, WR
65
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
66
  while (dataByteRead[1] == 1'b1) //while trans in progress
67
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
68
  //$write("Data[7:0] sent, SR = 0x%x\n", dataByteRead );
69
 
70
end
71
endtask
72
 
73
// ------------------ read ----------------------
74
task read;
75
input [7:0] i2cAddr;
76
input [7:0] regAddr;
77
input [31:0] expectedData;
78
output [31:0] data;
79
input stop;
80
 
81
begin
82
 
83
  //i2c address
84
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, i2cAddr);  //write
85
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h90); //STA, WR
86
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
87
  while (dataByteRead[1] == 1'b1) //while trans in progress
88
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
89
  //$write("I2C device address sent, SR = 0x%x\n", dataByteRead );
90
  #5000;
91
 
92
  //slave reg address
93
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, regAddr);
94
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , {1'b0, stop, 6'b010000}); //STO?, WR
95
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
96
  while (dataByteRead[1] == 1'b1) //while trans in progress
97
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
98
  //$write("Slave reg address sent, SR = 0x%x\n", dataByteRead );
99
  #5000;
100
 
101
  //i2c address
102
  testHarness.u_wb_master_model.wb_write(1, `TXR_REG, {i2cAddr[7:1], 1'b1}); //read
103
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h90); //STA, WR
104
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
105
  while (dataByteRead[1] == 1'b1) //while trans in progress
106
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
107
  //$write("I2C device address sent, SR = 0x%x\n", dataByteRead );
108
 
109
  //data[31:24]
110
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h20); //RD, ACK
111
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
112
  while (dataByteRead[1] == 1'b1) //while trans in progress
113
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
114
  //$write("Data[31:24] rxed, SR = 0x%x\n", dataByteRead );
115
  testHarness.u_wb_master_model.wb_read(1, `RXR_REG, readData[31:24]);
116
 
117
  //data[23:16]
118
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h20); //RD, ACK
119
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
120
  while (dataByteRead[1] == 1'b1) //while trans in progress
121
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
122
  //$write("Data[23:16] rxed, SR = 0x%x\n", dataByteRead );
123
  testHarness.u_wb_master_model.wb_read(1, `RXR_REG, readData[23:16]);
124
 
125
  //data[15:8]
126
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , 8'h20); //RD, ACK
127
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
128
  while (dataByteRead[1] == 1'b1) //while trans in progress
129
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
130
  //$write("Data[15:8] rxed, SR = 0x%x\n", dataByteRead );
131
  testHarness.u_wb_master_model.wb_read(1, `RXR_REG, readData[15:8]);
132
 
133
  //data[7:0]
134
  testHarness.u_wb_master_model.wb_write(1, `CR_REG , {1'b0, 1'b0, 6'b101000}); //STO, RD, NAK
135
  testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
136
  while (dataByteRead[1] == 1'b1) //while trans in progress
137
    testHarness.u_wb_master_model.wb_read(1, `SR_REG , dataByteRead);
138
  //$write("Data[7:0] rxed, SR = 0x%x\n", dataByteRead );
139
  testHarness.u_wb_master_model.wb_read(1, `RXR_REG, readData[7:0]);
140
 
141
  data = readData;
142
  if (data != expectedData) begin
143
    $write("***** I2C Read ERROR: At 0x%0x. Expected 0x%0x, got 0x%0x\n", regAddr, expectedData, data);
144
    $stop;
145
  end
146
  else
147
    $write("I2C Read: At [0x%0x] = 0x%0x\n", regAddr, data);
148
end
149
endtask
150
 
151
endmodule
152
 

powered by: WebSVN 2.1.0

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