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.
Hello 赵子成
Please refer attached demo code of how to access paged RAM .
If you can't open this demo project, set your IDE as "use text based project", restart CodeWarrior.
Have a great day,
Jun Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jennie,
I have looked through your demo, I think my operation about variable(Even pointer to that variable) in Paged Ram is the same with you.
I still don't know what's wrong with my code.
Thanks.
Hi,
It always helps to create compilable project demonstrating problem and sharing it.
How big is your data in paged RAM? If more than 4k then try setting compiler->Code Generation->Assume object are in same page for = never for different objects. Try also searching forum for -PSegObj, it was explained several times already.
Edward
Hi Edward,
The data in paged RAM is 3840 bytes(Less than 4K).
And I have already set compier:setting compiler->Code Generation->Assume object are in same page for = never for different objects.
Also Add -PSegObj.
Problem still exists.
Then you must be mixing plain pointers with paged pointers. Please share compilable project to get further help.
Edward
Hi Edward,
It is hard to share the project because the codes are very big.
I have shared the relatived codes above.
What you say "mixing plain pointers with paged pointers", Can you explain this?
Maybe this is a hint for me.
Thanks.
I didn't ask you to share production project. I ask you to create small project to demonstrate problem. Please respect those who offer you help.
These are not compilable, tons of undefined symbols. Do you think it's very interesting to fill in the gaps? No, sorry
Edward
Hi Edward,
I am so sorry.
I have created a compilable project, but I found I can't upload the attachment. Maybe I have not enough right.
I will upload the project using other way tomorrow.
Thanks.
BTW, is your code working if you avoid R-page pointers and use simple pointers? You need to suppress #pragma __RPAGE_SEG line for this and add somewhere at top or in common header #pragma __rptr to make preprocessor hiding all __rprt's to compiler. If you can't do it because of lack of RAM, perhaps you can reproduce problem in your shareable prioject?
I tried making it working but don't see yet where __rprt's could fail. Would be nice to see some data which works well nonpaged and breaks with __rptr.
Edward
Hi Edward
I have uploaded the project.
I have to use the paged ram and global ram because of lacking of local ram(8K bytes).
In this project you can see astLecuCellVoltFilter and au16LecuCellVolt and g_unParData are placed in paged ram.
And g_stLogBuf and g_unVarData are placed in global ram.
And also you can see their address in <Bak_BMS_APP.map>.
The problem is that the data in au16LecuCellVolt sometimes become wrong.(The codes "u16Data = SWF_GetAverageValueForFarBuf(&(astLecuCellVoltFilter[i][j]))"sometimes get wrong result.)
I am long for your help. Thank you.
Hi,
Thanks for project, but I'm unable to build it. First of all for some weird reason CW5.1 is unable to load *.mcp as project. Renaming to XML and importing I get some rescued items and linker emits some messages which I don't understand, it doesn't build.
Still questions arise. We should be able to reproduce your situation. How? Any test data available? What steps are needed to initialize, run your functions and see some results which deviate from expected results?
One more thing I forgot about. Since you say it is random, sometimes good and sometimes not, I guess it may be related to interrupts or preemptive RTOS. Are you using paged variables (not necessarily the same, could be different *paged* variables) simultaneously from different preemptive tasks or [interrupts and main task]? If that's the case then you need to save/restore RPAGE so that it is the same after return to preempted task or from interrupt. For second (interrupts and main) try enabling compiler options->code generation-> RPAGE Register is used for paging. For preemptive RTOS perhaps you need to do some modifications in RTOS settings.
Edward
Hi Edward,
You can open CW5.1 and Edit->Preferences->IDE Extras->Click Use text-based projects like below:
And I don't use OS. The variable in paged RAM is only used in a single task(not interrupt).It is static variable, used only in one file.
Hi,
yes, I figured "use text-based projects". It is the same as importing project as xml. In both cases I see rescued items and multiple include of same files.
It builds after some manipulations, but it is still not clear what should I check, which data is sometimes wrong and sometimes good, how to see it? BTW, it is not necessarily RPAGE related, it could be something else.
Edward
Hi Edward,
I hope you can check the variables of astLecuCellVoltFilter and au16LecuCellVolt.
I am not sure whether they are wrong usage in the following function:
SWF_InitForFarBuf(&(astLecuCellVoltFilter[i][j]), au16LecuCellVolt[i][j], 5, 20);
SWF_PushForFarBuf(&(astLecuCellVoltFilter[i][j]), au16CellVoltData[i][j]);
SWF_GetAverageValueForFarBuf(&(astLecuCellVoltFilter[i][j]));
Especially the pointers definition of __rptr.
Thank you.
Usage seems fine, as well __rptr.
I asked you to check whether it works for you removing __rptr and #pragma.. __RPAGE_SEG... Is algorithm really OK? I can't check it without knowledge of what do you get and what do you expect, please provide.
Edward