- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I would like to translate KBA224452 into Japanese.
Thanks,
Kenshow
Original KBA: KBA224452
Global Variables Not working When Used in CY_ISR - KBA224452
Translated by Kenshow
==============================
タイトル: CY_ISRで使用するとグローバル変数が機能しない - KBA224452
バージョン: **
質問:
メイン関数とCY_ISRで使用されるグローバル変数が機能していません。なぜですか?
回答:
より高いレベルの最適化では、グローバル変数はコンパイラによって最適化されます。これは、変数がCY_ISRなどの関数によってのみ変更される場合に発生します。次のサイプレス開発者コミュニティメンバーのBob Marlowe さんからのコードスニペットに示すように、volatileキーワードを使用して、同様の変数を最適化しないようコンパイラに通知します。
コード例:
uint8 FlagToCheck = FALSE;
CY_ISR(SecHandler)
{
SecTimer_Stop();
SecTimer_ReadStatusRegister();
FlagToCheck = TRUE;
}
int main(void)
{
CyGlobalIntEnable; /* グローバル割り込みを有効にします。*/
Timeout_StartEx(SecHandler);
SecTimer_Start();
LED_Write(LEDOFF);
/* ここに初期化/起動コードを配置します(例:MyInst_Start()) */
while(!FlagToCheck)
{
}
LED_Write(LEDON);
while(TRUE)
{
CyDelay(100);
}
}
この例では、コンパイラーの最適化がより高いレベルに設定されている場合、LED_Write(LEDON)は実行されません。ただし、volatileキーワードを追加すると、LED_Write(LEDON)が実行されます。
==============================
8-Apr-2020
Kenshow
- Tags:
- mcu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, Kenshow-san
We receive your translation, it will be published to KBA to Community.
After upload, You will receive the points as the word of KBA.
Please note that due to the current volume of works, Please bear with me for the delayed the response.
It can be delayed, but it will be surely processed.
Thanks for your contribution to CDC!
Will keep you update the status.
Thanks,
Jenna Jo