Skip to content
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

Test: Increase the UART flush delay #12262

Merged
merged 4 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion TESTS/mbed_drivers/reset_reason/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@
#define MSG_KEY_RESET_REASON "reason"
#define MSG_KEY_DEVICE_RESET "reset"

#define SERIAL_FLUSH_TIME_MS 20
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
* before the UART peripheral shutdown. The UART shutdown happens when the
* device is entering the deepsleep mode or performing a reset.
*
* With the current API, it is not possible to check if the hardware buffers
* are empty. However, it is possible to determine the time required for the
* buffers to flush.
*
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 150

typedef enum {
CMD_STATUS_CONTINUE,
Expand Down
10 changes: 5 additions & 5 deletions TESTS/mbed_drivers/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
* are empty. However, it is possible to determine the time required for the
* buffers to flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
* To be on the safe side, set the wait time to 20 ms.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

int CASE_INDEX_START;
int CASE_INDEX_CURRENT;
Expand Down
22 changes: 13 additions & 9 deletions TESTS/mbed_drivers/watchdog_reset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
* are empty. However, it is possible to determine the time required for the
* buffers to flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
* To be on the safe side, set the wait time to 20 ms.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

#define TIMEOUT_US (1000 * (TIMEOUT_MS))
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
Expand Down Expand Up @@ -112,10 +112,11 @@ void test_simple_reset()

// Phase 1. -- run the test code.
// Init the watchdog and wait for a device reset.
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
Watchdog &watchdog = Watchdog::get_instance();
TEST_ASSERT_FALSE(watchdog.is_running());
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
Expand All @@ -141,10 +142,11 @@ void test_sleep_reset()
}

// Phase 1. -- run the test code.
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
Watchdog &watchdog = Watchdog::get_instance();
TEST_ASSERT_FALSE(watchdog.is_running());
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
Expand Down Expand Up @@ -232,10 +234,11 @@ void test_restart_reset()
// The watchdog should trigger before twice the timeout value.
wait_us(TIMEOUT_US / 2 + TIMEOUT_US);

if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
TEST_ASSERT_TRUE(watchdog.is_running());
// Watchdog should fire before twice the timeout value.
Expand Down Expand Up @@ -268,10 +271,11 @@ void test_kick_reset()
wait_us(TIMEOUT_US - KICK_ADVANCE_US);
watchdog.kick();
}
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
// Watchdog should fire before twice the timeout value.
wait_us(2 * TIMEOUT_US); // Device reset expected.

Expand Down
23 changes: 11 additions & 12 deletions TESTS/mbed_hal/lp_ticker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,20 @@ ticker_irq_handler_type prev_handler;

#define LP_TICKER_OV_LIMIT 4000

/* Flush serial buffer before deep sleep
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
* before the UART peripheral shutdown. The UART shutdown happens when the
* device is entering the deepsleep mode or performing a reset.
*
* Since deepsleep() may shut down the UART peripheral, we wait for some time
* to allow for hardware serial buffers to completely flush.
* With the current API, it is not possible to check if the hardware buffers
* are empty. However, it is possible to determine the time required for the
* buffers to 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.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

void busy_wait_ms(int ms)
{
Expand Down
15 changes: 8 additions & 7 deletions TESTS/mbed_hal/reset_reason/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@
#define MSG_KEY_RESET_REASON "reason"
#define MSG_KEY_DEVICE_RESET "reset"

/* To prevent loss of Greentea data, flush serial buffers before the UART peripheral shutdown. The UART shutdown happens when the
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
* before the UART peripheral shutdown. The UART shutdown happens when the
* device is entering the deepsleep mode or performing a reset.
*
* With the current API, it is not possible to check if the hardware buffers
* are empty. However, you can determine the amount of time required for the
* are empty. However, it is possible to determine the time required for the
* buffers to flush.
*
* For example, NUMAKER_PFM_NUC472:
* The UART peripheral has 16-byte Tx FIFO. With a baud rate of 9600,
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
* To be on the safe side, set the wait time to 20 ms.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

typedef enum {
CMD_STATUS_CONTINUE,
Expand Down
23 changes: 11 additions & 12 deletions TESTS/mbed_hal/sleep/sleep_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@
#include "hal/us_ticker_api.h"
#include "hal/lp_ticker_api.h"

/* Flush serial buffer before deep sleep
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
* before the UART peripheral shutdown. The UART shutdown happens when the
* device is entering the deepsleep mode or performing a reset.
*
* Since deepsleep() may shut down the UART peripheral, we wait for some time
* to allow for hardware serial buffers to completely flush.
* With the current API, it is not possible to check if the hardware buffers
* are empty. However, it is possible to determine the time required for the
* buffers to 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.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

#define US_PER_S 1000000

Expand Down
10 changes: 5 additions & 5 deletions TESTS/mbed_hal/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
* are empty. However, it is possible to determine the time required for the
* buffers to flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
* To be on the safe side, set the wait time to 20 ms.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

int CASE_INDEX_START;
int CASE_INDEX_CURRENT;
Expand Down
23 changes: 14 additions & 9 deletions TESTS/mbed_hal/watchdog_reset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
* are empty. However, it is possible to determine the time required for the
* buffers to flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
* To be on the safe side, set the wait time to 20 ms.
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 20
#define SERIAL_FLUSH_TIME_MS 150

#define TIMEOUT_US (1000 * (TIMEOUT_MS))
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
Expand Down Expand Up @@ -111,10 +111,11 @@ void test_simple_reset()
// Phase 1. -- run the test code.
// Init the watchdog and wait for a device reset.
watchdog_config_t config = { TIMEOUT_MS };
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
// Watchdog should fire before twice the timeout value.
wait_us(2 * TIMEOUT_US); // Device reset expected.
Expand All @@ -138,10 +139,11 @@ void test_sleep_reset()

// Phase 1. -- run the test code.
watchdog_config_t config = { TIMEOUT_MS };
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
sleep_manager_lock_deep_sleep();
if (sleep_manager_can_deep_sleep()) {
Expand Down Expand Up @@ -176,6 +178,7 @@ void test_deepsleep_reset()
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
if (!sleep_manager_can_deep_sleep()) {
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
Expand Down Expand Up @@ -221,10 +224,11 @@ void test_restart_reset()
// The watchdog should trigger before twice the timeout value.
wait_us(TIMEOUT_US / 2 + TIMEOUT_US);

if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
// Watchdog should fire before twice the timeout value.
wait_us(2 * TIMEOUT_US); // Device reset expected.
Expand Down Expand Up @@ -254,10 +258,11 @@ void test_kick_reset()
wait_us(TIMEOUT_US - KICK_ADVANCE_US);
hal_watchdog_kick();
}
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
// Watchdog should fire before twice the timeout value.
wait_us(2 * TIMEOUT_US); // Device reset expected.

Expand Down