;****************************************************************************************************************************************** 
; 文件名称:	system_SWM120.s
; 功能说明:	SWM120单片机的启动文件
; 技术支持:	http://www.synwit.com.cn/e/tool/gbook/?bid=1
; 注意事项:
; 版本日期: V1.0.0		2012年10月30日
; 升级记录: 
;
;
;******************************************************************************************************************************************
; @attention
;
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION 
; REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE 
; FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT 
; OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
; -ECTION WITH THEIR PRODUCTS.
;
; COPYRIGHT 2012 Synwit Technology
;******************************************************************************************************************************************


; Sram Switch Configuration
; 			Code Size (in Bytes) 	 	Sram Size (in Bytes)
;	0			16k	(0x0-0x3FFF)			2k (0x20000000-0x200007FF)
;	1			14k	(0x0-0x37FF)			4k (0x20000000-0x20000FFF)
;	2			12k	(0x0-0x2FFF)			6k (0x20000000-0x200017FF)
;	3		  17.5k (0x0-0x45FF)		  0.5k (0x20000000-0x200001FF)
;	other		16k							2k 

SRAM_SWITCH		EQU     1;	

; Encryption Configuration
;   0xABCD1234	:   SWD cannot be used	
;	other			SWD can be used

ENCRYPT_FLAG	EQU     0;


; <h> Stack Configuration
;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Stack_Size      EQU     0x400;

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp    


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size       EQU     0x000;

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit


                PRESERVE8
                THUMB


; Vector Table Mapped to Address 0 at Reset

                AREA    RESET, DATA, READONLY
                EXPORT  __Vectors
                EXPORT  __Vectors_End
                EXPORT  __Vectors_Size

__Vectors       DCD     Stack_Mem + Stack_Size    ; Top of Stack 
                DCD     Reset_Handler             ; Reset Handler
                DCD     NMI_Handler               ; NMI Handler
                DCD     HardFault_Handler         ; Hard Fault Handler
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     ENCRYPT_FLAG              ; Encryption flag
                DCD     0		                  ; Reserved
                DCD     0                         ; Reserved
                DCD     SRAM_SWITCH               ; Switch sram
                DCD     SVC_Handler               ; SVCall Handler
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     PendSV_Handler            ; PendSV Handler
                DCD     SysTick_Handler           ; SysTick Handler

                ; External Interrupts
                DCD     GPIO0_Handler           ;  0: Default
				DCD     GPIO1_Handler           ;  1: Default
				DCD     BOD_Handler           	;  2: Default
				DCD		WDT_Handler				;  3: Default
				DCD     TIMER0_Handler          ;  4: Default
				DCD     PWM_Handler           	;  5: Default
				DCD     ADC_Handler           	;  6: Default
			   	DCD     Default_Handler         ;  7: Default
				DCD     UART_Handler            ;  8: Default
			    DCD     SSI_Handler             ;  9: Default
				DCD     Default_Handler         ;  10: Default
				DCD     TIMER1_Handler          ;  11: Default
				DCD     GPIO2_Handler           ;  12: Default
				DCD     GPIO3_Handler           ;  13: Default
				DCD     GPIO4_Handler           ;  14: Default
				DCD     GPIO5_Handler           ;  15: Default
				DCD     GPIO6_Handler           ;  16: Default
				DCD     GPIO7_Handler           ;  17: Default
				DCD     TIMER2_Handler          ;  18: Default
				DCD     TIMER3_Handler          ;  19: Default
				DCD     Default_Handler         ;  20: Default
				DCD     Default_Handler         ;  21: Default
				DCD     GPIO8_Handler           ;  22: Default
				DCD     GPIO9_Handler           ;  23: Default
				DCD     GPIO10_Handler          ;  24: Default
				DCD     GPIO11_Handler          ;  25: Default
				DCD     Default_Handler         ;  26: Default
				DCD     Default_Handler         ;  27: Default
				DCD     Default_Handler         ;  28: Default
				DCD     Default_Handler         ;  29: Default
				DCD     PID_Handler         	;  30: Default
				DCD     Default_Handler         ;  31: Default

__Vectors_End

__Vectors_Size 	EQU 	__Vectors_End - __Vectors

                AREA    |.text|, CODE, READONLY


; Reset Handler

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main
				
                LDR     R0, =__main
                BX      R0
                ENDP


; Dummy Exception Handlers (infinite loops which can be modified)

NMI_Handler     PROC
                EXPORT  NMI_Handler               	[WEAK]
                B       .
                ENDP
HardFault_Handler	PROC
                EXPORT  HardFault_Handler         	[WEAK]
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler               	[WEAK]
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler            	[WEAK]
                B       .
                ENDP
SysTick_Handler PROC
                EXPORT  SysTick_Handler           	[WEAK]
                B       .
                ENDP

Default_Handler PROC
                EXPORT  Default_Handler           	[WEAK]
                B       .
                ENDP

GPIO0_Handler PROC
			  	EXPORT GPIO0_Handler		  		[WEAK]
                B       .
                ENDP
GPIO1_Handler PROC
			  	EXPORT GPIO1_Handler		  		[WEAK]
                B       .
                ENDP
GPIO2_Handler PROC
			  	EXPORT GPIO2_Handler		  		[WEAK]
                B       .
                ENDP
GPIO3_Handler PROC
			  	EXPORT GPIO3_Handler		  		[WEAK]
                B       .
                ENDP				               
GPIO4_Handler PROC
			  	EXPORT GPIO4_Handler		  		[WEAK]
                B       .
                ENDP
GPIO5_Handler PROC
			  	EXPORT GPIO5_Handler		  		[WEAK]
                B       .
                ENDP
GPIO6_Handler PROC
			  	EXPORT GPIO6_Handler		  		[WEAK]
                B       .
                ENDP
GPIO7_Handler PROC
			  	EXPORT GPIO7_Handler		  		[WEAK]
                B       .
                ENDP
GPIO8_Handler PROC
			  	EXPORT GPIO8_Handler		  		[WEAK]
                B       .
                ENDP
GPIO9_Handler PROC
			  	EXPORT GPIO9_Handler		  		[WEAK]
                B       .
                ENDP
GPIO10_Handler PROC
			  	EXPORT GPIO10_Handler		  		[WEAK]
                B       .
                ENDP
GPIO11_Handler PROC
			  	EXPORT GPIO11_Handler		  		[WEAK]
                B       .
                ENDP				               
GPIO12_Handler PROC
			  	EXPORT GPIO12_Handler		  		[WEAK]
                B       .
                ENDP
GPIO13_Handler PROC
			  	EXPORT GPIO13_Handler		  		[WEAK]
                B       .
                ENDP
GPIO14_Handler PROC
			  	EXPORT GPIO14_Handler		  		[WEAK]
                B       .
                ENDP
GPIO15_Handler PROC
			  	EXPORT GPIO15_Handler		  		[WEAK]
                B       .
                ENDP
								
TIMER0_Handler PROC
                EXPORT  TIMER0_Handler           	[WEAK]
				B       .
                ENDP

TIMER1_Handler PROC
                EXPORT  TIMER1_Handler           	[WEAK]
				B       .
                ENDP				

TIMER2_Handler PROC
                EXPORT  TIMER2_Handler           	[WEAK]
				B       .
                ENDP

TIMER3_Handler PROC
                EXPORT  TIMER3_Handler           	[WEAK]
				B       .
                ENDP
								
UART_Handler PROC
                EXPORT  UART_Handler           		[WEAK]
				B       .
                ENDP

SSI_Handler PROC
                EXPORT  SSI_Handler           		[WEAK]
				B       .
                ENDP

I2C_Handler PROC
                EXPORT  I2C_Handler           		[WEAK]
				B       .
                ENDP

WDT_Handler PROC
                EXPORT  WDT_Handler           		[WEAK]
				B       .
                ENDP								
PWM_Handler PROC
                EXPORT  PWM_Handler           		[WEAK]
				B       .
                ENDP
								
ADC_Handler PROC
                EXPORT  ADC_Handler           		[WEAK]
				B       .
                ENDP
BOD_Handler PROC
                EXPORT  BOD_Handler           		[WEAK]
				B       .
                ENDP
				
PID_Handler PROC
                EXPORT  PID_Handler           		[WEAK]
				B       .
                ENDP												
				ALIGN



; User Initial Stack & Heap

                IF      :DEF:__MICROLIB
                
                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit
                
                ELSE
                
                IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap
__user_initial_stackheap

                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR

                ALIGN

                ENDIF


                END
