Project

General

Profile

Download (4.37 KB) Statistics
| Branch: | Tag: | Revision:
1
/* Cstartup header for the application to be started by at91dfu 
2
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by 
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 */
19

    
20

    
21
//#define DEBUG_LL
22

    
23
	.equ AIC_FVR,         (260) 
24
	.equ AIC_EOICR,       (304)
25
	.equ AT91C_BASE_AIC,  (0xFFFFF000)
26
	.equ ARM_MODE_FIQ,       0x11
27
	.equ ARM_MODE_IRQ,       0x12
28
	.equ ARM_MODE_SVC,       0x13
29

    
30
	.equ I_BIT,              0x80
31
	.equ F_BIT,              0x40
32

    
33

    
34
#define AT91C_BASE_PIOA	0xFFFFF400
35
#define AT91C_BASE_TC0	0xFFFA0000
36
#define AT91C_TC_SWTRG	(1 << 2)
37
#define PIOA_SODR	0x30
38
#define PIOA_CODR	0x34
39
#define PIOA_PDSR	0x3c
40
#define PIOA_ISR	0x4c
41
#define PIOA_IDR	0x44
42
#define PIO_DATA	(1 << 27)
43
#define TC_CCR		0x00
44

    
45

    
46
#define PIO_LED1	(1 << 25) /* this only works on OpenPICC, not Olimex */
47

    
48
#ifdef DEBUG_LL
49
/* Debugging macros for switching on/off LED1 (green) */
50
#define PIOA_PER	0xFFFFF400
51
#define PIOA_OER	0xFFFFF410
52
	.macro	led1on
53
		ldr	r2, =AT91C_BASE_PIOA
54
		mov	r1, #PIO_LED1
55
		str	r1, [r2, #PIOA_CODR]
56
	.endm
57
	.macro	led1off
58
		ldr	r2, =AT91C_BASE_PIOA
59
		mov	r1, #PIO_LED1
60
		str	r1, [r2, #PIOA_SODR]
61
	.endm
62
	.macro	ledinit
63
		ldr	r2, =PIOA_PER
64
		mov	r1, #PIO_LED1
65
		str	r1, [r2]
66
		ldr	r2, =PIOA_OER
67
		str	r1, [r2]
68
		led1off
69
	.endm
70
#else
71
	.macro ledinit
72
	.endm
73
	.macro led1on
74
	.endm
75
	.macro led1off
76
	.endm
77
#endif
78

    
79
	.global	_startup
80
	.func _startup
81
_startup:
82
#ifndef RUN_FROM_RAM
83
	/* Relocate .data section (copy from Flash to RAM) */
84
	ldr	r1, =_etext
85
	ldr	r2, =_data
86
	ldr	r3, =_edata
87
loop_r:	cmp	r2, r3
88
	ldrlo	r0, [r1], #4
89
	strlo	r0, [r2], #4
90
	blo	loop_r
91
#endif
92

    
93
	/* Clear .bss section (Zero init) */
94
	mov	r0, #0
95
	ldr	r1, =__bss_start__
96
	ldr	r2, =__bss_end__
97
loop_z:	cmp	r1, r2
98
	strlo	r0, [r1], #4
99
	blo	loop_z
100

    
101
	/* initialize FIQ mode registers */ 
102
	msr	CPSR_c, #ARM_MODE_FIQ | I_BIT | F_BIT
103
	ldr	r10, =AT91C_BASE_PIOA
104
	ldr	r12, =AT91C_BASE_TC0
105
	mov	r9, #AT91C_TC_SWTRG
106
	msr	CPSR_c, #ARM_MODE_SVC
107

    
108
	led1on
109

    
110
	/* prepare C function call to main */
111
	mov	r0, #0	/* argc = 0 */
112
	ldr	lr, =exit
113
	ldr	r10, =main
114

    
115
	bx	r10
116

    
117
        .size   _startup, . - _startup
118
        .endfunc
119
		
120
/* "exit" dummy to avoid sbrk write read etc. needed by the newlib default "exit" */
121
        .global exit
122
        .func   exit
123
exit:
124
        b    .
125
	.size   exit, . - exit
126
        .endfunc
127

    
128

    
129
#define LED_TRIGGER
130
#define CALL_PIO_IRQ_DEMUX
131

    
132
	.text
133
	.arm
134
	.section .fastrun, "ax"
135

    
136
	.global fiq_handler
137
	.func fiq_handler
138
fiq_handler:
139
		/* code that uses pre-initialized FIQ reg */
140
		/* r8	AT91C_BASE_AIC (dfu init)
141
		   r9	AT91C_TC_SWTRG
142
		   r10	AT91C_BASE_PIOA
143
		   r11	tmp
144
		   r12	AT91C_BASE_TC0
145
		   r13	stack
146
		   r14	lr
147
		 */
148

    
149
		ldr	r8, [r10, #PIOA_ISR]
150
		tst	r8, #PIO_DATA		/* check for PIO_DATA change */
151
		ldrne	r11, [r10, #PIOA_PDSR]
152
		tstne	r11, #PIO_DATA		/* check for PIO_DATA == 1 */
153
		strne	r9, [r12, #TC_CCR]	/* software trigger */
154
#ifdef LED_TRIGGER
155
		movne 	r11, #PIO_LED1
156
		strne	r11, [r10, #PIOA_CODR] /* enable LED */
157
#endif
158

    
159
#if 1
160
		movne	r11, #PIO_DATA
161
		strne	r11, [r10, #PIOA_IDR]	/* disable further PIO_DATA FIQ */
162
#endif
163

    
164
		/*- Mark the End of Interrupt on the AIC */
165
		ldr	r11, =AT91C_BASE_AIC
166
		str	r11, [r11, #AIC_EOICR]
167

    
168
#ifdef LED_TRIGGER
169
		mov 	r11, #PIO_LED1
170
		str	r11, [r10, #PIOA_SODR] /* disable LED */
171
#endif
172

    
173
#ifdef CALL_PIO_IRQ_DEMUX
174
		/* push r0, r1-r3, r12, r14 onto FIQ stack */
175
		stmfd	sp!, { r0-r3, r12, lr}
176
		mov	r0, r8
177

    
178
		/* enable interrupts while handling demux */
179
		/* msr	CPSR_c, #F_BIT | ARM_MODE_SVC */
180

    
181
		/* Call C function, give PIOA_ISR as argument */
182
		ldr	r11, =__pio_irq_demux
183
		mov	r14, pc
184
		bx	r11 
185

    
186
		/* msr	CPSR_c, #I_BIT | F_BIT | ARM_MODE_FIQ */
187
		ldmia	sp!, { r0-r3, r12, lr }
188
#endif
189

    
190
		/*- Restore the Program Counter using the LR_fiq directly in the PC */
191
		subs        pc, lr, #4
192

    
193
        .size   fiq_handler, . - fiq_handler
194
        .endfunc
195
        .end
196

    
(3-3/3)
Add picture from clipboard (Maximum size: 48.8 MB)