]> git.sur5r.net Git - freertos/blob - Demo/ARM7_STR75x_GCC/SystemFiles/crt0_STR75x_FreeRTOS.s
First version of STR75x RIDE port and demo.
[freertos] / Demo / ARM7_STR75x_GCC / SystemFiles / crt0_STR75x_FreeRTOS.s
1 /*\r
2 This is the default Startup for STR75x devices for the GNU toolchain\r
3 \r
4 It has been designed by ST Microelectronics and modified by Raisonance.\r
5 \r
6 You can use it, modify it, distribute it freely but without any waranty.\r
7 \r
8 */\r
9 .extern main\r
10 \r
11            \r
12 \r
13 /*; Depending on Your Application, Disable or Enable the following Defines*/\r
14   /*; --------------------------------------------------------------------------\r
15   ;                      SMI Bank0 configuration\r
16 ; ----------------------------------------------------------------------------*/\r
17 .set SMI_Bank0_EN, 0 /*; enable access the SMI Bank0 if 1*/\r
18 \r
19 /*; ----------------------------------------------------------------------------\r
20   ;                      Memory remapping\r
21 ; ----------------------------------------------------------------------------*/\r
22 .set Remap_SRAM, 0   /* remap SRAM at address 0x00 if 1 */\r
23  \r
24 /*  ; ----------------------------------------------------------------------------\r
25   ;                      EIC initialization\r
26   ; ----------------------------------------------------------------------------*/\r
27 .set EIC_INIT, 1     /*; Configure and Initialize EIC if 1*/\r
28 \r
29 \r
30 ;/* the following are useful for initializing the .data section */\r
31 .extern _sidata ;/* start address for the initialization values of the .data section. defined in linker script */\r
32 .extern _sdata ;/* start address for the .data section. defined in linker script */\r
33 .extern _edata ;/* end address for the .data section. defined in linker script */\r
34 \r
35 ;/* the following are useful for initializing the .bss section */\r
36 .extern _sbss ;/* start address for the .bss section. defined in linker script */\r
37 .extern _ebss ;/* end address for the .bss section. defined in linker script */\r
38 \r
39 ;/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs */\r
40 .set  Mode_USR, 0x10            ;/* User Mode */\r
41 .set  Mode_FIQ, 0x11            ;/* FIQ Mode */\r
42 .set  Mode_IRQ, 0x12            ;/* IRQ Mode */\r
43 .set  Mode_SVC, 0x13            ;/* Supervisor Mode */\r
44 .set  Mode_ABT, 0x17            ;/* Abort Mode */\r
45 .set  Mode_UNDEF, 0x1B          ;/* Undefined Mode */\r
46 .set  Mode_SYS, 0x1F            ;/* System Mode */\r
47 \r
48 .equ  I_Bit, 0x80               ;/* when I bit is set, IRQ is disabled */\r
49 .equ  F_Bit, 0x40               ;/* when F bit is set, FIQ is disabled */\r
50 \r
51 /*; --- System memory locations */\r
52 \r
53 ;/* init value for the stack pointer. defined in linker script */\r
54 .extern _estack\r
55 \r
56 ;/* Stack Sizes. The default values are in the linker script, but they can be overriden. */\r
57 .extern _UND_Stack_Init\r
58 .extern _SVC_Stack_Init\r
59 .extern _ABT_Stack_Init\r
60 .extern _FIQ_Stack_Init\r
61 .extern _IRQ_Stack_Init\r
62 .extern _USR_Stack_Init\r
63 \r
64 .extern _UND_Stack_Size\r
65 .extern _SVC_Stack_Size\r
66 .extern _ABT_Stack_Size\r
67 .extern _FIQ_Stack_Size\r
68 .extern _IRQ_Stack_Size\r
69 .extern _USR_Stack_Size\r
70 .extern vTaskSwitchContext\r
71 .extern ulCriticalNesting\r
72 \r
73 SVC_Stack           =     _SVC_Stack_Init /*_estack*/           /*; 32 byte SVC stack at*/\r
74                                               /*; top of memory */\r
75                                               \r
76 IRQ_Stack           =     _IRQ_Stack_Init /*SVC_Stack - 32*/     /*; followed by IRQ stack */\r
77 USR_Stack           =     _USR_Stack_Init /*IRQ_Stack-256*/    /*; followed by USR stack */\r
78 FIQ_Stack           =     _FIQ_Stack_Init /*USR_Stack-256*/    /*; followed by FIQ stack*/\r
79 ABT_Stack           =     _ABT_Stack_Init /*FIQ_Stack-64*/     /*; followed by ABT stack */\r
80 UNDEF_Stack         =     _UND_Stack_Init /*ABT_Stack-0*/     /*; followed by UNDEF stack */\r
81 \r
82 /*; --- System memory locations*/\r
83 \r
84 /*; MRCC Register*/\r
85 MRCC_PCLKEN_Addr    =    0x60000030  /*; Peripheral Clock Enable register base address*/\r
86 \r
87 /*; CFG Register*/\r
88 CFG_GLCONF_Addr     =    0x60000010  /*; Global Configuration register base address*/\r
89 SRAM_mask           =    0x0002      /*; to remap RAM at 0x0*/\r
90 \r
91 /*; GPIO Register*/\r
92 GPIOREMAP0R_Addr    =    0xFFFFE420\r
93 SMI_EN_Mask         =    0x00000001\r
94 \r
95 /*; SMI Register*/\r
96 SMI_CR1_Addr        =    0x90000000\r
97 \r
98 /*; --- Stack Addres for each ARM mode*/\r
99 /*; add FIQ_Stack, ABT_Stack, UNDEF_Stack here if you need them*/\r
100 \r
101 \r
102 /*; --- EIC Registers offsets*/\r
103 EIC_base_addr       =    0xFFFFF800         /*; EIC base address*/\r
104 ICR_off_addr        =    0x00               /*; Interrupt Control register offset*/\r
105 CICR_off_addr       =    0x04               /*; Current Interrupt Channel Register*/\r
106 CIPR_off_addr       =    0x08               /*; Current Interrupt Priority Register offset*/\r
107 IVR_off_addr        =    0x18               /*; Interrupt Vector Register offset*/\r
108 FIR_off_addr        =    0x1C               /*; Fast Interrupt Register offset*/\r
109 IER_off_addr        =    0x20               /*; Interrupt Enable Register offset*/\r
110 IPR_off_addr        =    0x40               /*; Interrupt Pending Bit Register offset*/\r
111 SIR0_off_addr       =    0x60               /*; Source Interrupt Register 0*/\r
112 \r
113 /***************************************************************************************/\r
114 \r
115 \r
116 .globl _start\r
117 .globl _startup\r
118 \r
119 .text\r
120 _startup:\r
121 _start:\r
122         LDR     PC, Reset_Addr\r
123         LDR     PC, Undefined_Addr\r
124         LDR     PC, SWI_Addr\r
125         LDR     PC, Prefetch_Addr\r
126         LDR     PC, Abort_Addr\r
127         NOP                          /*; Reserved vector*/\r
128         LDR     PC, IRQ_Addr\r
129         LDR     PC, FIQ_Addr\r
130 \r
131 \r
132 \r
133 \r
134 \r
135 Reset_Addr      : .long     Reset_Handler\r
136 Undefined_Addr  : .long     UndefinedHandler\r
137 SWI_Addr        : .long     SWIHandler\r
138 Prefetch_Addr   : .long     PrefetchAbortHandler\r
139 Abort_Addr      : .long     DataAbortHandler\r
140                   .long 0      /*; Reserved vector*/\r
141 IRQ_Addr        : .long     IRQHandler\r
142 FIQ_Addr        : .long     FIQHandler\r
143 \r
144 .text\r
145 /*;*******************************************************************************\r
146 ;              Peripherals IRQ handlers address table\r
147 ;********************************************************************************/\r
148 \r
149 /* execution goes there when an interrupt occurs and there is no associated ISR */\r
150 .globl __wrongvector\r
151 __wrongvector:\r
152         ldr     PC, __wrongvector_Addr  \r
153 __wrongvector_Addr:\r
154         .long 0\r
155 \r
156 WAKUP_Addr         :.long       WAKUPIRQHandler\r
157 TIM2_OC2_Addr      :.long       TIM2_OC2IRQHandler\r
158 TIM2_OC1_Addr      :.long       TIM2_OC1IRQHandler\r
159 TIM2_IC12_Addr     :.long       TIM2_IC12IRQHandler\r
160 TIM2_UP_Addr       :.long       TIM2_UPIRQHandler\r
161 TIM1_OC2_Addr      :.long       TIM1_OC2IRQHandler\r
162 TIM1_OC1_Addr      :.long       TIM1_OC1IRQHandler\r
163 TIM1_IC12_Addr     :.long       TIM1_IC12IRQHandler\r
164 TIM1_UP_Addr       :.long       TIM1_UPIRQHandler\r
165 TIM0_OC2_Addr      :.long       TIM0_OC2IRQHandler\r
166 TIM0_OC1_Addr      :.long       TIM0_OC1IRQHandler\r
167 TIM0_IC12_Addr     :.long       TIM0_IC12IRQHandler\r
168 TIM0_UP_Addr       :.long       TIM0_UPIRQHandler\r
169 PWM_OC123_Addr     :.long       PWM_OC123IRQHandler\r
170 PWM_EM_Addr        :.long       PWM_EMIRQHandler\r
171 PWM_UP_Addr        :.long       PWM_UPIRQHandler\r
172 I2C_Addr           :.long       I2CIRQHandler\r
173 SSP1_Addr          :.long       SSP1IRQHandler\r
174 SSP0_Addr          :.long       SSP0IRQHandler\r
175 UART2_Addr         :.long       UART2IRQHandler\r
176 UART1_Addr         :.long       UART1IRQHandler\r
177 UART0_Addr         :.long       vSerialISR\r
178 CAN_Addr           :.long       CANIRQHandler\r
179 USB_LP_Addr        :.long       USB_LPIRQHandler\r
180 USB_HP_Addr        :.long       USB_HPIRQHandler\r
181 ADC_Addr           :.long       ADCIRQHandler\r
182 DMA_Addr           :.long       DMAIRQHandler\r
183 EXTIT_Addr         :.long       EXTITIRQHandler\r
184 MRCC_Addr          :.long       MRCCIRQHandler\r
185 FLASHSMI_Addr      :.long       FLASHSMIIRQHandler\r
186 RTC_Addr           :.long       RTCIRQHandler\r
187 TB_Addr            :.long       vPortTickISR\r
188 \r
189 /*;*******************************************************************************\r
190 ;                         Exception Handlers\r
191 ;********************************************************************************/\r
192 \r
193 \r
194 /*;*******************************************************************************\r
195 ;* FreeRTOS.org macros for saving and restoring a task context\r
196 ;*******************************************************************************/\r
197 \r
198         .macro portSAVE_CONTEXT MACRO\r
199 \r
200         /* ; Push R0 as we are going to use the register. */\r
201         STMDB   SP!, {R0}\r
202 \r
203         /* ; Set R0 to point to the task stack pointer. */\r
204         STMDB   SP, {SP}^\r
205         NOP\r
206         SUB             SP, SP, #4\r
207         LDMIA   SP!, {R0}\r
208 \r
209         /* ; Push the return address onto the stack.    */\r
210         STMDB   R0!, {LR}\r
211 \r
212         /* ; Now we have saved LR we can use it instead of R0.  */\r
213         MOV             LR, R0\r
214 \r
215         /* ; Pop R0 so we can save it onto the system mode stack. */\r
216         LDMIA   SP!, {R0}\r
217 \r
218         /* ; Push all the system mode registers onto the task stack. */\r
219         STMDB   LR, {R0-LR}^\r
220         NOP\r
221         SUB             LR, LR, #60\r
222 \r
223         /* ; Push the SPSR onto the task stack.  */\r
224         MRS             R0, SPSR\r
225         STMDB   LR!, {R0}\r
226 \r
227         LDR             R0, =ulCriticalNesting \r
228         LDR             R0, [R0]\r
229         STMDB   LR!, {R0}\r
230 \r
231         /* ; Store the new top of stack for the task.   */\r
232         LDR             R1, =pxCurrentTCB\r
233         LDR             R0, [R1]\r
234         STR             LR, [R0]\r
235 \r
236         .endm\r
237 \r
238 \r
239         .macro portRESTORE_CONTEXT MACRO\r
240 \r
241         /* ; Set the LR to the task stack.      */\r
242         LDR             R1, =pxCurrentTCB\r
243         LDR             R0, [R1]\r
244         LDR             LR, [R0]\r
245 \r
246         /* ; The critical nesting depth is the first item on the stack.         \r
247         ; Load it into the ulCriticalNesting variable.  */\r
248         LDR             R0, =ulCriticalNesting\r
249         LDMFD   LR!, {R1}\r
250         STR             R1, [R0]\r
251 \r
252         /* ; Get the SPSR from the stack.       */\r
253         LDMFD   LR!, {R0}\r
254         MSR             SPSR_cxsf, R0\r
255 \r
256         /* ; Restore all system mode registers for the task. */\r
257         LDMFD   LR, {R0-R14}^\r
258         NOP\r
259 \r
260         /* ; Restore the return address. */\r
261         LDR             LR, [LR, #+60]\r
262 \r
263         /* ; And return - correcting the offset in the LR to obtain the         \r
264         ; correct address.      */\r
265         SUBS    PC, LR, #4\r
266         \r
267         .endm\r
268 \r
269 \r
270 \r
271 /*;*******************************************************************************\r
272 ;* Macro Name     : SaveContext\r
273 ;* Description    : This macro used to save the context before entering\r
274 ;                   an exception handler.\r
275 ;* Input          : The range of registers to store.\r
276 ;* Output         : none\r
277 ;********************************************************************************/\r
278 \r
279        .macro SaveContext $r0,$r12\r
280         STMFD  sp!,{r0-r12,lr} /*; Save The workspace plus the current return*/\r
281                                /*; address lr_ mode into the stack.*/\r
282         MRS    r1,spsr         /*; Save the spsr_mode into r1.*/\r
283         STMFD  sp!,{r1}        /*; Save spsr.*/\r
284         .endm\r
285 \r
286 /*;*******************************************************************************\r
287 ;* Macro Name     : RestoreContext\r
288 ;* Description    : This macro used to restore the context to return from\r
289 ;                   an exception handler and continue the program execution.\r
290 ;* Input          : The range of registers to restore.\r
291 ;* Output         : none\r
292 ;********************************************************************************/\r
293 \r
294         .macro RestoreContext $r0,$r12\r
295         LDMFD   sp!,{r1}        /*; Restore the saved spsr_mode into r1.*/\r
296         MSR     spsr_cxsf,r1    /*; Restore spsr_mode.*/\r
297         LDMFD   sp!,{r0-r12,pc}^/*; Return to the instruction following...*/\r
298                                 /*; ...the exception interrupt.*/\r
299         .endm\r
300 \r
301 \r
302 \r
303 /*;*******************************************************************************\r
304 ;* Function Name  : UndefinedHandler\r
305 ;* Description    : This function called when undefined instruction\r
306 ;                   exception is entered.\r
307 ;* Input          : none\r
308 ;* Output         : none\r
309 ;*********************************************************************************/\r
310 \r
311 UndefinedHandler:\r
312         SaveContext r0,r12    /*; Save the workspace plus the current*/\r
313                               /*; return address lr_ und and spsr_und.*/\r
314         BL      Undefined_Handler/*; Branch to Undefined_Handler*/\r
315         RestoreContext r0,r12 /*; Return to the instruction following...*/\r
316                               /*; ...the undefined instruction.*/\r
317 \r
318 /*;*******************************************************************************\r
319 ;* Function Name  : SWIHandler\r
320 ;* Description    : This function called when SWI instruction executed.\r
321 ;* Input          : none\r
322 ;* Output         : none\r
323 ;********************************************************************************/\r
324 \r
325 SWIHandler:\r
326                 ADD     LR, LR, #4\r
327         portSAVE_CONTEXT        \r
328         LDR R0, =vTaskSwitchContext\r
329         MOV LR, PC\r
330         BX R0\r
331         portRESTORE_CONTEXT \r
332 \r
333 \r
334 /*;*******************************************************************************\r
335 ;* Function Name  : IRQHandler\r
336 ;* Description    : This function called when IRQ exception is entered.\r
337 ;* Input          : none\r
338 ;* Output         : none\r
339 ;********************************************************************************/\r
340 \r
341 \r
342 IRQHandler:\r
343 \r
344         portSAVE_CONTEXT                                        /*; Save the context of the current task. */\r
345 \r
346         LDR    r0, =EIC_base_addr\r
347         LDR    r1, =IVR_off_addr\r
348         LDR    lr, =ReturnAddress                       /*; Load the return address. */\r
349         ADD    pc,r0,r1                                         /*; Branch to the IRQ handler. */\r
350 ReturnAddress:\r
351         LDR    r0, =EIC_base_addr\r
352         LDR    r2, [r0, #CICR_off_addr]         /*; Get the IRQ channel number. */\r
353         MOV    r3,#1\r
354         MOV    r3,r3,LSL r2\r
355         STR    r3,[r0, #IPR_off_addr]           /*; Clear the corresponding IPR bit. */\r
356         \r
357         portRESTORE_CONTEXT                                     /*; Restore the context of the selected task. */\r
358 \r
359 /*;*******************************************************************************\r
360 ;* Function Name  : PrefetchAbortHandler\r
361 ;* Description    : This function called when Prefetch Abort\r
362 ;                   exception is entered.\r
363 ;* Input          : none\r
364 ;* Output         : none\r
365 ;*********************************************************************************/\r
366 \r
367 PrefetchAbortHandler:\r
368                 NOP\r
369                 B PrefetchAbortHandler\r
370 \r
371 /*;*******************************************************************************\r
372 ;* Function Name  : DataAbortHandler\r
373 ;* Description    : This function is called when Data Abort\r
374 ;                   exception is entered.\r
375 ;* Input          : none\r
376 ;* Output         : none\r
377 ;********************************************************************************/\r
378 \r
379 DataAbortHandler:\r
380                 NOP\r
381                 NOP\r
382                 B DataAbortHandler\r
383                               /*; ...has generated the data abort exception.*/\r
384 \r
385 /*;*******************************************************************************\r
386 ;* Function Name  : FIQHandler\r
387 ;* Description    : This function is called when FIQ\r
388 ;*                  exception is entered.\r
389 ;* Input          : none\r
390 ;* Output         : none\r
391 ;********************************************************************************/\r
392 \r
393 FIQHandler:\r
394         SUB    lr,lr,#4       /*; Update the link register.*/\r
395         SaveContext r0,r7     /*; Save the workspace plus the current*/\r
396                               /*; return address lr_ fiq and spsr_fiq.*/\r
397         BL      FIQ_Handler   /*; Branch to FIQ_Handler.*/\r
398         RestoreContext r0,r7  /*; Restore the context and return to the...*/\r
399                               /*; ...program execution.*/\r
400 \r
401 /*;*******************************************************************************\r
402 ;* Macro Name     : IRQ_to_SYS\r
403 ;* Description    : This macro used to switch form IRQ mode to SYS mode\r
404 ;* Input          : none.\r
405 ;* Output         : none\r
406 ;*******************************************************************************/\r
407        .macro IRQ_to_SYS\r
408 \r
409         MSR    cpsr_c,#0x1F\r
410         STMFD  sp!,{lr}\r
411        .endm\r
412 /*;*******************************************************************************\r
413 ;* Macro Name     : SYS_to_IRQ\r
414 ;* Description    : This macro used to switch from SYS mode to IRQ mode\r
415 ;                   then to return to IRQHnadler routine.\r
416 ;* Input          : none.\r
417 ;* Output         : none.\r
418 ;*******************************************************************************/\r
419       .macro SYS_to_IRQ\r
420        LDMFD  sp!,{lr}      /*; Restore the link register. */\r
421         MSR    cpsr_c,#0xD2  /*; Switch to IRQ mode.*/\r
422         MOV    pc,lr         /*; Return to IRQHandler routine to clear the*/\r
423                              /*; pending bit.*/\r
424        .endm\r
425 \r
426 /*;*******************************************************************************\r
427 ;* Function Name  : WAKUPIRQHandler\r
428 ;* Description    : This function used to switch to SYS mode before entering\r
429 ;*                  the WAKUP_IRQHandler function located in 75x_it.c.\r
430 ;*                  Then to return to IRQ mode after the\r
431 ;*                  WAKUP_IRQHandler function termination.\r
432 ;* Input          : none\r
433 ;* Output         : none\r
434 ;*******************************************************************************/\r
435 WAKUPIRQHandler:\r
436         IRQ_to_SYS\r
437         BL     WAKUP_IRQHandler\r
438         SYS_to_IRQ\r
439 \r
440 /*;*******************************************************************************\r
441 ;* Function Name  : TIM2_OC2IRQHandler\r
442 ;* Description    : This function used to switch to SYS mode before entering\r
443 ;*                  the TIM3_OC2_IRQHandler function located in 75x_it.c.\r
444 ;*                  Then to return to IRQ mode after the\r
445 ;*                  TIM2_OC2_IRQHandler function termination.\r
446 ;* Input          : none\r
447 ;* Output         : none\r
448 ;*******************************************************************************/\r
449 TIM2_OC2IRQHandler:\r
450         IRQ_to_SYS\r
451         BL     TIM2_OC2_IRQHandler\r
452         SYS_to_IRQ\r
453 \r
454 /*;*******************************************************************************\r
455 ;* Function Name  : TIM2_OC1IRQHandler\r
456 ;* Description    : This function used to switch to SYS mode before entering\r
457 ;*                  the TIM2_OC1_IRQHandler function located in 75x_it.c.\r
458 ;*                  Then to return to IRQ mode after the\r
459 ;*                  TIM2_OC1_IRQHandler function termination.\r
460 ;* Input          : none\r
461 ;* Output         : none\r
462 ;*******************************************************************************/\r
463 TIM2_OC1IRQHandler:\r
464         IRQ_to_SYS\r
465         BL     TIM2_OC1_IRQHandler\r
466         SYS_to_IRQ\r
467 \r
468 /*;*******************************************************************************\r
469 ;* Function Name  : TIM2_IC12IRQHandler\r
470 ;* Description    : This function used to switch to SYS mode before entering\r
471 ;*                  the TIM2_IC12_IRQHandler function located in 75x_it.c.\r
472 ;*                  Then to return to IRQ mode after the\r
473 ;*                  TIM2_IC12_IRQHandler function termination.\r
474 ;* Input          : none\r
475 ;* Output         : none\r
476 ;*******************************************************************************/\r
477 TIM2_IC12IRQHandler:\r
478         IRQ_to_SYS\r
479         BL     TIM2_IC12_IRQHandler\r
480         SYS_to_IRQ\r
481 \r
482 /*;*******************************************************************************\r
483 ;* Function Name  : TIM2_UPIRQHandler\r
484 ;* Description    : This function used to switch to SYS mode before entering\r
485 ;*                  the TIM2_UP_IRQHandler function located in 75x_it.c.\r
486 ;*                  Then to return to IRQ mode after the\r
487 ;*                  TIM3_UP_IRQHandler function termination.\r
488 ;* Input          : none\r
489 ;* Output         : none\r
490 ;*******************************************************************************/\r
491 TIM2_UPIRQHandler:\r
492         IRQ_to_SYS\r
493         BL     TIM2_UP_IRQHandler\r
494         SYS_to_IRQ\r
495 \r
496 /*;*******************************************************************************\r
497 ;* Function Name  : TIM1_OC2IRQHandler\r
498 ;* Description    : This function used to switch to SYS mode before entering\r
499 ;*                  the TIM1_OC2_IRQHandler function located in 75x_it.c.\r
500 ;*                  Then to return to IRQ mode after the\r
501 ;*                  TIM1_OC2_IRQHandler function termination.\r
502 ;* Input          : none\r
503 ;* Output         : none\r
504 ;*******************************************************************************/\r
505 TIM1_OC2IRQHandler:\r
506         IRQ_to_SYS\r
507         BL     TIM1_OC2_IRQHandler\r
508         SYS_to_IRQ\r
509 \r
510 /*;*******************************************************************************\r
511 ;* Function Name  : TIM1_OC1IRQHandler\r
512 ;* Description    : This function used to switch to SYS mode before entering\r
513 ;*                  the TIM1_OC1_IRQHandler function located in 75x_it.c.\r
514 ;*                  Then to return to IRQ mode after the\r
515 ;*                  TIM1_OC1_IRQHandler function termination.\r
516 ;* Input          : none\r
517 ;* Output         : none\r
518 ;*******************************************************************************/\r
519 TIM1_OC1IRQHandler:\r
520         IRQ_to_SYS\r
521         BL     TIM1_OC1_IRQHandler\r
522         SYS_to_IRQ\r
523 \r
524 /*;*******************************************************************************\r
525 ;* Function Name  : TIM1_IC12IRQHandler\r
526 ;* Description    : This function used to switch to SYS mode before entering\r
527 ;*                  the TIM1_IC12_IRQHandler function located in 75x_it.c.\r
528 ;*                  Then to return to IRQ mode after the\r
529 ;*                  TIM1_IC12_IRQHandler function termination.\r
530 ;* Input          : none\r
531 ;* Output         : none\r
532 ;*******************************************************************************/\r
533 TIM1_IC12IRQHandler:\r
534         IRQ_to_SYS\r
535         BL     TIM1_IC12_IRQHandler\r
536         SYS_to_IRQ\r
537 \r
538 /*;*******************************************************************************\r
539 ;* Function Name  : TIM1_UPIRQHandler\r
540 ;* Description    : This function used to switch to SYS mode before entering\r
541 ;*                  the TIM1_UP_IRQHandler function located in 75x_it.c.\r
542 ;*                  Then to return to IRQ mode after the\r
543 ;*                  TIM1_UP_IRQHandler function termination.\r
544 ;* Input          : none\r
545 ;* Output         : none\r
546 ;*******************************************************************************/\r
547 TIM1_UPIRQHandler:\r
548         IRQ_to_SYS\r
549         BL     TIM1_UP_IRQHandler\r
550         SYS_to_IRQ\r
551 \r
552 /*;*******************************************************************************\r
553 ;* Function Name  : TIM0_OC2IRQHandler\r
554 ;* Description    : This function used to switch to SYS mode before entering\r
555 ;*                  the TIM0_OC2_IRQHandler function located in 75x_it.c.\r
556 ;*                  Then to return to IRQ mode after the\r
557 ;*                  TIM0_OC2_IRQHandler function termination.\r
558 ;* Input          : none\r
559 ;* Output         : none\r
560 ;*******************************************************************************/\r
561 TIM0_OC2IRQHandler:\r
562         IRQ_to_SYS\r
563         BL     TIM0_OC2_IRQHandler\r
564         SYS_to_IRQ\r
565 \r
566 /*;*******************************************************************************\r
567 ;* Function Name  : TIM0_OC1IRQHandler\r
568 ;* Description    : This function used to switch to SYS mode before entering\r
569 ;*                  the TIM0_OC1_IRQHandler function located in 75x_it.c.\r
570 ;*                  Then to return to IRQ mode after the\r
571 ;*                  TIM0_OC1_IRQHandler function termination.\r
572 ;* Input          : none\r
573 ;* Output         : none\r
574 ;*******************************************************************************/\r
575 TIM0_OC1IRQHandler:\r
576         IRQ_to_SYS\r
577         BL     TIM0_OC1_IRQHandler\r
578         SYS_to_IRQ\r
579 \r
580 /*;*******************************************************************************\r
581 ;* Function Name  : TIM0_IC12IRQHandler\r
582 ;* Description    : This function used to switch to SYS mode before entering\r
583 ;*                  the TIM0_IC12_IRQHandler function located in 75x_it.c.\r
584 ;*                  Then to return to IRQ mode after the\r
585 ;*                  TIM0_IC12_IRQHandler function termination.\r
586 ;* Input          : none\r
587 ;* Output         : none\r
588 ;********************************************************************************/\r
589 TIM0_IC12IRQHandler:\r
590         IRQ_to_SYS\r
591         BL     TIM0_IC12_IRQHandler\r
592         SYS_to_IRQ\r
593 \r
594 /*;*******************************************************************************\r
595 ;* Function Name  : TIM0_UPIRQHandler\r
596 ;* Description    : This function used to switch to SYS mode before entering\r
597 ;*                  the TIM0_UP_IRQHandler function located in 75x_it.c.\r
598 ;*                  Then to return to IRQ mode after the\r
599 ;*                  TIM0_UP_IRQHandler function termination.\r
600 ;* Input          : none\r
601 ;* Output         : none\r
602 ;********************************************************************************/\r
603 TIM0_UPIRQHandler:\r
604         IRQ_to_SYS\r
605         BL     TIM0_UP_IRQHandler\r
606         SYS_to_IRQ\r
607 \r
608 /*;*******************************************************************************\r
609 ;* Function Name  : PWM_OC123IRQHandler\r
610 ;* Description    : This function used to switch to SYS mode before entering\r
611 ;*                  the PWM_OC123_IRQHandler function located in 75x_it.c.\r
612 ;*                  Then to return to IRQ mode after the\r
613 ;*                    PWM_OC123_IRQHandler function termination.\r
614 ;* Input          : none\r
615 ;* Output         : none\r
616 ;********************************************************************************/\r
617 PWM_OC123IRQHandler:\r
618         IRQ_to_SYS\r
619         BL     PWM_OC123_IRQHandler\r
620         SYS_to_IRQ\r
621 \r
622 /*;*******************************************************************************\r
623 ;* Function Name  : PWM_EMIRQHandler\r
624 ;* Description    : This function used to switch to SYS mode before entering\r
625 ;*                  the PWM_EM_IRQHandler function located in 75x_it.c.\r
626 ;*                  Then to return to IRQ mode after the\r
627 ;*                  PWM_EM_IRQHandler function termination.\r
628 ;* Input          : none\r
629 ;* Output         : none\r
630 ;*******************************************************************************/\r
631 PWM_EMIRQHandler:\r
632         IRQ_to_SYS\r
633         BL     PWM_EM_IRQHandler\r
634         SYS_to_IRQ\r
635 \r
636 /*;*******************************************************************************\r
637 ;* Function Name  : PWM_UPIRQHandler\r
638 ;* Description    : This function used to switch to SYS mode before entering\r
639 ;*                  the PWM_UP_IRQHandler function located in 75x_it.c.\r
640 ;*                  Then to return to IRQ mode after the\r
641 ;*                  PWM_UP_IRQHandler function termination.\r
642 ;* Input          : none\r
643 ;* Output         : none\r
644 ;*******************************************************************************/\r
645 PWM_UPIRQHandler:\r
646         IRQ_to_SYS\r
647         BL     PWM_UP_IRQHandler\r
648         SYS_to_IRQ\r
649 \r
650 /*;*******************************************************************************\r
651 ;* Function Name  : I2CIRQHandler\r
652 ;* Description    : This function used to switch to SYS mode before entering\r
653 ;*                  the I2C_IRQHandler function located in 75x_it.c.\r
654 ;*                  Then to return to IRQ mode after the\r
655 ;*                  I2C_IRQHandler function termination.\r
656 ;* Input          : none\r
657 ;* Output         : none\r
658 ;*******************************************************************************/\r
659 I2CIRQHandler:\r
660         IRQ_to_SYS\r
661         BL     I2C_IRQHandler\r
662         SYS_to_IRQ\r
663 \r
664 /*;*******************************************************************************\r
665 ;* Function Name  : SSP1IRQHandler\r
666 ;* Description    : This function used to switch to SYS mode before entering\r
667 ;*                  the SSP1_IRQHandler function located in 75x_it.c.\r
668 ;*                  Then to return to IRQ mode after the\r
669 ;*                  SSP1_IRQHandler function termination.\r
670 ;* Input          : none\r
671 ;* Output         : none\r
672 ;*******************************************************************************/\r
673 SSP1IRQHandler:\r
674         IRQ_to_SYS\r
675         BL     SSP1_IRQHandler\r
676         SYS_to_IRQ\r
677 \r
678 /*;*******************************************************************************\r
679 ;* Function Name  : SSP0IRQHandler\r
680 ;* Description    : This function used to switch to SYS mode before entering\r
681 ;*                  the SSP0_IRQHandler function located in 75x_it.c.\r
682 ;*                  Then to return to IRQ mode after the\r
683 ;*                  SSP0_IRQHandler function termination.\r
684 ;* Input          : none\r
685 ;* Output         : none\r
686 ;*******************************************************************************/\r
687 SSP0IRQHandler:\r
688         IRQ_to_SYS\r
689         BL     SSP0_IRQHandler\r
690         SYS_to_IRQ\r
691 \r
692 /*;*******************************************************************************\r
693 ;* Function Name  : UART2IRQHandler\r
694 ;* Description    : This function used to switch to SYS mode before entering\r
695 ;*                  the UART2_IRQHandler function located in 75x_it.c.\r
696 ;*                  Then to return to IRQ mode after the\r
697 ;*                  UART2_IRQHandler function termination.\r
698 ;* Input          : none\r
699 ;* Output         : none\r
700 ;*******************************************************************************/\r
701 UART2IRQHandler:\r
702         IRQ_to_SYS\r
703         BL     UART2_IRQHandler\r
704         SYS_to_IRQ\r
705 \r
706 /*;*******************************************************************************\r
707 ;* Function Name  : UART1IRQHandler\r
708 ;* Description    : This function used to switch to SYS mode before entering\r
709 ;*                  the UART1_IRQHandler function located in 75x_it.c.\r
710 ;*                  Then to return to IRQ mode after the\r
711 ;*                  UART1_IRQHandler function termination.\r
712 ;* Input          : none\r
713 ;* Output         : none\r
714 ;*******************************************************************************/\r
715 UART1IRQHandler:\r
716         IRQ_to_SYS\r
717         BL     UART1_IRQHandler\r
718         SYS_to_IRQ\r
719 \r
720 /*;*******************************************************************************\r
721 ;* Function Name  : UART0IRQHandler\r
722 ;* Description    : This function used to switch to SYS mode before entering\r
723 ;*                  the UART0_IRQHandler function located in 75x_it.c.\r
724 ;*                  Then to return to IRQ mode after the\r
725 ;*                  UART0_IRQHandler function termination.\r
726 ;* Input          : none\r
727 ;* Output         : none\r
728 ;********************************************************************************/\r
729 UART0IRQHandler:\r
730         IRQ_to_SYS\r
731         BL     UART0_IRQHandler\r
732         SYS_to_IRQ\r
733 \r
734 /*;*******************************************************************************\r
735 ;* Function Name  : CANIRQHandler\r
736 ;* Description    : This function used to switch to SYS mode before entering\r
737 ;*                  the CAN_IRQHandler function located in 75x_it.c.\r
738 ;*                  Then to return to IRQ mode after the\r
739 ;*                  CAN_IRQHandler function termination.\r
740 ;* Input          : none\r
741 ;* Output         : none\r
742 ;********************************************************************************/\r
743 CANIRQHandler:\r
744         IRQ_to_SYS\r
745         BL     CAN_IRQHandler\r
746         SYS_to_IRQ\r
747 \r
748 /*;*******************************************************************************\r
749 ;* Function Name  : USB_LPIRQHandler\r
750 ;* Description    : This function used to switch to SYS mode before entering\r
751 ;*                  the USB_LP_IRQHandler function located in 75x_it.c.\r
752 ;*                  Then to return to IRQ mode after the\r
753 ;*                  USB_LP_IRQHandler function termination.\r
754 ;* Input          : none\r
755 ;* Output         : none\r
756 ;********************************************************************************/\r
757 USB_LPIRQHandler:\r
758         IRQ_to_SYS\r
759         BL     USB_LP_IRQHandler\r
760         SYS_to_IRQ\r
761 \r
762 /*;*******************************************************************************\r
763 ;* Function Name  : USB_HPIRQHandler\r
764 ;* Description    : This function used to switch to SYS mode before entering\r
765 ;*                  the USB_HP_IRQHandler function located in 75x_it.c.\r
766 ;*                  Then to return to IRQ mode after the\r
767 ;*                  USB_HP_IRQHandler function termination.\r
768 ;* Input          : none\r
769 ;* Output         : none\r
770 ;********************************************************************************/\r
771 USB_HPIRQHandler:\r
772         IRQ_to_SYS\r
773         BL     USB_HP_IRQHandler\r
774         SYS_to_IRQ\r
775 \r
776 /*;*******************************************************************************\r
777 ;* Function Name  : ADCIRQHandler\r
778 ;* Description    : This function used to switch to SYS mode before entering\r
779 ;*                  the ADC_IRQHandler function located in 75x_it.c.\r
780 ;*                  Then to return to IRQ mode after the\r
781 ;*                  ADC_IRQHandler function termination.\r
782 ;* Input          : none\r
783 ;* Output         : none\r
784 ;********************************************************************************/\r
785 ADCIRQHandler:\r
786         IRQ_to_SYS\r
787         BL     ADC_IRQHandler\r
788         SYS_to_IRQ\r
789 \r
790 /*;*******************************************************************************\r
791 ;* Function Name  : DMAIRQHandler\r
792 ;* Description    : This function used to switch to SYS mode before entering\r
793 ;*                  the DMA_IRQHandler function located in 75x_it.c.\r
794 ;*                  Then to return to IRQ mode after the\r
795 ;*                  DMA_IRQHandler function termination.\r
796 ;* Input          : none\r
797 ;* Output         : none\r
798 ;********************************************************************************/\r
799 DMAIRQHandler:\r
800         IRQ_to_SYS\r
801         BL     DMA_IRQHandler\r
802         SYS_to_IRQ\r
803 \r
804 /*;*******************************************************************************\r
805 ;* Function Name  : EXTITIRQHandler\r
806 ;* Description    : This function used to switch to SYS mode before entering\r
807 ;*                  the EXTIT_IRQHandler function located in 75x_it.c.\r
808 ;*                  Then to return to IRQ mode after the\r
809 ;*                  EXTIT_IRQHandler function termination.\r
810 ;* Input          : none\r
811 ;* Output         : none\r
812 ;********************************************************************************/\r
813 EXTITIRQHandler:\r
814         IRQ_to_SYS\r
815         BL     EXTIT_IRQHandler\r
816         SYS_to_IRQ\r
817 \r
818 /*;*******************************************************************************\r
819 ;* Function Name  : MRCCIRQHandler\r
820 ;* Description    : This function used to switch to SYS mode before entering\r
821 ;*                  the MRCC_IRQHandler function located in 75x_it.c.\r
822 ;*                  Then to return to IRQ mode after the\r
823 ;*                  MRCC_IRQHandler function termination.\r
824 ;* Input          : none\r
825 ;* Output         : none\r
826 ;********************************************************************************/\r
827 MRCCIRQHandler:\r
828         IRQ_to_SYS\r
829         BL     MRCC_IRQHandler\r
830         SYS_to_IRQ\r
831 \r
832 /*;*******************************************************************************\r
833 ;* Function Name  : FLASHSMIIRQHandler\r
834 ;* Description    : This function used to switch to SYS mode before entering\r
835 ;*                  the FLASHSMI_IRQHandler function located in 75x_it.c.\r
836 ;*                  Then to return to IRQ mode after the\r
837 ;*                  FLASHSMI_IRQHandler function termination.\r
838 ;* Input          : none\r
839 ;* Output         : none\r
840 ;********************************************************************************/\r
841 FLASHSMIIRQHandler:\r
842         IRQ_to_SYS\r
843         BL     FLASHSMI_IRQHandler\r
844         SYS_to_IRQ\r
845 \r
846 /*;*******************************************************************************\r
847 ;* Function Name  : RTCIRQHandler\r
848 ;* Description    : This function used to switch to SYS mode before entering\r
849 ;*                  the RTC_IRQHandler function located in 75x_it.c.\r
850 ;*                  Then to return to IRQ mode after the\r
851 ;*                  RTC_IRQHandler function termination.\r
852 ;* Input          : none\r
853 ;* Output         : none\r
854 ;********************************************************************************/\r
855 RTCIRQHandler:\r
856         IRQ_to_SYS\r
857         BL     RTC_IRQHandler\r
858         SYS_to_IRQ\r
859 \r
860 /*;*******************************************************************************\r
861 ;* Function Name  : TBIRQHandler\r
862 ;* Description    : This function used to switch to SYS mode before entering\r
863 ;*                  the TB_IRQHandler function located in 75x_it.c.\r
864 ;*                  Then to return to IRQ mode after the\r
865 ;*                  TB_IRQHandler function termination.\r
866 ;* Input          : none\r
867 ;* Output         : none\r
868 ;********************************************************************************/\r
869 TBIRQHandler:\r
870         IRQ_to_SYS\r
871         BL     TB_IRQHandler\r
872         SYS_to_IRQ\r
873 /*;**********************************************************************************/\r
874 \r
875 Reset_Handler:\r
876         LDR     pc, =NextInst\r
877 \r
878 NextInst:\r
879 /*; Reset all Peripheral Clocks*/\r
880 /*; This is usefull only when using debugger to Reset\Run the application*/\r
881 \r
882      .if SMI_Bank0_EN\r
883         LDR     r0, =0x01000000          /*; Disable peripherals clock (except GPIO)*/\r
884      .else\r
885         LDR     r0, =0x00000000          /*; Disable peripherals clock*/\r
886      .endif\r
887         LDR     r1, =MRCC_PCLKEN_Addr\r
888         STR     r0, [r1]\r
889 \r
890      .if SMI_Bank0_EN\r
891         LDR     r0, =0x1875623F          /*; Peripherals kept under reset (except GPIO)*/\r
892      .else\r
893         LDR     r0, =0x1975623F          /*; Peripherals kept under reset*/\r
894      .endif     \r
895            \r
896         STR     r0, [r1,#4]              \r
897         MOV     r0, #0\r
898         NOP                              /*; Wait*/\r
899         NOP\r
900         NOP\r
901         NOP\r
902         STR     r0, [r1,#4]              /*; Disable peripherals reset*/\r
903 \r
904 /*; Initialize stack pointer registers\r
905   ; Enter each mode in turn and set up the stack pointer*/\r
906 \r
907 \r
908 \r
909         MSR     CPSR_c, #Mode_FIQ|I_Bit|F_Bit /*; No interrupts*/\r
910         ldr     sp, =FIQ_Stack\r
911 \r
912         MSR     CPSR_c, #Mode_IRQ|I_Bit|F_Bit /*; No interrupts*/\r
913         ldr     sp, =IRQ_Stack\r
914 \r
915         MSR     CPSR_c, #Mode_ABT|I_Bit|F_Bit /*; No interrupts*/\r
916         ldr     sp, =ABT_Stack\r
917 \r
918         MSR     CPSR_c, #Mode_UNDEF|I_Bit|F_Bit /*; No interrupts*/\r
919         ldr     sp,  =UNDEF_Stack\r
920 \r
921         MSR     CPSR_c, #Mode_SVC|I_Bit|F_Bit /*; No interrupts*/\r
922         ldr     sp, =_estack\r
923 \r
924 /*; ------------------------------------------------------------------------------\r
925 ; Description  :  Enable SMI Bank0: enable GPIOs clock in MRCC_PCLKEN register, \r
926 ;                 enable SMI alternate function in GPIO_REMAP register and enable \r
927 ;                 Bank0 in SMI_CR1 register.\r
928 ; ------------------------------------------------------------------------------*/\r
929   .if SMI_Bank0_EN\r
930         MOV     r0, #0x01000000\r
931         LDR     r1, =MRCC_PCLKEN_Addr\r
932         STR     r0, [r1]                 /*; Enable GPIOs clock*/\r
933 \r
934         LDR     r1, =GPIOREMAP0R_Addr\r
935         MOV     r0, #SMI_EN_Mask\r
936         LDR     r2, [r1]\r
937         ORR     r2, r2, r0\r
938         STR     r2, [r1]                 /*; Enable SMI alternate function  */\r
939 \r
940         LDR     r0, =0x251               /*; SMI Bank0 enabled, Prescaler = 2, Deselect Time = 5*/\r
941         LDR     r1, =SMI_CR1_Addr\r
942         STR     r0, [r1]                 /*; Configure CR1 register */\r
943         LDR     r0, =0x00\r
944         STR     r0, [r1,#4]              /*; Reset CR2 register */\r
945   .endif\r
946 \r
947 /*; ----------------------------------------------------------------------------\r
948 ; Description  :  Remapping SRAM at address 0x00 after the application has \r
949 ;                 started executing. \r
950 ; ----------------------------------------------------------------------------*/\r
951  .if  Remap_SRAM\r
952         MOV     r0, #SRAM_mask\r
953         LDR     r1, =CFG_GLCONF_Addr\r
954         LDR     r2, [r1]                  /*; Read GLCONF Register*/\r
955         BIC     r2, r2, #0x03             /*; Reset the SW_BOOT bits*/\r
956         ORR     r2, r2, r0                /*; Change the SW_BOOT bits*/\r
957         STR     r2, [r1]                  /*; Write GLCONF Register*/\r
958   .endif\r
959 \r
960 /*;-------------------------------------------------------------------------------\r
961 ;Description  : Initialize the EIC as following :\r
962 ;              - IRQ disabled\r
963 ;              - FIQ disabled\r
964 ;              - IVR contains the load PC opcode\r
965 ;              - All channels are disabled\r
966 ;              - All channels priority equal to 0\r
967 ;              - All SIR registers contains offset to the related IRQ table entry\r
968 ;-------------------------------------------------------------------------------*/\r
969   .if EIC_INIT\r
970         LDR     r3, =EIC_base_addr\r
971         LDR     r4, =0x00000000\r
972         STR     r4, [r3, #ICR_off_addr]   /*; Disable FIQ and IRQ*/\r
973         STR     r4, [r3, #IER_off_addr]   /*; Disable all interrupts channels*/\r
974 \r
975         LDR     r4, =0xFFFFFFFF\r
976         STR     r4, [r3, #IPR_off_addr]   /*; Clear all IRQ pending bits*/\r
977 \r
978         LDR     r4, =0x18\r
979         STR     r4, [r3, #FIR_off_addr]   /*; Disable FIQ channels and clear FIQ pending bits*/\r
980 \r
981         LDR     r4, =0x00000000\r
982         STR     r4, [r3, #CIPR_off_addr]  /*; Reset the current priority register*/\r
983 \r
984         LDR     r4, =0xE59F0000           /*; Write the LDR pc,pc,#offset..*/\r
985         STR     r4, [r3, #IVR_off_addr]   /*; ..instruction code in IVR[31:16]*/\r
986 \r
987 \r
988         LDR     r2,= 32                   /*; 32 Channel to initialize*/\r
989         LDR     r0, =WAKUP_Addr           /*; Read the address of the IRQs address table*/\r
990         LDR     r1, =0x00000FFF\r
991         AND     r0,r0,r1\r
992         LDR     r5,=SIR0_off_addr         /*; Read SIR0 address*/\r
993         SUB     r4,r0,#8                  /*; subtract 8 for prefetch*/\r
994         LDR     r1, =0xF7E8               /*; add the offset to the 0x00 address..*/\r
995                                           /*; ..(IVR address + 7E8 = 0x00)*/\r
996                                           /*; 0xF7E8 used to complete the LDR pc,offset opcode*/\r
997         ADD     r1,r4,r1                  /*; compute the jump offset*/\r
998 EIC_INI:\r
999         MOV     r4, r1, LSL #16           /*; Left shift the result*/\r
1000         STR     r4, [r3, r5]              /*; Store the result in SIRx register*/\r
1001         ADD     r1, r1, #4                /*; Next IRQ address*/\r
1002         ADD     r5, r5, #4                /*; Next SIR*/\r
1003         SUBS    r2, r2, #1                /*; Decrement the number of SIR registers to initialize*/\r
1004         BNE     EIC_INI                   /*; If more then continue*/\r
1005 \r
1006  .endif\r
1007 \r
1008 \r
1009 \r
1010 \r
1011 \r
1012   /* ;copy the initial values for .data section from FLASH to RAM */\r
1013         ldr     R1, =_sidata\r
1014         ldr     R2, =_sdata\r
1015         ldr     R3, =_edata\r
1016 _reset_inidata_loop:\r
1017         cmp     R2, R3\r
1018         ldrlO   R0, [R1], #4\r
1019         strlO   R0, [R2], #4\r
1020         blO     _reset_inidata_loop\r
1021 \r
1022         ;/* Clear the .bss section */\r
1023         mov   r0,#0                                             ;/* get a zero */\r
1024         ldr   r1,=_sbss                         ;/* point to bss start */\r
1025         ldr   r2,=_ebss                         ;/* point to bss end */\r
1026 _reset_inibss_loop:\r
1027         cmp   r1,r2                                             ;/* check if some data remains to clear */\r
1028         strlo r0,[r1],#4                                ;/* clear 4 bytes */\r
1029         blo   _reset_inibss_loop        ;/* loop until done */\r
1030 \r
1031 /************************************************************************************************/\r
1032 \r
1033 /*; --- Now enter the C code */\r
1034         B       main   /*; Note : use B not BL, because an application will*/\r
1035                          /*; never return this way*/\r
1036 \r
1037 \r
1038 \r
1039 \r
1040 \r
1041 \r
1042 \r
1043 \r
1044 \r
1045 \r
1046 \r
1047 \r
1048 \r
1049 \r
1050 \r
1051 \r
1052 \r
1053 \r
1054 \r
1055 \r
1056 \r
1057 \r
1058 \r