Task Synchronization

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Task Synchronization

1,541 次查看
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,375 次查看
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 项奖励
回复