Skip to content

Commit d51e078

Browse files
committed
[components][pm]fix some issues with low power components
1 parent 623ddc6 commit d51e078

File tree

8 files changed

+32
-30
lines changed

8 files changed

+32
-30
lines changed

bsp/es32f0334/drivers/drv_pm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2019-04-08 wangyq the first version
9+
* 2019-05-06 Zero-Free adapt to the new power management interface
910
*/
1011

1112
#include <rthw.h>

bsp/es32f0654/drivers/drv_pm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2019-04-01 wangyq the first version
9+
* 2019-05-06 Zero-Free adapt to the new power management interface
910
*/
1011

1112
#include <rthw.h>

bsp/stm32/libraries/HAL_Drivers/drv_lptim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Change Logs:
77
* Date Author Notes
8-
* 2017-08-01 tanek the first version
8+
* 2019-05-06 Zero-Free first version
99
*/
1010

1111
#include <board.h>

bsp/stm32/libraries/HAL_Drivers/drv_lptim.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Change Logs:
77
* Date Author Notes
8-
* 2012-08-21 heyuanjie87 the first version
8+
* 2019-05-06 Zero-Free first version
99
*/
1010

1111
#ifndef __DRV_PMTIMER_H__

bsp/stm32/libraries/HAL_Drivers/drv_pm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*
66
* Change Logs:
77
* Date Author Notes
8-
* 2018-07-31 tanek first version
9-
* 2018-05-05 Zero-Free adapt to the new power management interface
8+
* 2019-05-06 Zero-Free first version
109
*/
1110

1211
#include <board.h>
@@ -79,7 +78,7 @@ static uint8_t run_speed[PM_RUN_MODE_MAX][2] =
7978
{2, 3},
8079
};
8180

82-
static void run(struct rt_pm *pm, uint8_t mode, uint32_t frequency)
81+
static void run(struct rt_pm *pm, uint8_t mode)
8382
{
8483
static uint8_t last_mode;
8584
static char *run_str[] = PM_RUN_MODE_NAMES;

components/drivers/include/drivers/pm.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum
7777
* device control flag to request or release power
7878
*/
7979
#define RT_PM_DEVICE_CTRL_REQUEST 0x01
80-
#define RT_PM_DEVICE_CTRL_RELEASE 0x02
80+
#define RT_PM_DEVICE_CTRL_RELEASE 0x00
8181

8282
struct rt_pm;
8383

@@ -87,7 +87,7 @@ struct rt_pm;
8787
struct rt_pm_ops
8888
{
8989
void (*sleep)(struct rt_pm *pm, uint8_t mode);
90-
void (*run)(struct rt_pm *pm, uint8_t mode, uint32_t frequency);
90+
void (*run)(struct rt_pm *pm, uint8_t mode);
9191
void (*timer_start)(struct rt_pm *pm, rt_uint32_t timeout);
9292
void (*timer_stop)(struct rt_pm *pm);
9393
rt_tick_t (*timer_get_tick)(struct rt_pm *pm);
@@ -97,7 +97,7 @@ struct rt_device_pm_ops
9797
{
9898
int (*suspend)(const struct rt_device *device, uint8_t mode);
9999
void (*resume)(const struct rt_device *device, uint8_t mode);
100-
int (*frequency_change)(const struct rt_device *device, uint8_t mode, uint32_t frequency);
100+
int (*frequency_change)(const struct rt_device *device, uint8_t mode);
101101
};
102102

103103
struct rt_device_pm
@@ -122,7 +122,6 @@ struct rt_pm
122122
rt_uint8_t device_pm_number;
123123
struct rt_device_pm *device_pm;
124124

125-
rt_uint32_t frequency;
126125
/* if the mode has timer, the corresponding bit is 1*/
127126
rt_uint8_t timer_mask;
128127
rt_uint8_t flags;
@@ -144,7 +143,7 @@ struct rt_pm_notify
144143

145144
void rt_pm_request(uint8_t sleep_mode);
146145
void rt_pm_release(uint8_t sleep_mode);
147-
int rt_pm_run_mode_set(uint8_t run_mode, uint32_t frequency);
146+
int rt_pm_run_enter(uint8_t run_mode);
148147

149148
void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops);
150149
void rt_pm_device_unregister(struct rt_device *device);

components/drivers/pm/pm.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ static struct rt_pm_notify _pm_notify;
2222

2323
#define RT_PM_TICKLESS_THRESH (2)
2424

25-
RT_WEAK uint32_t rt_pm_enter_critical(void)
25+
RT_WEAK uint32_t rt_pm_enter_critical(uint8_t sleep_mode)
2626
{
2727
return rt_hw_interrupt_disable();
2828
}
2929

30-
RT_WEAK void rt_pm_exit_critical(uint32_t ctx)
30+
RT_WEAK void rt_pm_exit_critical(uint32_t ctx, uint8_t sleep_mode)
3131
{
3232
rt_hw_interrupt_enable(ctx);
3333
}
@@ -37,17 +37,19 @@ RT_WEAK void rt_pm_exit_critical(uint32_t ctx)
3737
*/
3838
static int _pm_device_suspend(uint8_t mode)
3939
{
40-
int index;
40+
int index, ret = RT_EOK;
4141

4242
for (index = 0; index < _pm.device_pm_number; index++)
4343
{
4444
if (_pm.device_pm[index].ops->suspend != RT_NULL)
4545
{
46-
return _pm.device_pm[index].ops->suspend(_pm.device_pm[index].device, mode);
46+
ret = _pm.device_pm[index].ops->suspend(_pm.device_pm[index].device, mode);
47+
if(ret != RT_EOK)
48+
break;
4749
}
4850
}
4951

50-
return RT_EOK;
52+
return ret;
5153
}
5254

5355
/**
@@ -69,15 +71,15 @@ static void _pm_device_resume(uint8_t mode)
6971
/**
7072
* This function will update the frequency of all registered devices
7173
*/
72-
static void _pm_device_frequency_change(uint8_t mode, uint32_t frequency)
74+
static void _pm_device_frequency_change(uint8_t mode)
7375
{
7476
rt_uint32_t index;
7577

7678
/* make the frequency change */
7779
for (index = 0; index < _pm.device_pm_number; index ++)
7880
{
7981
if (_pm.device_pm[index].ops->frequency_change != RT_NULL)
80-
_pm.device_pm[index].ops->frequency_change(_pm.device_pm[index].device, mode, frequency);
82+
_pm.device_pm[index].ops->frequency_change(_pm.device_pm[index].device, mode);
8183
}
8284
}
8385

@@ -92,9 +94,9 @@ static void _pm_frequency_scaling(struct rt_pm *pm)
9294
{
9395
level = rt_hw_interrupt_disable();
9496
/* change system runing mode */
95-
pm->ops->run(pm, pm->run_mode, pm->frequency);
97+
pm->ops->run(pm, pm->run_mode);
9698
/* changer device frequency */
97-
_pm_device_frequency_change(pm->run_mode, pm->frequency);
99+
_pm_device_frequency_change(pm->run_mode);
98100
pm->flags &= ~RT_PM_FREQUENCY_PENDING;
99101
rt_hw_interrupt_enable(level);
100102
}
@@ -138,7 +140,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, uint8_t mode)
138140
}
139141
else
140142
{
141-
level = rt_pm_enter_critical();
143+
level = rt_pm_enter_critical(mode);
142144

143145
/* Notify app will enter sleep mode */
144146
if (_pm_notify.notify)
@@ -151,7 +153,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, uint8_t mode)
151153
_pm_device_resume(mode);
152154
if (_pm_notify.notify)
153155
_pm_notify.notify(RT_PM_EXIT_SLEEP, mode, _pm_notify.data);
154-
rt_pm_exit_critical(level);
156+
rt_pm_exit_critical(level, mode);
155157

