Trying to run a function in RAM and not in Flash using function pointer

From: golson (golson_at_worldnet.att.net)
Date: 01/02/04


Date: 2 Jan 2004 10:32:34 -0800

I have written a C function to copy a flash write routine that is in
Flash memory to RAM memory. I have then created a function that
uses a Function Pointer to run the copied function in RAM.

My problem is that I have not successfully been able to run the
function out of
RAM.

Here is my function

void write_data_params(void)
{

        int (* p) (unsigned short *src_addr, unsigned long dst_addr, int
write_size); // p is a pointer to a function

        short_int_array[0] = 0x2211;
        short_int_array[1] = 0x4433;
        short_int_array[2] = 0x6655;
        short_int_array[3] = 0x8877;
        short_int_array[4] = 0xaa99;
        short_int_array[5] = 0xbbaa;
        short_int_array[6] = 0xddcc;
        short_int_array[7] = 0xffee;
        short_int_array[8] = 0x2221;
        short_int_array[9] = 0x2423;
        short_int_array[10] = 0x2625;
        short_int_array[11] = 0x2827;
        short_int_array[12] = 0x2a29;
        short_int_array[13] = 0x2c2b;
        short_int_array[14] = 0x2e2d;
        short_int_array[15] = 0x302f;
        short_int_array[16] = 0x3231;
        short_int_array[17] = 0x3433;
        short_int_array[18] = 0x3635;
        short_int_array[19] = 0x3837;
        ret_value_flash_data_write = fmWriteFunctoRam(); // write function
to RAM
        // p = (UHWORD *) fmDataWriteG; // when using this statement
running function inflash
        p = (int (*) (unsigned short *, unsigned long, int )) 0x10005000;
        sprintf(str, " p %x *p %x \r\n", p, ( UHWORD*)p); // p
10005000 *p 10005000
        uprintLine(str);

        ret_value_flash_data_write = p(short_int_array, 0x30000, 40);

    return;
}

Result when I try running this function

  p 10005000 *p 10005000
Soft reset occurred

> peekw 0x10005000 10
peekw 0x10005000 10

Memory dump:

10005000: E1A0C00D E92DD800 E24CB004 E24DD064
10005010: E50B0010 E50B1014 E50B2018 E3A03000
10005020: E50B301C E59F003C EBFFE328 E24B206C
10005030: E51B3010 E1D3C0B0 E51B3018 E58D3000

I tried to see the Value at location p which is the function pointer.
it shows to be 10005000 and the Address shows to be the same value
10005000.

when I do a memory dump I can see the data at 10005000 is E1A0C00D.

After the statement

ret_value_flash_data_write = p(short_int_array, 0x30000, 40);

the function should run in RAM. But it gives a invalid instruction
and a Soft Reset occurs.

I tried assigning p to be the Function Address located in the FLASH
MEMORY with the statement
// p = (UHWORD *) fmDataWriteG; // when using this statement running
function inflash

and it did run.

Unfortunately, I need to run the function in RAM and Not FLASH for my
application.

Thank You for your help



Relevant Pages

  • Re: Memory configuration of WinCE Image
    ... Actually I am not sure how to configure my PB to dowload image in RAM? ... As the error is pointing of lack of memory, I have configured memory in my ... Board registers. ... for the new boot flash address: ...
    (microsoft.public.windowsce.platbuilder)
  • Re: What File System supports Application XIP
    ... > You won't gain at runtime by using XIP though. ... I thought that when you XIPed from flash, ... directly back to the flash memory address. ... There shouldn't be a RAM ...
    (Linux-Kernel)
  • Re: Kernel running XIP or from RAM?
    ... You mentioned the struct might be in flash even if the kernel has been ... downloaded into RAM. ... >> I would like to print some memory stats showing how the physical chip ...
    (microsoft.public.windowsce.app.development)
  • Re: Memory configuration of WinCE Image
    ... Since you said you saved image to Flash, here I saw the issue too. ... I'd rather download image to RAM to debug something. ... the configuration of OEM address table from oemaddrtab_cfg.inc. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Type safety
    ... if I know that on my machine ROM routines are from addresses ... then by examining the bits of a function pointer I can tell ... so you know if its in ROM or RAM? ... I can think of one immediately: a memory test routine. ...
    (comp.lang.c)