
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
XMC7000ファミリにおけるソフトウェア実行時間を測定 - KBA234432
Community Translation: Measurement of software execution time in XMC7000 family- KBA234432
Translated by: NXTY_Shirakawa
Question
あるソフトウェアの実行時間を知りたいです。 デバッガを使わずに実行時間を測定する方法はありますか?
Answer
ハードウェア タイマー (TCPWM) を使用して、おおよそのソフトウェア実行時間を測定できます。 「Hello World」のコード スニペットを次に示します。
Code 1. Original “Hello World”
#include <stdio.h> int main() { printf("Hello World"); return 0; } |
ソフトウェアの実行時間を測定するには、「Hello World」コードに次の変更を加えます。
- TCPWM タイマー開始コマンドと TCPWM タイマー停止コマンドを printf ("Hello World") の前後に追加します。
Code 2 Adding TCPWM Timer Start and Timer Stop Commands
#include <stdio.h> int main() { // Initialize Clock Divider and TCPWM (For more details, please see Technical Reference Manual) : // If you need, please Enter Critical section to avoid any interrupt during measurement. uint32_t saveIntrEnabled = Cy_SysLib_EnterCriticalSection(); // Interrupt Disable & Save Current Status : // Timer Stop/Clear/Start (Please use INLINE function to reduce software offset like below) Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Stop Command (If Timer is Starting) Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM,0); // Timer Counter Clear Command Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Start Command printf("Hello World"); // Timer Stop (Please use INLINE function to reduce software offset like below) Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Stop Command // Read and Save the counter value uint32_t TimerCount = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM); : // If you need, restore interrupt status Cy_SysLib_ExitCriticalSection(saveIntrEnabled); // Interrupt Restore Previous Status return 0; } |
2.次に、対応する TCPWM のタイマー値を読み取るコマンドを追加します。 このタイマー値は、クロック数をカウントします。 したがって、ソフトウェアの実行時間は次のように計算できます。
Example:
Clock Frequency = 25 MHz, Value of TimerCount = 0x0F98 (0d3992)
測定時間をより正確にするために、以下の対策を行ってください。
- クロック速度を上げる
- カウンターを開始してから停止するまでの時間を測定します。 次に、カウント値から減算します。 次に例を示します。
#include <stdio.h>
int main() {
:
// Timer Stop/Clear/Start (Please use INLINE function to reduce software offset like below)
Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Stop Command (If Timer is Starting)
Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM,0); // Timer Counter Clear Command
Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Start Command
printf("Hello World");
// Timer Stop (Please use INLINE function to reduce software offset like below)
Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Stop Command
// Read and Save the counter value
uint32_t TimerCount = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM);
:
// Measure the time from starting the counter to stopping
Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Stop Command (If Timer is Starting)
Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM,0); // Timer Counter Clear Command
Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM); // Timer Start Command
uint32_t SwOffsetCount = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM);
uint32_t TimerCountDuringHelloWorld = TimerCount – SwOffsetCount;
return 0;
}