@@ -214,6 +214,34 @@ cd src-gen/LfcCentricZephyr
214
214
west build -t run
215
215
```
216
216
217
+ # Timing-precision
218
+ There exist two different Zephyr implementations of the LF timing API. The
219
+ default is based on the [ Zephyr Kernel
220
+ Timing] ( https://docs.zephyrproject.org/latest/kernel/services/timing/clocks.html ) .
221
+ It is simple and supported on all boards with Zephyr support. However it is not
222
+ that precise. E.g. for the nRF52 boards it is based on a 32KHz timer, while for
223
+ many other boards is a 10Khz timer. This limits the timing-precision to 10s-100s
224
+ of microseconds.
225
+
226
+ If this is not sufficient, the LF timing API based on the [ Zephyr
227
+ Counter] ( https://docs.zephyrproject.org/latest/hardware/peripherals/counter.html )
228
+ can be used. This is an abstraction of a generic timer peripheral which is found
229
+ on many MCUs. The Counter API can give time-precision in the order of 10s of
230
+ nanoseconds. Not all boards have implemented the Counter API, and not all
231
+ implementations includes all the features that is needed to implement the LF
232
+ timing API. Currently we have only tested with nRF52, iMXRT1170 and ESP32.
233
+
234
+ To compile with the Counter API, we must enable the counter device in the ` prj.conf ` file:
235
+ ```
236
+ CONFIG_COUNTER=y
237
+ ```
238
+ and pass an extra flag to CMake:
239
+
240
+ ```
241
+ cd apps/NrfBlinky
242
+ west lfc src/NrfBlinky.lf --build "-p always -b nrf52dk_nrf52832 -- -DLF_ZEPHYR_CLOCK_COUNTER=1"
243
+ ```
244
+
217
245
# C libraries
218
246
Zephyr has support for three C library implementations.
219
247
- Newlib (Default library used by LF)
@@ -234,6 +262,7 @@ to use Picolibc instead put the following in your `prj.conf` file:
234
262
CONFIG_NEWLIB_LIBC=n
235
263
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=n
236
264
CONFIG_PICOLIBC=y
265
+ CONFIG_PICOLIBC_IO_FLOAT=y
237
266
```
238
267
239
268
With some additional work we could also get the LF runtime working with Minimal
@@ -276,12 +305,9 @@ From here you can step through the LF program. To get a more visual interface yo
276
305
## Timing in QEMU emulations
277
306
The QEMU emulation is not cycle-accurate and implements optimizations such that
278
307
if the system goes to sleep, like when the last active thread in the program
279
- calls ` k_sleep() ` , then the emulator fast-forwards time. This does not affect
280
- the QEMU-emulation of the * unthreaded* runtime since it implements sleeping
281
- between events using * busy-waits* . However, the * threaded* runtime sleeps
282
- between events using a call to ` k_cond_timedwait ` which has the side-effect that
283
- QEMU fast-forwards time. This causes the emulation of threaded programs to
284
- appear as if the ` fast ` target property was set to ` true ` .
308
+ calls ` k_sleep() ` , then the emulator fast-forwards time. This causes the
309
+ emulation of threaded programs to appear as if the ` fast ` target property was
310
+ set to ` true ` .
285
311
286
312
## Troubleshooting
287
313
0 commit comments