We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to run a short function from internal xdata!
I use the DS80C390, I use the configuration with my internal xdata on 00F000h–00FFFFh and no external xdata. I have 128k code space.
IDM = b00 P4CNT = b100
I have a byte array which I use to allocate space in the xdata range:
xdata tyu8 aru8Code[SIZE];
Here I copy my function to xdata:
tyu8 code* u8CodePtr; tyu8 u8Index = 0; for ( u8CodePtr = ((tyu8 code*) MyFunc); u8CodePtr < ((tyu8 code*) MyFunc+SIZE); u8CodePtr++, u8Index++ ) { aru8Code[u8Index] = *u8CodePtr; }
Here I want to call my function in xdata:
((void(*)(void)) aru8Code)();
Somehow it doesn't work, the processor restarts all the time. What am I missing?
CODE and XDATA are two completely separate memory spaces. Code can not be run from XDATA, unless the processor supports a remapping so a region of XDATA will be also accessible as CODE.
Do you have any such remapping? Because just casting between XDATA and CODE pointers doesn't work.
READ
Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer’s Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
The separation of Code and Xdata in general for the 8051 architecture is correct. The DS80C390 however offers to remap 4K Xdata into Code space.
Please read the processors data sheet in detail and find:
"The DS80C390 can configure its 4kB of internal SRAM as combined program and data memory. This allows the application software to execute self-modifiable code."
But it's not as simple as in your example. There must configuration bits be set. And the correct addresses must be used. It's time to study the data sheet.
Best regards J. Christoph