Merge pull request #13976 from maribu/pm_get_blocker

sys/pm: Add pm_get_blocker()
This commit is contained in:
Kaspar Schleiser 2020-04-29 12:37:15 +02:00 committed by GitHub
commit 9a4537eef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View File

@ -83,6 +83,15 @@ void pm_unblock(unsigned mode);
*/ */
void pm_set(unsigned mode); void pm_set(unsigned mode);
/**
* @brief Get currently blocked PM modes
*
* @return The current blocker state
*
* This function atomically retrieves the currently blocked PM modes.
*/
pm_blocker_t pm_get_blocker(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -36,7 +36,7 @@
/** /**
* @brief Global variable for keeping track of blocked modes * @brief Global variable for keeping track of blocked modes
*/ */
volatile pm_blocker_t pm_blocker = { .val_u32 = PM_BLOCKER_INITIAL }; static volatile pm_blocker_t pm_blocker = { .val_u32 = PM_BLOCKER_INITIAL };
void pm_set_lowest(void) void pm_set_lowest(void)
{ {
@ -79,6 +79,11 @@ void pm_unblock(unsigned mode)
irq_restore(state); irq_restore(state);
} }
pm_blocker_t pm_get_blocker(void)
{
return pm_blocker;
}
#ifndef PROVIDES_PM_LAYERED_OFF #ifndef PROVIDES_PM_LAYERED_OFF
void pm_off(void) void pm_off(void)
{ {

View File

@ -28,7 +28,6 @@
#ifdef MODULE_PM_LAYERED #ifdef MODULE_PM_LAYERED
#include "pm_layered.h" #include "pm_layered.h"
extern volatile pm_blocker_t pm_blocker; /* sys/pm_layered/pm.c */
#endif /* MODULE_PM_LAYERED */ #endif /* MODULE_PM_LAYERED */
static void _print_usage(void) { static void _print_usage(void) {
@ -107,6 +106,7 @@ static int cmd_unblock(char *arg)
return 1; return 1;
} }
pm_blocker_t pm_blocker = pm_get_blocker();
if (pm_blocker.val_u8[mode] == 0) { if (pm_blocker.val_u8[mode] == 0) {
printf("Mode %d is already unblocked.\n", mode); printf("Mode %d is already unblocked.\n", mode);
return 1; return 1;
@ -125,6 +125,7 @@ static int cmd_show(char *arg)
(void)arg; (void)arg;
uint8_t lowest_allowed_mode = 0; uint8_t lowest_allowed_mode = 0;
pm_blocker_t pm_blocker = pm_get_blocker();
for (unsigned i = 0; i < PM_NUM_MODES; i++) { for (unsigned i = 0; i < PM_NUM_MODES; i++) {
printf("mode %u blockers: %u \n", i, pm_blocker.val_u8[i]); printf("mode %u blockers: %u \n", i, pm_blocker.val_u8[i]);
if (pm_blocker.val_u8[i]) { if (pm_blocker.val_u8[i]) {

View File

@ -44,8 +44,6 @@ extern int _pm_handler(int argc, char **argv);
#ifdef MODULE_PM_LAYERED #ifdef MODULE_PM_LAYERED
extern volatile pm_blocker_t pm_blocker; /* sys/pm_layered/pm.c */
#ifdef MODULE_PERIPH_RTC #ifdef MODULE_PERIPH_RTC
static int check_mode_duration(int argc, char **argv) static int check_mode_duration(int argc, char **argv)
{ {
@ -101,6 +99,7 @@ static int cmd_unblock_rtc(int argc, char **argv)
return 1; return 1;
} }
pm_blocker_t pm_blocker = pm_get_blocker();
if (pm_blocker.val_u8[mode] == 0) { if (pm_blocker.val_u8[mode] == 0) {
printf("Mode %d is already unblocked.\n", mode); printf("Mode %d is already unblocked.\n", mode);
return 1; return 1;