156158
return;
157159
}
@@ -202,7 +204,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, uint8_t mode)
202204
if (_pm_notify.notify)
203205
_pm_notify.notify(RT_PM_EXIT_SLEEP, mode, _pm_notify.data);
204206

205-
rt_pm_exit_critical(level);
207+
rt_pm_exit_critical(level, mode);
206208
}
207209
}
208210

@@ -381,11 +383,11 @@ static rt_size_t _rt_pm_device_write(rt_device_t dev,
381383
{
382384
/* get request */
383385
request = *(unsigned char *)buffer;
384-
if (request == '1')
386+
if (request == 0x01)
385387
{
386388
rt_pm_request(pos);
387389
}
388-
else if (request == '0')
390+
else if (request == 0x00)
389391
{
390392
rt_pm_release(pos);
391393
}
@@ -416,7 +418,7 @@ static rt_err_t _rt_pm_device_control(rt_device_t dev,
416418
return RT_EOK;
417419
}
418420

419-
int rt_pm_run_mode_set(uint8_t mode, uint32_t frequency)
421+
int rt_pm_run_enter(uint8_t mode)
420422
{
421423
rt_base_t level;
422424
struct rt_pm *pm;
@@ -429,15 +431,14 @@ int rt_pm_run_mode_set(uint8_t mode, uint32_t frequency)
429431
if (mode < pm->run_mode)
430432
{
431433
/* change system runing mode */
432-
pm->ops->run(pm, mode, frequency);
434+
pm->ops->run(pm, mode);
433435
/* changer device frequency */
434-
_pm_device_frequency_change(mode, frequency);
436+
_pm_device_frequency_change(mode);
435437
}
436438
else
437439
{
438440
pm->flags |= RT_PM_FREQUENCY_PENDING;
439441
}
440-
pm->frequency = frequency;
441442
pm->run_mode = mode;
442443
rt_hw_interrupt_enable(level);
443444

@@ -525,9 +526,9 @@ static void rt_pm_run_mode_switch(int argc, char **argv)
525526
mode = atoi(argv[1]);
526527
}
527528

528-
rt_pm_run_mode_set(mode, 0);
529+
rt_pm_run_enter(mode);
529530
}
530-
MSH_CMD_EXPORT_ALIAS(rt_pm_run_mode_switch, pm_run_set, switch power management run mode);
531+
MSH_CMD_EXPORT_ALIAS(rt_pm_run_mode_switch, pm_run, switch power management run mode);
531532

532533
static void rt_pm_dump_status(void)
533534
{

examples/pm/timer_app.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2018-08-07 Tanek first implementation
9+
* 2019-05-06 Zero-Free adapt to the new power management interface
910
*/
1011

1112
#include <board.h>

0 commit comments

Comments
 (0)