Task Synchronization

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Task Synchronization

1,176件の閲覧回数
huangnanjing
Contributor I

In mqx_tasks.c, the global data structures such as "struct AccelSensor thisAccel and MagSensor thisMag" are shared resources between the high priority Sampling Task and the low priority Fusion Task, I do not see any synchronization object being used in the source code to protect those shared resources.  Is there a possibility for a race condition in the sensor fusion library?

Example:

 

Sampling Task updates fGsAvg[i]

thisAccel.fGsAvg[i] = (float)thisAccel.iGsAvg[i] * thisAccel.fgPerCount;

 

Fusion Task accesses pthisAccel->fGsAvg

eCompassNED(pthisSV->fR, &(pthisSV->fDelta), pthisMag->fBcAvg, pthisAccel->fGsAvg);

 

case NED:
feCompassNED(pthisSV->fR, &(pthisSV->fDelta), pthisMag->fBcAvg, pthisAccel->fGsAvg);
break;
case ANDROID:
feCompassAndroid(pthisSV->fR, &(pthisSV->fDelta), pthisMag->fBcAvg, pthisAccel->fGsAvg);
break;
case WIN8:
default:
feCompassWin8(pthisSV->fR, &(pthisSV->fDelta), pthisMag->fBcAvg, pthisAccel->fGsAvg);

 

Thank you

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 返信

1,010件の閲覧回数
michaelestanley
NXP Employee
NXP Employee

You just missed the synchronization functions.  Look at the top and bottom of the while(1) loop in RdSensData_task in mqx_tasks.c.  Near the top you will find:

_lwevent_wait_for(&(Globals.SamplingEventStruct), 1, FALSE, NULL);

That event is set in FTM_OnCounterRestart() in Events.c.  That is, when the main loop counter indicates start of a new read sample.

Near the bottom you will find

_lwevent_set(&(globalsRunKFEventStruct), 1);

which then triggers

_lwevent_wait_for(&globals.RunKFEventStruct), 1, FALSE, NULL);

inside Fusion_task().

0 件の賞賛
返信