Reset Sources and the Reset Cause Register

The boot banner appears twice. Power stayed on, nobody touched the board, and the second boot looks healthy. One small register can say what happened, if the restart did not erase it.

You Will Be Able To

  • Tell a cold reset from a warm reset, and name the five reset sources of ap_soc.
  • Say which domains each source resets, and why the debugger resets less.
  • Read a reset cause word, and say what it can and cannot tell.
Lesson
S5.4
Time
24 min
Runs on
Your browser
Check
6 questions

A device in the field restarts once a week. Every restart looks the same: the same banner, the same healthy boot. Somewhere on the chip, one bit knows whether a person pressed a button or the software hung. Where does that bit have to live to still be there?

Before You Start

You need Reset and Interrupts in One Picture: what a reset does to the processor. You need APB, a Few Signals at a Time: a read has a setup cycle and an access cycle.

This page ends at a register that software reads over the bus, like any register of a peripheral. The Anatomy of a Peripheral shows what a register block is. Read it first if a register behind a bus is new to you.

Two sources on this page are devices that later pages build. For now one line each is enough, and both are in the word table.

Five questions this page answers
Question
1What is a cold reset, and what is a warm reset?
2Which domains does a debug request reset?
3What does the reset cause register tell boot software?
4What can a cause word not tell?
5Why must the reset pin be high for two samples?

The Idea: A Restart Must Leave a Note

A reset puts storage into a known starting state. A chip can be reset for several reasons, and after the reset it looks the same whatever the reason was. That is the point of a reset, and it is also a loss: the reason is gone.

The reason matters. A restart at power-up is normal. A restart by the watchdog means that software hung, and someone should hear of it. So a chip keeps a note. A small register records which source asked for the reset. Boot software reads it first thing.

For the note to survive, the reset must not reach it. Here two words help. A cold reset is the reset at power-up: the supply has just come on, and everything starts fresh, the note included. A warm reset is any reset while the power stays on. It restarts chosen parts of the chip and leaves the rest alone. The note is in the rest.

So each thing that can reset the chip needs two decisions. What does it reset? And is the record outside that reach? A debugger, the tool an engineer uses to stop and inspect a running chip, shows why the first answer varies. It wants to restart the processor and stay attached. So its reset must not touch the debug logic.

New Words

New words on this page
WordMeaning
Reset sourceAnything that can ask for a reset of the chip.
Power-on reset (POR)A circuit that holds the chip in reset while the supply comes up, and a little longer.
Cold resetThe reset at power-up. Everything starts from its reset value, the reset record included.
Warm resetA reset while the power stays on. Chosen parts restart. The reset record, and some other state, is kept.
WatchdogA timer that software must restart again and again. If software stops doing so, the watchdog asks for a reset.
DebuggerA tool on a desk computer that controls the chip through a few debug pins.
Reset domainA group of flip-flops that are reset together, by the same reset signal.
Reset cause registerA register with one bit for each reset source. A bit that is 1 says: this source has reset the chip.
Sticky bitA bit that stays 1 once it is set. Here neither a read nor a warm reset clears it.
Pin filterLogic that accepts a level on a pin only after it has been seen for several samples in a row.
The five reset sources of ap_soc
SourceCold or warmCore domainBus and I/O domainDebug domainIts bit in the cause register
Power-on resetcoldresetresetresetbit 0
Reset pin, heldwarmresetresetruns onbit 1
Watchdogwarmresetresetruns onbit 2
Software requestwarmresetresetruns onbit 3
Debug requestwarmresetruns onruns onbit 4

The reset cause register is at 0x10004004, in a block called ap_sysctl. Reach and bit numbers are choices of ap_soc.

One Picture: From a Request to the Next Boot

Five Sources, Three Domains, One RecordStep through the picture. It starts with the one cold reset and ends with the read at the next boot.
  • Power
  • Control / FSM
  • Clock / reset
  • Memory
  • Processor
  • Peripheral
  • Debug
Five Sources, Three Domains, One RecordStep through the picture. It starts with the one cold reset and ends with the read at the next boot. component Power-on reset the supply has justcome up component Four warmsources reset pin, watchdog,software, debugger component Reset controller in the block calledap_crg; it stays onthrough every warmreset component Reset causeregister one sticky bit foreach source component Core domain the processor component Bus and I/Odomain the bus and theperipherals component Debug domain the logic a debuggertalks to component Boot software reads the causeregister after reset cold: everythingstarts a new recordrequestsevery sourceall but the debuggerpower-on onlysets one bitthe cause word
  1. component Power-on resetthe supply has just come up
    • cold: everything → Reset controller
    • starts a new record → Reset cause register
  2. component Reset controllerin the block called ap_crg; it stays on through every warm reset
    • every source → Core domain
    • all but the debugger → Bus and I/O domain
    • power-on only → Debug domain
    • sets one bit → Reset cause register
  3. component Reset cause registerone sticky bit for each source
    • the cause word → Boot software
  4. component Core domainthe processor
  5. component Bus and I/O domainthe bus and the peripherals
  6. component Debug domainthe logic a debugger talks to
  7. component Four warm sourcesreset pin, watchdog, software, debugger
    • requests → Reset controller
  8. component Boot softwarereads the cause register after reset
  1. The cold reset

    Power comes up. The power-on reset puts every flip-flop of the chip into its starting state. That includes the record itself: a new history begins.

  2. Four warm sources

    With the supply still on, four things can ask for a reset. They are a person at the reset pin, the watchdog, running software, and a debugger. Each sends a request to the reset controller.

  3. Each source has a reach

    The controller does not reset everything for every request. The pin, the watchdog and software restart the processor and the peripherals. The debugger restarts the processor only, and stays attached.

  4. The record

    As the controller accepts a request, it sets one bit in the reset cause register: the bit of that source. The register sits outside the reach of all four warm sources.

  5. The next boot

    The chip restarts and looks the same as after any reset. Boot software reads the cause register over the bus and learns why it is running again.

Read the diagram as text
  • Power-on reset: the supply has just come up
  • Four warm sources: reset pin, watchdog, software, debugger
  • Reset controller: in the block called ap_crg; it stays on through every warm reset
  • Reset cause register: one sticky bit for each source
  • Core domain: the processor
  • Bus and I/O domain: the bus and the peripherals
  • Debug domain: the logic a debugger talks to
  • Boot software: reads the cause register after reset
  • Power-on reset → Reset controller: cold: everything
  • Power-on reset → Reset cause register: starts a new record
  • Four warm sources → Reset controller: requests
  • Reset controller → Core domain: every source
  • Reset controller → Bus and I/O domain: all but the debugger
  • Reset controller → Debug domain: power-on only
  • Reset controller → Reset cause register: sets one bit
  • Reset cause register → Boot software: the cause word

Reset in ap_soc. Which source resets which domain is a choice of our chip.

The Smallest Example, Worked by Hand

Follow one history. The cause word has five bits. Bit 0 is on the right. Each accepted source sets its own bit, and nothing but a cold reset clears one.

One history of the cause word, by hand
EventBit setCause word in binaryIn hexadecimal
Power comes up00 000101
The reset pin is held10 001103
The watchdog fires20 011107
Software asks for a reset30 11110f
The debugger asks for a reset41 11111f

Now read a word the way boot software must. Take 07: binary 0 0111. Bits 0, 1 and 2 are set. So power-on, the pin and the watchdog have each reset the chip since power came up.

That is all the word says. It does not say which came last. It does not say whether the watchdog fired once or ten times. A bit that is already 1 cannot be set again.

The pin needs one more table. A reset pin picks up noise, and a spike must not restart the chip. So the controller looks at the pin on every clock edge, and acts only on two high samples in a row.

The pin filter, by hand
Samples of the pinHigh samples in a rowResult
1, then 01No reset. The cause word does not change.
1, then 12Warm reset of the core and the bus and I/O domain. Bit 1 is set.
1, 0, 11, then 1 againNo reset. A low sample starts the count again.

