;/****************************************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. ;** ;**------------------------------------------------------------------------------------------------------ ;** Modified by: zhangbin ;** Modified date: 2006-12-20 ;** Version: 1.2 ;** Descriptions: Modify PLL Config Method. ;** ;********************************************************************************************************/ RAM_SIZE EQU 0x2000 IRQ_STAXK_SIZE EQU (8 * 3) ;/* 允许3层嵌套 */ StackIRQ EQU (RAM_SIZE + 0X40000000) StackUsr EQU (StackIRQ - IRQ_STAXK_SIZE * 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 0xa1b11fa4 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, ResetInitData MSR CPSR_c, #(SYS32Mode | NoInt | NoFIQ) LDR SP, ResetInitData+4 IMPORT |Image$$RO$$Limit| IMPORT |Image$$RW$$Base| IMPORT |Image$$ZI$$Base| IMPORT |Image$$ZI$$Limit| LDR R0, ResetInitData+8 LDR R1, ResetInitData+12 LDR R3, ResetInitData+16 CMP R0, R1 BEQ LOOP1 LOOP0 CMP R1, R3 LDRCC R2, [R0], #4 STRCC R2, [R1], #4 BCC LOOP0 LOOP1 LDR R1, ResetInitData+20 MOV R2, #0 LOOP2 CMP R3, R1 STRCC R2, [R3], #4 BCC LOOP2 LDR R1, ResetInitData+24 BX R1 ResetInitData DCD StackIRQ DCD StackUsr DCD |Image$$RO$$Limit| DCD |Image$$RW$$Base| DCD |Image$$ZI$$Base| DCD |Image$$ZI$$Limit| DCD Main|1 ;********************************************************************************************************/ ;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, IRQ_HandlerData 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}^ ; IRQ_HandlerData DCD VICVectAddr ;/********************************************************************************************************* ;** 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, SetISRData 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, TargetInitData 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, #1 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, TargetInitData+4 LDR R4, TargetInitData+8 STR R4, [R3] POP {R4, PC} code32 SetISRData DCD VICVectCntl0 TargetInitData DCD MEMMAP DCD VICDefVectAddr DCD IRQ_Exception|1 ;/********************************************************************************************************* ;** 以下为一些与系统相关的库函数的实现 ;** 具体作用请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 ;**------------------------------------------------------------------------------------------------------- ;** 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 END ;/********************************************************************************************************* ;** End Of File ;********************************************************************************************************/