1 /* 2 * Percepio Trace Recorder Initialization v4.5.1 3 * Copyright 2021 Percepio AB 4 * www.percepio.com 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 * 8 * This file should only be included in a project if there is a need to 9 * initialize the Trace Recorder before main() has been called. 10 * An example of this scenario is if you have a global object instance that has 11 * a constructor that creates an object that should be traced. 12 * This file will make it easier to initiate the recorder correctly. 13 * 14 * Usage: 15 * Add a call to TraceRecorderInit::Initialize() wherever a traced object is 16 * created before the Trace Recorder is normally initialized. This will ensure 17 * the Trace Recorder is initialized only once. 18 * 19 * Set TRC_CFG_RECORDER_DATA_PTR_INIT to 0 in trcSnapshotConfig.h to ensure 20 * RecorderInitialized isn't initialized to 0 after the recorder has been 21 * already initialized. 22 * 23 * Finally, call vTraceEnable(TRC_START) after hardware is initialized to 24 * start gathering trace events. 25 */ 26 27 #include "TraceRecorderInit.h" 28 #include "trcRecorder.h" 29 30 extern "C" uint32_t RecorderInitialized; 31 32 /* Public */ Initialize()33bool TraceRecorderInit::Initialize() 34 { 35 /* Lazy initialization, and constructor is only run once ensuring that we only initialize the recorder once */ 36 static TraceRecorderInit instance; 37 38 return instance.IsInitialized(); 39 } 40 41 /* Private */ TraceRecorderInit()42TraceRecorderInit::TraceRecorderInit() 43 { 44 RecorderInitialized = 0; 45 vTraceInitialize(); 46 } 47 ~TraceRecorderInit()48TraceRecorderInit::~TraceRecorderInit() 49 { 50 } 51 IsInitialized()52bool TraceRecorderInit::IsInitialized() 53 { 54 return RecorderInitialized != 0; 55 } 56