Skip to content

Commit 8ebb363

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
FastModel: add HAL sleep implementation
1 parent 5c06f99 commit 8ebb363

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
/** \addtogroup hal */
3+
/** @{*/
4+
/* mbed Microcontroller Library
5+
* Copyright (c) 2018 Arm Limited
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
21+
#include "sleep_api.h"
22+
#include "us_ticker_api.h"
23+
24+
#include "PeripheralNames.h"
25+
#define US_TICKER_COUNTER CMSDK_DUALTIMER1
26+
#define US_TICKER_INTERRUPT CMSDK_DUALTIMER2
27+
#define US_TICKER_TIMER_IRQn DUALTIMER_IRQn
28+
29+
30+
#if DEVICE_SLEEP
31+
32+
void hal_sleep(void)
33+
{
34+
__WFI();
35+
}
36+
37+
/* Since there is no power management function implemented in MPS2,
38+
* Also Deep Sleep mode mean to save power which is not practical on a simulator.
39+
* So mbed HAL Deep sleep is mocked by Sleep,
40+
* representing a "Waiting For Interrupt" state,
41+
* but disabling the Microsec ticker in addition */
42+
43+
void hal_deepsleep(void)
44+
{
45+
#if DEVICE_USTICKER
46+
uint32_t val = US_TICKER_COUNTER->TimerValue;
47+
US_TICKER_COUNTER->TimerControl &= ~CMSDK_DUALTIMER1_CTRL_EN_Msk;
48+
US_TICKER_INTERRUPT->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk;
49+
US_TICKER_INTERRUPT->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_INTEN_Msk;
50+
#endif
51+
52+
__WFI();
53+
54+
#if DEVICE_USTICKER
55+
US_TICKER_COUNTER->TimerLoad = val;
56+
US_TICKER_COUNTER->TimerControl |= CMSDK_DUALTIMER1_CTRL_EN_Msk;
57+
US_TICKER_INTERRUPT->TimerControl |= CMSDK_DUALTIMER1_CTRL_INTEN_Msk;
58+
US_TICKER_INTERRUPT->TimerControl |= CMSDK_DUALTIMER2_CTRL_EN_Msk;
59+
#endif
60+
}
61+
62+
#endif
63+
64+
/**@}*/

0 commit comments

Comments
 (0)