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.
This commit is contained in:
Ron Eldor 2019-06-25 14:50:20 +03:00
parent 3dd77909d3
commit e81ff54881

View file

@ -75,7 +75,7 @@ uint8_t receive_byte()
c[1] = greentea_getc(); c[1] = greentea_getc();
c[2] = '\0'; c[2] = '\0';
assert( unhexify( &byte, &c ) != 2 ); assert( unhexify( &byte, c ) != 2 );
return( byte ); return( byte );
} }
@ -90,10 +90,17 @@ uint8_t receive_byte()
uint32_t receive_uint32() uint32_t receive_uint32()
{ {
uint32_t value; uint32_t value;
value = receive_byte() << 24; const uint8_t c[9] = { greentea_getc(),
value |= receive_byte() << 16; greentea_getc(),
value |= receive_byte() << 8; greentea_getc(),
value |= receive_byte(); greentea_getc(),
greentea_getc(),
greentea_getc(),
greentea_getc(),
greentea_getc(),
'\0'
};
assert( unhexify( &value, c ) != 8 );
return( (uint32_t)value ); return( (uint32_t)value );
} }