📄 startup.s
字号:
;/****************************************Copyright (c)**************************************************
;** Guangzhou ZHIYUAN electronics Co.,LTD.
;** http://www.zyinside.com
;**
;**--------------File Info-------------------------------------------------------------------------------
;** File name: Startup.s
;** Last modified Date: 2006-02-22
;** Last Version: 1.0
;** Descriptions: The start up codes for LPC2200, including the initializing codes for the entry point of exceptions and the stacks of user tasks.
;** Every project should have a independent copy of this file for related modifications
;**------------------------------------------------------------------------------------------------------
;** Created by: Chenmingji
;** Created date: 2005-11-22
;** Version: 1.0
;** Descriptions: The original version
;**
;**------------------------------------------------------------------------------------------------------
;** Modified by: zhangbin
;** Modified date: 2006-6-28
;** Version: 1.1
;** Descriptions: Clear VICVectAddr Register In ResetInit.
;**
;********************************************************************************************************/
preserve8
IRQ_STACK_LEGTH EQU (8 * 3) ;/* 允许3层嵌套 */
StackIRQ EQU (IrqStackSpace + IRQ_STACK_LEGTH * 4 - 4)
INCLUDE LPC2294.INC ; Include the head file 引入头文件
NoInt EQU 0x80
NoFIQ EQU 0x40
UND32Mode EQU 0x1b
USR32Mode EQU 0x10
SVC32Mode EQU 0x13
SYS32Mode EQU 0x1f
IRQ32Mode EQU 0x12
FIQ32Mode EQU 0x11
TMode EQU 0x20
IMPORT __use_no_semihosting_swi
IMPORT Main
;The exported labels
;给外部使用的标号在这声明
EXPORT Reset
CODE32
AREA vectors,CODE,READONLY
ENTRY
;interrupt vectors
;中断向量表
Reset
B ResetInit
B ErrReset
B SoftwareInterrupt
B ErrReset
B ErrReset
DCD 0xa1b11fa0
B IRQ_Handler
SUB LR, LR, #4
; add FIQ ISR
LDMFD SP!, {PC}^
;********************************************************************************************************/
;
; you can use "B ResetInit"
;
;********************************************************************************************************/
ErrReset
B .
;********************************************************************************************************/
;软中断
SoftwareInterrupt
CMP R0, #3
LDRLO PC, [PC, R0, LSL #2]
MOVS PC, LR
;------------------------------------------------------------------------------------------------
SwiFunction
DCD IRQSave ;0
DCD FIQSave ;1
DCD FIQRestore ;2
;------------------------------------------------------------------------------------------------
FIQSave
MRS R0, SPSR
ORR R1, R0, #NoFIQ
MSR SPSR_c, R1
MOVS PC, LR
;------------------------------------------------------------------------------------------------
IRQSave
MRS R0, SPSR
ORR R1, R0, #NoInt
MSR SPSR_c, R1
MOVS PC, LR
;------------------------------------------------------------------------------------------------
FIQRestore
IRQRestore
MSR SPSR_c, R1
MOVS PC, LR
;********************************************************************************************************/
ResetInit
MSR CPSR_c, #(IRQ32Mode | NoInt | NoFIQ)
LDR SP, =StackIRQ
MSR CPSR_c, #(SYS32Mode | NoInt | NoFIQ)
LDR SP, =StackUsr
LDR R0, =VICVectAddr
MOV R1, #0x00
STR R1, [R0]
IMPORT |Image$$IROM1$$RO$$Limit|
IMPORT |Image$$IROM1$$RW$$Base|
IMPORT |Image$$IROM1$$ZI$$Base|
IMPORT |Image$$IROM1$$ZI$$Limit|
LDR R0, =|Image$$IROM1$$RO$$Limit|
LDR R1, =|Image$$IROM1$$RW$$Base|
LDR R3, =|Image$$IROM1$$ZI$$Base|
CMP R0, R1
BEQ LOOP1
LOOP0
CMP R1, R3
LDRCC R2, [R0], #4
STRCC R2, [R1], #4
BCC LOOP0
LOOP1
LDR R1, =|Image$$IROM1$$ZI$$Limit|
MOV R2, #0
LOOP2
CMP R3, R1
STRCC R2, [R3], #4
BCC LOOP2
LDR R1, =Main+1
BX R1
LTORG
;********************************************************************************************************/
;IRQ中断服务程序
IRQ_Handler
SUB LR, LR, #4 ; Calculate the returning address 计算返回地址
STMFD SP!, {R0-R3, R12, LR} ; Protects the task environments 保存任务环境
MRS R3, SPSR ; Protects the status variable 保存状态
STMFD SP, {R3, LR}^ ; Protects SPSR and SP in user status, Notice: DO NOT write back.保存SPSR和用户状态的SP,注意不能回写
; If the SP is written back, it should be adjusted to its appropriate value later.如果回写的是用户的SP,所以后面要调整SP
LDR R2, =VICVectAddr
SUB SP, SP, #4*2
MSR CPSR_c, #(NoInt | SYS32Mode) ; Switch to the System Mode 切换到系统模式
LDR R3, [R2]
ADD LR, PC, #1
BX R3
CODE16
BX PC
NOP
CODE32
MSR CPSR_c, #(NoInt | IRQ32Mode) ; Switch bak to IRQ mode 切换回irq模式
LDMFD SP, {R3, LR}^ ; Recover SPSR and SP in user status, Notic: DO NOT write back. 恢复SPSR和用户状态的SP,注意不能回写
; If the SP is written back, it should be adjusted to its appropriate value later.如果回写的是用户的SP,所以后面要调整SP
MSR SPSR_cxsf, R3
ADD SP, SP, #4*2 ;
LDMFD SP!, {R0-R3, R12, PC}^ ;
LTORG
;/*********************************************************************************************************
;** Function name: SetISR
;**
;** Descriptions: Set ISR function for VIC
;**
;** input parameters: Channel : VIC Channel
;** PRI : VIC PRI
;** Function : VIC ISR function
;** Returned value: None
;**
;** Created by: Chenmingji
;** Created Date: 2006/02/22
;**-------------------------------------------------------------------------------------------------------
;** Modified by:
;** Modified date:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
CODE16
EXPORT SetISR
SetISR
CMP R1, #0x10
BCS SetISREnd
CMP R2, #0
BEQ SetISREnd
CMP R0, #0x20
BCS SetISREnd
PUSH {R0}
LSL R1, R1, #2
MOV R3, #0x20
ORR R0, R3
LDR R3, =VICVectCntl0
STR R0, [R3, R1]
MOV R0, #1
ORR R2, R0
SUB R3, #(VICVectCntl0 - VICVectAddr0 - 1)
SUB R3, #1
STR R2, [R3, R1]
SUB R3, #(VICVectAddr0 - VICIntEnable)
POP {R1}
LSL R0, R1
STR R0, [R3]
SetISREnd
BX LR
;/*********************************************************************************************************
;** Function name: TargetInit
;**
;** Descriptions: config VPBDIV, PLLCFG and MAMTIM
;**
;** input parameters: vpbdiv pllcfg and mamtim
;** Returned value: None
;**
;********************************************************************************************************/
EXPORT TargetInit
IMPORT IRQ_Exception
TargetInit
PUSH {R4, LR}
LDR R3, =MEMMAP
MOV R4, #0x01
STR R4, [R3]
ADD R3, #(VPBDIV - MEMMAP)
STR R0, [R3]
ADD R3, #(PLLCON - VPBDIV)
CMP R1, #0xff
BHI TargetInit1
STR R1, [R3, #(PLLCFG - PLLCON)]
MOV R4, #3
STR R4, [R3]
MOV R4, #0xaa
STR R4, [R3, #(PLLFEED - PLLCON)]
MOV R4, #0x55
STR R4, [R3, #(PLLFEED - PLLCON)]
TargetInit1
SUB R3, #(PLLCON - MAMCR)
MOV R4, #0
STR R4, [R3]
STR R2, [R3, #(MAMTIM - MAMCR)]
MOV R4, #0x02
STR R4, [R3]
LDR R3, =VICDefVectAddr
LDR R4, =IRQ_Exception
STR R4, [R3]
POP {R4, PC}
LTORG
;/*********************************************************************************************************
;** 以下为一些与系统相关的库函数的实现
;** 具体作用请ads的参考编译器与库函数手册
;** 用户可以根据自己的要求修改
;********************************************************************************************************/
;/*********************************************************************************************************
;** The implementations for some library functions
;** For more details, please refer to the ADS compiler handbook and The library
;** function manual
;** User could change it as needed
;********************************************************************************************************/
CODE32
EXPORT __rt_div0
EXPORT fputc
EXPORT fgetc
EXPORT _sys_close
EXPORT _sys_write
EXPORT _sys_read
EXPORT _sys_istty
EXPORT _sys_seek
EXPORT _sys_ensure
EXPORT _sys_flen
EXPORT _sys_tmpnam
EXPORT _sys_command_string
__rt_div0
fputc
fgetc
_sys_close
_sys_write
_sys_read
_sys_istty
_sys_seek
_sys_ensure
_sys_flen
_sys_tmpnam
_sys_command_string
B .
CODE16
EXPORT _ttywrch
_ttywrch
B .
;/*********************************************************************************************************
;** unction name 函数名称: CrpData
;** Descriptions 功能描述: encrypt the chip
;** input parameters 输 入: None 无
;** Returned value 输 出 : None 无
;** Used global variables 全局变量: None 无
;** Calling modules 调用模块: None 无
;**
;** Created by 作 者: Chenmingji 陈明计
;** Created Date 日 期: 2004/03/27 2004年3月27日
;**-------------------------------------------------------------------------------------------------------
;** Modified by 修 改:
;** Modified date 日 期:
;**-------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
IF :DEF: EN_CRP
IF . >= 0x1fc
INFO 1,"\nThe data at 0x000001fc must be 0x87654321.\nPlease delete some source before this line."
ENDIF
CrpData
WHILE . < 0x1fc
NOP
WEND
CrpData1
DCD 0x87654321 ;/*When the Data is 为0x87654321,user code be protected. 当此数为0x87654321时,用户程序被保护 */
ENDIF
AREA MyStacks, DATA, NOINIT, ALIGN=2
IrqStackSpace SPACE IRQ_STACK_LEGTH * 4 ;Stack spaces for Interrupt ReQuest Mode 中断模式堆栈空间
AREA Stacks, DATA, NOINIT
StackUsr
END
;/*********************************************************************************************************
;** End Of File
;********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -