summaryrefslogtreecommitdiff
path: root/include/timer.h
Commit message (Collapse)AuthorAgeFilesLines
* Update license boilerplate text in source code filesMike Frysinger2022-09-121-1/+1
| | | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: Icd3a1723c20595356af83d190b2c6a9078b3013b Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3891203 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* include/timer.h: Format with clang-formatJack Rosenthal2022-07-011-7/+6
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Ifea78096fc47bb49e4011046cd91584c16ff8365 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3730423 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* timer.h: Avoid redefining clock_t when compiling with libcTom Hughes2022-06-091-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | Move the clock_t typedef to the "builtin" directory, which the directory containing headers that mirror those in the C standard library. The "builtin" directory can then be excluded when building with the standard library. include/timer.h:31:14: error: typedef redefinition with different types ('long' vs 'unsigned long') typedef long clock_t; ^ /usr/armv7m-cros-eabi/include/sys/types.h:107:19: note: previous definition is here typedef _CLOCK_T_ clock_t; ^ BRANCH=none BUG=b:234181908 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ib2381664535781035b367b414c5f00639ce9b9af Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3691958 Reviewed-by: Edward Hill <ecgh@chromium.org>
* zephyr: test: Make get_time mockableAaron Massey2021-10-281-0/+13
| | | | | | | | | | | | | | | | | | Some driver code paths require control of the return value of get_time in order to be properly tested. Now get_time can be mocked during tests. BRANCH=none BUG=b:184856083 TEST=zmake testall and make runhosttests Signed-off-by: Aaron Massey <aaronmassey@chromium.org> Change-Id: I7f66542aaef015263af66d872978c40746a77292 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219471 Commit-Queue: Aaron Massey <aaronmassey@google.com> Tested-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Yuval Peress <peress@google.com>
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* motion sense: Calculate loop time based on sensor needsMathew King2019-04-271-9/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the motion sense loop bases its sleep time based on the fastest active sensor. This method has several flaws: 1. It does not take into account any task switching overhead 2. With a mix of interrupt driven and forced sensors the sleep time gets recalculated every time there is an interrupt causing the loop to oversleep 3. If multiple sensors do not have rates that are in sync the timing of the slower sensor will be off. For example if there was a sensor running at 50 Hz and one running at 20 Hz the slower sensor would end up being sampled at about 16 Hz instead of 20 Hz This change calculates an ideal read time for every forced mode sensor and calculates the sleep time based on the nearest read time. Every time a sensor is read the next read time is calculated based on the ideal read time not the actual read time so that reading does not drift because of system load or other overhead. BUG=b:129159505 TEST=Ran sensor CTS tests on arcada, without this change the magnetometer was failing 50 Hz tests at about 38 Hz with 30% jitter with this change in place 50 Hz was spot on with about 10% jitter BRANCH=none Change-Id: Ia4fccb083713b490518d45e7398eb3be3b957eae Signed-off-by: Mathew King <mathewk@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1574786 Reviewed-by: Jett Rink <jettrink@chromium.org>
* power: Allow board to take custom action on G3 timer expirationDaisuke Nojiri2019-03-281-0/+1
| | | | | | | | | | | | | | | | | | | | | This patch introduces board_system_is_idle callback function. It's called when system is in G3. A board can customize its action taken when system is idle in G3 using battery thresholds, expiration timer, etc. determined at runtime. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=nami,strago,coral TEST=Verify Vayne cut off battery on G3 idle expiration while other Nami's hibernate. Change-Id: I6118a074ac7d844b99d9c0f3eb638b72d5894008 Reviewed-on: https://chromium-review.googlesource.com/1512623 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* timer: fix clock() implementation to match TPM2 library expectationsnagendra modadugu2016-07-211-3/+2
| | | | | | | | | | | | | | | | | | | | | | | The clock() function was introduced to provide free running clock for the TPM2 library, which expects this clock to run with a millisecond resolution. This patch fixes the bug where the function in fact was returning the clock running at a microsecond resolution. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 BUG=chrome-os-partner:50115 TEST=with the appropriate modification of the user of this function all lockout related TCG tests pass. Signed-off-by: nagendra modadugu <ngm@google.com> Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/361180 (cherry picked from commit b4e78b309900402499b8742199fb4536570d3000) (cherry picked from commit fefaa02a4f2c807a3ad50137bd7dba7f5f081c31) Change-Id: Ic02fffca610426d22e58609eb8c3693aec96ad5c Reviewed-on: https://chromium-review.googlesource.com/362118
* Enforce compilation without system headersStefan Reinauer2016-02-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces HOST_CPPFLAGS to be used for all objects being compiled with HOSTCC rather then the target compiler. Since glibc is not linked into the EC, no glibc include files should be included in the EC code base. Hence, create local definitions for clock_t and wchar_t that match what the glibc include would have done, and remove some unneeded includes. Due to very eager optimization, we have to give gcc a little notch to not kick out memset. Signed-off-by: Stefan Reinauer <reinauer@chromium.org> BUG=chrome-os-partner:43025 BUG=chrome-os-partner:49517 BRANCH=none TEST=compile tested Change-Id: Idf3a2881fa8352756b0927b09c6a97473358f239 Reviewed-on: https://chromium-review.googlesource.com/322435 Commit-Ready: Patrick Georgi <pgeorgi@chromium.org> Tested-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* motion_sense: calculate threshold properlyGwendal Grignou2015-08-241-0/+10
| | | | | | | | | | | | | | | | Working on light sensor, sensor were read on every time, SENSOR_EC_THRES was not taken into account. Fix 64/32 conversions and add a function for dealing with rollover. TEST=Set light sensor probe at 1s. Set accel sensor at 100Hz to fill fifo often; verify that light sensor is queried every second only. BRANCH=smaug BUG=chrome-os-partner:39900 Change-Id: If1df53c1a9a304c992f8e517f5d516210118a437 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/291992 Reviewed-by: Sheng-liang Song <ssl@chromium.org>
* export MSDN clock() functionVadim Bendebury2015-08-141-0/+9
| | | | | | | | | | | | | | | | TPM implementation requires a free running clock with granularity better than a 10 us. clock_t definition comes from the toolchain includes. BRANCH=none BUG=chrome-os-partner:43025 TEST=none yet Change-Id: Id3de5fd055aa598afe15657011b88d2c6be4cdfb Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/289953 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cleanup: More comments in timer.hRandall Spangler2013-11-211-1/+10
| | | | | | | | | | | | | | | Indicate when usleep() and udelay() may be called. No code changes, just comments. BUG=none BRANCH=none TEST=Build any platform. Heck, it's just comments. Change-Id: I0182c153c29965b25d5294d838c1406c30115099 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/177452 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Use SECOND and MSEC constantsRandall Spangler2012-10-291-15/+70
| | | | | | | | | | | | | | | | | | We'd defined them in a number of different files. This moves definitions to timer.h, and uses them everywhere we have large delays (since 10*SECOND is less typo-prone than 10000000). Also add msleep() and sleep() inline functions. No need for mdelay() or delay(), since any delays that long should use sleep funcs instead of spin-waiting. BUG=chrome-os-partner:15579 BRANCH=none TEST=boot system; taskinfo displays similar numbers to before Change-Id: I2a92a9f10f46b6b7b6571759b1f8ab4ecfbf8259 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/36726
* add a function to fast forward system timerVincent Palatin2012-08-061-0/+8
| | | | | | | | | | | | | | | | | | | When we wake up from a deep sleep mode, the system timer clock might have been stopped. We need to be able to set using another time source (e.g. the RTC). Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=chrome-os-partner:8866 TEST=make BOARD=snow && make BOARD=link on Snow, on a software implementing STOP mode, check the system time is still accurate by comparing it to the wall clock. Change-Id: Ieddbb423d052c7aceb398470866b25b25a74c0a0 Reviewed-on: https://gerrit.chromium.org/gerrit/29314 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
* Add time_since32() to return microseconds since a start timeSimon Glass2012-06-281-0/+17
| | | | | | | | | | | | | | | | | | | | | | It is useful to implement timeouts like this: start = get_time(); while (time_since32(start) < 1000) ... Add a function to make this easy. Note that for efficiency we only support a 32-bit return value which limits the timeouts to about an hour. BUG=chrome-os-partner:10888 TEST=manual: build for all boards boot on snow Change-Id: I200cb04f5a76b4c76a9bc314d927e4bab1f08a56 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/26289 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* timer: Allow callers to pass 'now' to timestamp_expired()Simon Glass2012-05-141-1/+2
| | | | | | | | | | | To avoid calling get_time() when the caller already knows the value, add a parameter to timestamp_expired(). BUG=chrome-os-partner:9424 TEST=build and boot on Daisy Change-Id: Ibb97c86f429ec4b814e17b41cbf79b612a75097a Signed-off-by: Simon Glass <sjg@chromium.org>
* timer: Add timestamp_expired() to check for expirySimon Glass2012-05-021-0/+8
| | | | | | | | | | | | Rather than open code this each time, create a function for this. The wrap-around condition may not be needed, if the timer starts at zero, since we have 64 bits to play with. BUG=chrome-os-partner:9424 TEST=build and boot on daisy Change-Id: I84ae651212769b5927c452bc03f31f60a25a829e Signed-off-by: Simon Glass <sjg@chromium.org>
* Watchdog fixesRandall Spangler2012-04-251-26/+17
| | | | | | | | | | | | | | | | | | 1) When frequency changes, reload the watchdog timer right away, or it may expire before the next reload. (Only matters when re-enabling the PLL.) 2) Split out the timer/task debug output used by the watchdog into their own routines, instead of assuming it's safe to call the command handlers. Also make the flushes in those print routines safe to call from interrupt level. Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=none TEST=waitms 1500; should print task dump again Change-Id: I07e0ed24a526ae499566dab0bbeb0f5755cd5be6
* Initial sources import 3/3Vincent Palatin2011-12-071-0/+60
source files mainly done by Vincent. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> Change-Id: Ic2d1becd400c9b4b4a14d4a243af1bdf77d9c1e2