Appiko
Macros | Functions
Profiler timer

Driver to use timer for code profiling and time-stamping. More...

Macros

#define PROFILER_TIMER   CONCAT_2(NRF_TIMER,TIMER_USED_PROFILE_TIMER)
 
#define PRINT_TIME
 

Functions

void profiler_timer_init (void)
 
void printfcomma (uint32_t num)
 
uint32_t read_time_us (void)
 
bool profiler_timer_is_on (void)
 
void profiler_timer_deinit ()
 Fully stop the profiling timer to save power. profiler_timer_init needs to be called again before using it.
 

Definitions for marking the beginning and ending of code to profile

Todo:
Make the PROFILE_START and PROFILE_STOP self configuring based on prescalar used
#define PROFILE_START   do{ PROFILER_TIMER->TASKS_CAPTURE[2] = 1; }while(0)
 
#define PROFILE_STOP
 

Detailed Description

Warning
Verify in the nrf5xxxx_peripheral.h file that the timer used can work up to 32 bit resolution

Macro Definition Documentation

◆ PRINT_TIME

#define PRINT_TIME
Value:
do{ PROFILER_TIMER->TASKS_CAPTURE[3] = 1; \
printfcomma(PROFILER_TIMER->CC[3]/16); \
log_printf("us\n"); }while(0)
#define PROFILER_TIMER

Print the current time in micro-seconds from the startup (beginning of TIMER0). This is used for time stamping at different parts in the code

Todo:
Make the PRINT_TIME self configuring based on prescalar used

Definition at line 52 of file profiler_timer.h.

◆ PROFILE_START

#define PROFILE_START   do{ PROFILER_TIMER->TASKS_CAPTURE[2] = 1; }while(0)

Point of start of profiling

Definition at line 61 of file profiler_timer.h.

◆ PROFILE_STOP

#define PROFILE_STOP
Value:
do{ PROFILER_TIMER->TASKS_CAPTURE[3] = 1; \
printfcomma((PROFILER_TIMER->CC[3] - PROFILER_TIMER->CC[2])/16); \
log_printf(".%03d",(int)((((PROFILER_TIMER->CC[3] - PROFILER_TIMER->CC[2]) & 0x0F)*125)/2)); \
log_printf("us\n"); }while(0)
#define PROFILER_TIMER

Point of end of profiling. The time from start is displayed in nano-seconds with an accuracy of 62.5 ns

Definition at line 63 of file profiler_timer.h.

◆ PROFILER_TIMER

#define PROFILER_TIMER   CONCAT_2(NRF_TIMER,TIMER_USED_PROFILE_TIMER)

Specify which timer would be used for the profiler timer module

Definition at line 47 of file profiler_timer.h.

Function Documentation

◆ printfcomma()

void printfcomma ( uint32_t  num)

Takes in an unsigned integer and prints it with a ',' after every three digits

Parameters
numNumber to be printed with commas

Definition at line 45 of file profiler_timer.c.

References printfcomma().

Referenced by printfcomma().

◆ profiler_timer_init()

void profiler_timer_init ( void  )

Initialize the timer to run at 16 MHz and with full 32 bit width

profiler_timer.c : Profiler timer Copyright (C) 2019 Appiko

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Definition at line 21 of file profiler_timer.c.

References PROFILER_TIMER.

Referenced by crystal_test(), and rc_test().

◆ profiler_timer_is_on()

bool profiler_timer_is_on ( void  )

Check if the profiler timer is already initialized

Returns
bool value indicating the on state if profiler timer

Definition at line 40 of file profiler_timer.c.

References PROFILER_TIMER.

◆ read_time_us()

uint32_t read_time_us ( void  )
inline

The time from start-up in micro-seconds

Returns
Time from start, the four most significant bits are always zero
Todo:
Take care of overflow of timer
Warning
The time overflows after 268 seconds

Definition at line 84 of file profiler_timer.h.

References PROFILER_TIMER.

Referenced by rc_test().