Tải bản đầy đủ (.pdf) (14 trang)

thiet ke vi mach voi hdl pham quoc cuong

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (790.31 KB, 14 trang )

ĐẠI HỌC QUỐC GIA THÀNH PHỐ HỒ CHÍ MINH
TRƯỜNG ĐẠI HỌC BÁCH KHOA
KHOA KHOA HỌC VÀ KỸ THUẬT MÁY TÍNH

------oOo-----

BÀI BÁO CÁO
Bài tập lớn môn Thiết kế vi mạch với HDL (Đề tài 8)

Sinh viên thực hiện:
1. 51003958 Ngô Nguyễn Hoàng Viên
2. 51002641 Hoàng Nguyễn Anh Quốc

TP.HCM, 1/2014

CuuDuongThanCong.com

/>

Mục lục
Giới thiệu ...................................................................................................................................................... 3
Đề tài ......................................................................................................................................................... 3
Bộ nhớ TCAM ............................................................................................................................................ 3
Board thực hành DE2 ................................................................................................................................ 4
Thiết kế ......................................................................................................................................................... 5
Mô hình Controller và Datapath ............................................................................................................... 5
Sơ đồ ASMD .............................................................................................................................................. 6
Code VERILOG ........................................................................................................................................... 7
DEMO .......................................................................................................................................................... 12
Thao tác trên board ................................................................................................................................ 12
Testcase................................................................................................................................................... 13


Tài liệu tham khảo ...................................................................................................................................... 14

Page 2

CuuDuongThanCong.com

/>

1. Giới thiệu.
1.1. Đề tài:


Tên đề tài:

Hiện thực mạch so trùng chuỗi TCAM dùng để so sánh các gói tin mạng gồm các trường
{Source IP, Destination IP}, có thể cấu hình nối tiếp.


Mục đích đề tài:
o Nắm vững kỹ năng thiết kế vi mạch bằng ngôn ngữ Verilog.
o Hiểu rõ về kiến trúc bộ nhớ TCAM và ứng dụng của nó.
o Sử dụng thành thạo board thí nghiệm DE2.

1.2. Bộ nhớ TCAM: (Ternary Content Addressable Memory).
TCAM là một loại bộ nhớ đặc biệt cho phép lưu trữ được 3 trạng thái: 0, 1 và X (don’t care).
Đồng thời đây là loại bộ nhớ truy xuất ngẫu nhiên tôc độ cao. Bộ nhớ TCAM được sử dụng trong
các router hiệu suất cao.

Page 3


CuuDuongThanCong.com

/>

1.3. Board thực hành DE2:

Để hiện thực đề tài trên, nhóm đã sử dụng:







16 switch gồm SW_0 - > SW_15 làm cổng nhập IP.
KEY_0 làm shift_button.
KEY_ 1 làm start_button.
KEY_3 làm reset_button.
LEDG_6 làm ngõ ra “Match” (báo có sự trùng IP).
LEDG_0 -> LEDG_3 làm ngõ ra “Address” (hiển thị địa chỉ trùng IP khi có sự trùng IP).

Page 4

CuuDuongThanCong.com

/>

2. Thiết kế:
2.1. Mơ hình Controller + Datapath.


Page 5

CuuDuongThanCong.com

/>

2.2. Sơ đồ ASMD.

0

0

1

Page 6

CuuDuongThanCong.com

/>

2.3. Code VERILOG.
module TCAM_Compare (Address, match, Ip_half_input, next_button, start_button, reset_button, clk_50MHz);
output [3:0] Address;
output match
input [15:0] Ip_haft_input;
input next_button, start_button, reset_button;
input clk_50Mhz;
wire [63:0] Data_read, Data_write;
wire match, mostmtach;
wire Select;

Controller_Unit M1 (Data_read, Select, Address, Data_write, clk, start_button, reset, match, mostmatch);
Datapath_Unit M2 (Data_write, match, mostmatch, Data_read, Ip_half_input, next_button, Select, clk);
endmodule
module Controller_Unit (Data_read, Select, Address, Data_write, clk, start_button, reset, match, mostmatch);
output [63:0] Data_read;
output Select;
output [3:0] Address;
input [63:0] Data_write;
input clk, start_button, reset_button, match, mostmatch;

Clock_Div C1 (clk, clk_1kHz);
Control_Signal C2 (Address, pointer, pointer_lt, Done, Select, state, match, clk);
State_tranmit C3 (state, start_button, reset_button, clk, Done, pointer_lt, max_pointer_lt);
Memory_Reg C4 (Data_read, Data_write, address, clk_1kHz, write);
endmodule
module Clock_Div (clk_out, clk_in);
output clk_out;
input
clk_in;
reg
[15:0] count;
always @ (posedge clk_in)
count <= count + 1;
assign
clk_out = count[15];
endmodule

