AnsweredAssumed Answered

What the problem to access variables in Paged Ram?

Question asked by 赵子成 on Jan 5, 2019
Latest reply on Jan 9, 2019 by Edward Karpicz

Hi All,

 

I define the variables as follows:

static UINT16  au16CellVoltData[4][12];

#pragma DATA_SEG __RPAGE_SEG PAGED_RAM
static ST_SLIDE_WIN_FILTER_FOR_FAR_BUF astLecuCellVoltFilter[4][12];
static UINT16 au16LecuCellVolt[4][12][5];
#pragma DATA_SEG DEFAULT

 

ST_SLIDE_WIN_FILTER_FOR_FAR_BUF is defined as :

typedef struct stSlideWinFilterForFarBuf_t
{
UINT16 *__rptr pu16Buf; //Pointer to the buffer define in PAGED_RAM
UINT16 u16Capacity;
UINT16 u16Tail; 
UINT16 u16ValidNum; 
UINT16 u16RestartRate; 

}ST_SLIDE_WIN_FILTER_FOR_FAR_BUF;

 

To create a software Filter, I define the follow 3 functions:

******************************************************************************************************************************

void SWF_InitForFarBuf(ST_SLIDE_WIN_FILTER_FOR_FAR_BUF *__rptr pstFilter, UINT16 *__rptr pBuf, UINT16 u16Capacity, UINT16 u16RestartRate)
{
pstFilter->pu16Buf = pBuf;
pstFilter->u16Capacity = u16Capacity;
pstFilter->u16ValidNum = 0;
pstFilter->u16Tail = 0;
pstFilter->u16RestartRate = u16RestartRate;
}

 

void SWF_PushForFarBuf(ST_SLIDE_WIN_FILTER_FOR_FAR_BUF *__rptr pstFilter, UINT16 uiLatestData)
{
SINT16 s16Diff;
UINT16 u16Diff;
UINT32 u32Last;

if(pstFilter->u16ValidNum == 0)
{
pstFilter->pu16Buf[0] = uiLatestData;
pstFilter->u16Tail = 0;
pstFilter->u16ValidNum = 1;

return;
}

u32Last = pstFilter->pu16Buf[pstFilter->u16Tail];
s16Diff = uiLatestData - u32Last;
u16Diff = CALC_ABS(s16Diff);

if(u16Diff > u32Last * pstFilter->u16RestartRate / 100)
{
pstFilter->pu16Buf[0] = uiLatestData;
pstFilter->u16Tail = 0;
pstFilter->u16ValidNum = 1;

return;
}


pstFilter->u16Tail++;

if(pstFilter->u16Tail >= pstFilter->u16Capacity)
{
pstFilter->u16Tail = 0;
}

pstFilter->pu16Buf[pstFilter->u16Tail] = uiLatestData;


pstFilter->u16ValidNum++;

if(pstFilter->u16ValidNum > pstFilter->u16Capacity)
{
pstFilter->u16ValidNum = pstFilter->u16Capacity;
}

return;
}

 

UINT16 SWF_GetAverageValueForFarBuf(ST_SLIDE_WIN_FILTER_FOR_FAR_BUF *__rptr pstFilter)
{
UINT32 uiSum = 0;
UINT16 i;
UINT16 uiAverage;


if(pstFilter->u16ValidNum == 0)
{
return 0;
}


for(i = 0; i < pstFilter->u16ValidNum; i++)
{
uiSum += pstFilter->pu16Buf[i];
}

uiAverage = uiSum / pstFilter->u16ValidNum;

return uiAverage;
}

***************************************************************************************************************

I use these 3 function as follow:

for(i = 0; i < 4; i++)
{
for(j = 0; j < 12; j++)
{
SWF_InitForFarBuf(&(astLecuCellVoltFilter[i][j]), au16LecuCellVolt[i][j], 5, 20);

SWF_PushForFarBuf(&(astLecuCellVoltFilter[i][j]), au16CellVoltData[i][j]);
u16Data = SWF_GetAverageValueForFarBuf(&(astLecuCellVoltFilter[i][j]));
}
}

 

But the problem is that the data in au16LecuCellVolt buffer is wrong sometimes.

I don't know why.

I have look through the ducument of <TN238.pdf>,  maybe there is something wrong in the function about the Paged Ram buffer. Can anyone tell me why?

Thanks.

Outcomes