⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 在2812中将FLASH中的程序移到RAM中执行
💻 C
字号:
1cmd定义:

ramfuncs            : LOAD = FLASHJ,  PAGE = 0
                         RUN = RAMH0,  PAGE = 0
                         LOAD_START(_RamfuncsLoadStart),
                         LOAD_END(_RamfuncsLoadEnd),
                         RUN_START(_RamfuncsRunStart)

secureRamFuncs    :   LOAD = FLASHP,   PAGE = 0          /* Used by InitFlash() in SysCtrl.c */ 
                         RUN =  RAMH0 ,   PAGE = 0 
                         LOAD_START(_secureRamFuncs_loadstart),
                         LOAD_END(_secureRamFuncs_loadend),
                         RUN_START(_secureRamFuncs_runstart)

2定义变量(装载或运行的起始地址)
extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadEnd;
extern Uint16 RamfuncsRunStart;


extern Uint16 secureRamFuncs_runstart;
extern Uint16 secureRamFuncs_loadstart;
extern Uint16 secureRamFuncs_loadend;

3把要拷贝到RAM里的函数(eva_timer1_isr,eva_timer2_isr...)定义到段ramfuncs

  #pragma CODE_SECTION(eva_timer1_isr, "ramfuncs");
  #pragma CODE_SECTION(eva_timer2_isr, "ramfuncs");
  #pragma CODE_SECTION(evb_timer3_isr, "ramfuncs");
4把要初始化的flash控制寄存器函数定义到段secureRamFuncs
#pragma CODE_SECTION(InitFlash, "secureRamFuncs")
void InitFlash(void);
// 声明中断函数
  interrupt void eva_timer1_isr(void);
  interrupt void eva_timer2_isr(void);
  interrupt void evb_timer3_isr(void);
  interrupt void evb_timer4_isr(void);
//初始化flash 控制寄存器函数为
void InitFlash(void)
{
        asm(" EALLOW");                                                                       // Enable EALLOW protected register access
        FlashRegs.FPWR.bit.PWR = 3;                                                // Pump and bank set to active mode
        FlashRegs.FSTATUS.bit.V3STAT = 1;                                // Clear the 3VSTAT bit
        FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF;        // Sleep to standby transition cycles
        FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF;        // Standby to active transition cycles
        FlashRegs.FBANKWAIT.bit.RANDWAIT = 5;                        // Random access waitstates
        FlashRegs.FBANKWAIT.bit.PAGEWAIT = 5;                        // Paged access waitstates
        FlashRegs.FOTPWAIT.bit.OPTWAIT = 5;                                // Random access waitstates
        FlashRegs.FOPT.bit.ENPIPE = 1;                                        // Enable the flash pipeline
        asm(" EDIS");                                                                        // Disable EALLOW protected register access

/*** Force a complete pipeline flush to ensure that the write to the last register
     configured occurs before returning.  Safest thing is to wait 8 full cycles. ***/

    asm(" RPT #7 || NOP");
}
//复制中断向量到ram的函数为
void InitPieVectTable(void)
{
        int16        i;
        Uint32 *Source = (void *) &ieVectTableInit;
        Uint32 *Dest = (void *) &ieVectTable;
                
        EALLOW;        
        for(i=0; i < 128; i++)
                *Dest++ = *Source++;          

        EDIS;

        // Enable the PIE Vector Table
        PieCtrl.PIECRTL.bit.ENPIE = 1;        
                        
}
4.在主函数中执行调用以下函数

        /*初始化PIE矢量表*/
        InitPieVectTable();        

     memcpy(  &secureRamFuncs_runstart,
               &secureRamFuncs_loadstart,
                 &secureRamFuncs_loadend - &secureRamFuncs_loadstart);
    
      InitFlash();
memcpy(  &RamfuncsRunStart,
                 &RamfuncsLoadStart,
                 &RamfuncsLoadEnd - &RamfuncsLoadStart);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -