Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions sw/device/lib/hal/rstmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@

#include "hal/rstmgr.h"
#include "hal/mmio.h"
#include "hal/mocha.h"
#include <stdint.h>

uint32_t rstmgr_reset_reason_get(rstmgr_t rstmgr)
{
return DEV_READ(rstmgr + RSTMGR_RESET_INFO_REG);
}

void rstmgr_reset_reason_clear(rstmgr_t rstmgr, uint32_t reason)
{
DEV_WRITE(rstmgr + RSTMGR_RESET_INFO_REG, reason);
}

void rstmgr_software_reset_request(rstmgr_t rstmgr)
{
DEV_WRITE(rstmgr + RSTMGR_RESET_REQ_REG, RSTMGR_RESET_REQ_TRUE);
}

bool rstmgr_software_reset_info_get(rstmgr_t rstmgr)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can now remove this function. I think it was only used in the software_reset test.

{
if (DEV_READ(rstmgr + RSTMGR_RESET_INFO_REG) & RSTMGR_RESET_INFO_SW_RESET) {
if (rstmgr_reset_reason_get(rstmgr) & RSTMGR_RESET_INFO_SW_RESET) {
// Clear the info bit before returning.
DEV_WRITE(rstmgr + RSTMGR_RESET_INFO_REG, RSTMGR_RESET_INFO_SW_RESET);
rstmgr_reset_reason_clear(rstmgr, RSTMGR_RESET_INFO_SW_RESET);
return true;
}
return false;
Expand Down
5 changes: 5 additions & 0 deletions sw/device/lib/hal/rstmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
#define RSTMGR_RESET_REQ_REG (0x4)
#define RSTMGR_RESET_REQ_TRUE (kMultiBitBool4True)
#define RSTMGR_RESET_INFO_REG (0x8)
#define RSTMGR_RESET_INFO_POR (0x1)
#define RSTMGR_RESET_INFO_LOW_PWR (0x2)
#define RSTMGR_RESET_INFO_SW_RESET (0x4)

typedef void *rstmgr_t;

#define RSTMGR_FROM_BASE_ADDR(addr) ((rstmgr_t)(addr))

uint32_t rstmgr_reset_reason_get(rstmgr_t rstmgr);
void rstmgr_reset_reason_clear(rstmgr_t rstmgr, uint32_t reason);

void rstmgr_software_reset_request(rstmgr_t rstmgr);
bool rstmgr_software_reset_info_get(rstmgr_t rstmgr);
18 changes: 12 additions & 6 deletions sw/device/tests/rstmgr/software_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
bool test_main()
{
rstmgr_t rstmgr = mocha_system_rstmgr();
uint32_t reason = rstmgr_reset_reason_get(rstmgr);

if (rstmgr_software_reset_info_get(rstmgr)) {
return true;
if (reason & RSTMGR_RESET_INFO_POR) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is a good change!

rstmgr_reset_reason_clear(rstmgr, RSTMGR_RESET_INFO_POR);
rstmgr_software_reset_request(rstmgr);

// Must wait here for reset to happen.
while (1) {
}
}
// Request a reset of the system.
rstmgr_software_reset_request(rstmgr);

// Must wait here for reset to happen.
while (1) {
if (reason & RSTMGR_RESET_INFO_SW_RESET) {
rstmgr_reset_reason_clear(rstmgr, RSTMGR_RESET_INFO_SW_RESET);
return true;
}

return false;
}