The Rules

  1. Rule 1: A cold reset starts everything, the record included.

    In ap_soc only the power-on reset is cold. After it the cause word reads 01.

  2. Rule 2: A warm reset restarts chosen domains and keeps the power on.

    The reach of each source is fixed. The table of sources lists it.

  3. Rule 3: Each accepted source sets its own bit in the reset cause register.

    The register is outside the reach of every warm source.

  4. Rule 4: The bits are sticky.

    A warm reset does not clear them, and a read does not clear them. Only a cold reset starts a new record.

  5. Rule 5: The word names the sources seen since the last cold reset.

    It holds no order and no count.

  6. Rule 6: The reset pin counts only after two high samples in a row.

    One high sample resets nothing and records nothing.

Sources for These Rules

Every rule on this page describes ap_soc. The reach of each source, the bit numbers, the sticky bits and the depth of the pin filter are our choices.

Cold reset and warm reset are common words in chip and board documents. No standard in our reference library defines them, so the page defines them itself.

The two rows of the bus read, setup and then access: Arm AMBA APB Protocol Specification, IHI 0024 issue E, sections 3.3 and 4.1. Arm AMBA AHB Protocol Specification, IHI 0033 issue C, sections 3.1, 4.2, 5.1.1 and 7.1.2.

Reset at one flip-flop is in Reset: Assert, Release and What RTL Cannot Show.

Now Run It

The lab at the end of this page has the reset controller and the cause register behind the bridge to APB. Test code, a bus-functional model, stands in for the processor: it drives the bus as boot software would. The four warm requests are inputs that the test code raises.

Printed by the lab on Icarus. Every "read=" value is the cause word in hexadecimal.
power sample core=1 io=1 debug=1
read sel=1 enable=0 hready=0
read sel=1 enable=1 hready=1
power read=01
short pin sample core=0 io=0 debug=0
short pin read=01
held pin sample core=0 io=0 debug=0
held pin sample core=1 io=1 debug=0
held pin read=03
watchdog sample core=1 io=1 debug=0
watchdog read=07
software sample core=1 io=1 debug=0
software read=0f
debug sample core=1 io=0 debug=0
debug read=1f

Rule 1 at work: the first row shows all three domains in reset, and the first read returns 01. That read takes two clock edges, the two "read" rows: setup, then access.

Rule 6 at work: the short pin leaves core=0, and the read after it is still 01. The held pin shows core=0 on its first sample and core=1, io=1 on its second. Then the word is 03.

Rules 2 to 4 at work: the watchdog resets the core and the bus and I/O domain, and debug stays 0. The read returns 07: the bits of power-on and of the pin are still there.

The last source is the debugger. Its row shows core=1 with io=0 and debug=0: the processor restarts, and the peripherals and the debug logic run on.

Which Reset Reaches Which Domain?Step through the samples. Each column is one look at the three reset outputs, in the order of the run.
0123456sourcepowershort pinheld pinwatchdogsoftwaredebugcore domainbus and I/O domaindebug domain
Scroll horizontally ↔
  1. Sample 0

    Power-on reset: the cold reset. All three domains are in reset.

  2. Sample 1

    The pin is high for one sample only. No domain is reset.

  3. Sample 2

    The pin again. Its first high sample: nothing yet.

  4. Sample 3

    Its second high sample in a row: the core and the bus and I/O domain are reset. The debug domain is not.

  5. Sample 4

    The watchdog: the same two domains.

  6. Sample 5

    A software request: the same two domains again.

  7. Sample 6

    A debug request: the core domain only.

Drawn from the seven "sample" rows of the lab. 1 means that the domain is held in reset.

This lab leaves things out. The pin arrives already sampled into the clock of the controller. There is no real watchdog and no debugger. And the lab does not show how a reset is released: that is the next page.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
A cause register in hardwareSoftware writes a log before it resetsA hung program cannot write a log. The register costs a few flip-flops that need a reset of their own.
Sticky bits, one for each sourceOne field that holds the last sourceNothing is lost if two resets come before a read. Order and count are not kept.
A debug request resets the core onlyIt resets everything, like the pinThe debugger stays attached and can watch the first instruction. The peripherals keep their old state.
Two samples on the pinAct on the first high sampleA spike of noise does not restart the chip. A real press is seen one sample later.

The Trap: Reading the Highest Bit as the Latest

A field report says "cause 07, so the last reset was the watchdog". Bit 2 is the highest bit that is set. But a bit position names a source. It carries no time. The watchdog may have fired on the first day, and the pin every day since.