Page 7

CuuDuongThanCong.com


/>

module Control_Signal (Address, pointer, pointer_lt, Done, Select, state, match, clk);
output
[3:0] Address;
output reg
[3:0] pointer;
output reg
pointer_lt, Done, Select;
input
[1:0] state;
input
match, clk;
reg
[3:0] max_pointer;
assign Address = (match == 1'b1) ? pointer : 4'bz;
assign pointer_lt = (pointer <= max_pointer)? 1'b1 : 1'b0;
always @ (posedge clk_1kHz) begin
if (state == S_idle) begin
pointer <= 4'b0;
end
else if (state == S_run) begin
pointer <= pointer + 1;
end
else if (state == S_write) begin
max_pointer <= max_pointer + 1;
end
else if (state == S_update) begin
pointer <= 0;

end
end
endmodule

Page 8

CuuDuongThanCong.com

/>

module State_tranmit (state, start_button, reset_button, clk, Done, pointer_lt, max_pointer_lt);
output reg
[1:0] state;
input
start_button, reset_button;
input
match, mostmatch, Done;
input
clk;
input
Done, pointer_lt, max_pointer_lt;
reg
[1:0] next_state;
parameter
S_idle = 0, S_run = 1, S_update = 2, S_write = 3;
always @ (posedge clk) begin
if (reset_button == 1'b1) state <= S_idle;
else state <= next_state;
end
always @ (state, start_button, reset_button, match, mostmatch, Done, pointer_lt, max_pointer_lt) begin

next_state = state;
case (state)
S_idle: begin
if (start_button == 1'b1) next_state = S_run;
end
S_run: begin
if (match == 1'b1) next_state = S_idle;
else if (mostmatch == 1'b1) next_state = S_update;
else if (pointer_lt == 1'b0) next_state = S_write;
else next_state = S_run;
end
S_update: begin
next_state = S_run;
end
S_write: begin
if (Done == 1'b0) next_state = S_write;
else next_state = S_idle;
end
default: next_state = S_idle;
endcase
end
endmodule
module Memory_Reg (Data_out, Data_in, address, clk, write);
output [63:0] Data_out;
input
[63:0] Data_in;
input
[3:0] address;
input
clk, write;

reg
[63:0] memory [15:0];

// External static RAM

assign Data_out = memory[address];
always @ (posedge clk)
if (write == 1'b1) memory[address] <= Data_in;
endmodule

Page 9

CuuDuongThanCong.com

/>

module
output
output
input
input
input
input
wire
wire
wire

Datapath_Unit (Data_write, match, mostmatch, Data_read, Ip_half_input, next_button, Select, clk);
[63:0] Data_wirte;
match, mostmatch;

[63:0] Data_read;
[15:0] Ip_half;
shift_button;
Select, clk;
[31:0] Ip_full;
[63:0] Data_out;
[31:0] mask_ref;

Input_data
Select_data
Compare_data
endmodule

D1 (Ip_full, Ip_half, shift_button);
D2 (Data_write, Data_out, Data_read, Ip_full, mask_ref, Select, clk);
D3 (match, mostmatch, mask_ref, Data_write, Data_out);

module Input_data (Ip_full, Ip_half_input, shift_button);
output [31:0] Ip_full;
input
[15:0] Ip_half_input;
input
shift_button;
always @ (posedge shift_button) Ip_full[31:0] <= {Ip_full[15:0], Ip_half_input[15:0]};
endmodule
module Select_data (Data_write, Data_out, Data_read, Ip_input, mask_ref, Select, clk);
output [63:0] Data_write;
output [63:0] Data_out;
input
[63:0] Data_read;

input
[32:0] Ip_input;
input
[32:0] mask_ref;
input
Select, clk;
reg
[31:0] mask;
always @ (posedge clk) begin
if (Select == 1'b0) mask <= 32'hFFFFFFFF;
else mask <= mask_ref;
Data_write <= {Ip_input, mask};
Data_out <= Data_read;
end
endmodule

Page
10

CuuDuongThanCong.com

/>

module Compare_data (match, mostmatch, mask_out, Data_in_1, Data_in_2);
output match, mostmatch;
output [31:0] mask_out;
input
[63:0] Data_in_1, Data_in_2;
wire
[31:0] Ip_1 = Data_in_1[63:32];

wire
[31:0] mask_1 = Data_in_1 [31:0];
wire
[31:0] Ip_2 = Data_in_2[63:32];
wire
[31:0] mask_2 = Data_in_2 [31:0];
wire
[31:0] Ip_compare, mask_compare;
assign
assign

Ip_compare = (Ip_1~^Ip_2);
mask_compare = mask_1~^mask_2;

assign
assign

mask_out = (mostmatch)? (mask_1&(~Ip_compare)) : mask_1;
match = &(Ip_compare|(~(mask_1&mask_2)));

assign temp[1] = Ip_compare[0];
assign temp[2] = temp[1] | Ip_compare[1];
assign temp[3] = temp[2] | Ip_compare[2];
assign temp[4] = temp[3] | Ip_compare[3];
assign temp[5] = temp[4] | Ip_compare[4];
assign temp[6] = temp[5] | Ip_compare[5];
assign temp[7] = temp[6] | Ip_compare[6];
assign temp[8] = temp[7] | Ip_compare[7];
assign temp[9] = temp[8] | Ip_compare[8];
assign temp[10] = temp[9] | Ip_compare[9];

assign temp[11] = temp[10] | Ip_compare[10];
assign temp[12] = temp[11] | Ip_compare[11];
assign temp[13] = temp[12] | Ip_compare[12];
assign temp[14] = temp[13] | Ip_compare[13];
assign temp[15] = temp[14] | Ip_compare[14];
assign temp[16] = temp[15] | Ip_compare[15];
assign temp[17] = temp[16] | Ip_compare[16];
assign temp[18] = temp[17] | Ip_compare[17];
assign temp[19] = temp[18] | Ip_compare[18];
assign temp[20] = temp[19] | Ip_compare[19];
assign temp[21] = temp[20] | Ip_compare[20];
assign temp[22] = temp[21] | Ip_compare[21];
assign temp[23] = temp[22] | Ip_compare[22];
assign temp[24] = temp[23] | Ip_compare[23];
assign temp[25] = temp[24] | Ip_compare[24];
assign temp[26] = temp[25] | Ip_compare[25];
assign temp[27] = temp[26] | Ip_compare[26];
assign temp[28] = temp[27] | Ip_compare[27];
assign temp[29] = temp[28] | Ip_compare[28];
assign temp[30] = temp[29] | Ip_compare[29];
assign temp[31] = temp[30] | Ip_compare[30];
assign
mostmatch = (&(mask_compare))&(~|(temp[31:1]&Ip_compare[31:1]));
endmodule

Page
11

CuuDuongThanCong.com


/>

3. Demo:
3.1. Thao tác trên board.
Bước 1: Sử dụng 16 switch trên board gồm SW0 đến SW15 để nhập 16 bit IP theo định dạng
MSB (tức là SW0 nhập bit thấp nhất và SW15 nhập bit cao nhất) trong đó gạt lên là bit 1 còn gạt
xuống la bit 0.
Bước 2: Tiếp theo nhấn shift_button (KEY0) để buff dữ liệu vừa nhập.
Bước 3: Lặp lại bước 1 và bước 2 để nhập phần IP còn lại. Nếu ta lặp lại bước 1 và bước 2 nhiều
lần thêm nữa thì IP mà mạch xử lý thì chỉ là IP được nhập 2 lần sau cùng.
Bước 4: Nhấn start_button (KEY1) để mạch thực sự bắt đầu chức năng lưu giữ IP vừa nhập và
thông báo kết quả xử lý.
Bước 5: Từ kết quả xử lý được nhận thấy ở các LEDG, ta biết được: “Nếu led_6 sáng tức là có
tồn tại IP vừa nhập trong bộ nhớ, và các led_0, led_1, led_2, led_3 sẽ cho biết địa chỉ của vùng
nhớ trong bộ nhớ có lưu trữ IP vừa nhập.”
Bước 6: Có thể trỡ lại bước 1 để nhập thêm IP vào bộ nhớ hoặc nhấn reset_button (KEY3) để
xóa bộ nhớ.

Page
12

CuuDuongThanCong.com

/>

3.2. Testcase.
Input
IP
192.168.21.5
201.222.35.0

192.36.111.5
192.168.21.5
201.222.35.1
201.222.35.0
50.12.11.1
50.12.11.1
201.222.35.3
201.222.35.2
201.222.35.1
23.21.20.19
23.21.20.19

Output
Match
0
0
0
1
0
1
0
1
0
0
1
0
1

Address
---------0000

---0001
---0011
------0001
---0100

Page
13

CuuDuongThanCong.com

/>

4. Tài liệu tham khảo:
[1]. />[2]. Michael D. Ciletti (2010), Advanced Digital Design With the Verilog HDL.
[3]. ALTERA, DE2 User manual.

Page
14

CuuDuongThanCong.com

/>


×