tests: periph_pm: add peripheral test.#8848
Conversation
|
Cool! Useful for reference measurements to compare with what the real application uses |
|
Sorry, but it looks like a duplicate of #7666. |
|
@aabadie Oops, yes. I did search for @vincent-d Maybe we can merge both PR's? |
|
I have no time to work on this at the moment, so you can go ahead with this one! I'll try to review it. If it gets merged, we'll close mine. |
10766ec to
2a4baff
Compare
|
Merged this with the work by @vincent-d in #7666. I chose to add an additional Screenshot below show a gap of three seconds of scheduled unblocking. The other gap is a normal unblock (with UART events inbetween). |
2a4baff to
fa9846c
Compare
tests/periph_pm/README.md
Outdated
| @@ -0,0 +1,14 @@ | |||
| Expected result | |||
| =============== | |||
| You should be presented with the RIOT shell, providing you with three commands to test the power | |||
There was a problem hiding this comment.
There are a bit more than three commands ;)
vincent-d
left a comment
There was a problem hiding this comment.
Quickly tested on stm32f4, pm_unblock_rtc works fine.
Except minor comment, it's looks OK.
aabadie
left a comment
There was a problem hiding this comment.
Looks good. I have a few comments and questions.
I'll test it on stm32l0.
tests/periph_pm/Makefile
Outdated
| @@ -0,0 +1,11 @@ | |||
| APPLICATION = periph_pm | |||
There was a problem hiding this comment.
You don't need to set this variable
tests/periph_pm/README.md
Outdated
|
|
||
| Some power modes may require a certain event to wake up. Reset the CPU if needed. | ||
|
|
||
| If a RTC peripheral is available, an additional command to temporary unblock a power mode is |
| #ifdef MODULE_PERIPH_RTC | ||
| #include "periph/rtc.h" | ||
| #endif | ||
| #include "pm_layered.h" |
There was a problem hiding this comment.
I think this include should be made conditional with #ifdef MODULE_PM_LAYERED
tests/periph_pm/main.c
Outdated
|
|
||
| rtc_get_time(&time); | ||
| time.tm_sec += duration; | ||
| while (time.tm_sec > 60) { |
There was a problem hiding this comment.
Do you think it would make sense to use mktime/localtime functions to automatically compute the correct struct tm ?
There was a problem hiding this comment.
Not sure how I would use these methods to just add a certain amount of seconds.
I copied this part from #7666.
There was a problem hiding this comment.
there can be side effects if adding the duration (in seconds) also increases hour. I think those functions handles that better (not tested though)
There was a problem hiding this comment.
Ah I see. Found something here, and it seems to work (ok, I didn't test whole hours, but minutes is OK).
tests/periph_pm/main.c
Outdated
| char line_buf[SHELL_DEFAULT_BUFSIZE]; | ||
|
|
||
| /* print some information about the modes */ | ||
| printf("This application allows you to test the power management\n" |
There was a problem hiding this comment.
Not sure if power management is a peripheral. I would just say to test the CPU power management
tests/periph_pm/main.c
Outdated
| /** | ||
| * @brief List of shell commands for this example. | ||
| */ | ||
| static const shell_command_t shell_commands[] = { |
There was a problem hiding this comment.
In general this array is created just before the main function
There was a problem hiding this comment.
I don't understand this. Can you explain?
Do you mean that I should move this just before the main method?
There was a problem hiding this comment.
Yes, and then you don't need to declare the command functions.
tests/periph_pm/main.c
Outdated
| #ifdef MODULE_PM_LAYERED | ||
| { "block", "block power mode", cmd_block }, | ||
| #endif | ||
| { "lowest", "enter lowest mode", cmd_lowest }, |
There was a problem hiding this comment.
Why is this command needed ? if one unblocks a power mode with unblock command, then the main thread (only thread running) will be blocked (waiting for incoming commands), so the system should switch to idle thread that automatically calls pm_set_lowest.
There was a problem hiding this comment.
Out-of-curiosity, do you confirm that it works as expected (in terms of power consumption) ?
fa9846c to
ba346ae
Compare
|
Fixed the comments and rebased. |
| #include "periph/rtc.h" | ||
| #endif | ||
| #endif | ||
| #include "pm_layered.h" |
There was a problem hiding this comment.
include is still out of the conditional #ifdef
There was a problem hiding this comment.
Oops, sorry. Fixed that one.
tests/periph_pm/main.c
Outdated
|
|
||
| return 0; | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Maybe add a comment mentioning which block is closed here (MODULE_PM_LAYERED)
| } | ||
|
|
||
| #ifdef MODULE_PM_LAYERED | ||
| static int cmd_set(int argc, char **argv) |
There was a problem hiding this comment.
Maybe these functions could be grouped in the same #ifdef MODULE_PM_LAYERED above block.
tests/periph_pm/main.c
Outdated
| */ | ||
| static const shell_command_t shell_commands[] = { | ||
| #ifdef MODULE_PM_LAYERED | ||
| { "block", "block power mode", cmd_block }, |
There was a problem hiding this comment.
Same here, this line can be moved before the unblock line.
There was a problem hiding this comment.
Wanted to keep it sorted alphabetically. Will move it to first one in the other MODULE_PM_LAYERED block.
tests/periph_pm/Makefile
Outdated
| BOARD ?= slstk3401a | ||
| include ../Makefile.tests_common | ||
|
|
||
| FEATURES_REQUIRED += periph_pm |
There was a problem hiding this comment.
I don't think this is needed, this feature is already optional by default (see Makefile.dep). And that's probably why the CI is failing.
76411af to
3bf1f8a
Compare
| #endif /* MODULE_PERIPH_RTC */ | ||
| #endif /* MODULE_PM_LAYERED */ | ||
|
|
||
| static int cmd_off(int argc, char **argv) |
There was a problem hiding this comment.
cmd_off and cmd_reboot should be moved to the top and then all functions that requires MODULE_PM_LAYERED could be grouped in the same conditional #ifdef.
There was a problem hiding this comment.
I'd like to keep it this way: I now have the commands grouped together, and utility functions on top.
| "The available power modes are 0 - %d. Lower-numbered power modes\n" | ||
| "save more power, but may require an event/interrupt to wake up\n" | ||
| "the CPU. Reset the CPU if needed.\n", | ||
| PM_NUM_MODES - 1); |
There was a problem hiding this comment.
The use of PM_NUM_MODE should be excluded for boards not providing the pm_layered module.
47fd045 to
095d8a8
Compare
|
Few MSP430-based board don't compile due to missing |
|
If we can get #6445 finished all such problems would go away. |
+1 for that solution (already used in other places) |
095d8a8 to
78cb81e
Compare
|
@aabadie Can I squash? Murdock is almost happy now :-) |
aabadie
left a comment
There was a problem hiding this comment.
Few remaining comments, mainly regarding the parse_mode function.
tests/periph_pm/main.c
Outdated
| return -1; | ||
| } | ||
|
|
||
| int mode = atoi(argv[1]); |
tests/periph_pm/main.c
Outdated
|
|
||
| int mode = atoi(argv[1]); | ||
|
|
||
| if (mode < 0 || mode >= (int) PM_NUM_MODES) { |
There was a problem hiding this comment.
then here there's no need to check that mode is negative
tests/periph_pm/main.c
Outdated
| #ifdef MODULE_PM_LAYERED | ||
| static int cmd_block(int argc, char **argv) | ||
| { | ||
| int mode = parse_mode(argc, argv); |
| { | ||
| int mode = parse_mode(argc, argv); | ||
|
|
||
| if (mode < 0) { |
There was a problem hiding this comment.
parse_mode function is already testing this
There was a problem hiding this comment.
This would indicate a error code, so I need to check this here.
| { | ||
| int mode = parse_mode(argc, argv); | ||
|
|
||
| if (mode < 0) { |
There was a problem hiding this comment.
same comment about parse_mode
There was a problem hiding this comment.
This would indicate a error code, so I need to check this here.
tests/periph_pm/main.c
Outdated
|
|
||
| static int cmd_unblock(int argc, char **argv) | ||
| { | ||
| int mode = parse_mode(argc, argv); |
There was a problem hiding this comment.
arf, sorry, re-read the parse_mode function and testing the negative returned value is perfectly fine. The comment about uint8_t (in parse_mode) still stands.
| int mode = parse_mode(argc, argv); | ||
| int duration = parse_duration(argc, argv); | ||
|
|
||
| if (mode < 0 || duration < 0) { |
There was a problem hiding this comment.
This would indicate a error code, so I need to check this here.
78cb81e to
ea04b6f
Compare
|
Processed feedback and rebased. |
|
@aabadie Good enough to squash? |
aabadie
left a comment
There was a problem hiding this comment.
Played a bit with the test application and I have other comments.
I think it works but the commands messages (in case of usage errors) could be improved. I'm proposing a refactoring of parse_mode and parse_duration function.
| #ifdef MODULE_PM_LAYERED | ||
| static int parse_mode(int argc, char **argv) | ||
| { | ||
| if (argc < 2) { |
There was a problem hiding this comment.
This should be moved to each command function handler and if a wrong number of arguments is given, the command prints a usage message Usage: unblock <power mode> or Usage: unblock_rtc <power mode> <duration>.
Otherwise the error message doesn't give any hint on how to correctly use the command. Maybe introduce a _check_usage(int argc, int expected_argc) function for this ?
Then the parse_mode and parse_duration could be simplified with this signature:
static int _parse_mode(const char * mode)
static int _parse_duration(const char * duration)ea04b6f to
ad6b12d
Compare
|
@aabadie Have improved argument parsing + usage message. Is this better? |
aabadie
left a comment
There was a problem hiding this comment.
no more comment, ACK
Please squash.
For the record, I tested a bit the application with an stm32l0 based board and had some problems: low power modes doesn't switch automatically the first time, I have to insist a bit with the unblock command (several calls in a row). This is unrelated to this PR but at least the application is useful to exhibit the problem.
ad6b12d to
74d496f
Compare
|
Squashed. Murdock is green. |
|
Then go! |


Contribution description
This PR adds a test application for
periph_pm. Although you need a way to measure power consumption to really use this test, I think its a nice way to play with (or debug) the power modes and observe what the CPU will do.I had this one lying around, somewhere. Initially I used this (before
periph_pm) to test the power modes on the EFM32 development kits, but rearranged it forperiph_pm.Issues/PRs references
None