x393  1.0
FPGAcodeforElphelNC393camera
All Classes Namespaces Files Functions Variables
sensor_i2c_io.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
41 module sensor_i2c_io#(
42  parameter SENSI2C_ABS_ADDR = 'h410,
43  parameter SENSI2C_REL_ADDR = 'h420,
44  parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR
45  parameter SENSI2C_CTRL_ADDR = 'h402, // channel 0 will be 'h402..'h403
46  parameter SENSI2C_CTRL_MASK = 'h7fe,
47  parameter SENSI2C_CTRL = 'h0,
48  parameter SENSI2C_STATUS = 'h1,
49  parameter SENSI2C_STATUS_REG = 'h20,
50  // Control register bits
51  parameter SENSI2C_CMD_TABLE = 29, // [29]: 1 - write to translation table (ignore any other fields), 0 - write other fields
52  parameter SENSI2C_CMD_TAND = 28, // [28]: 1 - write table address (8 bits), 0 - write table data (28 bits)
53  parameter SENSI2C_CMD_RESET = 14, // [14] reset all FIFO (takes 16 clock pulses), also - stops i2c until run command
54  parameter SENSI2C_CMD_RUN = 13, // [13:12]3 - run i2c, 2 - stop i2c (needed before software i2c), 1,0 - no change to run state
55  parameter SENSI2C_CMD_RUN_PBITS = 1,
56  parameter SENSI2C_CMD_SOFT_SDA = 6, // [7:6] - SDA software control: 0 - nop, 1 - low, 2 - active high, 3 - float
57  parameter SENSI2C_CMD_SOFT_SCL = 4, // [5:4] - SCL software control: 0 - nop, 1 - low, 2 - active high, 3 - float
58  parameter SENSI2C_CMD_FIFO_RD = 3, // advance I2C read data FIFO by 1
59  parameter SENSI2C_CMD_ACIVE = 2, // [2] - SENSI2C_CMD_ACIVE_EARLY0, SENSI2C_CMD_ACIVE_SDA
60  parameter SENSI2C_CMD_ACIVE_EARLY0 = 1, // release SDA==0 early if next bit ==1
61  parameter SENSI2C_CMD_ACIVE_SDA = 0, // drive SDA=1 during the second half of SCL=1
62  //i2c page table bit fields
63  parameter SENSI2C_TBL_RAH = 0, // high byte of the register address
64  parameter SENSI2C_TBL_RAH_BITS = 8,
65  parameter SENSI2C_TBL_RNWREG = 8, // read register (when 0 - write register
66  parameter SENSI2C_TBL_SA = 9, // Slave address in write mode
67  parameter SENSI2C_TBL_SA_BITS = 7,
68  parameter SENSI2C_TBL_NBWR = 16, // number of bytes to write (1..10)
69  parameter SENSI2C_TBL_NBWR_BITS = 4,
70  parameter SENSI2C_TBL_NBRD = 16, // number of bytes to read (1 - 8) "0" means "8"
71  parameter SENSI2C_TBL_NBRD_BITS = 3,
72  parameter SENSI2C_TBL_NABRD = 19, // number of address bytes for read (0 - 1 byte, 1 - 2 bytes)
73  parameter SENSI2C_TBL_DLY = 20, // bit delay (number of mclk periods in 1/4 of SCL period)
74  parameter SENSI2C_TBL_DLY_BITS= 8,
75 // I/O parameters
76  parameter integer SENSI2C_DRIVE = 12,
77  parameter SENSI2C_IBUF_LOW_PWR = "TRUE",
78 `ifdef HISPI
79  parameter SENSI2C_IOSTANDARD = "LVCMOS18",
80 `else
81  parameter SENSI2C_IOSTANDARD = "LVCMOS25",
82 `endif
83  parameter SENSI2C_SLEW = "SLOW",
84  parameter NUM_FRAME_BITS = 4
85 )(
86  input mrst, // @mclk
87  input mclk, // global clock, half DDR3 clock, synchronizes all I/O through the command port
88  input [7:0] cmd_ad, // byte-serial command address/data (up to 6 bytes: AL-AH-D0-D1-D2-D3
89  input cmd_stb, // strobe (with first byte) for the command a/d
90  output [7:0] status_ad, // status address/data - up to 5 bytes: A - {seq,status[1:0]} - status[2:9] - status[10:17] - status[18:25]
91  output status_rq, // input request to send status downstream
92  input status_start,// Acknowledge of the first status packet byte (address)
93  input frame_sync, // increment/reset frame number
94  input [NUM_FRAME_BITS-1:0] frame_num_seq, // frame number from the command sequencer (to sync i2c)
95  inout scl,
96  inout sda
97 );
98  wire scl_in;
99  wire sda_in;
100  wire scl_out;
101  wire sda_out;
102  wire scl_en;
103  wire sda_en;
104 
105  sensor_i2c #(
125  .SENSI2C_TBL_RAH (SENSI2C_TBL_RAH), // high byte of the register address
127  .SENSI2C_TBL_RNWREG (SENSI2C_TBL_RNWREG), // read register (when 0 - write register
128  .SENSI2C_TBL_SA (SENSI2C_TBL_SA), // Slave address in write mode
130  .SENSI2C_TBL_NBWR (SENSI2C_TBL_NBWR), // number of bytes to write (1..10)
132  .SENSI2C_TBL_NBRD (SENSI2C_TBL_NBRD), // number of bytes to read (1 - 8) "0" means "8"
134  .SENSI2C_TBL_NABRD (SENSI2C_TBL_NABRD), // number of address bytes for read (0 - 1 byte, 1 - 2 bytes)
135  .SENSI2C_TBL_DLY (SENSI2C_TBL_DLY), // bit delay (number of mclk periods in 1/4 of SCL period)
138  ) sensor_i2c_i (
139  .mrst (mrst), // input
140  .mclk (mclk), // input
141  .cmd_ad (cmd_ad), // input[7:0]
142  .cmd_stb (cmd_stb), // input
143  .status_ad (status_ad), // output[7:0]
144  .status_rq (status_rq), // output
145  .status_start (status_start), // input
146  .frame_sync (frame_sync), // input
147  .frame_num_seq (frame_num_seq), // input[3:0]
148  .scl_in (scl_in), // input
149  .sda_in (sda_in), // input
150  .scl_out (scl_out), // output
151  .sda_out (sda_out), // output
152  .scl_en (scl_en), // output
153  .sda_en (sda_en) // output
154  );
155 
156  iobuf #(
157  .DRIVE (SENSI2C_DRIVE),
158  .IBUF_LOW_PWR (SENSI2C_IBUF_LOW_PWR),
159  .IOSTANDARD (SENSI2C_IOSTANDARD),
160  .SLEW (SENSI2C_SLEW)
161  ) iobuf_scl_i (
162  .O (scl_in), // output
163  .IO (scl), // inout
164  .I (scl_out), // input
165  .T (!scl_en) // input
166  );
167 
168  iobuf #(
169  .DRIVE (SENSI2C_DRIVE),
170  .IBUF_LOW_PWR (SENSI2C_IBUF_LOW_PWR),
171  .IOSTANDARD (SENSI2C_IOSTANDARD),
172  .SLEW (SENSI2C_SLEW)
173  ) iobuf_sda_i (
174  .O (sda_in), // output
175  .IO (sda), // inout
176  .I (sda_out), // input
177  .T (!sda_en) // input
178  );
179 // So simulation will show different when SDA is not driven
180 `ifndef SIMULATION
181  mpullup i_scl_pullup(scl);
182  mpullup i_sda_pullup(sda);
183 `endif
184 
185 endmodule
186 
187 
8270SENSI2C_STATUS_REG'h20
Definition: sensor_i2c_io.v:49
iobuf_sda_i iobuf
8290SENSI2C_TBL_NBRD_BITS3
Definition: sensor_i2c_io.v:71
[7:0] 8183cmd_ad
Definition: sensor_i2c.v:80
i_sda_pullup mpullup
8264SENSI2C_REL_ADDR'h420
Definition: sensor_i2c_io.v:43
8266SENSI2C_CTRL_ADDR'h402
Definition: sensor_i2c_io.v:45
11290T
Definition: iobuf.v:51
8275SENSI2C_CMD_RUN_PBITS1
Definition: sensor_i2c_io.v:55
sensor_i2c_i sensor_i2c
8296SENSI2C_IOSTANDARD"LVCMOS18"
Definition: sensor_i2c_io.v:79
[7:0] 8303status_ad
Definition: sensor_i2c_io.v:88
integer 8294SENSI2C_DRIVE12
Definition: sensor_i2c_io.v:76
8263SENSI2C_ABS_ADDR'h410
Definition: sensor_i2c_io.v:42
[7:0] 8301cmd_ad
Definition: sensor_i2c_io.v:86
8187status_start
Definition: sensor_i2c.v:88
8281SENSI2C_CMD_ACIVE_SDA0
Definition: sensor_i2c_io.v:61
11288IO
Definition: iobuf.v:49
8295SENSI2C_IBUF_LOW_PWR"TRUE"
Definition: sensor_i2c_io.v:77
[NUM_FRAME_BITS-1:0] 8307frame_num_seq
Definition: sensor_i2c_io.v:92
8265SENSI2C_ADDR_MASK'h7f0
Definition: sensor_i2c_io.v:44
8280SENSI2C_CMD_ACIVE_EARLY01
Definition: sensor_i2c_io.v:60
8288SENSI2C_TBL_NBWR_BITS4
Definition: sensor_i2c_io.v:69
[NUM_FRAME_BITS-1:0] 8189frame_num_seq
Definition: sensor_i2c.v:90
[7:0] 8185status_ad
Definition: sensor_i2c.v:86
11287O
Definition: iobuf.v:48
8297SENSI2C_SLEW"SLOW"
Definition: sensor_i2c_io.v:81
8267SENSI2C_CTRL_MASK'h7fe
Definition: sensor_i2c_io.v:46
11289I
Definition: iobuf.v:50