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

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

9.2.5.1. Button PIO 割り込みを処理するためのハードウェア ISR の記述

この例は、プッシュボタンに接続された 4 ビット PIO ペリフェラルを備えた Nios® V プロセッサー・システムに基づいています。ボタンが押されるたびに IRQ が生成されます。 ISR コードは、PIO ペリフェラルのエッジ・キャプチャー・レジスターを読み取り、その値をグローバル変数に保存します。グローバル変数のアドレスは、コンテキスト・ポインターで ISR に渡されます。

Button PIO 割り込みを処理するためのハードウェア ISR の記述

#include "system.h" #include "altera_avalon_pio_regs.h" #include "alt_types.h" static void handle_button_interrupts(void * context) { /* Cast context to edge_capture's type. It is important that this be declared volatile to avoid unwanted compiler optimization. */ volatile int * edge_capture_ptr = (volatile int * ) context; /* Read the edge capture register on the button PIO. Store value.*/ * edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); /* Write to the edge capture register to reset it. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0); /* Read the PIO to delay ISR exit. This is done to prevent a spurious interrupt in systems with high processor -> pio latency and fast interrupts. */ IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); }