You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/tick_sources.md
+79-21Lines changed: 79 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -28,21 +28,22 @@ The frequency of the Watchdog Oscillator is voltage and temperature dependent as
28
28
Timing consistency may vary as much as 20% between two devices in same setup due to individual device differences, or between a prototype and production device due to setup differences.
29
29
30
30
## Alternative tick sources
31
-
For applications requiring high precision timing, the Ticks can be sourced from a hardware timer or external clock.
31
+
For applications requiring high precision timing, the Ticks can be sourced from one of the hardware timers or an external clock input.
32
32
33
-
First, you switch it in `FreeRTOSVariant.h` header by removing or undefining `portUSE_WDTO` and defining `portUSE_TIMER0`.
33
+
First, you switch it in `FreeRTOSVariant.h` header by removing or undefining `portUSE_WDTO` and defining, here for example, the 8-bit Timer0`portUSE_TIMER0`.
34
34
35
35
```cpp
36
36
#undef portUSE_WDTO
37
37
#defineportUSE_TIMER0
38
-
#defineportTICK_PERIOD_MS 16
39
38
```
40
39
41
-
Next, in your app you provide two pieces of code: the initialisation function and the ISR hook. Their implementation depends of what is your tick source.
40
+
Next, in your app you provide two pieces of code: the initialisation functions and the ISR hook. Their implementation depends on your tick source.
41
+
42
+
## Timer specific initialisation and ISR functions
42
43
44
+
For implementation examples for many different timers, including the RTC Timer2 available on some devices, please refer to `port.c` in the [AVRfreeRTOS Repository](https://github.com/feilipu/avrfreertos/tree/master/freeRTOS10xx/portable).
43
45
44
-
## Hardware timer Timer0
45
-
### Timer initialisation function
46
+
### Hardware timer Timer0
46
47
_NOTE: This code snippet is verified to work on Atmega2560. Full code available [here](./tick_sources_timer0.cpp)._
The context is saved at the start of `portSchedulerTick()`, then the tick count is incremented, finally the new context is loaded - so no dirtying occurs.
163
+
The register context is saved at the start of `vPortYieldFromTick()`, then the tick count is incremented, finally the new context is loaded - so no dirtying occurs.
106
164
107
165
108
-
For **cooperative** scheduler, the context is not saved because no switching is intended; therefore `naked` attribute cannot be applied because cooperative `portSchedulerTick()` dirties the context.
166
+
For **cooperative** scheduler, the register context is not saved because no switching is intended; therefore `naked` attribute cannot be applied because cooperative `xTaskIncrementTick()` dirties the context.
0 commit comments