Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Counting Watchdog Resets

Hello

I have a NIOS 2 application that has an Interval timer configured as a Watchdog timer. This works as expected in my code, causing a CPU reset as appropriate for the circumstances. However, I would like to monitor the occurances of the timeouts by incrementing a counter whenever this happens. I have been unable to find a way to distinguish as normal reset from a watchdog reset. Can anyone suggest a way that this can be done??

Thank you for your help.

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You could route the reset pulse to outside the sopc system. Then, create a custom component with a counter that increments the count every time the wd count is input, as well as trigger the system reset. Just have to catch the edge of the wd input signal, make sure you don't count too many, and make sure the count doesn't get reset based on the reset signal.

    -kevin
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    something like:::

    
    entity ent is
    port(
    clk : in std_logic;
    timeout_pulse : in std_logic;
    reset_request : out std_logic;
    avs_read : in std_logic;
    avs_read_data : out std_logic_vector(31 downto 0)
    );
    end ent;
    architecture stl of ent is
      signal cnt : std_logic_vector(31 downto 0);
    begin
    process(clk)
    begin
      if(rising_edge(clk)) then
        if(timeout_pulse = '1') then
          cnt <= cnt + 1;
        end if;
      end if;
    end process;
    reset_request <= timeout_pulse;
    avs_read_data <= cnt;
    end stl;
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you very much kbs972 for your response.

    I was hoping for a simpler method of doing this. For example, when the NIOS boots it could check a NIOS register for the cause of the reset. I have read that for exception handling that there is a "cause code" that includes a "reset" code (0) and a "processor only reset request" code (1). Since the Watchdog causes a "reset request" when it times out, I suspect that the "cause code" would be set to 1 and if I could access this code when the processor restarts I would be able to increment my counter in software if the "cause code" was 1. Do you (or anyone else) know how to access this "cause code" value, and if my suspicions are correct??

    Thanks again for your help.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have a similar approach. I do not need to count the watchdog resets, but want to distinguish between a watchdog and a normal external reset for built-in test.

    If someone has a simple solution, I would be happy :-)

    Thanks in advance
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your reply. I have been working on this and have found a solution, for my purposes anyway. I decided that since I could not identify a Watchdog reset, I would identify the normal POR instead. I created a VHDL latch and placed it outside the NIOS. The latch would be set by the reset signal from outside the FPGA, generated from a seperate reset chip. I added a single output port to my NIOS and connected it to the latch reset. I also added a single input port to check the latch output state. In software my program would check the status of the latch first and if it was not set (reset), then the reset did not happen due to a POR so it must be a Watchdog reset. I could then count the resets when the latch was reset, but not if it was set. This seems to work okay in my application. I hope my explaination is clear and you find the idea useable.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your quick reply. I think I understand the spirit of your solution and will implement it this way.

    Unbelievable that it is not possible for the watchdog timer module itself to provide this information.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hello

    I have a NIOS 2 application that has an Interval timer configured as a Watchdog timer. This works as expected in my code, causing a CPU reset as appropriate for the circumstances. However, I would like to monitor the occurances of the timeouts by incrementing a counter whenever this happens. I have been unable to find a way to distinguish as normal reset from a watchdog reset. Can anyone suggest a way that this can be done??

    Thank you for your help.

    --- Quote End ---

    Hi there

    Since you have your watchdog worked fine, I have a question about the Watchdog. I configured the timer as a watchdog. I was trying to use "IOWR(WATCHDOG_BASE, 1, 0xffff);" to start the watchdog. But it did not trigger the CPU reset. Can you please give me some advise?