0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arty A7 100TボードとAXI Timerで時間計測

Posted at

実行環境

  • Ubuntu 22.04.5 LTS
  • Vivado 2023.2
  • Vitis Unified IDE 2023.2
  • Arty A7 100T
  • Serial Port Terminal
  • Micro USB Type-B(2.0)-USB Type-Aケーブル
  • Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz

step1: VivadoでのHW作成

  1. Vivadoを起動
  2. プロジェクト作成 (design sourceや制約ファイルなどは何も追加せず全部OKでいい。ボードファイルの追加に関しては省略。)
  3. Create Block Design
  4. BoardタブからSystem Clock, USB UART, AXI Timerを追加
  5. Diagram+からMicroBlazeを追加
  6. clk_wiz_0をダブルクリック, Output ClocksからReset TypeActive Lowに変更
  7. Run Block Automationをクリック, Local Memory32KBに変更 (それ以上ならなんでもいい)
  8. Run Connection Automationをクリック, 全部選択, OK (画像はブロック図全体像)

step2: VitisでSW作成, 書き込み, 実行

以下のコードを実行

#define __MICROBLAZE__
#include <unistd.h>
#include <sys/_intsup.h>
#include <xstatus.h>
#include "xparameters.h"
#include "platform.h"
#include "xil_printf.h"
#include "xtmrctr.h"

XTmrCtr TimerCounterInst;

int init(){
	int Status;

	Status = XTmrCtr_Initialize(&TimerCounterInst, XPAR_AXI_TIMER_0_BASEADDR);
	if (Status != XST_SUCCESS) {
		xil_printf("Timer Initialize Error\n\r");
        return XST_FAILURE;
	}

	XTmrCtr_SetOptions(&TimerCounterInst, 0, XTC_AUTO_RELOAD_OPTION);
	XTmrCtr_Start(&TimerCounterInst, 0);
    return XST_SUCCESS;
}

int main()
{
    u32 tStart, tEnd;
    init_platform();

    int res = init();
    if(res != XST_SUCCESS)return 0;

    tStart = XTmrCtr_GetValue(&TimerCounterInst, 0);
    usleep(1000);
    usleep(1000);
    usleep(1000);
    tEnd = XTmrCtr_GetValue(&TimerCounterInst, 0);

    xil_printf("End - Start = %u\n\r", (unsigned int)(tEnd - tStart));
    double fval= (tEnd - tStart) / 100000000.0 * 1000; // ms (周波数100000000.0Hzで除することでsに変換し、1000倍してmsに変換)
    int whole, thousandths;
    whole = fval; // 整数
    thousandths = (fval - whole) * 1000; // 小数点以下3桁
    xil_printf("Time = %d.%03d ms\n\r", whole, thousandths);

    cleanup_platform();
    return 0;
}

注意点

  • printfは重いのでxil_printfを工夫して使う
    Vivadoで設定したMicroBlazeLocal Memoryサイズを超える大きさの実行ファイルになるとエラーとなるためstdio.hprintf関数のような重めの関数は避けるのがいい。
    そこでxil_printf関数を使用しているが、これは小数点型の表示に使う%fなどに対応していない。整数部と小数点以下部を分けて表示するよう工夫する。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?