summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Purchase <shotofadds@rockbox.org>2009-06-24 07:37:11 +0000
committerRob Purchase <shotofadds@rockbox.org>2009-06-24 07:37:11 +0000
commitf62388f82c1a3cbc5e47c8e002abb5a514e9251b (patch)
tree5fc6d6af526ca3ac3119104048b3c05cf185e191
parent5e24a2c98c9a7eb1b725c9bbb0233f9cf82004fb (diff)
downloadrockbox-f62388f82c1a3cbc5e47c8e002abb5a514e9251b.tar.gz
rockbox-f62388f82c1a3cbc5e47c8e002abb5a514e9251b.zip
TCC78x: Enable interrupts/threading in the bootloader (required now that the storage driver yields).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21486 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/telechips.c64
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/target/arm/tcc780x/crt0.S43
-rw-r--r--firmware/target/arm/tcc780x/kernel-tcc780x.c24
-rw-r--r--firmware/target/arm/tcc780x/system-tcc780x.c8
-rw-r--r--firmware/target/arm/tcc780x/timer-tcc780x.c23
6 files changed, 52 insertions, 112 deletions
diff --git a/bootloader/telechips.c b/bootloader/telechips.c
index 1e54f5d37d..8babbf3b62 100644
--- a/bootloader/telechips.c
+++ b/bootloader/telechips.c
@@ -57,19 +57,18 @@ extern int line;
57#define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */ 57#define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
58 58
59/* The following function is just test/development code */ 59/* The following function is just test/development code */
60#ifdef CPU_TCC77X
61void show_debug_screen(void) 60void show_debug_screen(void)
62{ 61{
63 int button; 62 int button;
64 int power_count = 0; 63 int power_count = 0;
65 int count = 0; 64 int count = 0;
66 bool do_power_off = false; 65 bool do_power_off = false;
67 66
68 lcd_puts_scroll(0,0,"this is a very long line to test scrolling"); 67 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
69 while (!do_power_off) { 68 while (!do_power_off) {
70 line = 1; 69 line = 1;
71 button = button_get(false); 70 button = button_get(false);
72 71
73 /* Power-off if POWER button has been held for a time 72 /* Power-off if POWER button has been held for a time
74 This loop is currently running at about 100 iterations/second 73 This loop is currently running at about 100 iterations/second
75 */ 74 */
@@ -107,6 +106,7 @@ void show_debug_screen(void)
107#endif 106#endif
108 count++; 107 count++;
109 printf("Count: %d",count); 108 printf("Count: %d",count);
109 lcd_update();
110 sleep(HZ/10); 110 sleep(HZ/10);
111 111
112 } 112 }
@@ -122,57 +122,6 @@ void show_debug_screen(void)
122 while (true); 122 while (true);
123} 123}
124 124
125#else /* !CPU_TCC77X */
126
127void show_debug_screen(void)
128{
129 int button;
130 int power_count = 0;
131 int count = 0;
132 bool do_power_off = false;
133#ifdef HAVE_BUTTON_DATA
134 unsigned int data;
135#endif
136
137 while(!do_power_off) {
138 line = 0;
139 printf("Hello World!");
140
141#ifdef HAVE_BUTTON_DATA
142 button = button_read_device(&data);
143#else
144 button = button_read_device();
145#endif
146
147 /* Power-off if POWER button has been held for a long time
148 This loop is currently running at about 100 iterations/second
149 */
150 if (button & POWEROFF_BUTTON) {
151 power_count++;
152 if (power_count > 200)
153 do_power_off = true;
154 } else {
155 power_count = 0;
156 }
157
158 printf("Btn: 0x%08x",button);
159
160 count++;
161 printf("Count: %d",count);
162 }
163
164 lcd_clear_display();
165 line = 0;
166 printf("POWER-OFF");
167
168 /* Power-off */
169 power_off();
170
171 printf("(NOT) POWERED OFF");
172 while (true);
173}
174#endif
175
176void* main(void) 125void* main(void)
177{ 126{
178#ifdef TCCBOOT 127#ifdef TCCBOOT
@@ -182,11 +131,10 @@ void* main(void)
182 131
183 system_init(); 132 system_init();
184 power_init(); 133 power_init();
185#ifndef COWON_D2 134
186 /* The D2 doesn't enable threading or interrupts */
187 kernel_init(); 135 kernel_init();
188 enable_irq(); 136 enable_irq();
189#endif 137
190 lcd_init(); 138 lcd_init();
191 139
192 adc_init(); 140 adc_init();
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 0eff012660..6f23012b61 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1202,6 +1202,7 @@ drivers/pcf50606.c
1202target/arm/lcd-as-memframe.S 1202target/arm/lcd-as-memframe.S
1203target/arm/tcc780x/adc-tcc780x.c 1203target/arm/tcc780x/adc-tcc780x.c
1204target/arm/tcc780x/system-tcc780x.c 1204target/arm/tcc780x/system-tcc780x.c
1205target/arm/tcc780x/kernel-tcc780x.c
1205target/arm/tcc780x/cowond2/button-cowond2.c 1206target/arm/tcc780x/cowond2/button-cowond2.c
1206target/arm/tcc780x/cowond2/lcd-cowond2.c 1207target/arm/tcc780x/cowond2/lcd-cowond2.c
1207target/arm/tcc780x/cowond2/power-cowond2.c 1208target/arm/tcc780x/cowond2/power-cowond2.c
@@ -1209,7 +1210,6 @@ target/arm/tcc780x/cowond2/powermgmt-cowond2.c
1209target/arm/tcc780x/cowond2/backlight-cowond2.c 1210target/arm/tcc780x/cowond2/backlight-cowond2.c
1210target/arm/usb-tcc.c 1211target/arm/usb-tcc.c
1211#ifndef BOOTLOADER 1212#ifndef BOOTLOADER
1212target/arm/tcc780x/kernel-tcc780x.c
1213target/arm/tcc780x/timer-tcc780x.c 1213target/arm/tcc780x/timer-tcc780x.c
1214target/arm/wmcodec-telechips.c 1214target/arm/wmcodec-telechips.c
1215target/arm/tcc780x/debug-tcc780x.c 1215target/arm/tcc780x/debug-tcc780x.c
diff --git a/firmware/target/arm/tcc780x/crt0.S b/firmware/target/arm/tcc780x/crt0.S
index 03f17957c5..f02a204d7e 100644
--- a/firmware/target/arm/tcc780x/crt0.S
+++ b/firmware/target/arm/tcc780x/crt0.S
@@ -94,9 +94,8 @@ start_loc:
94 ldr pc, =copied_start /* jump to the relocated start_loc: */ 94 ldr pc, =copied_start /* jump to the relocated start_loc: */
95 95
96copied_start: 96copied_start:
97#endif 97#endif /* TCCBOOT */
98#else 98#endif /* BOOTLOADER */
99 /* We don't use interrupts in the bootloader */
100 99
101 /* Set up stack for IRQ mode */ 100 /* Set up stack for IRQ mode */
102 mov r0,#0xd2 101 mov r0,#0xd2
@@ -107,13 +106,15 @@ copied_start:
107 mov r0,#0xd1 106 mov r0,#0xd1
108 msr cpsr, r0 107 msr cpsr, r0
109 ldr sp, =fiq_stack 108 ldr sp, =fiq_stack
110 109
110#ifndef BOOTLOADER
111 /* Load the banked FIQ mode registers with useful values here. 111 /* Load the banked FIQ mode registers with useful values here.
112 These values will be used in the FIQ handler in pcm-tcc780x.c */ 112 These values will be used in the FIQ handler in pcm-tcc780x.c */
113 .equ DADO_BASE, 0xF0059020 113 .equ DADO_BASE, 0xF0059020
114 114
115 ldr r10, =DADO_BASE 115 ldr r10, =DADO_BASE
116 ldr r11, =dma_play_data 116 ldr r11, =dma_play_data
117#endif
117 118
118 /* Let abort and undefined modes use IRQ stack */ 119 /* Let abort and undefined modes use IRQ stack */
119 mov r0,#0xd7 120 mov r0,#0xd7
@@ -122,7 +123,6 @@ copied_start:
122 mov r0,#0xdb 123 mov r0,#0xdb
123 msr cpsr, r0 124 msr cpsr, r0
124 ldr sp, =irq_stack 125 ldr sp, =irq_stack
125#endif
126 126
127 /* Switch to supervisor mode */ 127 /* Switch to supervisor mode */
128 mov r0,#0xd3 128 mov r0,#0xd3
@@ -176,18 +176,19 @@ copied_start:
176 mcr p15, 0, r0, c7, c6, 0 /* Invalidate Dcache */ 176 mcr p15, 0, r0, c7, c6, 0 /* Invalidate Dcache */
177 mcr p15, 0, r1, c8, c7, 0 /* Invalidate TLB */ 177 mcr p15, 0, r1, c8, c7, 0 /* Invalidate TLB */
178 178
179#if !defined(BOOTLOADER) && !defined(STUB) 179#ifndef STUB
180 180
181 /* Copy exception handler code to address 0 */ 181 /* Copy exception handler code to address 0 */
182 ldr r2, =_vectorsstart 182 mov r2, #0x0
183 ldr r3, =_vectorsend 183 ldr r3, =vectors_start
184 ldr r4, =_vectorscopy 184 ldr r4, =vectors_end
1851: 1851:
186 cmp r3, r2 186 cmp r4, r3
187 ldrhi r5, [r4], #4 187 ldrhi r5, [r3], #4
188 strhi r5, [r2], #4 188 strhi r5, [r2], #4
189 bhi 1b 189 bhi 1b
190 190
191#ifndef BOOTLOADER
191 /* Copy the IRAM (SRAM) */ 192 /* Copy the IRAM (SRAM) */
192 ldr r2, =_iramcopy 193 ldr r2, =_iramcopy
193 ldr r3, =_iramstart 194 ldr r3, =_iramstart
@@ -226,7 +227,8 @@ copied_start:
226 ldrhi r5, [r2], #4 227 ldrhi r5, [r2], #4
227 strhi r5, [r3], #4 228 strhi r5, [r3], #4
228 bhi 1b 229 bhi 1b
229#endif /* !BOOTLOADER,!STUB */ 230#endif /* !BOOTLOADER */
231#endif /* !STUB */
230 232
231 /* Initialise bss section to zero */ 233 /* Initialise bss section to zero */
232 ldr r2, =_edata 234 ldr r2, =_edata
@@ -250,10 +252,9 @@ copied_start:
250 bl main 252 bl main
251 /* main() should never return */ 253 /* main() should never return */
252 254
253#ifndef BOOTLOADER
254
255/* Exception handlers. Will be copied to address 0 after memory remapping */ 255/* Exception handlers. Will be copied to address 0 after memory remapping */
256 .section .vectors,"aw" 256
257vectors_start:
257 ldr pc, [pc, #24] 258 ldr pc, [pc, #24]
258 ldr pc, [pc, #24] 259 ldr pc, [pc, #24]
259 ldr pc, [pc, #24] 260 ldr pc, [pc, #24]
@@ -274,6 +275,7 @@ vectors:
274 .word reserved_handler 275 .word reserved_handler
275 .word irq_handler 276 .word irq_handler
276 .word fiq_handler 277 .word fiq_handler
278vectors_end:
277 279
278 .text 280 .text
279 281
@@ -304,13 +306,16 @@ data_abort_handler:
304 mov r1, #2 306 mov r1, #2
305 b UIE 307 b UIE
306 308
309#ifdef BOOTLOADER
310fiq_handler:
311 subs pc, lr, #4
312#endif
313
307#if defined(STUB) 314#if defined(STUB)
308UIE: 315UIE:
309 b UIE 316 b UIE
310#endif 317#endif
311 318
312 /* We don't use interrupts in the bootloader */
313
314/* Align stacks to cache line boundary */ 319/* Align stacks to cache line boundary */
315 .balign 16 320 .balign 16
316 321
@@ -321,5 +326,3 @@ irq_stack:
321/* 256 words of FIQ stack */ 326/* 256 words of FIQ stack */
322 .space 256*4 327 .space 256*4
323fiq_stack: 328fiq_stack:
324
325#endif
diff --git a/firmware/target/arm/tcc780x/kernel-tcc780x.c b/firmware/target/arm/tcc780x/kernel-tcc780x.c
index dee5e040e2..76395d2b33 100644
--- a/firmware/target/arm/tcc780x/kernel-tcc780x.c
+++ b/firmware/target/arm/tcc780x/kernel-tcc780x.c
@@ -38,5 +38,25 @@ void tick_start(unsigned int interval_in_ms)
38 TCFG(0) = TCFG_CLEAR | (0 << TCFG_SEL) | TCFG_IEN | TCFG_EN; 38 TCFG(0) = TCFG_CLEAR | (0 << TCFG_SEL) | TCFG_IEN | TCFG_EN;
39} 39}
40 40
41/* NB: Since we are using a single timer IRQ, tick tasks are dispatched as 41
42 part of the central timer IRQ processing in timer-tcc780x.c */ 42/* Timer interrupt processing - all timers (inc. tick) share a single IRQ */
43void TIMER0(void)
44{
45 if (TIREQ & TIREQ_TF0) /* Timer0 reached ref value */
46 {
47 /* Run through the list of tick tasks */
48 call_tick_tasks();
49
50 /* reset Timer 0 IRQ & ref flags */
51 TIREQ = TIREQ_TI0 | TIREQ_TF0;
52 }
53
54 if (TIREQ & TIREQ_TF4) /* Timer4 reached ref value */
55 {
56 /* dispatch user timer */
57 if (pfn_timer != NULL)
58 pfn_timer();
59
60 TIREQ = TIREQ_TI4 | TIREQ_TF4;
61 }
62}
diff --git a/firmware/target/arm/tcc780x/system-tcc780x.c b/firmware/target/arm/tcc780x/system-tcc780x.c
index ab8a6cf218..6362f17f71 100644
--- a/firmware/target/arm/tcc780x/system-tcc780x.c
+++ b/firmware/target/arm/tcc780x/system-tcc780x.c
@@ -23,8 +23,6 @@
23#include "system.h" 23#include "system.h"
24#include "panic.h" 24#include "panic.h"
25 25
26#if !defined(BOOTLOADER)
27
28#define default_interrupt(name) \ 26#define default_interrupt(name) \
29 extern __attribute__((weak,alias("UIRQ"))) void name (void) 27 extern __attribute__((weak,alias("UIRQ"))) void name (void)
30 28
@@ -144,8 +142,6 @@ void irq_handler(void)
144 "subs pc, lr, #4 \n"); /* Return from IRQ */ 142 "subs pc, lr, #4 \n"); /* Return from IRQ */
145} 143}
146 144
147#endif /* !defined(BOOTLOADER) */
148
149 145
150/* TODO - these should live in the target-specific directories and 146/* TODO - these should live in the target-specific directories and
151 once we understand what all the GPIO pins do, move the init to the 147 once we understand what all the GPIO pins do, move the init to the
@@ -254,8 +250,6 @@ void system_init(void)
254 /* mask all interrupts */ 250 /* mask all interrupts */
255 IEN = 0; 251 IEN = 0;
256 252
257#if !defined(BOOTLOADER)
258
259 /* Set DAI interrupts as FIQ, all others are IRQ. */ 253 /* Set DAI interrupts as FIQ, all others are IRQ. */
260 IRQSEL = ~(DAI_RX_IRQ_MASK | DAI_TX_IRQ_MASK); 254 IRQSEL = ~(DAI_RX_IRQ_MASK | DAI_TX_IRQ_MASK);
261 255
@@ -272,8 +266,6 @@ void system_init(void)
272 } 266 }
273 267
274 ALLMASK = 3; /* Global FIQ/IRQ unmask */ 268 ALLMASK = 3; /* Global FIQ/IRQ unmask */
275
276#endif /* !defined(BOOTLOADER) */
277 269
278 gpio_init(); 270 gpio_init();
279 clock_init(); 271 clock_init();
diff --git a/firmware/target/arm/tcc780x/timer-tcc780x.c b/firmware/target/arm/tcc780x/timer-tcc780x.c
index ca6613a3ff..a6c8c1c060 100644
--- a/firmware/target/arm/tcc780x/timer-tcc780x.c
+++ b/firmware/target/arm/tcc780x/timer-tcc780x.c
@@ -81,26 +81,3 @@ void __timer_unregister(void)
81 81
82 restore_interrupt(oldstatus); 82 restore_interrupt(oldstatus);
83} 83}
84
85
86/* Timer interrupt processing - all timers (inc. tick) have a single IRQ */
87void TIMER0(void)
88{
89 if (TIREQ & TIREQ_TF0) /* Timer0 reached ref value */
90 {
91 /* Run through the list of tick tasks */
92 call_tick_tasks();
93
94 /* reset Timer 0 IRQ & ref flags */
95 TIREQ = TIREQ_TI0 | TIREQ_TF0;
96 }
97
98 if (TIREQ & TIREQ_TF4) /* Timer4 reached ref value */
99 {
100 /* dispatch user timer */
101 if (pfn_timer != NULL)
102 pfn_timer();
103
104 TIREQ = TIREQ_TI4 | TIREQ_TF4;
105 }
106}