HEW中RX62N工程自动生成文件的解析

阅读: 评论:0

HEW中RX62N工程自动生成文件的解析

HEW中RX62N工程自动生成文件的解析

HEW中RX62N工程自动生成文件的解析

分类: 单片机 RX62N 2012-02-11 23:20  461人阅读  评论(0)  收藏  举报 initialization exception vector 编译器 processing struct 在为 RX62N编写程序时,我们会发现开发环境自动为我们添加了好多文件,这些代码的主要功能是系统初始化,但是对于刚入手的人来说,需要了解一下

我按照系统初始化的过程来写,
    首先设置Fixed vector table,参考Hardware Manual 2.6节。

定义各个向量的函数。Reset是系统通电或重启之后执行的向量函数,是设置向量表的重点。(intprg.c)

[cpp]  view plain copy
  1. #pragma section IntPRG  
  2.   
  3.     // Exception(Supervisor Instruction)  
  4.    void Excep_SuperVisorInst(void){/* brk(); */}  
  5.   
  6.     // Exception(Undefined Instruction)  
  7.     void Excep_UndefinedInst(void){/* brk(); */}  
  8.   
  9.     // Exception(Floating Point)  
  10.     void Excep_FloatingPoint(void){/* brk(); */}  
  11.   
  12.     // NMI  
  13.     void NonMaskableInterrupt(void){/* brk(); */}  
  14.   
  15.     // Dummy  
  16.     void Dummy(void){/* brk(); */}  

构建Fixed vector table,表中Reserved向量用Dummy填充。(vecttbl.c)
  [cpp]  view plain copy
  1. #pragma section C FIXEDVECT  
  2.   
  3.   void* const Fixed_Vectors[] = {  
  4.   
  5.   //;0xffffffd0 Exception(Supervisor Instruction)  
  6.       (void*) Excep_SuperVisorInst,  
  7.   
  8.   //;0xffffffd4 Reserved  
  9.     Dummy,  
  10.   
  11.   //;0xffffffd8 Reserved  
  12.       Dummy,  
  13.   
  14.   //;0xffffffdc Exception(Undefined Instruction)  
  15.       (void*) Excep_UndefinedInst,  
  16.   
  17.   //;0xffffffe0 Reserved  
  18.       Dummy,  
  19.   
  20.   //;0xffffffe4 Exception(Floating Point)  
  21.       (void*) Excep_FloatingPoint,  
  22.   
  23.   //;0xffffffe8 Reserved  
  24.       Dummy,  
  25.   
  26.   //;0xffffffec Reserved  
  27.       Dummy,  
  28.   
  29.   //;0xfffffff0 Reserved  
  30.       Dummy,  
  31.   
  32.   //;0xfffffff4 Reserved  
  33.       Dummy,  
  34.   
  35.   //;0xfffffff8 NMI  
  36.       (void*) NonMaskableInterrupt,  
  37.   
  38.   //;0xfffffffc RESET  
  39.   PowerON_Reset_PC  
  40.   
  41.   };  


 

初始化系统。系统的初始化过程在Reset向量函数中完成。初始化过程有如下一些内容:

(1) Initialization of PSW forInitial Setting Processing

   初始化PSW寄存器


(2) Initialization of StackPointer
   初始化堆栈指针,使用#pragma entry PowerON_Reset_PC,可以使编译器自动初始化堆栈指针。堆栈的大小如下定义(stacksct.h)

[plain]  view plain copy
  1. #pragma stacksize su=0x300  
  2. #pragma stacksize si=0x100  

(3) Initialization of GeneralRegisters Used as Base Registers
   初始化标准寄存器,同样使用#pragma entry PowerON_Reset_PC,可以使编译器自动初始化寄存器。

(4) Initialization of ControlRegisters
   初始化控制寄存器

(5) Initialization Processingof Sections
   调用_INITSCT( )初始化Sections,在调用该函数前,需要声明DTBL和BTBL,注意Section 的名称是固定的,代码如下:(dbsct.c)

    [cpp]  view plain copy
  1. #pragma unpack  
  2.   
  3.     #pragma section C C$DSEC  
  4.   
  5.     extern const struct {  
  6.         _UBYTE *rom_s; /* Start address of the initialized data section in ROM */  
  7.         _UBYTE *rom_e; /* End address of the initialized data section in ROM */  
  8.         _UBYTE *ram_s; /* Start address of the initialized data section in RAM */  
  9.     } _DTBL[] = {  
  10.         { __sectop("D"), __secend("D"), __sectop("R") },  
  11.         { __sectop("D_2"), __secend("D_2"), __sectop("R_2") },  
  12.         { __sectop("D_1"), __secend("D_1"), __sectop("R_1") }  
  13.     };  
  14.   
  15.     #pragma section C C$BSEC  
  16.     extern const struct {  
  17.         _UBYTE *b_s; /* Start address of non-initialized data section */  
  18.         _UBYTE *b_e; /* End address of non-initialized data section */  
  19.     } _BTBL[] = {  
  20.         { __sectop("B"), __secend("B") },  
  21.         { __sectop("B_2"), __secend("B_2") },  
  22.         { __sectop("B_1"), __secend("B_1") }  
  23.     };  
  24.   
  25.     #pragma section  
  26.     /* 
  27.     ** CTBL prevents excessive output of L1100 messages when linking. 
  28.     ** Even if CTBL is deleted, the operation of the program does not change. 
  29.     */  
  30.     _UBYTE * const _CTBL[] = {  
  31.         __sectop("C_1"), __sectop("C_2"), __sectop("C"),  
  32.         __sectop("W_1"), __sectop("W_2"), __sectop("W")  
  33.     };  
  34.       
  35.     #pragma packoption  

(6) Initialization Processingof Libraries
   调用_INITLIB( )初始化运行库

(7) Initialization of GlobalClass Objects

(8) Initialization of PSW formain Function Execution

(9) Changing of PM Bit in PSW

(10) User Program Execution
   执行用户程序,也就是执行main函数

(11) Global Class ObjectPostprocessing

以下为系统初始化的一个例子(resetprg.c)
    [cpp]  view plain copy
  1. #define PSW_init 0x00010000  
  2. #define FPSW_init 0x00000100  
  3. #pragma section ResetPRG  
  4. #pragma entry PowerON_Reset_PC  
  5.   
  6. void PowerON_Reset_PC(void)  
  7. {  
  8.    set_intb((unsigned long)__sectop("C$VECT"));  
  9.    set_fpsw(FPSW_init);  
  10.    _INITSCT();  
  11.     nop();  
  12.    set_psw(PSW_init);  
  13.    main();  
  14. }  

至此,RX62N初始化完成, 并执行main函数。



分享到: 

本文发布于:2024-01-29 07:27:43,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170648446813675.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:自动生成   文件   工程   HEW   RX62N
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23