mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-19 03:37:57 -04:00
fpga: Automatically control app_mode in hardware
Instead of manually switching to app mode using the APP_MODE register, app mode will be enabled when the CPU fetches an instruction outside of firmware ROM. Co-authored-by: Mikael Ågren <mikael@tillitis.se>
This commit is contained in:
parent
97de5e68fd
commit
24ef39b739
1 changed files with 19 additions and 6 deletions
|
@ -109,6 +109,7 @@ module tk1 #(
|
||||||
localparam FW_RAM_FIRST = 32'hd0000000;
|
localparam FW_RAM_FIRST = 32'hd0000000;
|
||||||
localparam FW_RAM_LAST = 32'hd0000fff; // 4 KB
|
localparam FW_RAM_LAST = 32'hd0000fff; // 4 KB
|
||||||
|
|
||||||
|
localparam FW_ROM_LAST = 32'h00001fff;
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
// Registers including update variables and write enable.
|
// Registers including update variables and write enable.
|
||||||
|
@ -117,6 +118,7 @@ module tk1 #(
|
||||||
reg cdi_mem_we;
|
reg cdi_mem_we;
|
||||||
|
|
||||||
reg app_mode_reg;
|
reg app_mode_reg;
|
||||||
|
reg app_mode_new;
|
||||||
reg app_mode_we;
|
reg app_mode_we;
|
||||||
|
|
||||||
reg [ 2 : 0] led_reg;
|
reg [ 2 : 0] led_reg;
|
||||||
|
@ -292,7 +294,7 @@ module tk1 #(
|
||||||
gpio2_reg[1] <= gpio2_reg[0];
|
gpio2_reg[1] <= gpio2_reg[0];
|
||||||
|
|
||||||
if (app_mode_we) begin
|
if (app_mode_we) begin
|
||||||
app_mode_reg <= 1'h1;
|
app_mode_reg <= app_mode_new;
|
||||||
end
|
end
|
||||||
|
|
||||||
if (led_we) begin
|
if (led_we) begin
|
||||||
|
@ -484,12 +486,27 @@ module tk1 #(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
// app_mode_ctrl
|
||||||
|
//
|
||||||
|
// Automatically lower privilege when executing above ROM.
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
always @* begin : app_mode_ctrl
|
||||||
|
app_mode_new = 1'h0;
|
||||||
|
app_mode_we = 1'h0;
|
||||||
|
|
||||||
|
if (cpu_valid & cpu_instr) begin
|
||||||
|
if (cpu_addr > FW_ROM_LAST) begin
|
||||||
|
app_mode_new = 1'h1;
|
||||||
|
app_mode_we = 1'h1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
// api
|
// api
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
always @* begin : api
|
always @* begin : api
|
||||||
app_mode_we = 1'h0;
|
|
||||||
led_we = 1'h0;
|
led_we = 1'h0;
|
||||||
gpio3_we = 1'h0;
|
gpio3_we = 1'h0;
|
||||||
gpio4_we = 1'h0;
|
gpio4_we = 1'h0;
|
||||||
|
@ -516,10 +533,6 @@ module tk1 #(
|
||||||
if (cs) begin
|
if (cs) begin
|
||||||
tmp_ready = 1'h1;
|
tmp_ready = 1'h1;
|
||||||
if (we) begin
|
if (we) begin
|
||||||
if (address == ADDR_APP_MODE_CTRL) begin
|
|
||||||
app_mode_we = 1'h1;
|
|
||||||
end
|
|
||||||
|
|
||||||
if (address == ADDR_LED) begin
|
if (address == ADDR_LED) begin
|
||||||
led_we = 1'h1;
|
led_we = 1'h1;
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue