New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable low-power ticker and Sleep for FastModels #10124
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c06f99
Fastmodel: add HAL low-power ticker implementation
8ebb363
FastModel: add HAL sleep implementation
0374309
FastModel: refactor us_ticker code, make names intuitive
2603e29
FastModel: Skip low-power ticker time drifting test for models
229e30a
FastModel: Enable low-power ticker and sleep
916ec21
FastModel: Add SPDX License Identifier
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2006-2019 ARM Limited | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <stddef.h> | ||
#include "lp_ticker_api.h" | ||
#include "PeripheralNames.h" | ||
|
||
#define LP_TICKER_INTERRUPT CMSDK_TIMER0 | ||
#define LP_TICKER_COUNTER CMSDK_TIMER1 | ||
#define LP_TICKER_TIMER_IRQn TIMER0_IRQn | ||
|
||
|
||
/* mbed OS HAL API defined lp_ticker as an increment ticker | ||
* MPS2 platform provided in SSE-200 are decrement tickers | ||
* with interrupt fired counter reaches 0. | ||
* | ||
* So 2 Timers are used to construct mbed OS HAL low power ticker. | ||
* | ||
* TIMER0 is for generating interrupts | ||
* and TIMER0 will turned off when it is generating interrupts | ||
* | ||
* TIMER1 is for counting, and returns inverted binary when read from it | ||
* Because TIMER1 is running at the speed of 25Mhz, it need to be shift by 10, | ||
* in order to meet mbed HAL lp_ticker definitions | ||
* | ||
*/ | ||
|
||
static int lp_ticker_inited = 0; | ||
|
||
void lp_ticker_internal_handler(void) | ||
{ | ||
LP_TICKER_INTERRUPT->CTRL &= ~CMSDK_TIMER_CTRL_IRQEN_Msk; | ||
LP_TICKER_INTERRUPT->CTRL &= ~CMSDK_TIMER_CTRL_EN_Msk; | ||
lp_ticker_irq_handler(); | ||
} | ||
|
||
|
||
void lp_ticker_init(void) | ||
{ | ||
if (lp_ticker_inited) { | ||
lp_ticker_disable_interrupt(); | ||
return; | ||
} | ||
|
||
LP_TICKER_COUNTER->CTRL = 0x0ul; | ||
LP_TICKER_INTERRUPT->CTRL = 0x0ul; | ||
|
||
LP_TICKER_COUNTER->RELOAD = 0xFFFFFFFFul; | ||
LP_TICKER_INTERRUPT->RELOAD = 0xFFFFFFFFul; | ||
|
||
LP_TICKER_COUNTER->CTRL |= CMSDK_TIMER_CTRL_EN_Msk; | ||
|
||
NVIC_SetVector(LP_TICKER_TIMER_IRQn, (uint32_t)lp_ticker_internal_handler); | ||
lp_ticker_inited = 1; | ||
} | ||
|
||
void lp_ticker_free(void) | ||
{ | ||
LP_TICKER_COUNTER->CTRL &= ~CMSDK_TIMER_CTRL_EN_Msk; | ||
lp_ticker_disable_interrupt(); | ||
lp_ticker_inited = 0; | ||
} | ||
|
||
uint32_t lp_ticker_read() | ||
{ | ||
return (~LP_TICKER_COUNTER->VALUE) >> 10; | ||
} | ||
|
||
void lp_ticker_set_interrupt(timestamp_t timestamp) | ||
{ | ||
uint32_t delta = (timestamp << 10) - (~LP_TICKER_COUNTER->VALUE); | ||
|
||
LP_TICKER_INTERRUPT->CTRL &= ~CMSDK_TIMER_CTRL_EN_Msk; | ||
LP_TICKER_INTERRUPT->RELOAD = delta; | ||
LP_TICKER_INTERRUPT->CTRL |= CMSDK_TIMER_CTRL_IRQEN_Msk; | ||
LP_TICKER_INTERRUPT->CTRL |= CMSDK_TIMER_CTRL_EN_Msk; | ||
|
||
NVIC_EnableIRQ(LP_TICKER_TIMER_IRQn); | ||
} | ||
|
||
void lp_ticker_fire_interrupt(void) | ||
{ | ||
NVIC_EnableIRQ(LP_TICKER_TIMER_IRQn); | ||
NVIC_SetPendingIRQ(LP_TICKER_TIMER_IRQn); | ||
} | ||
|
||
void lp_ticker_disable_interrupt(void) | ||
{ | ||
LP_TICKER_INTERRUPT->CTRL &= ~CMSDK_TIMER_CTRL_IRQEN_Msk; | ||
LP_TICKER_INTERRUPT->CTRL &= ~CMSDK_TIMER_CTRL_EN_Msk; | ||
NVIC_DisableIRQ(LP_TICKER_TIMER_IRQn); | ||
} | ||
|
||
void lp_ticker_clear_interrupt(void) | ||
{ | ||
LP_TICKER_INTERRUPT->INTCLEAR = CMSDK_TIMER_INTCLEAR_Msk; | ||
} | ||
|
||
const ticker_info_t *lp_ticker_get_info(void) | ||
{ | ||
static const ticker_info_t info = { | ||
24414, // 10 stages scaled from 25MHz (dived by 1024) | ||
22 // 22 bit counter | ||
}; | ||
return &info; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
/** \addtogroup hal */ | ||
/** @{*/ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2018-2019 Arm Limited | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
#include "sleep_api.h" | ||
#include "us_ticker_api.h" | ||
|
||
#include "PeripheralNames.h" | ||
#define US_TICKER_COUNTER CMSDK_DUALTIMER1 | ||
#define US_TICKER_INTERRUPT CMSDK_DUALTIMER2 | ||
#define US_TICKER_TIMER_IRQn DUALTIMER_IRQn | ||
|
||
|
||
#if DEVICE_SLEEP | ||
|
||
void hal_sleep(void) | ||
{ | ||
__WFI(); | ||
} | ||
|
||
/* Since there is no power management function implemented in MPS2, | ||
* Also Deep Sleep mode mean to save power which is not practical on a simulator. | ||
* So mbed HAL Deep sleep is mocked by Sleep, | ||
* representing a "Waiting For Interrupt" state, | ||
* but disabling the Microsec ticker in addition */ | ||
|
||
void hal_deepsleep(void) | ||
{ | ||
#if DEVICE_USTICKER | ||
uint32_t val = US_TICKER_COUNTER->TimerValue; | ||
US_TICKER_COUNTER->TimerControl &= ~CMSDK_DUALTIMER1_CTRL_EN_Msk; | ||
US_TICKER_INTERRUPT->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk; | ||
US_TICKER_INTERRUPT->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_INTEN_Msk; | ||
#endif | ||
|
||
__WFI(); | ||
|
||
#if DEVICE_USTICKER | ||
US_TICKER_COUNTER->TimerLoad = val; | ||
US_TICKER_COUNTER->TimerControl |= CMSDK_DUALTIMER1_CTRL_EN_Msk; | ||
US_TICKER_INTERRUPT->TimerControl |= CMSDK_DUALTIMER1_CTRL_INTEN_Msk; | ||
US_TICKER_INTERRUPT->TimerControl |= CMSDK_DUALTIMER2_CTRL_EN_Msk; | ||
#endif | ||
} | ||
|
||
#endif | ||
|
||
/**@}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to remove some tests because they are not passing....?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how is it not supported?
@ARMmbed/mbed-os-hal to review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is same story as #10030
For partner's targets/platforms, which will be used real life production. we are not allow them to skip tests, if they can't make them pass. The tests are mean to check that all platform comply with mbed HAL API.
FastModel it is a software simulator for Arm platform/cores. mean to be used as a tool for testing or early stage development. It is will never be used for any real IoT products.
They can simulator how ARM core works. One of issue for software simulator is they running on your host PC, they can't grantee the timing accuracy as microelectronics.
So the exception is just for the software models