failed approach
This commit is contained in:
Makefile
config/objects
gomspace
gomspace.mkclock.ccommands.cconn.ccsp.cwscript
libgscsp
include
gs
lib
libcsp
CHANGELOGCONTRIBUTORSCOPYINGINSTALL.rstREADME.rst
bindings
python
libcsp
doc
example.rsthistory.rstinterfaces.rstlibcsp.rstmemory.rstmtu.rstprotocolstack.rststructure.rsttopology.rst
examples
csp_if_fifo.ccsp_if_fifo_windows.ckiss.cpython_bindings_example_client.pypython_bindings_example_client_can.pypython_bindings_example_server.pysimple.czmqproxy.c
include
csp
src
arch
freertos
macosx
posix
windows
bindings
python
crypto
csp_bridge.ccsp_buffer.ccsp_conn.ccsp_conn.hcsp_crc32.ccsp_debug.ccsp_dedup.ccsp_dedup.hcsp_endian.ccsp_hex_dump.ccsp_iflist.ccsp_io.ccsp_io.hcsp_port.ccsp_port.hcsp_promisc.ccsp_promisc.hcsp_qfifo.ccsp_qfifo.hcsp_route.ccsp_route.hcsp_service_handler.ccsp_services.ccsp_sfp.cdrivers
interfaces
rtable
transport
utils
wafwscriptsrc
bindings
python
drivers
error.cfreertos
linux
local.hlog.crouter.crtable.cservice_dispatcher.cservice_handler.ctransaction.clibp60_client
libutil
include
deprecated
gs
uthash
util
base16.hbytebuffer.hbyteorder.hcheck.hclock.hconf_util.hcrc32.hcrc8.hdelay.h
drivers
endian.herror.hfletcher.hfunction_scheduler.hgosh
hexdump.hlinux
log.hlog
minmax.hmutex.hpgm.hqueue.hrtc.hsem.hstdio.hstring.htest
thread.htime.htimestamp.htypes.hunistd.hvmem.hwatchdog
zip
src
base16.cbytebuffer.cbyteorder.cclock.ccrc32.ccrc8.c
wscriptbindings
python
drivers
error.cfletcher.cfunction_scheduler.cgosh
hexdump.clinux
argp.cclock.ccommand_line.ccwd.cdelay.c
lock.clock.hdrivers
function.cmutex.cqueue.crtc.csem.csignal.cstdio.csysfs_helper.cthread.ctime.clog
rtc.cstdio.cstring.cstrtoint.ctest
time.ctimestamp.cvmem
watchdog
zip
mission
test/testtasks
28
gomspace/libutil/src/time.c
Normal file
28
gomspace/libutil/src/time.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
|
||||
|
||||
#include <gs/util/time.h>
|
||||
|
||||
uint32_t gs_time_diff_ms(uint32_t ref_ms, uint32_t now_ms)
|
||||
{
|
||||
if (now_ms >= ref_ms) {
|
||||
return (now_ms - ref_ms);
|
||||
}
|
||||
|
||||
// assuming time wrapped at max uint32_t
|
||||
return ((UINT32_MAX - ref_ms) + now_ms);
|
||||
}
|
||||
|
||||
bool gs_time_sleep_until_ms(uint32_t * ref_ms, uint32_t sleep_ms)
|
||||
{
|
||||
const uint32_t now = gs_time_rel_ms();
|
||||
*ref_ms += sleep_ms; // this is expected to be in the future
|
||||
uint32_t ms = gs_time_diff_ms(now, *ref_ms);
|
||||
if (ms > sleep_ms) {
|
||||
// we are behind - catch up, could be bad seed or too long processing
|
||||
*ref_ms = now;
|
||||
gs_time_sleep_ms(0); // yield - let others have a go
|
||||
return true;
|
||||
}
|
||||
gs_time_sleep_ms(ms);
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user