查看: 3413|回复: 1

[其他] iar平台下分散加载文件

[复制链接]

该用户从未签到

6

主题

10

帖子

0

注册会员

Rank: 2

积分
67
最后登录
2019-12-13
发表于 2018-4-5 13:24:06 | 显示全部楼层 |阅读模式
10NXP金币
各位大神:有木有遇到过某些程序经常被调(频繁的被调用),比如中断函数,中断频率比较高,为了提高运行效率,如何将中断函数上电后加载到ram,这样的话,可以大大提高运行效率。这样的话,应该要修改分散加载文件.icf文件。但是对这个不是很懂,求指教,谢谢!


哪位大哥有做过这样的(将中断函数转载在ram中),求给个.icf给参考学习下,感激不尽啊,急求!

最佳答案

查看完整内容

楼主你好! 如果要把中断函数加载到RAM,上电之后,就把中断向量表拷贝到RAM中。 不知道你用的什么芯片,你可以参考下KL25官方代码的启动代码: http://www.nxp.com/downloads/en/lab-test-software/KL25_SC.exe startup.c里面: void common_startup(void) { #if (defined(CW)) extern char __START_BSS[]; extern char __END_BSS[]; extern uint32 __DATA_ROM[]; extern uint32 __DATA_RAM[]; extern char ...
回复

使用道具 举报

该用户从未签到

712

主题

6371

帖子

0

超级版主

Rank: 8Rank: 8

积分
24884
最后登录
2025-7-20
发表于 2018-4-5 13:24:07 | 显示全部楼层
楼主你好!
如果要把中断函数加载到RAM,上电之后,就把中断向量表拷贝到RAM中。
不知道你用的什么芯片,你可以参考下KL25官方代码的启动代码:
http://www.nxp.com/downloads/en/lab-test-software/KL25_SC.exe
startup.c里面:
void
common_startup(void)
{

#if (defined(CW))       
    extern char __START_BSS[];
    extern char __END_BSS[];
    extern uint32 __DATA_ROM[];
    extern uint32 __DATA_RAM[];
    extern char __DATA_END[];
#endif

    /* Declare a counter we'll use in all of the copy loops */
    uint32 n;

#ifndef KEIL
    /* Declare pointers for various data sections. These pointers
     * are initialized using values pulled in from the linker file
     */
    uint8 * data_ram, * data_rom, * data_rom_end;
    uint8 * bss_start, * bss_end;
#endif

#if (defined(KEIL))
        extern uint32 Image$$VECTOR_ROM$$Base[];
        extern uint32 Image$$VECTOR_RAM$$Base[];
        #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base  
        #define __VECTOR_RAM Image$$VECTOR_RAM$$Base  
#elif (defined(IAR))
        /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
        extern uint32 __VECTOR_TABLE[];
        extern uint32 __VECTOR_RAM[];
#elif (defined(CW))
        #define __VECTOR_TABLE __vector_table  
        #define __VECTOR_RAM   __vector_ram
        extern uint32 __VECTOR_TABLE[];
        extern uint32 __VECTOR_RAM[];
#endif
       
    /* Copy the vector table to RAM */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < 0x104; n++)
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
    }
    /* Point the VTOR to the new copy of the vector table */
    write_vtor((uint32)__VECTOR_RAM);   
   
    /* Get the addresses for the .data section (initialized data section) */
    #if (defined(CW))
        data_ram = (uint8 *)__DATA_RAM;
        data_rom = (uint8 *)__DATA_ROM;
        data_rom_end  = (uint8 *)__DATA_END; /* This is actually a RAM address in CodeWarrior */
        n = data_rom_end - data_ram;
    #elif (defined(IAR))
        data_ram = __section_begin(".data");
        data_rom = __section_begin(".data_init");
        data_rom_end = __section_end(".data_init");
        n = data_rom_end - data_rom;
    #endif               

#ifndef __CC_ARM
               
        /* Copy initialized data from ROM to RAM */
        while (n--)
                *data_ram++ = *data_rom++;
       
       
    /* Get the addresses for the .bss section (zero-initialized data) */
    #if (defined(CW))
        bss_start = (uint8 *)__START_BSS;
        bss_end = (uint8 *)__END_BSS;
    #elif (defined(IAR))
        bss_start = __section_begin(".bss");
        bss_end = __section_end(".bss");
    #endif
       

    /* Clear the zero-initialized data section */
    n = bss_end - bss_start;
    while(n--)
      *bss_start++ = 0;
#endif

    /* Get addresses for any code sections that need to be copied from ROM to RAM.
     * The IAR tools have a predefined keyword that can be used to mark individual
     * functions for execution from RAM. Add "__ramfunc" before the return type in
     * the function prototype for any routines you need to execute from RAM instead
     * of ROM. ex: __ramfunc void foo(void);
     */
    #if (defined(IAR))
          uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
        uint8* code_relocate = __section_begin("CodeRelocate");
        uint8* code_relocate_end = __section_end("CodeRelocate");

        /* Copy functions from ROM to RAM */
        n = code_relocate_end - code_relocate;
        while (n--)
          *code_relocate_ram++ = *code_relocate++;
    #endif
}
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-7-21 03:29 , Processed in 0.080229 second(s), 19 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表