Sign in

username:

password:



Not a member?

Search rabbit-semi



Search tips

Subscribe to rabbit-semi



Ads

Discussion Groups

Discussion Groups | Rabbit-Semi | Problems with xmem2xmem/xalloc

This is a group for folks designing and programming embedded systems using the Rabbit Semiconductor C-programmable microcontroller. Rabbit Semi is a spin-off from Z-World who makes a variety of embedded modules and tools. This group is not affiliated with either Rabbit or Z-World, but is a user forum for sharing ideas, asking questions, flaunting knowledge, and other typical user group stuff. The Rabbit is a powerful uC, supported by a full-featured C-compiler.

Problems with xmem2xmem/xalloc - fairy_dave - Mar 16 22:34:07 2008

Howdy all,

I'm having some issues with the xmem2xmem and/or function. I'm trying
to have some memory allocated then read/save data blocks to/from it.
When I try this though I get the error "Run Time Error: Unexpected
interrupt".

The code goes along the lines of this:

DataLocation = xalloc(10 * (sizeof(structA) + 10 * sizeof(structB)));
.
.
.
.
.
void loadFunc(int indexNum)
{
unsigned long memoryPosition;
memoryPosition = DataLocation + indexNum * (sizeof(structA) + 10 *
sizeof(structB));
xmem2xmem(paddr(&localData), memoryPosition, (sizeof(structA) + 10 *
sizeof(structB));
}
.
.
.
void saveFunc(int indexNum)
{
unsigned long memoryPosition;
memoryPosition = DataLocation + indexNum * (sizeof(structA) + 10 *
sizeof(structB));
xmem2xmem(memoryPosition, paddr(&localData), (sizeof(structA) + 10 *
sizeof(structB));
}
Does anyone have any ideas as to what this may be? I've tried
disabling interrupts and various other possabilities with no success.

Dave
------------------------------------



(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )


Re: Problems with xmem2xmem/xalloc - fairy_dave - Mar 16 23:23:36 2008

I would have thought that would come out as a runtime error during
the call to the xalloc function?

Anyway, the total space being allocated is 0x7242 or 29250 bytes
long. DataLocation is a long and local data is:

struct structA localData;
struct structB localBData[10];
--- In r...@yahoogroups.com, Steve Trigero
wrote:
>
> You are overrunning memory somewhere. What is the size
> of structA and structB, localData, and DataLocation?
>
> ----- Original Message ----
> From: fairy_dave
> To: r...@yahoogroups.com
> Sent: Sunday, March 16, 2008 7:26:31 PM
> Subject: [rabbit-semi] Problems with xmem2xmem/xalloc
>
> Howdy all,
>
> I'm having some issues with the xmem2xmem and/or function. I'm
trying
> to have some memory allocated then read/save data blocks to/from
it.
> When I try this though I get the error "Run Time Error: Unexpected
> interrupt".
>
> The code goes along the lines of this:
>
> DataLocation = xalloc(10 * (sizeof(structA) + 10 * sizeof
(structB) ));
> .
> .
> .
> .
> .
> void loadFunc(int indexNum)
> {
> unsigned long memoryPosition;
> memoryPosition = DataLocation + indexNum * (sizeof(structA) + 10 *
> sizeof(structB) );
> xmem2xmem(paddr( &localData) , memoryPosition, (sizeof(structA) +
10 *
> sizeof(structB) );
> }
> .
> .
> .
> void saveFunc(int indexNum)
> {
> unsigned long memoryPosition;
> memoryPosition = DataLocation + indexNum * (sizeof(structA) + 10 *
> sizeof(structB) );
> xmem2xmem(memoryPos ition, paddr(&localData) , (sizeof(structA) +
10 *
> sizeof(structB) );
> }
>
> Does anyone have any ideas as to what this may be? I've tried
> disabling interrupts and various other possabilities with no
success.
>
> Dave
>
>
>
>
>







(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )

Re: Problems with xmem2xmem/xalloc - fairy_dave - Mar 17 2:03:10 2008

Current code reads:

struct LocalData
{
struct job A;
struct step B[NumberBPerA];
};
struct LocalData localData;
unsigned long DataLocation;
const long DATA_LEN = sizeof(localData);

void MemInit()
{
#GLOBAL_INIT
{
MemInit();
}

DataLocation = xalloc(DATA_LEN * NumberA);
Fetch(0);
}

int Fetch(unsigned int Index)
{
int i;
unsigned long memPos;

memPos = DataLocation;
memPos += (Index * DATA_LEN);
ipset(1);
i = xmem2root(&localData, memPos, (unsigned int)DATA_LEN);
ipres();
return 1;
}

void Save(unsigned int Index)
{
int i;
unsigned long memPos;

memPos = DataLocation;
memPos += (Index* DATA_LEN);
ipset(1);
i = root2xmem(memPos, &localData, (unsigned int)DATA_LEN);
ipres();
}

Any help would be greatly appreciated.

Dave

--- In r...@yahoogroups.com, "fairy_dave"
wrote:
>
> I moved structA and structB into a new structure and the program
> doesn't crash anymore. Only problem now is that after a perform a
save
> and then a load, and I read back gibberish. I'm reading/writing to
the
> same location each time, and the size being written is of the
correct
> size (I've checked the sizeof code). I also know the data is being
> transfered from xmem to root memory as the root memory block gets
weird
> data.
>
> --- In r...@yahoogroups.com, "fairy_dave" wrote:
> >
> > I would have thought that would come out as a runtime error
during
> > the call to the xalloc function?
> >
> > Anyway, the total space being allocated is 0x7242 or 29250 bytes
> > long. DataLocation is a long and local data is:
> >
> > struct structA localData;
> > struct structB localBData[10];
> >
>
------------------------------------



(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )

Re: Problems with xmem2xmem/xalloc - fairy_dave - Mar 17 5:17:57 2008

I moved structA and structB into a new structure and the program
doesn't crash anymore. Only problem now is that after a perform a save
and then a load, and I read back gibberish. I'm reading/writing to the
same location each time, and the size being written is of the correct
size (I've checked the sizeof code). I also know the data is being
transfered from xmem to root memory as the root memory block gets weird
data.

--- In r...@yahoogroups.com, "fairy_dave" wrote:
>
> I would have thought that would come out as a runtime error during
> the call to the xalloc function?
>
> Anyway, the total space being allocated is 0x7242 or 29250 bytes
> long. DataLocation is a long and local data is:
>
> struct structA localData;
> struct structB localBData[10];
------------------------------------



(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )

Re: Problems with xmem2xmem/xalloc - fairy_dave - Mar 18 4:23:02 2008

Okay, looks like the problem all along has been that I was calling my
init function from inside the GLOBAL_INIT function chain. I moved it
to the begining of my main loop and it all started working.

Dave

--- In r...@yahoogroups.com, "fairy_dave"
wrote:
>
> Current code reads:
>
> struct LocalData
> {
> struct job A;
> struct step B[NumberBPerA];
> };
> struct LocalData localData;
> unsigned long DataLocation;
> const long DATA_LEN = sizeof(localData);
>
> void MemInit()
> {
> #GLOBAL_INIT
> {
> MemInit();
> }
>
> DataLocation = xalloc(DATA_LEN * NumberA);
> Fetch(0);
> }
>
> int Fetch(unsigned int Index)
> {
> int i;
> unsigned long memPos;
>
> memPos = DataLocation;
> memPos += (Index * DATA_LEN);
> ipset(1);
> i = xmem2root(&localData, memPos, (unsigned int)DATA_LEN);
> ipres();
> return 1;
> }
>
> void Save(unsigned int Index)
> {
> int i;
> unsigned long memPos;
>
> memPos = DataLocation;
> memPos += (Index* DATA_LEN);
> ipset(1);
> i = root2xmem(memPos, &localData, (unsigned int)DATA_LEN);
> ipres();
> }
>
> Any help would be greatly appreciated.
>
> Dave
------------------------------------



(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )