Microblaze MCS の割り込み制御のコーディングテスト

昨日は、Microblaze MCS の組み込みまでをやっていました。次は割り込み、なのですが Xilinx さんの Web から資料探すのにはいつものことながら疲れるので必要最低限だけ。とりあえず UG647 Standalone (v.3.09.a), DS865 LogiCORE IP MicroBlaze Micro Controller System を見てやりました。

#include <stdio.h>
#include "platform.h"
#include "mb_interface.h"

#define GPO01 (*(unsigned char *) 0x80000010)
#define GPI01 (*(unsigned char *) 0x80000020)
#define IRQ_STATUS (*(unsigned int *) 0x80000030)
#define IRQ_PENDING (*(unsigned int *) 0x80000034)
#define IRQ_ENABLE (*(unsigned int *) 0x80000038)
#define IRQ_ACK (*(unsigned int *) 0x8000003C)

unsigned char i = 0;

void print(char *str);

void int00(void) {

	microblaze_disable_interrupts();
	GPO01 = i++;
	IRQ_ACK = 0x00000080;
	microblaze_enable_interrupts();
}

int main()
{
    init_platform();

    microblaze_register_handler((XInterruptHandler)int00,(void*)0);
    IRQ_ENABLE = 0x00000080;
    microblaze_enable_interrupts();

    while(1) {
    	;
    }
    return 0;
}
  • coregen の Microblaze 作成で FIT1(Fixed Interval Timer 1) をクロック 100MHz, 50000000 カウント(0.5秒)して FIT1 割り込み発生させるよう作成
  • Hello world application の雛形を修正し上記 C のソースのように割り込みルーチンで出力ポートに1足す
  • Verilog で、Microblaze MCS の出力ポートを Nexys3 の LED に関連付ける。

という動作をさせています。上記コーディングでは、複数の割り込み発生時には int00 で割り込みステータス見て処理を分岐させないといけませんが、割り込みの信号数少ない場合には比較的書きやすいので自分用のメモで残しておきます。