@@ -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 */
3838static 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
532533static void rt_pm_dump_status (void )
533534{
0 commit comments