mirror of https://github.com/ARMmbed/mbed-os.git
tests-mbed_hal-lp_ticker: change implementation of the delay before deep-sleep.
Serial buffer must be flushed before entering deep sleep mode. In the test this is done by the additional delay which is implemented on the busy loop which decrements given value down to 0 (`void wait_cycles(volatile unsigned int cycles)`). This solution is not appropriate since it is very target specific and the cycles value has been already increased few times. Additionally very big number of loop cycles which is suitable for fast targets may take much longer on slower boards and results in test timeout. It has been verified that 20ms is sufficient delay for the green-tea transmission. In this test we cannot simply use `wait_ms(20)` since this potentially may put board to sleep and wake up using lp ticker. The test re-initialzies the lp ticker(disables ticker interrupt) and this operation may break the schedule and time tracing by the upper layer. But we can use us ticker which is not affected by this test. The solution is to add a delay routine based on busy loop and us ticker only. This way are able to wait exactly 20 ms.pull/7494/head
parent
bcec185754
commit
832e8b3f36
|
|
@ -29,6 +29,8 @@ using namespace utest::v1;
|
|||
|
||||
volatile int intFlag = 0;
|
||||
|
||||
#define US_PER_MS 1000
|
||||
|
||||
#define TICKER_GLITCH_TEST_TICKS 1000
|
||||
|
||||
#define TICKER_INT_VAL 500
|
||||
|
|
@ -36,6 +38,29 @@ volatile int intFlag = 0;
|
|||
|
||||
#define LP_TICKER_OV_LIMIT 4000
|
||||
|
||||
/* Flush serial buffer before deep sleep
|
||||
*
|
||||
* Since deepsleep() may shut down the UART peripheral, we wait for some time
|
||||
* to allow for hardware serial buffers to completely flush.
|
||||
*
|
||||
* Take NUMAKER_PFM_NUC472 as an example:
|
||||
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
|
||||
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
|
||||
* 20ms here for safe.
|
||||
*
|
||||
* This should be replaced with a better function that checks if the
|
||||
* hardware buffers are empty. However, such an API does not exist now,
|
||||
* so we'll use the busy_wait_ms() function for now.
|
||||
*/
|
||||
#define SERIAL_FLUSH_TIME_MS 20
|
||||
|
||||
void busy_wait_ms(int ms)
|
||||
{
|
||||
const ticker_data_t *const ticker = get_us_ticker_data();
|
||||
uint32_t start = ticker_read(ticker);
|
||||
while ((ticker_read(ticker) - start) < (uint32_t)(ms * US_PER_MS));
|
||||
}
|
||||
|
||||
/* Since according to the ticker requirements min acceptable counter size is
|
||||
* - 12 bits for low power timer - max count = 4095,
|
||||
* then all test cases must be executed in this time windows.
|
||||
|
|
@ -72,11 +97,6 @@ void ticker_event_handler_stub(const ticker_data_t * const ticker)
|
|||
lp_ticker_disable_interrupt();
|
||||
}
|
||||
|
||||
void wait_cycles(volatile unsigned int cycles)
|
||||
{
|
||||
while (cycles--);
|
||||
}
|
||||
|
||||
/* Test that the ticker has the correct frequency and number of bits. */
|
||||
void lp_ticker_info_test()
|
||||
{
|
||||
|
|
@ -97,8 +117,10 @@ void lp_ticker_deepsleep_test()
|
|||
|
||||
lp_ticker_init();
|
||||
|
||||
/* Wait for green tea UART transmission before entering deep-sleep mode. */
|
||||
wait_cycles(400000);
|
||||
/* Give some time Green Tea to finish UART transmission before entering
|
||||
* deep-sleep mode.
|
||||
*/
|
||||
busy_wait_ms(SERIAL_FLUSH_TIME_MS);
|
||||
|
||||
overflow_protect();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue