SHOW:
|
|
- or go back to the newest paste.
1 | - | moved to https://pastebin.com/PhSU0kPc |
1 | + | // This assumes PRUSS is clocked at 200 MHz, which is its typical clock frequency. |
2 | // | |
3 | // A more generic version of this code for any frequency and period: https://pastebin.com/rBR4v35a | |
4 | ||
5 | // Initialization from python (using py-uio): | |
6 | // pruss.ecap.pwm.initialize( 200000000 ) # 1 second period | |
7 | ||
8 | struct Timestamp { | |
9 | uint32_t s; | |
10 | uint32_t ns; | |
11 | }; | |
12 | ||
13 | // Returns timestamp in seconds and nanoseconds (with 5ns precision). | |
14 | // Must be called at least once every second to ensure correct timekeeping. | |
15 | struct Timestamp timestamp() | |
16 | { | |
17 | static struct Timestamp now = { 0, 0 }; | |
18 | uint32_t ns = CT_ECAP.TSCTR * 5; | |
19 | if( ns < now.ns ) // ecap counter has wrapped | |
20 | ++now.s; | |
21 | now.ns = ns; | |
22 | return now; | |
23 | } |