From 72662a495ce3e92fe6bad77352e80af387eb0820 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Tue, 25 Jun 2019 14:50:20 +0300 Subject: [PATCH] Refactor receive_uint32() Call `greentea_getc()` 8 times, and then `unhexify` once, instead of calling `receive_byte()`, which inside calls `greentea_getc()` twice, for every hex digit. --- tests/suites/target_test.function | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/suites/target_test.function b/tests/suites/target_test.function index 4522fbf0c..71675bdf1 100644 --- a/tests/suites/target_test.function +++ b/tests/suites/target_test.function @@ -75,7 +75,7 @@ uint8_t receive_byte() c[1] = greentea_getc(); c[2] = '\0'; - assert( unhexify( &byte, &c ) != 2 ); + assert( unhexify( &byte, c ) != 2 ); return( byte ); } @@ -90,10 +90,17 @@ uint8_t receive_byte() uint32_t receive_uint32() { uint32_t value; - value = receive_byte() << 24; - value |= receive_byte() << 16; - value |= receive_byte() << 8; - value |= receive_byte(); + const uint8_t c[9] = { greentea_getc(), + greentea_getc(), + greentea_getc(), + greentea_getc(), + greentea_getc(), + greentea_getc(), + greentea_getc(), + greentea_getc(), + '\0' + }; + assert( unhexify( &value, c ) != 8 ); return( (uint32_t)value ); }