Line 3... |
Line 3... |
////
|
////
|
//// AES CORE BLOCK
|
//// AES CORE BLOCK
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This file is part of the APB to AES128 project
|
//// This file is part of the APB to I2C project
|
////
|
////
|
//// http://www.opencores.org/cores/apbtoaes128/
|
//// http://www.opencores.org/cores/apbi2c/
|
////
|
////
|
////
|
////
|
////
|
////
|
//// Description
|
//// Description
|
////
|
////
|
Line 94... |
Line 94... |
output dma_req_rd,
|
output dma_req_rd,
|
output reg start_core,
|
output reg start_core,
|
output [31:0] PRDATA,
|
output [31:0] PRDATA,
|
//INPUTS
|
//INPUTS
|
input [3:0] PADDR,
|
input [3:0] PADDR,
|
input [31:0] PWDATA,
|
input [12:0] PWDATA,
|
input PWRITE,
|
input PWRITE,
|
input PENABLE,
|
input PENABLE,
|
input PSEL,
|
input PSEL,
|
input PCLK,
|
input PCLK,
|
input PRESETn,
|
input PRESETn,
|
Line 160... |
Line 160... |
localparam INPUT = 3'd1;
|
localparam INPUT = 3'd1;
|
localparam START = 3'd2;
|
localparam START = 3'd2;
|
localparam WAIT = 3'd3;
|
localparam WAIT = 3'd3;
|
localparam OUTPUT = 3'd4;
|
localparam OUTPUT = 3'd4;
|
|
|
reg [31:0] bus_out;
|
wire [31:0] bus_out;
|
reg [31:0] bus_out_mux;
|
reg [31:0] bus_out_mux;
|
reg cnt_en;
|
reg cnt_en;
|
reg enable_clear;
|
reg enable_clear;
|
reg access_permission;
|
reg access_permission;
|
reg first_block_set;
|
reg first_block_set;
|
Line 178... |
Line 178... |
wire err_ie;
|
wire err_ie;
|
wire ccf_ie;
|
wire ccf_ie;
|
wire errc;
|
wire errc;
|
wire ccfc;
|
wire ccfc;
|
wire aes_cr_wr_en;
|
wire aes_cr_wr_en;
|
|
//wire aes_sr_wr_en;
|
wire wr_err_en;
|
wire wr_err_en;
|
wire rd_err_en;
|
wire rd_err_en;
|
wire write_completed;
|
wire write_completed;
|
wire read_completed;
|
wire read_completed;
|
wire key_deriv;
|
wire key_deriv;
|
Line 192... |
Line 193... |
reg rd_err;
|
reg rd_err;
|
reg ccf;
|
reg ccf;
|
reg [2:0] state, next_state;
|
reg [2:0] state, next_state;
|
reg [1:0] cnt;
|
reg [1:0] cnt;
|
reg dma_req;
|
reg dma_req;
|
|
wire enable;
|
|
|
// Write and read enable signals
|
// Write and read enable signals
|
assign write_en = PSEL & PENABLE & PWRITE;
|
assign write_en = PSEL & PENABLE & PWRITE;
|
assign read_en = PSEL & ~PWRITE;
|
assign read_en = (PSEL & ~PWRITE & (ccf_set | ccf))?1'b1:
|
|
((PSEL & ~PWRITE)&(PADDR >= AES_KEYR0 & PADDR <= AES_IVR3 ))?1'b1:1'b0;
|
|
|
// Configuration Register Logic
|
// Configuration Register Logic
|
assign dma_out_en = aes_cr[10];
|
assign dma_out_en = aes_cr[10];
|
assign dma_in_en = aes_cr[9];
|
assign dma_in_en = aes_cr[9];
|
assign err_ie = aes_cr[8];
|
assign err_ie = aes_cr[8];
|
Line 216... |
Line 219... |
assign chmod_in = PWDATA[6:5];
|
assign chmod_in = PWDATA[6:5];
|
|
|
always @(posedge PCLK, negedge PRESETn)
|
always @(posedge PCLK, negedge PRESETn)
|
begin
|
begin
|
if(!PRESETn)
|
if(!PRESETn)
|
aes_cr <= AES_CR_RESET;
|
aes_cr <= AES_CR_RESET[10:0];
|
else
|
else
|
begin
|
begin
|
if(enable_clear)
|
if(enable_clear)
|
aes_cr[0] <= 1'b0;
|
aes_cr[0] <= 1'b0;
|
else
|
else
|
Line 239... |
Line 242... |
end
|
end
|
end
|
end
|
end
|
end
|
|
|
// Status Register Logic
|
// Status Register Logic
|
assign aes_sr_wr_en = (PADDR == AES_SR) & write_en & access_permission;
|
//assign aes_sr_wr_en = (PADDR == AES_SR) & write_en & access_permission;
|
|
|
always @(posedge PCLK, negedge PRESETn)
|
always @(posedge PCLK, negedge PRESETn)
|
begin
|
begin
|
if(!PRESETn)
|
if(!PRESETn)
|
|
begin
|
{wr_err, rd_err, ccf} <= AES_SR_RESET;
|
{wr_err, rd_err, ccf} <= AES_SR_RESET;
|
|
|
|
end
|
else
|
else
|
begin
|
begin
|
// Write Error Flag
|
// Write Error Flag
|
if(wr_err_en)
|
if(wr_err_en)
|
wr_err <= 1'b1;
|
wr_err <= 1'b1;
|
Line 402... |
Line 408... |
|
|
// DMA Requests Logic
|
// DMA Requests Logic
|
always @(posedge PCLK, negedge PRESETn)
|
always @(posedge PCLK, negedge PRESETn)
|
begin
|
begin
|
if(!PRESETn)
|
if(!PRESETn)
|
dma_req <= 0;
|
dma_req <= 1'b0;
|
else
|
else
|
dma_req <= cnt[0];
|
dma_req <= cnt[0];
|
end
|
end
|
|
|
assign dma_req_wr = (dma_req ^ cnt[0]) & dma_in_en & enable & (state == INPUT || state == IDLE);
|
assign dma_req_wr = (dma_req ^ cnt[0]) & dma_in_en & enable & (state == INPUT || state == IDLE);
|
Line 421... |
Line 427... |
bus_out_mux = 32'd0;
|
bus_out_mux = 32'd0;
|
case(PADDR)
|
case(PADDR)
|
AES_CR:
|
AES_CR:
|
bus_out_mux = {{19{1'b0}}, aes_cr[10:7], 2'b00, aes_cr[6:0]};
|
bus_out_mux = {{19{1'b0}}, aes_cr[10:7], 2'b00, aes_cr[6:0]};
|
AES_SR:
|
AES_SR:
|
bus_out_mux = {{29{1'b0}}, wr_err, rd_err, ccf};
|
begin
|
|
|
|
bus_out_mux = {{29{1'b0}}, wr_err, rd_err, (ccf)?1'b1:(ccfc && aes_cr_wr_en)?1'b0:1'b1};
|
|
/*
|
|
if(~ccfc && ~aes_cr_wr_en)
|
|
begin
|
|
bus_out_mux = {{29{1'b0}}, wr_err, rd_err, (ccf)?1'b1:(ccfc && aes_cr_wr_en)?1'b0:1'b1};
|
|
end
|
|
else
|
|
begin
|
|
bus_out_mux = {{29{1'b0}}, wr_err, rd_err, (ccf_set | ccf)?1'b1:1'b0};
|
|
end
|
|
*/
|
|
end
|
AES_DINR, AES_DOUTR:
|
AES_DINR, AES_DOUTR:
|
bus_out_mux = col_bus;
|
bus_out_mux = col_bus;
|
AES_KEYR0, AES_KEYR1, AES_KEYR2, AES_KEYR3:
|
AES_KEYR0, AES_KEYR1, AES_KEYR2, AES_KEYR3:
|
|
if(!enable)
|
bus_out_mux = key_bus;
|
bus_out_mux = key_bus;
|
AES_IVR0, AES_IVR1, AES_IVR2, AES_IVR3:
|
AES_IVR0, AES_IVR1, AES_IVR2, AES_IVR3:
|
if(!enable)
|
if(!enable)
|
bus_out_mux = iv_bus;
|
bus_out_mux = iv_bus;
|
|
|
endcase
|
endcase
|
end
|
end
|
|
|
// The output Bus is registered
|
// The output Bus is registered
|
always @(posedge PCLK, negedge PRESETn)
|
|
begin
|
assign bus_out =(read_en)? bus_out_mux:32'd0;
|
if(!PRESETn)
|
|
bus_out <= 32'd0;
|
/*
|
else
|
always @(posedge PCLK, negedge PRESETn)
|
if(read_en)
|
begin
|
bus_out <= bus_out_mux;
|
if(!PRESETn)
|
end
|
bus_out <= 32'd0;
|
|
else
|
|
if(read_en)
|
|
bus_out <= bus_out_mux;
|
|
end
|
|
*/
|
|
|
endmodule
|
endmodule
|
|
|
No newline at end of file
|
No newline at end of file
|