尝试使用函数指针在RAM中而不是在Flash中运行函数 [英] Trying to run a function in RAM and not in Flash using function pointer

查看:62
本文介绍了尝试使用函数指针在RAM中而不是在Flash中运行函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个C函数来将闪存写入例程复制到RAM内存中,该闪存写入例程位于
闪存中。然后我创建了一个函数,

使用函数指针在RAM中运行复制的函数。


我的问题是我没能成功从

RAM中运行

功能。


这是我的功能


void write_data_params(void)

{


int(* p)(unsigned short * src_addr,unsigned long dst_addr,int

write_size); // p是指向函数的指针


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(); //写函数

到RAM

// p =(UHWORD *)fmDataWriteG; //当使用此语句时

运行函数inflash

p =(int(*)(unsigned short *,unsigned long,int))0x10005000;

sprintf(str,p%x * p%x \\\\ n,p,(UHWORD *)p); // p

10005000 * p 10005000

uprintLine(str);

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


返回;

}


尝试运行此功能时的结果


p 10005000 * p 10005000

发生软复位

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



peekw 0x10005000 10


内存转储:

10005000:E1A0C00D E92DD800 E24CB004 E24DD064

10005010:E50B0010 E50B1014 E50B2018 E3A03000

10005020:E50B301C E59F003C EBFFE328 E24B206C

10005030:E51B3010 E1D3C0B0 E51B3018 E58D3000

我试图在位置p看到值,这是函数指针。

显示为10005000,地址显示为相同的值

10005000.


当我进行内存转储时我可以看到数据10005000是E1A0C00D。
统计之后e $

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


函数应该在RAM中运行。但是它给出了无效的指令

并且发生了软复位。


我尝试将p指定为位于FLASH中的函数地址

MEMORY声明

// p =(UHWORD *)fmDataWriteG; //当使用这个语句运行时

函数inflash


它确实运行了。


不幸的是,我需要为我的

应用程序在RAM和非FLASH中运行该功能。


感谢您的帮助


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

推荐答案

golson< go **** @ worldnet.att.net>这样说:
golson <go****@worldnet.att.net> spoke thus:
我编写了一个C函数来将闪存中的闪存写入例程复制到RAM存储器中。然后我创建了一个函数,它使用函数指针在RAM中运行复制的函数。
等。
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. etc.




(以下欢迎文本最初由Ben Pfaff撰写)


你的问题在外面comp.lang.c的域名,它讨论了

只有标准的C编程语言,包括标准的C

库。与人们期望的很多

相比,这是一个非常狭窄的话题。


为了您的方便,下面的列表包含的主题不是

on-topic for comp.lang.c,并建议您浏览新闻组

如果您对这些主题有疑问。在发布到任何这些新闻组之前,请务必遵守正确的
网络礼节。特别是,你应该阅读小组的章程和常见问题,如果有的话(常见问题是

来自 www.faqs.org 和其他来源)。如果那些人没有回答你的问题,那么你应该浏览至少两周

的近期文章,以确保你的问题还没有。

已被回答。


*特定于操作系统的问题,例如如何清除屏幕,

访问网络,列出目录中的文件,或者阅读

管道子进程的输出。这些问题应该是针对特定于操作系统的新闻组,例如

comp.os.ms-windows.programmer.misc,comp.unix.programmer或者

comp.os.linux.development.apps。


*编译器特有的问题,例如安装问题和

标题的位置文件。在

编译器特定的新闻组中询问这些,例如gnu.gcc.help或

comp.os.ms-windows.programmer.misc。有关编写

编译器的问题在comp.compilers中是合适的。


*特定于处理器的问题,例如关于

汇编的问题和机器代码。 x86问题适用于
comp.lang.asm.x86,嵌入式系统处理器问题可能适用于comp.arch.embedded中的


*特定于ABI的问题,例如如何将汇编

代码连接到C.这些问题都是处理器和

特定于操作系统的问题,通常应该是在特定操作系统中询问

新闻组。


*算法,除了有关

算法的C实现的问题。 如何在C中实现算法X?关于算法的C实现不是一个问题,它是一个

的源代码请求。新闻组comp.programming和

comp.theory可能是合适的。


*使C与其他语言互操作。对于这种互操作,C没有

设施。这些问题应该直接指向系统或编译器特定的新闻组。 C ++

具有与C互操作的功能,因此请考虑

comp.lang.c ++来解决这些问题。


* C标准,而不是标准C.关于

的问题C标准最好在comp.std.c中询问。


* C ++。请不要将有关C ++

的问题发布或交叉发布到comp.lang.c.在C ++新闻组中询问C ++问题,例如comp.lang.c ++或comp.lang.c ++。版本的



*测试帖子。请在一个用于测试的新闻组中进行测试,

,例如alt.test。


news.groups.questions是一个讨论适当的好地方

给定主题的新闻组。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



