|
|
|
|
// this file is the test circuit
|
// this file is the test circuit
|
// author: Simom Panti
|
// author: Simom Panti
|
//
|
//
|
|
|
|
|
module csa_fpga(
|
module csa_fpga(
|
output bell
|
output bell
|
, input clk
|
, input clk
|
, input rst
|
, input rst
|
, input flaga
|
, input flaga
|
, input flagb
|
, input flagb
|
, input flagc
|
, input flagc
|
, output slcs
|
, output slcs
|
, output pktend
|
, output pktend
|
, output reg sloe
|
, output reg sloe
|
, output reg slwr
|
, output reg slwr
|
, output reg slrd
|
, output reg slrd
|
, output reg [ 1:0] fifoadr
|
, output reg [ 1:0] fifoadr
|
, inout [15:0] fd
|
, inout [15:0] fd
|
, input ifclk
|
, input ifclk
|
, output [ 7:0] led
|
, output [ 7:0] led
|
, output [ 3:0] ledseg
|
, output [ 3:0] ledseg
|
, output [ 7:0] seg_d
|
, output [ 7:0] seg_d
|
);
|
);
|
|
|
|
|
wire usbclk = ifclk;
|
wire usbclk = ifclk;
|
wire ep6_havedata = flaga;
|
wire ep6_havedata = flaga;
|
wire ep2_haveroom = flagc;
|
wire ep2_haveroom = flagc;
|
wire ep8_havedata = flagb;
|
wire ep8_havedata = flagb;
|
|
|
assign bell = 1'h1;
|
assign bell = 1'h1;
|
|
|
`define CNT_WIDTH 25
|
`define CNT_WIDTH 25
|
`define STA_WIDTH 4
|
`define STA_WIDTH 4
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
// led control
|
// led segement control
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
reg [`CNT_WIDTH-1:0]led_cnt;
|
|
|
|
always @(posedge usbclk)
|
ledseg_cnt ledseg_cnt(
|
led_cnt <= led_cnt + `CNT_WIDTH'h00001;
|
|
|
|
wire sec_clk = led_cnt[`CNT_WIDTH-1];
|
|
|
|
led_cnt led1(
|
|
.clk (usbclk)
|
|
, .rst (rst)
|
|
, .scan (sec_clk)
|
|
, .led (led)
|
|
);
|
|
|
|
|
|
wire seg_clk = led_cnt[`CNT_WIDTH-16];
|
|
ledseg_cnt ledseg1(
|
|
.clk (usbclk)
|
.clk (usbclk)
|
, .rst (rst)
|
, .rst (rst)
|
, .scan (seg_clk)
|
|
, .data (usb_dat_in)
|
, .data (usb_dat_in)
|
, .seg (ledseg)
|
, .seg (ledseg)
|
, .segd (seg_d)
|
, .segd (seg_d)
|
);
|
);
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
// usb interface
|
// usb interface
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
assign slcs =1'h0;
|
assign slcs =1'h0;
|
assign pktend=1'h1;
|
assign pktend=1'h1;
|
|
|
`define EP2_W 2'h0
|
`define EP2_W 2'h0
|
`define EP6_R 2'h1
|
`define EP6_R 2'h1
|
`define EP8_R 2'h2
|
`define EP8_R 2'h2
|
`define NO_ACT 2'h3
|
`define NO_ACT 2'h3
|
|
|
reg [ 1:0] last_action;
|
reg [ 1:0] last_action;
|
reg [15:0] usb_dat_out;
|
reg [15:0] usb_dat_out;
|
reg [15:0] usb_dat_in;
|
reg [15:0] usb_dat_in;
|
|
|
always @(posedge usbclk)
|
always @(posedge usbclk)
|
if(ep6_havedata)
|
if(ep6_havedata)
|
begin
|
begin
|
sloe<=1'h0;
|
sloe<=1'h0;
|
fifoadr<=2'h2;
|
fifoadr<=2'h2;
|
slrd<=1'h0;
|
slrd<=1'h0;
|
slwr<=1'h1;
|
slwr<=1'h1;
|
last_action<=`EP6_R;
|
last_action<=`EP6_R;
|
end
|
end
|
else
|
else
|
if(ep8_havedata)
|
if(ep8_havedata)
|
begin
|
begin
|
sloe<=1'h0;
|
sloe<=1'h0;
|
fifoadr<=2'h3;
|
fifoadr<=2'h3;
|
slrd<=1'h0;
|
slrd<=1'h0;
|
slwr<=1'h1;
|
slwr<=1'h1;
|
last_action<=`EP8_R;
|
last_action<=`EP8_R;
|
end
|
end
|
else
|
else
|
if(ep2_haveroom)
|
if(ep2_haveroom)
|
begin
|
begin
|
// ouput data
|
// ouput data
|
sloe<=1'h1;
|
sloe<=1'h1;
|
fifoadr<=2'h0;
|
fifoadr<=2'h0;
|
slwr<=1'h0;
|
slwr<=1'h0;
|
slrd<=1'h1;
|
slrd<=1'h1;
|
last_action<=`EP2_W;
|
last_action<=`EP2_W;
|
|
|
end
|
end
|
else
|
else
|
begin
|
begin
|
sloe<=1'h1;
|
sloe<=1'h1;
|
fifoadr<=2'h0;
|
fifoadr<=2'h0;
|
slwr<=1'h1;
|
slwr<=1'h1;
|
slrd<=1'h1;
|
slrd<=1'h1;
|
last_action<=`NO_ACT;
|
last_action<=`NO_ACT;
|
end
|
end
|
|
|
always @(posedge usbclk)
|
always @(posedge usbclk)
|
if(last_action==`EP8_R )
|
if(last_action==`EP8_R )
|
usb_dat_in<=fd;
|
usb_dat_in<=fd;
|
|
|
assign fd=(sloe)?usb_dat_out:16'hzzzz;
|
assign fd=(sloe)?usb_dat_out:16'hzzzz;
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
// csa decrypt module
|
// csa decrypt module
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
decrypt csa_decrypt(
|
decrypt csa_decrypt(
|
. clk (usbclk)
|
. clk (usbclk)
|
,. rst (rst)
|
,. rst (rst)
|
,. ck (64'h0000000000000000)
|
,. ck (64'h0000000000000000)
|
,. key_en (1'h0)
|
,. key_en (1'h0)
|
,. even_odd (1'h0)
|
,. even_odd (1'h0)
|
,. en ()
|
,. en ()
|
,. encrypted ()
|
,. encrypted ()
|
,. decrypted ()
|
,. decrypted ()
|
,. invalid ()
|
,. invalid ()
|
);
|
);
|
|
|
|
|
endmodule
|
endmodule
|
|
|
|
|