私は、いくつかの重要な自動車用モジュールでコードを実行しています。 「メインモジュール」、揮発性資格の喪失
Main Module.c
//The structure x contains the major data that needs to be stored in case of a crash event. i.e. a real car crash
// x contains data such a vehicle speed, environment data, sensor data, CAN related data,etc. Basically x itself has lot of structures inside it.
typedef struct x x_tst;
volatile x_tst x_ast[5];
//x_ast is being used in realtime and background functions, considering proper interrupt disabling and enabling.
は、以下のコードである「x_ast」揮発性変数/配列を所有している - 以下のコードは、モジュールの一部である
:次は、コードの概算ですモジュール "DependentModule"の一部で、バッファ "x_ast"の共有を可能にします。
DependentModule.c
extern volatile x_tst x_ast[5];
//x_ast is owned by a separate module
//Now I need to share this buffer "x_ast" to a different module that will inturn fill data in it for some conditions. Say for a particular condition that is activated, the buffer "x_ast" will be shared across to a module "Conditional Data Record".
//The base address of first indexed buffer "x_ast[1]" is provided to "Conditional Data Record" for access.
//The main module will not access the buffer that is shared, once the "Conditional Data Record" is activated/requested.
// Below is a mechanism to share the buffer "x_ast" to module "Conditional Data Record".
// This API will be called by module - "Conditional Data Record" once it is activated. It is ensured that this takes place only during intialization of whole system, and no other time.
boolean GetConditionalBuffer(uint8 **PtrToBuffer)
{
boolean BufferShared = FALSE;
void* Temp_ptr;
*PtrToBuffer = NULL;
// if module "Conditional Data Record" is activated? then share the buffer "x_ast", else do not share the buffer.
if(Conditional Data Record == activated) {
Temp_ptr = (x_tst*)&x_ast[1];
*PtrToBuffer = Temp_ptr;
BufferShared = TRUE;
}
return BufferShared;
}
Referring to the line of code:
Temp_ptr = (x_tst*)&x_ast[1];
コード(Tempptr =(x_tstの*)& x_ast [1];)の上の行警告 "メッセージ(7:0312)スロー。揮発性資格の損失危険ポインタキャスト結果を " 上記の警告は必須の警告ですので、解決する必要があります。
volatile変数のアドレスをvoidポインターに割り当てて、volatile修飾を失うことを理解しています。 私は警告を解決しようとするさまざまな方法を試みましたが、決定的な方法を得ることはできませんでした。
コードを修正してこの警告を削除したり、この警告を回避する方法はありますか。
代わりに、関数は 'volatile void ** PtrToBuffer'をとるようにしてください。もう一つのオプションは、あなたの仕事を別のバッファで行い、必要に応じて揮発性バッファに/からコピーすることです。後者は危険性がより低い。バッファーをロックする必要があることを覚えておいてください。これは、ユーザー自身と、これらのバックグラウンド関数の1つが並行してアクセスするのを防ぐためです。 –
同意条件は、モジュール "条件付きデータレコード"で処理されます。競合状態が回避されることが保証される。 –
関数がバッファをロックしていることを意味している場合は、その関数を 'volatile void ** PtrToBuffer'にします。 (揮発性でないuint8_t)。バッファをロックしても、volatileとwriteをキャストすると、未定義の動作が発生します。代入演算子を使用して、一度にバッファ1の値を読み書きする必要があります。 –