-
Notifications
You must be signed in to change notification settings - Fork 3k
Add wait_ns API #9812
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
Merged
Merged
Add wait_ns API #9812
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,96 @@ | ||
/* | ||
* Copyright (c) 2018, ARM Limited, All Rights Reserved | ||
* 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 "mbed.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity.h" | ||
#include "utest.h" | ||
#include "platform/mbed_wait_api.h" | ||
#include "hal/us_ticker_api.h" | ||
#include "hal/lp_ticker_api.h" | ||
|
||
using namespace utest::v1; | ||
|
||
/* This test is created based on the test for Timer class. | ||
* Since low power timer is less accurate than regular | ||
* timer we need to adjust delta. | ||
*/ | ||
|
||
/* | ||
* Define tolerance as follows: | ||
* Timer might be +/-5% out; wait_ns is permitted 40% slow, but not fast. | ||
* Therefore minimum measured time should be 95% of requested, maximum should | ||
* be 145%. Unity doesn't let us specify an asymmetric error though. | ||
* | ||
* Would be nice to have tighter upper tolerance, but in practice we've seen | ||
* a few devices unable to sustain theoretical throughput - flash wait states? | ||
*/ | ||
#define TOLERANCE_MIN 0.95f | ||
#define TOLERANCE_MAX 1.45f | ||
#define MIDPOINT ((TOLERANCE_MIN+TOLERANCE_MAX)/2) | ||
#define DELTA (MIDPOINT-TOLERANCE_MIN) | ||
|
||
/* This test verifies if wait_ns's wait time | ||
* is accurate, according to a timer. | ||
* | ||
* Given timer is created. | ||
* When timer is used to measure delay. | ||
* Then the results are valid (within acceptable range). | ||
*/ | ||
template<int wait_val_ms, class CompareTimer> | ||
void test_wait_ns_time_measurement() | ||
{ | ||
CompareTimer timer; | ||
|
||
float wait_val_s = (float)wait_val_ms / 1000; | ||
|
||
/* Start the timer. */ | ||
timer.start(); | ||
|
||
/* Wait <wait_val_ms> ms - arithmetic inside wait_ns will overflow if | ||
* asked for too large a delay, so break it up. | ||
*/ | ||
for (int i = 0; i < wait_val_ms; i++) { | ||
wait_ns(1000000); | ||
} | ||
|
||
/* Stop the timer. */ | ||
timer.stop(); | ||
|
||
/* Check results - wait_val_us us have elapsed. */ | ||
TEST_ASSERT_FLOAT_WITHIN(DELTA * wait_val_s, MIDPOINT * wait_val_s, timer.read()); | ||
} | ||
|
||
utest::v1::status_t test_setup(const size_t number_of_cases) | ||
{ | ||
GREENTEA_SETUP(15, "default_auto"); | ||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
#if DEVICE_LPTICKER | ||
Case("Test: wait_ns - compare with lp_timer 1s", test_wait_ns_time_measurement<1000, LowPowerTimer>), | ||
#endif | ||
Case("Test: wait_ns - compare with us_timer 1s", test_wait_ns_time_measurement<1000, Timer>) | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
||
int main() | ||
{ | ||
return !Harness::run(specification); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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.
Could we resolve the TODO before committing this?
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.
We don't actually have any M33 targets yet, do we? So don't think I've got anything I can test this on.
My belief is that the M33 is basically an M4 in terms of internal architecture, but no firm evidence. Could leave the
__CORTEX_M == 33
case out and deal with it when we have the first actual target.