-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GetTickCount64 has a documented resolution of 10-16 ms. Switch code to QueryPerformanceCounter which like has better resolution.
- Loading branch information
1 parent
5b47040
commit fc28c25
Showing
6 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
Submodule Boards
updated
1013 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2021-2022 Jean Gressmann <[email protected]> | ||
* Copyright (c) 2021-2025 Jean Gressmann <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -123,3 +123,23 @@ void log_candump( | |
fprintf(f, "\n"); | ||
} | ||
} | ||
|
||
static uint64_t s_perf_counter_freq = 1; | ||
|
||
void app_init() | ||
{ | ||
QueryPerformanceFrequency((LARGE_INTEGER*)&s_perf_counter_freq); | ||
|
||
} | ||
|
||
uint64_t mono_ticks() | ||
{ | ||
uint64_t now; | ||
QueryPerformanceCounter((LARGE_INTEGER*)&now); | ||
return now; | ||
} | ||
|
||
uint64_t mono_millis() | ||
{ | ||
return (mono_ticks() * 1000U) / s_perf_counter_freq; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2022 Jean Gressmann <[email protected]> | ||
* Copyright (c) 2020-2025 Jean Gressmann <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -157,6 +157,11 @@ void log_candump( | |
uint8_t dlc, | ||
uint8_t const* data); | ||
|
||
uint64_t mono_ticks(); | ||
uint64_t mono_millis(); | ||
|
||
void app_init(); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Jean Gressmann <[email protected]> | ||
* Copyright (c) 2020-2025 Jean Gressmann <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -495,8 +495,11 @@ int run(app_ctx* ac) | |
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); | ||
|
||
while (1) { | ||
|
||
uint64_t const wait_start_time = mono_millis(); | ||
auto r = WaitForMultipleObjects(static_cast<DWORD>(_countof(handles)), handles, FALSE, timeout_ms); | ||
uint64_t const now = mono_millis(); | ||
DWORD const elapsed_ms = (DWORD)(now - wait_start_time); | ||
|
||
if (r >= WAIT_OBJECT_0 && r < WAIT_OBJECT_0 + _countof(handles)) { | ||
auto index = r - WAIT_OBJECT_0; | ||
auto handle = handles[index]; | ||
|
@@ -522,8 +525,13 @@ int run(app_ctx* ac) | |
process_rx(ac); | ||
|
||
if (ac->tx_job_count) { | ||
timeout_ms = 0xffffffff; | ||
ULONGLONG now = GetTickCount64(); | ||
if (elapsed_ms >= timeout_ms) { | ||
timeout_ms = 0xffffffff; | ||
} | ||
else { | ||
timeout_ms -= elapsed_ms; | ||
} | ||
|
||
bool queued = false; | ||
|
||
for (size_t i = 0; i < ac->tx_job_count; ++i) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Jean Gressmann <[email protected]> | ||
* Copyright (c) 2020-2025 Jean Gressmann <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -695,7 +695,11 @@ int run_single(struct app_ctx* ac) | |
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); | ||
|
||
while (1) { | ||
uint64_t const wait_start_time = mono_millis(); | ||
error = sc_can_stream_rx(can_state.stream, timeout_ms); | ||
uint64_t const now = mono_millis(); | ||
DWORD const elapsed_ms = (DWORD)(now - wait_start_time); | ||
|
||
if (error) { | ||
if (SC_DLL_ERROR_USER_HANDLE_SIGNALED == error) { | ||
break; | ||
|
@@ -710,8 +714,12 @@ int run_single(struct app_ctx* ac) | |
} | ||
|
||
if (ac->tx_job_count) { | ||
timeout_ms = 0xffffffff; | ||
ULONGLONG now = GetTickCount64(); | ||
if (elapsed_ms >= timeout_ms) { | ||
timeout_ms = 0xffffffff; | ||
} | ||
else { | ||
timeout_ms -= elapsed_ms; | ||
} | ||
|
||
error = sc_can_stream_tx_batch_begin(can_state.stream); | ||
if (error) { | ||
|