いくつかの検索後の情報のためのいくつか:
" ARM Cortex-M3 ビットバンディング ARM のマイクロコントローラ コアは、セマフォを実装するさらに別の方法を提供します。システムバスレベル. それはどのようにセマフォに変換されますか? ビットバンド領域の変数はセマフォのコンテナとして機能します. すべてのクライアントはそのコンテナ内のビットを「所有」します. クライアントがセマフォを要求する必要があるときはいつでも, クライアントはそれ自身を設定します.ビットバンド エイリアス領域の対応する位置に 1 を書き込むことにより、ビット. 次に、コンテナー (ビットバンド領域) を読み取り、他のビットが設定されていないことを確認します。他のビットが設定されている場合、クライアントは自身のビットを再度クリアし、(おそらく待機後に) 再試行する必要があります。」(ソース)
これが私の大雑把な(テストされていない)解釈です:
/*
* Frees a lock.
*
* @note lock must point to a fully aligned 32 bit integer.
* (atomically set to 0)
*
* @returns 1 if successfull
*/
int rwl_FreeLock(volatile uint32_t *lock){
*lock = 0;
return 1; // always successful
}
/*
* Attempts to acquire a lock
* @param who is the client taking the lock
* @lock pointer to the mutex (uint32_t value in memory)
* @note lock must point to a fully aligned 32 bit integer.
* (atomically set to 1 only if set to 0)
*/
int rwl_TryLock(volatile uint32_t *lock, int who){
// initial check of lock
if(*lock == 0){
Var_SetBit_BB((uint32_t)lock, who);
if(*lock == (1<<who)){ // check that we still have exclusive access
// got the lock!
return 1;
} else {
// do not have the lock
Var_ResetBit_BB((uint32_t)lock, who); // clear the lock flag
return 0;
}
}
}
Var_Set_BB / Var_Reset_BB: ビット バンディングを使用してビットをセット / クリアします。(アトミック)
しかし、うまくいきません!!!