GBDKライブラリドキュメント
GBDK libraries documentation |
||
---|---|---|
前
Prev |
3章
ハードウェアへのアクセス
Chapter 3.Accessing hardware |
次
Next |
中断する、外部イベントが生じると直ちに、実行がコードの異なる部分にジャンプすることを可能にする-例えば垂直のブランクの期間に入るLCD、シリアルデータ、到着しやその終了計算に達するタイマー。
例のために、irq.cを見る。
Interrupts allow execution to jump to a different part of your code as soon as an external event occurs - for example the LCD entering the vertical blank period, serial data arriving or the timer reaching its end count.For an example see irq.c
GBDKの中で中断する、関数disable_interrupts()、enable_interrupts()、set_interrupts(UBYTE ier)と割り込みサービスルーチン(ISR)リンカadd_VBLを使用して、扱われる、加えるadd_TIM、add_LCD、add_SIOとadd_JOYは、垂直のブランクのためのハンドラ、タイマー、LCD、シリアルとjoypadを中断します、それぞれ中断します。
システムは、最初にインストールされた第1のものを実行して、1つの割り込み当たり8までISRをサポートします。
Interrupts in GBDK are handled using the functions disable_interrupts(), enable_interrupts(), set_interrupts(UBYTE ier) and the interrupt service routine (ISR) linkers add_VBL, add_TIM, add_LCD, add_SIO and add_JOY which add interrupt handlers for the vertical blank, timer, LCD, serial and joypad interrupts respectively.The system supports up to eight ISRs per interrupt, executing the first one installed first.
例として、このコードは、タイマーが尽きるごとに計算を増加させる割り込みハンドラをインストールします。
As an example, this code installs an interrupt handler that increases count every time the timer runs out.
... UWORD count; void timer_isr(void) { count++; } int setup_isr(void) { disable_interrupts(); add_TIM(timer_isr); enable_interrupts(); set_interrupts(TIM_IFLAG); } ...これがタイマーが他のところにセットアップであると仮定することに注目する、またグローバル変数の使用。 ISRが呼ばれる前に、レジスタがすべて押されます。
割り込みがいつでも生じることができるとともに、ISRはいかなる引数もとることができないか、や何も返すことができません。
より大きなプログラムと通信するそのただ一つの方法は、グローバル上記の変数によってあります。
割り込みがタイマーISRを加える前にどのようにして無効にならなければならないか注意してください。そうすれば、set_interrupts呼び出しが任意の他のものを不能にすることは中断します。
多数の割り込みや適切なIFLAGをともに使用すること。
As an interrupt can occur at any time, an ISR cannot take any arguments or return anything.Its only way of communicating with the greater program is through the global variable above.Note how interrupts have to be disabled before adding the timer ISR and that the set_interrupts call will disable any other interrupts.To use multiple interrupts, or the relevant IFLAGs together.
可能なものとして、と2.0b13でのように、小さなものとして、ISRは維持されなければならないし短くなければなりません、いかなるものも使用できない、long、熱望する、や浮動小数点変数、それらのためのコードがリエントラントでないように。
GBがその割り込みをサービスする時間をすべて費やし、主要なコードには予備の時間を持っていないように、ISRを十分に長く書くことができます。
ISRs must be kept as small and short as possible and as at 2.0b13 cannot use any long longs or floating point variables as the code for them is not re-entrant.It is possible to write a ISR long enough so that the GB spends all of its time servicing interrupts and has no time spare for the main code.
前
Prev |
ホーム
Home |
次
Next |
ハードウェアへのアクセス
Accessing hardware |
上
Up |
多数のバンク
Multiple banks |