-
Notifications
You must be signed in to change notification settings - Fork 13
[top,sw/dv] Clk pwr rst smoke tests #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
5f5191d
0345940
7adf270
20e0f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. The test now reads and clears the reset reason directly, so this function is not needed anymore. I will remove it from the HAL source and header. |
||
| { | ||
| 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright lowRISC contributors (COSMIC project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "hal/clkmgr.h" | ||
| #include "hal/mocha.h" | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
|
|
||
| static bool test_gateable_clock(clkmgr_t clkmgr) | ||
| { | ||
| bool initial = clkmgr_gateable_clock_get_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI); | ||
| bool toggled = !initial; | ||
|
|
||
| clkmgr_gateable_clock_set_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI, toggled); | ||
| if (clkmgr_gateable_clock_get_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI) != toggled) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way that we can confirm that the peripherals are actually stopped? I'm not sure whether reading a register will cause a bus error or just hang the design.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this software smoke test can safely check that. If we read from a peripheral after stopping its clock, it may hang the design. This test only checks that the clkmgr registers can be written and read back correctly. I think checking that the clock really stops should be done in DV, where we can observe the clock signals directly. |
||
| return false; | ||
| } | ||
|
|
||
| clkmgr_gateable_clock_set_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI, initial); | ||
| return clkmgr_gateable_clock_get_enabled(clkmgr, CLKMGR_GATEABLE_CLOCK_IO_PERI) == initial; | ||
| } | ||
|
|
||
| static bool test_hintable_clock(clkmgr_t clkmgr) | ||
| { | ||
| bool initial = clkmgr_hintable_clock_get_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN); | ||
| bool toggled = !initial; | ||
|
|
||
| clkmgr_hintable_clock_set_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN, toggled); | ||
| if (clkmgr_hintable_clock_get_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN) != toggled) { | ||
| return false; | ||
| } | ||
|
|
||
| if (toggled && !clkmgr_hintable_clock_get_enabled(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN)) { | ||
| return false; | ||
| } | ||
|
|
||
| clkmgr_hintable_clock_set_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN, initial); | ||
| return clkmgr_hintable_clock_get_hint(clkmgr, CLKMGR_HINTABLE_CLOCK_MAIN) == initial; | ||
| } | ||
|
|
||
| bool test_main() | ||
| { | ||
| clkmgr_t clkmgr = mocha_system_clkmgr(); | ||
| return test_gateable_clock(clkmgr) && test_hintable_clock(clkmgr); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't look like clock manager specific functions. Do they already exist elsewhere in the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find another helper for this, only the
DEV_READandDEV_WRITEmacros. I added these local helpers to avoid repeating the same code in this file. I can also remove them and useDEV_READ/DEV_WRITEdirectly if you prefer.