Nios® V プロセッサー・ソフトウェア開発者ハンドブック

ID 743810
日付 7/08/2024
Public
ドキュメント目次

9.2.5.2. HAL を使用した Button PIO ISR の登録

以下に示すコードに基づいて、以下の実行フローが可能になります。
  • ボタンが押され、IRQ が生成されます。
  • ISR が制御を取得します。
    • IIC を使用すると、HAL 一般例外ファネルがプロセッサーの制御を取得し、handle_button_interrupts() ISR をディスパッチします。
  • handle_button_interrupts() がハードウェア割り込みを処理して戻ります。
  • edge_capture の更新された値でプログラムの通常動作が継続します。

HAL を使用した Button PIO ISR の登録

#include "sys/alt_irq.h" #include "system.h" ... /* Declare a global variable to hold the edge capture value. */ volatile int edge_capture; ... /* Initialize the button_pio. */ static void init_button_pio() { /* Recast the edge_capture pointer to match the alt_irq_register() function prototype. */ void * edge_capture_ptr = (void * ) & edge_capture; /* Enable all 4 button interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); /* Register the ISR. */ alt_ic_isr_register(BUTTON_PIO_IRQ_INTERRUPT_CONTROLLER_ID, BUTTON_PIO_IRQ, handle_button_interrupts, edge_capture_ptr, 0x0); }