This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with linked list and xdata

I'm having a problem getting a linked list to work on Keil. I'm using an aduc842 microcontroller from Analog. Linked lists are something we do all the time in c and i'm baffled as to why i cant get it to work in this situation. This code works in the simulator but doesnt work on the actual hardware. Ive got 2k on chip xdata and it's configured as such. Ive tried using void * as well for the link node, which increases the size of the struct by one byte, and that didnt work either.

#include <ADuC842.h>
sbit led = 0xb4;
unsigned char xdata Store[1024] ;
unsigned char xdata * pStore ;
void xdata *  FetchMem ( unsigned int bytes ) {
	unsigned char xdata * ppStore ;
	ppStore = pStore ;
	pStore += bytes ;
	return ppStore ;
}

xdata struct Example {
	unsigned char a ;
	struct Example xdata * Next ;
} ;
struct Example xdata List ;
struct Example xdata * pList ;
int main (void ){
	unsigned char i ;
	FetchMem(1);
	pList=&List ;
	pList->a='a'; pList->Next = 0 ;
	{
		struct Example xdata * rec ;
		rec=FetchMem(sizeof(struct Example));
		rec->a='b'; rec->Next=0;
		pList->Next=rec; pList=rec;}
	{
		struct Example xdata * rec ;
		rec=FetchMem(sizeof(struct Example));
		rec->a='c'; rec->Next=0;
		pList->Next=rec; pList=rec;
	}
	{
		struct Example xdata * rec ;
		rec=FetchMem(sizeof(struct Example));
		rec->a='d'; rec->Next=0;
		pList->Next=rec; pList=rec;
	}
	pList=&List;
	for(;;){
		i=pList->a;
		if(pList->Next==0)break;
		pList=pList->Next;
	}
	led=!led;
	for(;;){}
}

Parents
  • This code works in the simulator but doesnt work on the actual hardware.

    Are you using different memory models (small/compact/large) on the simulator and on the actual hardware ?

    Also, be aware that for pointers, it might be necessary to specify _two_ memory areas - one indicating where the pointer points, and one where the pointer is located.

    For example:

    unsigned char xdata * someptr;
    

    is pointer to a location in xdata, but the pointer itself is located in the memory are specified by the memory model.


    unsigned char xdata * xdata someptr;
    

    would be a pointer to a location in xdata, and the pointer itself is located in xdata, too.

Reply
  • This code works in the simulator but doesnt work on the actual hardware.

    Are you using different memory models (small/compact/large) on the simulator and on the actual hardware ?

    Also, be aware that for pointers, it might be necessary to specify _two_ memory areas - one indicating where the pointer points, and one where the pointer is located.

    For example:

    unsigned char xdata * someptr;
    

    is pointer to a location in xdata, but the pointer itself is located in the memory are specified by the memory model.


    unsigned char xdata * xdata someptr;
    

    would be a pointer to a location in xdata, and the pointer itself is located in xdata, too.

Children
No data