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

G

golson

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
 
B

Ben Pfaff

Your question is outside the domain of comp.lang.c, which discusses
only the standard C programming language, including the standard C
library. This is a remarkably narrow topic compared to what many
people expect.

For your convenience, the list below contains topics that are not
on-topic for comp.lang.c, and suggests newsgroups for you to explore
if you have questions about these topics. Please do observe proper
netiquette before posting to any of these newsgroups. In particular,
you should read the group's charter and FAQ, if any (FAQs are
available from www.faqs.org and other sources). If those fail to
answer your question then you should browse through at least two weeks
of recent articles to make sure that your question has not already
been answered.

* OS-specific questions, such as how to clear the screen,
access the network, list the files in a directory, or read
"piped" output from a subprocess. These questions should be
directed to OS-specific newsgroups, such as
comp.os.ms-windows.programmer.misc, comp.unix.programmer, or
comp.os.linux.development.apps.

* Compiler-specific questions, such as installation issues and
locations of header files. Ask about these in
compiler-specific newsgroups, such as gnu.gcc.help or
comp.os.ms-windows.programmer.misc. Questions about writing
compilers are appropriate in comp.compilers.

* Processor-specific questions, such as questions about
assembly and machine code. x86 questions are appropriate in
comp.lang.asm.x86, embedded system processor questions may
be appropriate in comp.arch.embedded.

* ABI-specific questions, such as how to interface assembly
code to C. These questions are both processor- and
OS-specific and should typically be asked in OS-specific
newsgroups.

* Algorithms, except questions about C implementations of
algorithms. "How do I implement algorithm X in C?" is not a
question about a C implementation of an algorithm, it is a
request for source code. Newsgroups comp.programming and
comp.theory may be appropriate.

* Making C interoperate with other languages. C has no
facilities for such interoperation. These questions should
be directed to system- or compiler-specific newsgroups. C++
has features for interoperating with C, so consider
comp.lang.c++ for such questions.

* The C standard, as opposed to standard C. Questions about
the C standard are best asked in comp.std.c.

* C++. Please do not post or cross-post questions about C++
to comp.lang.c. Ask C++ questions in C++ newsgroups, such
as comp.lang.c++ or comp.lang.c++.moderated.

* Test posts. Please test in a newsgroup meant for testing,
such as alt.test.

news.groups.questions is a good place to ask about the appropriate
newsgroup for a given topic.
 
C

Christopher Benson-Manica

golson said:
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.

(The below welcome text was originally written by Ben Pfaff)

Your question is outside the domain of comp.lang.c, which discusses
only the standard C programming language, including the standard C
library. This is a remarkably narrow topic compared to what many
people expect.

For your convenience, the list below contains topics that are not
on-topic for comp.lang.c, and suggests newsgroups for you to explore
if you have questions about these topics. Please do observe proper
netiquette before posting to any of these newsgroups. In particular,
you should read the group's charter and FAQ, if any (FAQs are
available from www.faqs.org and other sources). If those fail to
answer your question then you should browse through at least two weeks
of recent articles to make sure that your question has not already
been answered.

* OS-specific questions, such as how to clear the screen,
access the network, list the files in a directory, or read
"piped" output from a subprocess. These questions should be
directed to OS-specific newsgroups, such as
comp.os.ms-windows.programmer.misc, comp.unix.programmer, or
comp.os.linux.development.apps.

* Compiler-specific questions, such as installation issues and
locations of header files. Ask about these in
compiler-specific newsgroups, such as gnu.gcc.help or
comp.os.ms-windows.programmer.misc. Questions about writing
compilers are appropriate in comp.compilers.

* Processor-specific questions, such as questions about
assembly and machine code. x86 questions are appropriate in
comp.lang.asm.x86, embedded system processor questions may
be appropriate in comp.arch.embedded.

* ABI-specific questions, such as how to interface assembly
code to C. These questions are both processor- and
OS-specific and should typically be asked in OS-specific
newsgroups.

* Algorithms, except questions about C implementations of
algorithms. "How do I implement algorithm X in C?" is not a
question about a C implementation of an algorithm, it is a
request for source code. Newsgroups comp.programming and
comp.theory may be appropriate.

* Making C interoperate with other languages. C has no
facilities for such interoperation. These questions should
be directed to system- or compiler-specific newsgroups. C++
has features for interoperating with C, so consider
comp.lang.c++ for such questions.

* The C standard, as opposed to standard C. Questions about
the C standard are best asked in comp.std.c.

* C++. Please do not post or cross-post questions about C++
to comp.lang.c. Ask C++ questions in C++ newsgroups, such
as comp.lang.c++ or comp.lang.c++.moderated.

* Test posts. Please test in a newsgroup meant for testing,
such as alt.test.

news.groups.questions is a good place to ask about the appropriate
newsgroup for a given topic.
 
B

Ben Pfaff

osmium said:
There must be a better phrase than "Welcome message" for a message that says
"Get the hell out of here". This is not in keeping with the avowed intent
of the owners of this newsgroup of being precise.

The intent of the message is *not* to say "get the hell out of
here". It is intended to, as gently as possible, explain why the
OP's article does not fall within clc's topic and guide the OP
to places on the net that better match his question. It is not
perfect, so suggestions for improvement are welcome.
 
