x393  1.0
FPGAcodeforElphelNC393camera
gpio393.v
Go to the documentation of this file.
1 
40 `timescale 1ns/1ps
41 
42 
43 // update to eliminate need for a shadow register
44 // each pair of data bits at write cycle control the data and enable in the following way:
45 // bit 1 bit 0 dibit enable data
46 // 0 0 0 - no change -
47 // 0 1 1 1 0
48 // 1 0 2 1 1
49 // 1 1 3 0 0
50 
51 
52 //Unified IO control for the 6 pins that are connected from the FPGA to the inter-board 16-pin connector
53 // those pins were controlled (in models 303, 313, 323 and earlier 333) by the control register, status was
54 // read through the status register.
55 
56 // Now each pin will be controlled by 2 bits (data+enable), total 12 bits that will come from one of 4 sources
57 // selected by bits [13:12] of the new control word:
58 // 0 - use bits [11:0] of the control word
59 // 1 - use channel A (camsync)
60 // 2 - use channel B (tbd)
61 // 3 - use channel C (tbd)
62 // Updating logic
63 // global enable signals (disabled channel will not compete for per-biot access)
64 // next 4 enable signals are controlled by bit pairs (0X - don't change, 10 - disable, 11 - enable)
65 // bit [25:24] - enable software bits (contolled by bits [23:0] (on at powerup)
66 // bit [27:26] - enable chn. A
67 // bit [29:28] - enable chn. B
68 // bit [31:30] - enable chn. C
69 // Enabled bits will be priority encoded (C - highest, software - lowest)
70 module gpio393 #(
71  parameter GPIO_ADDR = 'h700, //TODO: assign valid address
72  parameter GPIO_MASK = 'h7fe,
73  parameter GPIO_STATUS_REG_ADDR = 'h30, // address where status can be read out (10 GPIO inputs)
74 
75  parameter integer GPIO_DRIVE = 12,
76  parameter GPIO_IBUF_LOW_PWR = "TRUE",
77  parameter GPIO_IOSTANDARD = "DEFAULT", // power is 1.5V
78  parameter GPIO_SLEW = "SLOW",
79 
80  parameter GPIO_SET_PINS = 0, // Set GPIO output state, give control for some bits to other modules
81  parameter GPIO_SET_STATUS = 1, // set status mode
82  parameter GPIO_N = 10, // number of GPIO bits to control
83  parameter GPIO_PORTEN = 24 // bit number to control port enables (up from this)
84 
85  ) (
86 // input rst, // global reset
87  input mclk, // system clock
88  input mrst, // @posedge mclk, sync reset
89  input [7:0] cmd_ad, // byte-serial command address/data (up to 6 bytes: AL-AH-D0-D1-D2-D3
90  input cmd_stb, // strobe (with first byte) for the command a/d
91 
92  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]
93  output status_rq, // input request to send status downstream
94  input status_start, // Acknowledge of the first status packet byte (address)
95 
96  inout [GPIO_N-1:0] ext_pins, // GPIO pins (1.5V): assigned in 10389: [1:0] - i2c, [5:2] - gpio, [GPIO_N-1:6] - sync i/o
97  output [GPIO_N-1:0] io_pins, // values on the gpio pins (to use by other modules on ports A,B,C)
98 
99  input [GPIO_N-1:0] da, // port A data
100  input [GPIO_N-1:0] da_en, // port A data enable
101 
102  input [GPIO_N-1:0] db, // port A data
103  input [GPIO_N-1:0] db_en, // port A data enable
104 
105  input [GPIO_N-1:0] dc, // port A data
106  input [GPIO_N-1:0] dc_en); // port A data enable
107 
108  wire [GPIO_N-1:0] ds; // "software" data (programmed by lower 24 bits)
109  wire [GPIO_N-1:0] ds_en; // "software" data enable (programmed by lower 24 bits)
110  reg [3:0] ch_en = 0; // channel enable
111 
112  wire [31:0] cmd_data;
113  wire cmd_a; // just 1 bit
114  wire cmd_we;
115 
118 
119  wire [ GPIO_N-1:0] ds_en_m;
120  wire [ GPIO_N-1:0] da_en_m;
121  wire [ GPIO_N-1:0] db_en_m;
122  wire [ GPIO_N-1:0] dc_en_m;
123 
124  wire [ GPIO_N-1:0] io_t; // tri-state for the I/Os
125  wire [ GPIO_N-1:0] io_do; // data out for the I/Os
126 
127  assign set_mode_w = cmd_we && (cmd_a == GPIO_SET_PINS);
128  assign set_status_w = cmd_we && (cmd_a == GPIO_SET_STATUS);
129 
130 
131  assign dc_en_m = dc_en & {GPIO_N{ch_en[3]}};
132  assign db_en_m = db_en & {GPIO_N{ch_en[2]}} & ~dc_en_m;
133  assign da_en_m = da_en & {GPIO_N{ch_en[1]}} & ~dc_en_m & ~db_en_m;
134  assign ds_en_m = ds_en & {GPIO_N{ch_en[0]}} & ~dc_en_m & ~db_en_m & ~da_en_m;
135  assign io_do = (dc_en_m & dc) |
136  (db_en_m & db) |
137  (da_en_m & da) |
138  (ds_en_m & ds);
139  assign io_t = ~(dc_en_m | db_en_m | da_en_m | ds_en_m);
140 
141 // 0 0 0 - no change -
142 // 0 1 1 1 0
143 // 1 0 2 1 1
144 // 1 1 3 0 0
145 
146  always @ (posedge mclk) begin
147  if (mrst) ch_en[0] <= 0;
148  else if (set_mode_w && cmd_data[GPIO_PORTEN + 1]) ch_en[0] <= cmd_data[GPIO_PORTEN + 0];
149 
150  if (mrst) ch_en[1] <= 0;
151  else if (set_mode_w && cmd_data[GPIO_PORTEN + 3]) ch_en[1] <= cmd_data[GPIO_PORTEN + 2];
152 
153  if (mrst) ch_en[2] <= 0;
154  else if (set_mode_w && cmd_data[GPIO_PORTEN + 5]) ch_en[2] <= cmd_data[GPIO_PORTEN + 4];
155 
156  if (mrst) ch_en[3] <= 0;
157  else if (set_mode_w && cmd_data[GPIO_PORTEN + 7]) ch_en[3] <= cmd_data[GPIO_PORTEN + 6];
158 
159  end
160 
161  generate
162  genvar i;
163  for (i=0; i < GPIO_N; i=i+1) begin: gpio_block
164  gpio_bit gpio_bit_i (
165 // .rst (rst), // input
166  .clk (mclk), // input
167  .srst (mrst), // input
168  .we (set_mode_w), // input
169  .d_in (cmd_data[2*i +: 2]), // input[1:0]
170  .d_out (ds[i]), // output
171  .en_out (ds_en[i]) // output
172  );
173  iobuf #(
174  .DRIVE (GPIO_DRIVE),
175  .IBUF_LOW_PWR (GPIO_IBUF_LOW_PWR),
176  .IOSTANDARD (GPIO_IOSTANDARD),
177  .SLEW (GPIO_SLEW)
178  ) iobuf_gpio_i (
179  .O (io_pins[i]), // output
180  .IO (ext_pins[i]), // inout
181  .I (io_do[i]), // input
182  .T (io_t[i]) // input
183  );
184 
185  end
186 
187  endgenerate
188 
190  .ADDR (GPIO_ADDR),
191  .ADDR_MASK (GPIO_MASK),
192  .NUM_CYCLES (6),
193  .ADDR_WIDTH (1),
194  .DATA_WIDTH (32)
195  ) cmd_deser_32bit_i (
196  .rst (1'b0), //rst), // input
197  .clk (mclk), // input
198  .srst (mrst), // input
199  .ad (cmd_ad), // input[7:0]
200  .stb (cmd_stb), // input
201  .addr (cmd_a), // output[0:0]
202  .data (cmd_data), // output[31:0]
203  .we (cmd_we) // output
204  );
205 
207  .STATUS_REG_ADDR (GPIO_STATUS_REG_ADDR),
208  .PAYLOAD_BITS (12),
209  .REGISTER_STATUS (1)
210  ) status_generate_i (
211  .rst (1'b0), // rst), // input
212  .clk (mclk), // input
213  .srst (mrst), // input
214  .we (set_status_w), // input
215  .wd (cmd_data[7:0]), // input[7:0]
216  .status ({io_pins,2'b0}), // input[11:0]
217  .ad (status_ad), // output[7:0]
218  .rq (status_rq), // output
219  .start (status_start) // input
220  );
221 
222 
223 endmodule
224 
225 module gpio_bit (
226 // input rst, // global reset
227  input clk, // system clock
228  input srst, // @posedge clk - sync reset
229  input we,
230  input [1:0] d_in, // input bits
231  output d_out, // output data
232  output en_out); // enable output
233 
234  reg d_r = 0;
235  reg en_r = 0;
236 
237  assign d_out = d_r;
238  assign en_out = en_r;
239  always @ (posedge clk) begin
240  if (srst) d_r <= 0;
241  else if (we && (|d_in)) d_r <= !d_in[0];
242 
243  if (srst) en_r <= 0;
244  else if (we && (|d_in)) en_r <= !(&d_in);
245  end
246 
247 endmodule
10550d_out
Definition: gpio393.v:231
10533ds_enwire[GPIO_N-1:0]
Definition: gpio393.v:109
[GPIO_N-1:0] 10531dc_en
Definition: gpio393.v:106
cmd_deser_32bit_i cmd_deser
Definition: gpio393.v:189
10539set_status_wwire
Definition: gpio393.v:117
[GPIO_N-1:0] 10525io_pins
Definition: gpio393.v:97
10520cmd_stb
Definition: gpio393.v:90
10508GPIO_STATUS_REG_ADDR'h30
Definition: gpio393.v:73
10512GPIO_SLEW"SLOW"
Definition: gpio393.v:78
10515GPIO_N10
Definition: gpio393.v:82
[GPIO_N-1:0] 10530dc
Definition: gpio393.v:105
11290T
Definition: iobuf.v:51
integer 10509GPIO_DRIVE12
Definition: gpio393.v:75
[GPIO_N-1:0] 10528db
Definition: gpio393.v:102
10532dswire[GPIO_N-1:0]
Definition: gpio393.v:108
status_generate_i status_generate
Definition: gpio393.v:206
10535cmd_datawire[31:0]
Definition: gpio393.v:112
[7:0] 10521status_ad
Definition: gpio393.v:92
10546clk
Definition: gpio393.v:227
[ADDR_MASK2!=0?2:ADDR_MASK1!=0?1:0:0] 9935we
Definition: cmd_deser.v:60
10537cmd_wewire
Definition: gpio393.v:114
[7:0] 10519cmd_ad
Definition: gpio393.v:89
10510GPIO_IBUF_LOW_PWR"TRUE"
Definition: gpio393.v:76
10518mrst
Definition: gpio393.v:88
10544io_twire[GPIO_N-1:0]
Definition: gpio393.v:124
10545io_dowire[GPIO_N-1:0]
Definition: gpio393.v:125
10506GPIO_ADDR'h700
Definition: gpio393.v:71
10536cmd_awire
Definition: gpio393.v:113
10552d_rreg
Definition: gpio393.v:234
[GPIO_N-1:0] 10524ext_pins
Definition: gpio393.v:96
[GPIO_N-1:0] 10526da
Definition: gpio393.v:99
10538set_mode_wwire
Definition: gpio393.v:116
10553en_rreg
Definition: gpio393.v:235
10547srst
Definition: gpio393.v:228
10516GPIO_PORTEN24
Definition: gpio393.v:83
[DATA_WIDTH-1:0] 9934data
Definition: cmd_deser.v:59
[GPIO_N-1:0] 10527da_en
Definition: gpio393.v:100
[GPIO_N-1:0] 10529db_en
Definition: gpio393.v:103
10507GPIO_MASK'h7fe
Definition: gpio393.v:72
10511GPIO_IOSTANDARD"DEFAULT"
Definition: gpio393.v:77
10534ch_enreg[3:0]
Definition: gpio393.v:110
11288IO
Definition: iobuf.v:49
10543dc_en_mwire[GPIO_N-1:0]
Definition: gpio393.v:122
[7:0] 9931ad
Definition: cmd_deser.v:56
[ADDR_WIDTH-1:0] 9933addr
Definition: cmd_deser.v:58
[1:0] 10549d_in
Definition: gpio393.v:230
10513GPIO_SET_PINS0
Definition: gpio393.v:80
10517mclk
Definition: gpio393.v:87
10542db_en_mwire[GPIO_N-1:0]
Definition: gpio393.v:121
iobuf_gpio_i iobuf[generate]
Definition: gpio393.v:173
10540ds_en_mwire[GPIO_N-1:0]
Definition: gpio393.v:119
gpio_bit_i gpio_bit[generate]
Definition: gpio393.v:164
[ALL_BITS-1:0] 10777status
11287O
Definition: iobuf.v:48
10541da_en_mwire[GPIO_N-1:0]
Definition: gpio393.v:120
10514GPIO_SET_STATUS1
Definition: gpio393.v:81
11289I
Definition: iobuf.v:50
10522status_rq
Definition: gpio393.v:93
10551en_out
Definition: gpio393.v:232
10523status_start
Definition: gpio393.v:94