(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.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


Christopher Benson-Manica写道:
Christopher Benson-Manica writes:
golson< go **** @ worldnet.att.net> ;这样说:
golson <go****@worldnet.att.net> spoke thus:
我编写了一个C函数来将闪存中的闪存写入例程复制到RAM存储器中。然后我创建了一个函数,它使用函数指针在RAM中运行复制的函数。
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.
等。



(以下欢迎文本最初由Ben Pfaff撰写)



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




必须有一个比欢迎信息更好的短语。一条消息说

赶紧离开这里。这与精确的新闻组所有者的公开意图不一致




你的问题超出了comp.lang的范围。 c,其中仅讨论标准C编程语言,包括标准C
库。与许多人期望的相比,这是一个非常狭窄的话题。

为方便起见,下面的列表包含对于comp.lang.c不是主题的主题。 ,并建议新闻组供您探索
如果您对这些主题有疑问。在发布到任何这些新闻组之前,请务必遵守适当的网络礼节。特别是,你应该阅读小组的章程和FAQ,如果有的话(常见问题解答可以从 www.faqs.org 和其他来源)。如果那些人未能回答您的问题,那么您应该浏览至少两周的近期文章,以确保您的问题尚未得到解答。
*特定于操作系统的问题,例如如何清除屏幕,访问网络,列出目录中的文件,或阅读管道等问题。子进程的输出。这些问题应该针对特定于操作系统的新闻组,例如
comp.os.ms-windows.programmer.misc,comp.unix.programmer或
comp.os.linux。 development.apps。

*编译器特有的问题,例如安装问题和头文件的位置。在
特定于编译器的新闻组中询问这些内容,例如gnu.gcc.help或
comp.os.ms-windows.programmer.misc。关于编写
编译器的问题在comp.compilers中是合适的。

*特定于处理器的问题,例如关于组装和机器代码的问题。 x86问题适用于comp.lang.asm.x86,嵌入式系统处理器问题可能适合comp.arch.embedded。

* ABI特定问题,如如何将程序集代码连接到C.这些问题是处理器和
操作系统特定的,通常应该在特定于操作系统的新闻组中询问。

*算法,除了关于
算法的C实现的问题。 如何在C中实现算法X?不是关于算法的C实现的问题,它是对源代码的请求。新闻组comp.programming和
comp.theory可能是合适的。

*使C与其他语言互操作。 C没有这种互操作的设施。这些问题应该针对特定于系统或编译器的新闻组。 C ++具有与C进行互操作的功能,因此请考虑使用
comp.lang.c ++来解决这些问题。

* C标准,而不是标准C.关于
* C ++。请不要将有关C ++的问题发布或交叉发布到comp.lang.c.在C ++新闻组中询问C ++问题,例如comp.lang.c ++或comp.lang.c ++。moderated。

*测试帖子。请在用于测试的新闻组中进行测试,例如alt.test。

news.groups.questions是一个询问特定主题的适当新闻组的好地方。

-
Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我
ataru(at)cyberspace.org |不,我需要知道。欢迎火焰。



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.


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.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.



你的问题不在comp.lang.c的范围之内,后面讨论了

只有标准的C编程语言,包括标准C

库。与人们期望的很多

相比,这是一个非常狭窄的话题。


为了您的方便,下面的列表包含的主题不是

on-topic for comp.lang.c,并建议您浏览新闻组

如果您对这些主题有疑问。在发布到任何这些新闻组之前,请务必遵守正确的
网络礼节。特别是,你应该阅读小组的章程和常见问题,如果有的话(常见问题是

来自 www.faqs.org 和其他来源)。如果那些人没有回答你的问题,那么你应该浏览至少两周

的近期文章,以确保你的问题还没有。

已被回答。


*特定于操作系统的问题,例如如何清除屏幕,

访问网络,列出目录中的文件,或者阅读

管道子进程的输出。这些问题应该是针对特定于操作系统的新闻组,例如

comp.os.ms-windows.programmer.misc,comp.unix.programmer或者

comp.os.linux.development.apps。


*编译器特有的问题,例如安装问题和

标题的位置文件。在

编译器特定的新闻组中询问这些,例如gnu.gcc.help或

comp.os.ms-windows.programmer.misc。有关编写

编译器的问题在comp.compilers中是合适的。


*特定于处理器的问题,例如关于

汇编的问题和机器代码。 x86问题适用于
comp.lang.asm.x86,嵌入式系统处理器问题可能适用于comp.arch.embedded中的


*特定于ABI的问题,例如如何将汇编

代码连接到C.这些问题都是处理器和

特定于操作系统的问题,通常应该是在特定操作系统中询问

新闻组。


*算法,除了有关

算法的C实现的问题。 如何在C中实现算法X?关于算法的C实现不是一个问题,它是一个

的源代码请求。新闻组comp.programming和

comp.theory可能是合适的。


*使C与其他语言互操作。对于这种互操作,C没有

设施。这些问题应该直接指向系统或编译器特定的新闻组。 C ++

具有与C互操作的功能,因此请考虑

comp.lang.c ++来解决这些问题。


* C标准,而不是标准C.关于

的问题C标准最好在comp.std.c中询问。


* C ++。请不要将有关C ++

的问题发布或交叉发布到comp.lang.c.在C ++新闻组中询问C ++问题,例如comp.lang.c ++或comp.lang.c ++。版本的



*测试帖子。请在一个用于测试的新闻组中进行测试,

,例如alt.test。


news.groups.questions是一个讨论适当的好地方

给定主题的新闻组。


-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz 。$ \\

\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \\ \\

);}返回0;}
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.

--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}


这篇关于尝试使用函数指针在RAM中而不是在Flash中运行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