J

Joona I Palaste

The intent of the message is *not* to say "get the hell out of
here". It is intended to, as gently as possible, explain why the
OP's article does not fall within clc's topic and guide the OP
to places on the net that better match his question. It is not
perfect, so suggestions for improvement are welcome.

You are right that its intent is not to say "get the hell out of here",
but it's STILL not a "welcome message". I mean the message is welcome,
but it doesn't say "welcome". IYSWIM. Would "redirection message" be
better?

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
 
B

Ben Pfaff

Joona I Palaste said:
You are right that its intent is not to say "get the hell out of here",
but it's STILL not a "welcome message". I mean the message is welcome,
but it doesn't say "welcome". IYSWIM. Would "redirection message" be
better?

I've used "off-topic guidance" - comments?
 
J

Joona I Palaste

I've used "off-topic guidance" - comments?

Yes. I like that.
(Bonus points to anyone who can name the computer game that uses that as
a sample.)

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You have moved your mouse, for these changes to take effect you must shut down
and restart your computer. Do you want to restart your computer now?"
- Karri Kalpio
 
O

osmium

Christopher said:
(The below welcome text was originally written by Ben Pfaff)

There must be a better phrase than "Welcome message" for a message that says
"Get the hell out of here". This is not in keeping with the avowed intent
of the owners of this newsgroup of being precise.
 
J

Jack Klein

There must be a better phrase than "Welcome message" for a message that says
"Get the hell out of here". This is not in keeping with the avowed intent
of the owners of this newsgroup of being precise.

[snip]

There must be a better method of posting then over-quoting many, many
lines of material after your added comment.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
P

Peter Nilsson

Ben Pfaff said:
I've used "off-topic guidance" - comments?

Deventer (n.) A decision that's very hard to take because so little depends
on it - like which way to walk round a park.

- The Deeper Meaning of Liff, Adams & Lloyd

<g>
 
R

Randy Howard

Is it really necessary for both you and Ben Pfaff to post this to every
thread that is OT? One should be sufficient. Perhaps you should come
up with an algorithm to decide who will do it. Counting 1 bits in the
ASCII representation of the reply to address perhaps. Or maybe just
alternate odd and even days to save time and code space.
 
C

CBFalconer

Randy said:
Is it really necessary for both you and Ben Pfaff to post this to every
thread that is OT? One should be sufficient. Perhaps you should come
up with an algorithm to decide who will do it. Counting 1 bits in the
ASCII representation of the reply to address perhaps. Or maybe just
alternate odd and even days to save time and code space.

I suggest we loose Ben immediately (he originated it).
Christopher is required to wait until 2 hours past the time the
message was apparently posted. The unwashed public is required to
wait 4 hours, and is restricted from posting if Chris or Ben have
been there first. :)

This assumes all have newsreaders that properly translate posting
time into local time, or that maintain GMT throughout.
 
C

Christopher Benson-Manica

CBFalconer said:
I suggest we loose Ben immediately (he originated it).
Christopher is required to wait until 2 hours past the time the
message was apparently posted. The unwashed public is required to
wait 4 hours, and is restricted from posting if Chris or Ben have
been there first. :)

Um, I can work with that :) (this was the first time I noticed a
double welcome message, but I may have missed others...)
 
R

Richard Heathfield

Ben said:
I've used "off-topic guidance" - comments?

When I first saw this, it seemed to me that it meant the /guidance/ was
off-topic, which it isn't.

On the other hand, I can't at present think of anything better. If I get
inspired, I'll let you know.
 
P

Peter Pichler

Richard Heathfield said:
When I first saw this, it seemed to me that it meant the /guidance/ was
off-topic, which it isn't.

Oh, those ambiguities in English! How would you, for example, translate
"new car sale"? What exactly is "new" - the "cars" or the "sale"? ;-)
 
R

Richard Heathfield

CBFalconer said:
This assumes all have newsreaders that properly translate posting
time into local time, or that maintain GMT throughout.

That's just two different ways of saying the same thing.
 
C

CBFalconer

Peter said:
Oh, those ambiguities in English! How would you, for example,
translate "new car sale"? What exactly is "new" - the "cars" or
the "sale"? ;-)

It's like those "pre-owned" car sales. "They" want money for
them. However, I draw the inference that non-pre-owned cars have
no owner, and thus can be taken at will.

I think the odds are already favoring the honesty of the used car
dealer over the pre-owned car dealer. Not by much, though.
 
M

Mark McIntyre

Oh, those ambiguities in English! How would you, for example, translate
"new car sale"? What exactly is "new" - the "cars" or the "sale"? ;-)

delightfully, the answer is "both, depending on context". ObC: its a
bit like a comma in C.
 
K

Keith Thompson

Richard Heathfield said:
That's just two different ways of saying the same thing.

That's easy for you to say. Just wait until we all move to GMTland to
avoid the confusion; it'll be so crowded you won't even be able to see
your clocks.
 
R

Richard Bos

Richard Heathfield said:
When I first saw this, it seemed to me that it meant the /guidance/ was
off-topic, which it isn't.

On the other hand, I can't at present think of anything better. If I get
inspired, I'll let you know.

What about "topicality guidance"?

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top