Processing time measurement

Systick Timer による時間測定

volatile unsigned int temp0;
volatile unsigned int temp1;
volatile signed int time;

// Systickレジスタ
unsigned int *STK_CTRL	= (unsigned int *)0xE000E010;
unsigned int *STK_LOAD	= (unsigned int *)0xE000E014;
unsigned int *STK_VAL	= (unsigned int *)0xE000E018;
*STK_LOAD	 = 0x00ffffff;	// リロード値に最大値を設定, 24ビットダウンカウンタ
*STK_VAL	 = 0x00000000;	// カウンタ値にリロード値を設定
*STK_CTRL	 = 0x00000004;	// コアクロックを選択, 割り込みなし
*STK_CTRL	|= 0x00000001;	// カウンタ動作許可

temp0 = *STK_VAL;	// start
:
:
temp1 = *STK_VAL;	// end
time = temp0 - temp1;
printf ("time:%2d[clk]\r\n", time);

チェックサム処理時間測定

#define SIZE	1024
	unsigned char receiveDataBuffer[SIZE] = {0, 1, 2, 3, 4, 5, 6, 7};	// checksum = 0x1c
	unsigned long receiveCheckSum = 0;
	unsigned char receiveCheckSumByte = 0;	
	
	union union_tag {
		unsigned char *tempByte;
		unsigned long *tempWord;
	} union_v;	

	// 14336[clk]
	temp0 = *STK_VAL;	// start
	union_v.tempByte = receiveDataBuffer;
	for (long i = 1; i < SIZE ; i++) {
		receiveCheckSumByte += *union_v.tempByte;
		union_v.tempByte++;
	}
	temp1 = *STK_VAL;	// end
	time = temp0 - temp1;
	printf ("pattern:0\r\n");
	printf ("time:%2d[clk]\r\n", time);
	printf ("checkSum:%2x\r\n\r\n", receiveCheckSumByte);


	// 3392[clk]
	temp0 = *STK_VAL;	// start
	union_v.tempWord = (unsigned long *)receiveDataBuffer;
	for (long i = 1; i < (SIZE / 4); i++) {
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
	}
	*union_v.tempWord = receiveCheckSum;
	receiveCheckSumByte = 0;
	for (long i = 0; i < 4 ; i++) {
		receiveCheckSumByte += *union_v.tempByte;
		union_v.tempByte++;
	}
	temp1 = *STK_VAL;	// end
	time = temp0 - temp1;
	printf ("pattern:1\r\n");
	printf ("time:%2d[clk]\r\n", time);
	printf ("checkSum:%2x\r\n\r\n", receiveCheckSumByte);
	

	// 2658[clk]
	temp0 = *STK_VAL;	// start
	receiveCheckSum = 0;
	union_v.tempWord = (unsigned long *)receiveDataBuffer;
	for (long i = 1; i < (SIZE / 4 / 8); i++) {
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
		receiveCheckSum += *union_v.tempWord;
		union_v.tempWord++;
	}
	*union_v.tempWord = receiveCheckSum;
	receiveCheckSumByte = 0;
	for (long i = 0; i < 4 ; i++) {
		receiveCheckSumByte += *union_v.tempByte;
		union_v.tempByte++;
	}
	temp1 = *STK_VAL;	// end
	time = temp0 - temp1;
	printf ("pattern:2\r\n");
	printf ("time:%2d[clk]\r\n", time);
	printf ("checkSum:%2x\r\n\r\n", receiveCheckSumByte);


Please log in to post comments.