|
24 | 24 | 4. Delays |
25 | 25 | Delay_Us(n) |
26 | 26 | Delay_Ms(n) |
27 | | - DelaySysTick( uint32_t n ); |
| 27 | + DelaySysTick( uint32_t n ) |
| 28 | + TimeElapsed32( uint32_t now, uint32_t start); |
| 29 | + TimeElapsed32U( now, start ); // For if events could be in the future. |
| 30 | + funSysTick32() |
| 31 | + funSysTick64() |
28 | 32 |
|
29 | 33 | 5. printf |
30 | 34 | printf, _write may be semihosted, or printed to UART. |
@@ -889,7 +893,20 @@ extern "C" { |
889 | 893 | #define Ticks_from_Us(n) ((n) * DELAY_US_TIME) |
890 | 894 | #define Ticks_from_Ms(n) ((n) * DELAY_MS_TIME) |
891 | 895 |
|
892 | | -#define TimeElapsed32(now,start) ((uint32_t)((uint32_t)(now)-(uint32_t)(start))) |
| 896 | +#define TimeElapsed32(now,start) ((int32_t)((uint32_t)(now)-(uint32_t)(start))) |
| 897 | +#define TimeElapsed32u(now,start) ((uint32_t)((uint32_t)(now)-(uint32_t)(start))) |
| 898 | + |
| 899 | +// #define funSysTick32() is defined per-architecture. |
| 900 | + |
| 901 | +// Get a 64-bit timestamp. Please in general try to use 32-bit timestamps |
| 902 | +// whenever possible. Use functions that automatically handle rollover |
| 903 | +// correctly like TimeElapsed32( start, end ). Only use this in cases where |
| 904 | +// you must act on time periods exceeding 2^31 ticks. |
| 905 | +// |
| 906 | +// Also, if you are on a platform without a hardware 64-bit timer, you must |
| 907 | +// call this function at least once every 2^32 ticks to make sure MSBs aren't |
| 908 | +// lost. |
| 909 | +uint64_t funSysTick64( void ); |
893 | 910 |
|
894 | 911 | // Add a certain number of nops. Note: These are usually executed in pairs |
895 | 912 | // and take two cycles, so you typically would use 0, 2, 4, etc. |
@@ -1010,7 +1027,6 @@ RV_STATIC_INLINE void funPinAF(u32 pin, u32 af) |
1010 | 1027 |
|
1011 | 1028 | #if defined(__riscv) || defined(__riscv__) || defined( CH32V003FUN_BASE ) |
1012 | 1029 |
|
1013 | | - |
1014 | 1030 | // Stuff that can only be compiled on device (not for the programmer, or other host programs) |
1015 | 1031 |
|
1016 | 1032 | // Initialize the ADC calibrate it and set some sane defaults. |
|
0 commit comments