您的位置:首页 > 其它

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

2013-05-16 10:00 411 查看


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

分类: 单片机 RX62N2012-02-11
23:20 461人阅读 评论(0) 收藏 举报

initializationexceptionvector编译器processingstruct

在为 RX62N编写程序时,我们会发现开发环境自动为我们添加了好多文件,这些代码的主要功能是系统初始化,但是对于刚入手的人来说,需要了解一下

我按照系统初始化的过程来写,

首先设置Fixed vector table,参考Hardware Manual 2.6节。

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

[cpp] view
plaincopy

#pragma section IntPRG



// Exception(Supervisor Instruction)

void Excep_SuperVisorInst(void){/* brk(); */}



// Exception(Undefined Instruction)

void Excep_UndefinedInst(void){/* brk(); */}



// Exception(Floating Point)

void Excep_FloatingPoint(void){/* brk(); */}



// NMI

void NonMaskableInterrupt(void){/* brk(); */}



// Dummy

void Dummy(void){/* brk(); */}

构建Fixed vector table,表中Reserved向量用Dummy填充。(vecttbl.c)



[cpp] view
plaincopy

#pragma section C FIXEDVECT



void* const Fixed_Vectors[] = {



//;0xffffffd0 Exception(Supervisor Instruction)

(void*) Excep_SuperVisorInst,



//;0xffffffd4 Reserved

Dummy,



//;0xffffffd8 Reserved

Dummy,



//;0xffffffdc Exception(Undefined Instruction)

(void*) Excep_UndefinedInst,



//;0xffffffe0 Reserved

Dummy,



//;0xffffffe4 Exception(Floating Point)

(void*) Excep_FloatingPoint,



//;0xffffffe8 Reserved

Dummy,



//;0xffffffec Reserved

Dummy,



//;0xfffffff0 Reserved

Dummy,



//;0xfffffff4 Reserved

Dummy,



//;0xfffffff8 NMI

(void*) NonMaskableInterrupt,



//;0xfffffffc RESET

PowerON_Reset_PC



};



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

(1) Initialization of PSW forInitial Setting Processing

初始化PSW寄存器

(2) Initialization of StackPointer

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

[plain] view
plaincopy

#pragma stacksize su=0x300

#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
plaincopy

#pragma unpack



#pragma section C C$DSEC



extern const struct {

_UBYTE *rom_s; /* Start address of the initialized data section in ROM */

_UBYTE *rom_e; /* End address of the initialized data section in ROM */

_UBYTE *ram_s; /* Start address of the initialized data section in RAM */

} _DTBL[] = {

{ __sectop("D"), __secend("D"), __sectop("R") },

{ __sectop("D_2"), __secend("D_2"), __sectop("R_2") },

{ __sectop("D_1"), __secend("D_1"), __sectop("R_1") }

};



#pragma section C C$BSEC

extern const struct {

_UBYTE *b_s; /* Start address of non-initialized data section */

_UBYTE *b_e; /* End address of non-initialized data section */

} _BTBL[] = {

{ __sectop("B"), __secend("B") },

{ __sectop("B_2"), __secend("B_2") },

{ __sectop("B_1"), __secend("B_1") }

};



#pragma section

/*

** CTBL prevents excessive output of L1100 messages when linking.

** Even if CTBL is deleted, the operation of the program does not change.

*/

_UBYTE * const _CTBL[] = {

__sectop("C_1"), __sectop("C_2"), __sectop("C"),

__sectop("W_1"), __sectop("W_2"), __sectop("W")

};



#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
plaincopy

#define PSW_init 0x00010000

#define FPSW_init 0x00000100

#pragma section ResetPRG

#pragma entry PowerON_Reset_PC



void PowerON_Reset_PC(void)

{

set_intb((unsigned long)__sectop("C$VECT"));

set_fpsw(FPSW_init);

_INITSCT();

nop();

set_psw(PSW_init);

main();

}

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

分享到:

上一篇:Bash中循环遍历文件名中带有空格的文件
下一篇:基于S3C6410的小车***(一)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: