From 7c637c3d459bec015aef858299b93adfbe13fca2 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sat, 6 Apr 2024 15:18:48 +0200 Subject: [PATCH 1/3] Adjust usage of clock() --- ee/libpthreadglue/src/osal.c | 2 +- ee/network/tcpip/src/sys_arch.c | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/ee/libpthreadglue/src/osal.c b/ee/libpthreadglue/src/osal.c index 436c83b53d0..ebb8354a8a8 100644 --- a/ee/libpthreadglue/src/osal.c +++ b/ee/libpthreadglue/src/osal.c @@ -672,7 +672,7 @@ pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, uns if (pTimeout == NULL) { timeout = 0; } else { - timeout = *pTimeout; + timeout = *pTimeout * 1000; } while (1) { diff --git a/ee/network/tcpip/src/sys_arch.c b/ee/network/tcpip/src/sys_arch.c index 530c19cffd4..3b2371591da 100644 --- a/ee/network/tcpip/src/sys_arch.c +++ b/ee/network/tcpip/src/sys_arch.c @@ -80,13 +80,6 @@ static void free_msg(arch_message *msg) SignalSema(MsgCountSema); } -static inline u32_t ComputeTimeDiff(u32 start, u32 end) -{ - u32 NumTicksElasped=(end Date: Sat, 6 Apr 2024 15:27:54 +0200 Subject: [PATCH 2/3] Avoid the usage of CLOCK_PER_SEC in _times --- ee/libcglue/src/glue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/libcglue/src/glue.c b/ee/libcglue/src/glue.c index f457b0eef45..f96b4b98dcd 100644 --- a/ee/libcglue/src/glue.c +++ b/ee/libcglue/src/glue.c @@ -637,7 +637,7 @@ int _gettimeofday(struct timeval *tv, struct timezone *tz) #ifdef F__times clock_t _times(struct tms *buffer) { - clock_t clk = GetTimerSystemTime() / (kBUSCLK / CLOCKS_PER_SEC); + clock_t clk = GetTimerSystemTime() / (kBUSCLK / (1000 * 1000)); if (buffer != NULL) { buffer->tms_utime = clk; From 245fc5c6780c7738a501d3b7b2b8bd25266f0294 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sat, 6 Apr 2024 15:40:05 +0200 Subject: [PATCH 3/3] Fix nanosleep example --- ee/libcglue/samples/nanosleep/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ee/libcglue/samples/nanosleep/main.c b/ee/libcglue/samples/nanosleep/main.c index fc1359cf341..dbdda5676f3 100644 --- a/ee/libcglue/samples/nanosleep/main.c +++ b/ee/libcglue/samples/nanosleep/main.c @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) struct timespec tv = {0}; tv.tv_sec = 1; tv.tv_nsec = 0; - error_tolerance = 5; // 5 miliseconds of error tolerance + error_tolerance = 200; // 200 miliseconds of error tolerance #if defined(SCREEN_DEBUG) init_scr(); @@ -51,13 +51,13 @@ int main(int argc, char *argv[]) second_waited += tv.tv_sec; tv.tv_sec++; } - diff = (clock() - start); - diff_error = (second_waited * 1000) - diff; + diff = (clock() - start)/ 1000; + diff_error = abs((second_waited * 1000) - diff); custom_printf("Checking if we have waited %i seconds...\n", second_waited); custom_printf("We have waited: %lu milliseconds\n", diff); - if (abs(diff_error) < error_tolerance) { + if (diff_error < error_tolerance) { custom_printf("nanosecond looks to works properly\n"); } else { custom_printf("nanosecond is not accurate there is a difference of %lu milliseconds \n", diff_error);