Description
Application-defined function to get current CPU timestamp timer count.
Files
cpu_core.h /
Application’s cpu_bsp.c
Prototype
CPU_TS_TMR CPU_TS_TmrRd (void);
Arguments
None.
Returned Value
CPU timestamp timer count value.
Required Configuration
CPU_TS_TmrRd()
is an application/BSP function that must be defined by the developer if either of the following CPU features is enabled in cpu_cfg.h
:
- CPU timestamps when either
CPU_CFG_TS_32_EN
orCPU_CFG_TS_64_EN
isDEF_ENABLED
. See Timestamps Configuration. - CPU interrupts disabled time measurements when
CPU_CFG_INT_DIS_MEAS_EN
is#define'd
. See Interrupts Disabled Time Measurement Configuration.
Notes / Warnings
- CPU timestamp timer count values must be returned via word-size-configurable
CPU_TS_TMR
data type. If timer has more bits, truncate timer values’ higher-order bits greater than the configuredCPU_TS_TMR
timestamp timer data type word size. However, since the timer must not have less bits than the configuredCPU_TS_TMR
timestamp timer data type word size;CPU_CFG_TS_TMR_SIZE
must be configured so that all bits inCPU_TS_TMR
data type are significant. In other words, if timer size is not a binary-multiple of 8-bit octets (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple octet word size should be configured (e.g. to 16-bits). However, the minimum supported word size for CPU timestamp timers is 8-bits. - CPU timestamp timer should be an ‘up’ counter whose values increase with each time count. If timer is a ‘down’ counter whose values decrease with each time count, then the returned timer value must be ones-complemented.
- When applicable, CPU timestamp timer period should be less than the typical measured time but must be less than the maximum measured time; otherwise, timer resolution inadequate to measure desired times.
Implementation Template
Listing - CPU_TS_TmrRd() implementation template
CPU_TS_TMR CPU_TS_TmrRd (void) { CPU_TS_TMR ts_tmr_cnts; ... ts_tmr_cnts = /* Insert code to get/return CPU timestamp timer counts. */ ; ... return (ts_tmr_cnts); }
16-bit Up Timer Example
Listing - 16-bit Up timer example
CPU_TS_TMR CPU_TS_TmrRd (void) { CPU_TS_TMR ts_tmr_cnts; /* sizeof(CPU_TS_TMR) = 16 bits */ ts_tmr_cnts = /* Insert code to read 16-bit up timer value. */ ; return (ts_tmr_cnts); }
16-bit Down Timer Example
Listing - 16-bit Down timer example
CPU_TS_TMR CPU_TS_TmrRd (void) { CPU_INT16U tmr_val; CPU_TS_TMR ts_tmr_cnts; /* sizeof(CPU_TS_TMR) = 16 bits */ tmr_val = /* Insert code to read 16-bit down timer value. */ ; ts_tmr_cnts = ~tmr_val; /* Ones-complement 16-bit down timer value. */ return (ts_tmr_cnts); }
32-bit Up Timer Example
Listing - 32-bit Up timer example
CPU_TS_TMR CPU_TS_TmrRd (void) { CPU_TS_TMR ts_tmr_cnts; /* sizeof(CPU_TS_TMR) = 32 bits */ ts_tmr_cnts = /* Insert code to read 32-bit up timer value. */ ; return (ts_tmr_cnts); }
48-bit Down Timer Example
CPU_TS_TMR CPU_TS_TmrRd (void) { CPU_INT64U tmr_val; CPU_TS_TMR ts_tmr_cnts; /* sizeof(CPU_TS_TMR) = 32 bits */ tmr_val = /* Insert code to read 48-bit down timer value. */ ; ts_tmr_cnts = (CPU_TS_TMR)tmr_val; /* Truncate 48-bit timer value to 32-bit timestamp ... */ /* ... timer data type. */ ts_tmr_cnts = ~ts_tmr_cnts; /* Ones-complement truncated down timer value. */ return (ts_tmr_cnts); }