If the question is "which came first", the chip needs a register that keeps only the first event. If the question is "how often", it needs a counter. Decide which question the field will ask before the chip is built.

The worse trap is in the wiring. Someone connects the reset of the cause register to the same signal that resets the peripherals. It looks tidy: one reset for the whole block. Now every watchdog reset clears the bit that it has just set, and boot software reads 01 for ever. The second practice problem is that bug.

At Scale

This page5 sources, 3 domains
A phone chipdozens of sources and domains

This section looks ahead. Five sources and three domains become dozens of each, and the field report still holds one word.

  1. A table of reach

    A row for each source and a column for each domain. Add the record, its clock and the path that software reads it by. A flag behind a bridge that is still in reset helps nobody.

  2. The first reader

    Boot code saves the word before any driver clears it. The plan says what happens when a new event arrives on the same edge as the clear.

  3. Order and count

    A register for the first event and a counter for each source are cheap. They must be asked for before the chip is built.

  4. Release

    This page is about who asks for a reset. How a reset ends, cleanly and in the right order, is Reset Architecture.

Try It

Run the lab. Each source is tried in turn. After each one, test code reads the reset cause register.

Change the held pin from two clock edges to one. Which of the later reads lose bit 1?

Raise the watchdog and the software request together. Predict the read that follows.

