VERILOG的I2C代码块,注册接口变量,看一下注释就明白了。
//
registerInterface.v
This file is part of the i2cSlave opencores effort.
http://www.opencores.org/cores//
Module Description:
You will need to modify this file to implement your
interface.
Add your control and status bytes/bits to module inputs and outputs,
and also to the I2C read and write process blocks
To Do:
Author(s):
- Steve Fielding, sfielding@base2designs.com
//
Copyright © 2008 Steve Fielding and OPENCORES.ORG
This source file may be used and distributed without
restriction provided that this copyright statement is not
removed from the file and that any derivative work contains
the original copyright notice and the associated disclaimer.
This source file is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation;
either version 2.1 of the License, or (at your option) any
later version.
This source is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General
Public License along with this source; if not, download it
from http://www.opencores.org/lgpl.shtml
//
//
`include “i2cSlave_define.v”
//
// 这要注册接口模块的作用:它实际上就是I2C的CORE模块向用户(使用I2C CORE的人)声明。READ或WRITE这个操作时,寄存器的地址和数据时,实际
// 要写入哪一个地址值。I2C MODULE是通用的,但使用I2C的人需要说明一下,读写哪一个寄存器实际代表什么意思
//
module registerInterface #
(
parameter VCH_NUM = 4
)(
input clk,
input [7:0] addr, // 寄存器地址
input [7:0] dataIn, // 写入到寄存器中的数据
input writeEn,
output reg[7:0] dataOut, // 从寄存器中读出的数据
output reg[16 * VCH_NUM - 1 :0] vin_s_width,
output reg[16 * VCH_NUM - 1 :0] vin_s_height,
output reg[16 * VCH_NUM - 1 :0] clipper_left,
output reg[16 * VCH_NUM - 1 :0] clipper_width,
output reg[16 * VCH_NUM - 1 :0] clipper_top,
output reg[16 * VCH_NUM - 1 :0] clipper_height,
output reg[16 * VCH_NUM - 1 :0] vout_t_width,
output reg[16 * VCH_NUM - 1 :0] vout_t_height,
output reg[8 * VCH_NUM - 1 :0] alpha,
output reg[16 * VCH_NUM - 1 :0] disp_top,
output reg[16 * VCH_NUM - 1 :0] disp_left,
output reg[ 8 * VCH_NUM - 1 :0] source,
output reg[16 * VCH_NUM - 1 :0] scaler_k_h,
output reg[16 * VCH_NUM - 1 :0] scaler_k_v
);
parameter DEV_TYPE = 8’hA5;
parameter VERSION = 8’h01;
// 这个REG表示芯片状态CHIP_STATE,由用户写进来,再由用户读出去。
reg[7:0] chip_state;
// — I2C Read
always @(posedge clk) begin
case (addr)
8’hff: dataOut <= chip_state; // 0XFF代表CHIP_STATE这个功能值,当I2C总线上寄存器的值为0XFF时, 就把chip_state给到dataOut
default: dataOut <= 8’h00;
endcase
end
// — I2C Write
always @(posedge clk) begin
if (writeEn == 1’b1) begin // 表示写数据,也就是I2C的地址值的B0位,也就是区分WRITE和READ,
case (addr)
8’h00: vin_s_width [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h01: vin_s_width [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h02: vin_s_height [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h03: vin_s_height [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h04: clipper_left [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h05: clipper_left [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h06: clipper_width [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h07: clipper_width [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h08: clipper_top [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h09: clipper_top [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h0a: clipper_height [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h0b: clipper_height [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h0c: vout_t_width [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h0d: vout_t_width [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h0e: vout_t_height [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h0f: vout_t_height [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h10: alpha [ 8 * 1 - 1 : 8 * 1 - 8] <= dataIn;
8’h11: disp_top [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h12: disp_top [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h13: disp_left [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h14: disp_left [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h15: source [ 8 * 1 - 1 : 8 * 1 - 8] <= dataIn;
8’h16: scaler_k_h [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h17: scaler_k_h [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8’h18: scaler_k_v [16 * 1 - 9 : 16 * 1 - 16] <= dataIn;
8’h19: scaler_k_v [16 * 1 - 1 : 16 * 1 - 8] <= dataIn;
8'h20: vin_s_width [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h21: vin_s_width [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h22: vin_s_height [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h23: vin_s_height [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h24: clipper_left [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h25: clipper_left [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h26: clipper_width [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h27: clipper_width [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h28: clipper_top [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h29: clipper_top [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h2a: clipper_height [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h2b: clipper_height [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h2c: vout_t_width [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h2d: vout_t_width [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h2e: vout_t_height [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h2f: vout_t_height [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h30: alpha [ 8 * 2 - 1 : 8 * 2 - 8] <= dataIn;
8'h31: disp_top [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h32: disp_top [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h33: disp_left [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h34: disp_left [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h35: source [ 8 * 2 - 1 : 8 * 2 - 8] <= dataIn;
8'h36: scaler_k_h [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h37: scaler_k_h [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h38: scaler_k_v [16 * 2 - 9 : 16 * 2 - 16] <= dataIn;
8'h39: scaler_k_v [16 * 2 - 1 : 16 * 2 - 8] <= dataIn;
8'h40: vin_s_width [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h41: vin_s_width [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h42: vin_s_height [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h43: vin_s_height [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h44: clipper_left [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h45: clipper_left [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h46: clipper_width [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h47: clipper_width [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h48: clipper_top [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h49: clipper_top [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h4a: clipper_height [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h4b: clipper_height [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h4c: vout_t_width [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h4d: vout_t_width [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h4e: vout_t_height [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h4f: vout_t_height [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h50: alpha [ 8 * 3 - 1 : 8 * 3 - 8] <= dataIn;
8'h51: disp_top [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h52: disp_top [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h53: disp_left [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h54: disp_left [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h55: source [ 8 * 3 - 1 : 8 * 3 - 8] <= dataIn;
8'h56: scaler_k_h [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h57: scaler_k_h [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h58: scaler_k_v [16 * 3 - 9 : 16 * 3 - 16] <= dataIn;
8'h59: scaler_k_v [16 * 3 - 1 : 16 * 3 - 8] <= dataIn;
8'h60: vin_s_width [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h61: vin_s_width [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h62: vin_s_height [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h63: vin_s_height [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h64: clipper_left [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h65: clipper_left [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h66: clipper_width [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h67: clipper_width [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h68: clipper_top [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h69: clipper_top [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h6a: clipper_height [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h6b: clipper_height [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h6c: vout_t_width [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h6d: vout_t_width [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h6e: vout_t_height [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h6f: vout_t_height [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h70: alpha [ 8 * 4 - 1 : 8 * 4 - 8] <= dataIn;
8'h71: disp_top [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h72: disp_top [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h73: disp_left [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h74: disp_left [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h75: source [ 8 * 4 - 1 : 8 * 4 - 8] <= dataIn;
8'h76: scaler_k_h [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h77: scaler_k_h [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'h78: scaler_k_v [16 * 4 - 9 : 16 * 4 - 16] <= dataIn;
8'h79: scaler_k_v [16 * 4 - 1 : 16 * 4 - 8] <= dataIn;
8'hff: chip_state <= dataIn; // 0XFF代表CHIP_STATE这个物理量
default:;
endcase
end
end
endmodule