Names Printed by the Lab
NameMeaning
sampleA look at the three reset outputs, 1 ns after a clock edge. 1 means that the domain is held in reset.
core, io, debugThe reset outputs for the core domain, the bus and I/O domain and the debug domain.
read sel, enable, hreadyOne row for each clock edge of the first bus read: select, enable and "the transfer is complete".
read=The reset cause register as the read returned it, in hexadecimal.
short pin, held pinThe reset pin high for one sample, and high for two samples in a row.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: power sample core=1 io=1 debug=1 read sel=1 enable=0 hready=0 read sel=1 enable=1 hready=1 power read=01 short pin sample core=0 io=0 debug=0 short pin read=01 held pin sample core=0 io=0 debug=0 held pin sample core=1 io=1 debug=0 held pin read=03 watchdog sample core=1 io=1 debug=0 watchdog read=07 software sample core=1 io=1 debug=0 software read=0f debug sample core=1 io=0 debug=0 debug read=1f
Read included file: bridge.sv
`timescale 1ns/1ns
// ahb_apb_bridge.sv: an AHB subordinate that turns each accepted transfer into one APB transfer
// (read-only). The address phase is registered when HSEL, HREADY and a NONSEQ or SEQ transfer are
// all present. During SETUP and unfinished ACCESS the bridge keeps HREADYOUT low. A successful APB
// completion ends the AHB data phase with OKAY and HRDATA = PRDATA. A failed APB completion starts
// the two-cycle ERROR (HREADYOUT low then high, HRESP high in both). HWDATA and HWSTRB are data-phase signals the manager holds
// through the wait states, so PWDATA and PSTRB are driven from them directly; PADDR is the aligned
// word address (IHI 0024E 2.1.1 leaves an unaligned PADDR unpredictable). HPROT maps onto PPROT:
// privileged from HPROT[1], instruction from HPROT[0] = 0, and the access is Secure.
// A write therefore costs one setup and one access cycle: two cycles of data phase with no APB wait.
module ahb_apb_bridge (
  input  logic        hclk,
  input  logic        hresetn,
  input  logic        hsel,
  input  logic [31:0] haddr,
  input  logic [1:0]  htrans,
  input  logic        hwrite,
  input  logic [3:0]  hprot,
  input  logic [31:0] hwdata,
  input  logic [3:0]  hwstrb,
  input  logic        hready,
  output logic        hreadyout,
  output logic        hresp,
  output logic [31:0] hrdata,
  output logic        psel,
  output logic        penable,
  output logic        pwrite,
  output logic [31:0] paddr,
  output logic [31:0] pwdata,
  output logic [3:0]  pstrb,
  output logic [2:0]  pprot,
  input  logic        pready,
  input  logic [31:0] prdata,
  input  logic        pslverr);
  localparam int IDLE = 0, SETUP = 1, ACCESS = 2, ERR1 = 3, ERR2 = 4;
  bit trace = 0;
  int st = IDLE;
  logic        wr = 0;
  logic [31:0] a = 0;
  logic [2:0]  prot = 0;
  wire take = hsel && hready && htrans[1];
  assign psel      = (st == SETUP || st == ACCESS);
  assign penable   = (st == ACCESS);
  assign pwrite    = wr;
  assign paddr     = {a[31:2], 2'b00};     // APB leaves an unaligned PADDR unpredictable: the word, and PSTRB picks the bytes
  assign pwdata    = wr ? hwdata : 32'h0;
  assign pstrb     = wr ? hwstrb : 4'h0;
  assign pprot     = prot;
  assign hreadyout = (st == IDLE || st == ERR2) ? 1'b1 : (st == ACCESS) ? (pready === 1'b1 && pslverr !== 1'b1) : 1'b0;
  assign hresp     = (st == ERR1 || st == ERR2);
  assign hrdata    = (st == ACCESS) ? prdata : 32'h0;
  always @(posedge hclk or negedge hresetn) begin
    if (!hresetn) st <= IDLE;
    else begin
      case (st)
        SETUP:  st <= ACCESS;
        ACCESS: if (pready === 1'b1) begin
                  if (trace) $display("apb e%0d: %0s 0x%03h%0s", ($time - 5) / 10, wr ? "write" : "read", a[11:0], pslverr === 1'b1 ? " PSLVERR" : "");
                  st <= (pslverr === 1'b1) ? ERR1 : IDLE;
                end
        ERR1:   st <= ERR2;
        default: st <= IDLE;
      endcase
      // A new address phase can be taken whenever HREADY is 1: in IDLE, in the last cycle of ERROR,
      // or at the edge an access completes with OKAY.
      if (take && (st == IDLE || st == ERR2 || (st == ACCESS && pready === 1'b1 && pslverr !== 1'b1))) begin
        wr <= hwrite; a <= haddr; prot <= {~hprot[0], 1'b0, hprot[1]}; st <= SETUP;
      end
    end
  end
endmodule
Read included file: reset_bus.svh
// One aligned word at a time. The manager stands in for the future ap_rv32.
logic clk = 0, bus_reset_n;
always #5 clk = ~clk;
logic [31:0] addr = 0, wdata = 0;
logic write_req = 0, request = 0;
wire sel, enable, writing, ready, error, pready, slave_error;
wire [31:0] paddr, pwdata, prdata, rdata;
ahb_apb_bridge bridge (
  .hclk(clk), .hresetn(bus_reset_n), .hsel(addr[31:16] == 16'h1000),
  .haddr(addr), .htrans({request,1'b0}), .hwrite(write_req), .hprot(4'b0011),
  .hwdata(wdata), .hwstrb(4'hf), .hready(ready), .hreadyout(ready),
  .hresp(error), .hrdata(rdata), .psel(sel), .penable(enable), .pwrite(writing),
  .paddr(paddr), .pwdata(pwdata), .pstrb(), .pprot(), .pready(pready),
  .prdata(prdata), .pslverr(slave_error)
);
task automatic issue(input bit wr, input logic [31:0] address, data);
  @(negedge clk);
  write_req = wr;
  addr = address;
  request = 1;
  @(negedge clk);
  request = 0;
  addr = 0;
  wdata = data;
endtask
Read included file: ap_sysctl_reset_port.sv
// Reset-service words within the ap_soc laboratory system-control page.
// All manager accesses to this port are aligned, full-word APB transfers.
// The cause storage has a separate reset owner and enters through cause.
module ap_sysctl_reset_port (
  input  logic        clk, bus_reset_n,
  input  logic        sel, enable, writing,
  input  logic [31:0] paddr, pwdata,
  input  logic [4:0]  cause,
  input  logic        service_slot,
  output logic        page_selected, access_error, armed,
  output logic [31:0] read_data
);
  localparam logic [31:0] CAUSE = 32'h1000_4004, COMMAND = 32'h1000_4008;
  wire cause_read = !writing && paddr == CAUSE;
  wire command_write = writing && paddr == COMMAND;

  assign page_selected = sel && paddr[31:12] == CAUSE[31:12];
  assign read_data = cause_read ? {27'b0,cause} : 32'b0;
  assign access_error = page_selected && enable && !(cause_read || command_write);

  always_ff @(posedge clk or negedge bus_reset_n) begin
    if (!bus_reset_n)
      armed <= 0;
    else if (page_selected && enable && command_write)
      armed <= pwdata[0];
    else if (service_slot)
      armed <= 0;
  end
endmodule
Read included file: reset_sources.sv
// ap_soc lesson slice. The four warm requests are in the always-on clock domain.
// pin_sample is the pad level AFTER synchronization. POR starts a new log.
module reset_sources (
  input logic clk, por, pin_sample, watchdog, software_req, debug_req,
  output logic core_reset, io_reset, debug_reset,
  output logic [4:0] cause
);
  logic previous_pin;
  logic pin_qualified;
  assign io_reset = por || pin_qualified || watchdog || software_req;
  assign core_reset = io_reset || debug_req;
  assign debug_reset = por;

  always_ff @(posedge clk) begin
    if (por) begin
      previous_pin <= 0;
      pin_qualified <= 0;
      cause <= 5'b00001;
    end else begin
      previous_pin <= pin_sample;
      pin_qualified <= previous_pin && pin_sample;
      if (previous_pin && pin_sample) cause[1] <= 1;
      if (watchdog)      cause[2] <= 1;
      if (software_req)  cause[3] <= 1;
      if (debug_req)     cause[4] <= 1;
    end
  end
endmodule

Check Yourself

Predict the outputIn this run the last request is a second watchdog reset, in place of the debug request. What is the last row the lab prints?
`timescale 1ns/1ns
module tb;
  `include "reset_bus.svh"
  logic por = 1, pin_sample = 0, watchdog = 0, software_req = 0, debug_req = 0;
  wire core_reset, io_reset, debug_reset;
  wire [4:0] cause;
  reset_sources crg(.*);
  localparam CAUSE = 32'h1000_4004;
  assign pready = 1;
  wire page_selected, access_error;
  ap_sysctl_reset_port sysctl(.clk(clk),.bus_reset_n(bus_reset_n),
    .sel(sel),.enable(enable),.writing(writing),.paddr(paddr),.pwdata(pwdata),
    .cause(cause),.service_slot(1'b0),.page_selected(page_selected),
    .access_error(access_error),.armed(),.read_data(prdata));
  assign slave_error = access_error || (sel && !page_selected);
  // Assert with the I/O domain and release on a bus clock edge.
  always_ff @(posedge clk or posedge io_reset)
    bus_reset_n <= !io_reset;

  task automatic inspect(input string label_text, input bit trace_read);
    wait (bus_reset_n);
    issue(0, CAUSE, 0);
    do begin
      @(posedge clk);
      if (trace_read)
        $display("read sel=%b enable=%b hready=%b",sel,enable,ready);
    end while (!ready);
    if (error) $fatal(1,"Cause read failed");
    $display("%s read=%02h",label_text,rdata[7:0]);
  endtask

  task automatic pulse(input string label_text, input logic [3:0] sources, input int edges);
    @(negedge clk);
    {debug_req,software_req,watchdog,pin_sample} = sources;
    repeat (edges) begin
      @(posedge clk);
      #1;
      $display("%s sample core=%b io=%b debug=%b",label_text,core_reset,io_reset,debug_reset);
    end
    @(negedge clk);
    {debug_req,software_req,watchdog,pin_sample} = 0;
    @(posedge clk);
    inspect(label_text,0);
  endtask

  initial begin
    repeat (2) @(posedge clk);
    $display("power sample core=%b io=%b debug=%b",core_reset,io_reset,debug_reset);
    @(negedge clk);
    por = 0;
    inspect("power",1);
    pulse("short pin",1,1);
    pulse("held pin",1,2);
    pulse("watchdog",2,1);
    pulse("software",4,1);
    pulse("again",2,1);
    $finish;
  end
endmodule
Read included file: bridge.sv
`timescale 1ns/1ns
// ahb_apb_bridge.sv: an AHB subordinate that turns each accepted transfer into one APB transfer
// (read-only). The address phase is registered when HSEL, HREADY and a NONSEQ or SEQ transfer are
// all present. During SETUP and unfinished ACCESS the bridge keeps HREADYOUT low. A successful APB
// completion ends the AHB data phase with OKAY and HRDATA = PRDATA. A failed APB completion starts
// the two-cycle ERROR (HREADYOUT low then high, HRESP high in both). HWDATA and HWSTRB are data-phase signals the manager holds
// through the wait states, so PWDATA and PSTRB are driven from them directly; PADDR is the aligned
// word address (IHI 0024E 2.1.1 leaves an unaligned PADDR unpredictable). HPROT maps onto PPROT:
// privileged from HPROT[1], instruction from HPROT[0] = 0, and the access is Secure.
// A write therefore costs one setup and one access cycle: two cycles of data phase with no APB wait.
module ahb_apb_bridge (
  input  logic        hclk,
  input  logic        hresetn,
  input  logic        hsel,
  input  logic [31:0] haddr,
  input  logic [1:0]  htrans,
  input  logic        hwrite,
  input  logic [3:0]  hprot,
  input  logic [31:0] hwdata,
  input  logic [3:0]  hwstrb,
  input  logic        hready,
  output logic        hreadyout,
  output logic        hresp,
  output logic [31:0] hrdata,
  output logic        psel,
  output logic        penable,
  output logic        pwrite,
  output logic [31:0] paddr,
  output logic [31:0] pwdata,
  output logic [3:0]  pstrb,
  output logic [2:0]  pprot,
  input  logic        pready,
  input  logic [31:0] prdata,
  input  logic        pslverr);
  localparam int IDLE = 0, SETUP = 1, ACCESS = 2, ERR1 = 3, ERR2 = 4;
  bit trace = 0;
  int st = IDLE;
  logic        wr = 0;
  logic [31:0] a = 0;
  logic [2:0]  prot = 0;
  wire take = hsel && hready && htrans[1];
  assign psel      = (st == SETUP || st == ACCESS);
  assign penable   = (st == ACCESS);
  assign pwrite    = wr;
  assign paddr     = {a[31:2], 2'b00};     // APB leaves an unaligned PADDR unpredictable: the word, and PSTRB picks the bytes
  assign pwdata    = wr ? hwdata : 32'h0;
  assign pstrb     = wr ? hwstrb : 4'h0;
  assign pprot     = prot;
  assign hreadyout = (st == IDLE || st == ERR2) ? 1'b1 : (st == ACCESS) ? (pready === 1'b1 && pslverr !== 1'b1) : 1'b0;
  assign hresp     = (st == ERR1 || st == ERR2);
  assign hrdata    = (st == ACCESS) ? prdata : 32'h0;
  always @(posedge hclk or negedge hresetn) begin
    if (!hresetn) st <= IDLE;
    else begin
      case (st)
        SETUP:  st <= ACCESS;
        ACCESS: if (pready === 1'b1) begin
                  if (trace) $display("apb e%0d: %0s 0x%03h%0s", ($time - 5) / 10, wr ? "write" : "read", a[11:0], pslverr === 1'b1 ? " PSLVERR" : "");
                  st <= (pslverr === 1'b1) ? ERR1 : IDLE;
                end
        ERR1:   st <= ERR2;
        default: st <= IDLE;
      endcase
      // A new address phase can be taken whenever HREADY is 1: in IDLE, in the last cycle of ERROR,
      // or at the edge an access completes with OKAY.
      if (take && (st == IDLE || st == ERR2 || (st == ACCESS && pready === 1'b1 && pslverr !== 1'b1))) begin
        wr <= hwrite; a <= haddr; prot <= {~hprot[0], 1'b0, hprot[1]}; st <= SETUP;
      end
    end
  end
endmodule
Read included file: reset_bus.svh
// One aligned word at a time. The manager stands in for the future ap_rv32.
logic clk = 0, bus_reset_n;
always #5 clk = ~clk;
logic [31:0] addr = 0, wdata = 0;
logic write_req = 0, request = 0;
wire sel, enable, writing, ready, error, pready, slave_error;
wire [31:0] paddr, pwdata, prdata, rdata;
ahb_apb_bridge bridge (
  .hclk(clk), .hresetn(bus_reset_n), .hsel(addr[31:16] == 16'h1000),
  .haddr(addr), .htrans({request,1'b0}), .hwrite(write_req), .hprot(4'b0011),
  .hwdata(wdata), .hwstrb(4'hf), .hready(ready), .hreadyout(ready),
  .hresp(error), .hrdata(rdata), .psel(sel), .penable(enable), .pwrite(writing),
  .paddr(paddr), .pwdata(pwdata), .pstrb(), .pprot(), .pready(pready),
  .prdata(prdata), .pslverr(slave_error)
);
task automatic issue(input bit wr, input logic [31:0] address, data);
  @(negedge clk);
  write_req = wr;
  addr = address;
  request = 1;
  @(negedge clk);
  request = 0;
  addr = 0;
  wdata = data;
endtask
Read included file: ap_sysctl_reset_port.sv
// Reset-service words within the ap_soc laboratory system-control page.
// All manager accesses to this port are aligned, full-word APB transfers.
// The cause storage has a separate reset owner and enters through cause.
module ap_sysctl_reset_port (
  input  logic        clk, bus_reset_n,
  input  logic        sel, enable, writing,
  input  logic [31:0] paddr, pwdata,
  input  logic [4:0]  cause,
  input  logic        service_slot,
  output logic        page_selected, access_error, armed,
  output logic [31:0] read_data
);
  localparam logic [31:0] CAUSE = 32'h1000_4004, COMMAND = 32'h1000_4008;
  wire cause_read = !writing && paddr == CAUSE;
  wire command_write = writing && paddr == COMMAND;

  assign page_selected = sel && paddr[31:12] == CAUSE[31:12];
  assign read_data = cause_read ? {27'b0,cause} : 32'b0;
  assign access_error = page_selected && enable && !(cause_read || command_write);

  always_ff @(posedge clk or negedge bus_reset_n) begin
    if (!bus_reset_n)
      armed <= 0;
    else if (page_selected && enable && command_write)
      armed <= pwdata[0];
    else if (service_slot)
      armed <= 0;
  end
endmodule
Read included file: reset_sources.sv
// ap_soc lesson slice. The four warm requests are in the always-on clock domain.
// pin_sample is the pad level AFTER synchronization. POR starts a new log.
module reset_sources (
  input logic clk, por, pin_sample, watchdog, software_req, debug_req,
  output logic core_reset, io_reset, debug_reset,
  output logic [4:0] cause
);
  logic previous_pin;
  logic pin_qualified;
  assign io_reset = por || pin_qualified || watchdog || software_req;
  assign core_reset = io_reset || debug_req;
  assign debug_reset = por;

  always_ff @(posedge clk) begin
    if (por) begin
      previous_pin <= 0;
      pin_qualified <= 0;
      cause <= 5'b00001;
    end else begin
      previous_pin <= pin_sample;
      pin_qualified <= previous_pin && pin_sample;
      if (previous_pin && pin_sample) cause[1] <= 1;
      if (watchdog)      cause[2] <= 1;
      if (software_req)  cause[3] <= 1;
      if (debug_req)     cause[4] <= 1;
    end
  end
endmodule
ConceptWhat is the difference between a cold reset and a warm reset?
ConceptWhich domains does a debug request reset in ap_soc?
ConceptWhat does the reset cause register tell boot software?
ConceptA cause word reads 07. What can it not tell?
ConceptWhy must the reset pin be high for two samples in a row?

Common Mistakes

Wrong Reset the cause register with the watchdog reset.

The restart erases the only evidence before boot software runs.

Fix Only the cold reset may clear the record.

Wrong Read the highest set bit as the latest reset.

A bit position names a source. It holds no time.

Fix Report every source that is set, and ask for a first-event register if order matters.

Wrong Count high samples of the pin across a low sample.

A low sample ends the run of high samples.

Fix Start the count again after every low sample.

Remember

  • A cold reset comes with power-up and starts everything. A warm reset keeps power on and restarts chosen domains.
  • Each reset source has a reach. The debugger resets the processor only.
  • The reset cause register sets one sticky bit for each source, outside the reach of every warm reset.
  • The cause word names the sources seen since power-up. It holds no order and no count.

Practice

Report a problem with this page