diff options
Diffstat (limited to 'firmware/target')
17 files changed, 1165 insertions, 0 deletions
diff --git a/firmware/target/arm/at91sam/boot.lds b/firmware/target/arm/at91sam/boot.lds new file mode 100644 index 0000000000..c638511e47 --- /dev/null +++ b/firmware/target/arm/at91sam/boot.lds | |||
@@ -0,0 +1,81 @@ | |||
1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") | ||
2 | OUTPUT_ARCH(arm) | ||
3 | ENTRY(reset_handler) | ||
4 | STARTUP(target/arm/at91sam/lyre_proto1/crt0.o) | ||
5 | |||
6 | #define DRAMSIZE (MEMORYSIZE * 0x100000) | ||
7 | #define DRAMORIG 0x20000000 | ||
8 | #define IRAM0ORIG 0x200000 | ||
9 | #define IRAM0SIZE 4K | ||
10 | #define IRAM1ORIG 0x300000 | ||
11 | #define IRAM1SIZE 4K | ||
12 | #define STACKSIZE 2k | ||
13 | |||
14 | MEMORY | ||
15 | { | ||
16 | DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE | ||
17 | IRAM0 : ORIGIN = IRAM0ORIG, LENGTH = IRAM0SIZE | ||
18 | } | ||
19 | |||
20 | SECTIONS | ||
21 | { | ||
22 | /* We will put Rockbox bootloader at the last 1MByte of the SDRAM. */ | ||
23 | |||
24 | /* Example of a section: | ||
25 | * .section VMA(Virtual Memory Address) : LMA(Load Memory Address). | ||
26 | * VMA and LMA addresses can be verified by doing: | ||
27 | * "arm-elf-objdump -h bootloader.elf". */ | ||
28 | |||
29 | .vectors 0 : AT (DRAMORIG + DRAMSIZE - 1M) | ||
30 | { | ||
31 | _start_vectors_section = .; | ||
32 | *(.vectors) | ||
33 | *(.glue_7) | ||
34 | *(.glue_7t) | ||
35 | . = ALIGN(4); | ||
36 | _end_vectors_section = .; | ||
37 | } | ||
38 | |||
39 | .text (DRAMORIG + DRAMSIZE -1M + SIZEOF(.vectors)) : \ | ||
40 | AT (DRAMORIG + DRAMSIZE -1M + SIZEOF(.vectors)) | ||
41 | { | ||
42 | *(.text) | ||
43 | *(.text*) | ||
44 | *(.icode) | ||
45 | *(.icode*) | ||
46 | *(.rodata) | ||
47 | *(.rodata*) | ||
48 | . = ALIGN(4); | ||
49 | } | ||
50 | |||
51 | /* Initialized variables are placed on SDRAM, right after .vectors section. */ | ||
52 | /* Data section: VMA is the same as the LMA, right after the end of .vector */ | ||
53 | .data . : | ||
54 | { | ||
55 | *(.data) | ||
56 | *(.data*) | ||
57 | . = ALIGN(4); | ||
58 | _end_data_section = .; | ||
59 | } | ||
60 | |||
61 | /* Uninitialized variables are placed at SDRAM, right after .text section. */ | ||
62 | .bss (NOLOAD) : | ||
63 | |||
64 | { | ||
65 | _start_bss_section = .; | ||
66 | *(.bss) /* Bss section contains all uninitialized data generated by the compiler. */ | ||
67 | *(.bss*) | ||
68 | *(COMMON) | ||
69 | . = ALIGN(4); | ||
70 | _end_bss_section = .; | ||
71 | } | ||
72 | |||
73 | /* Stack is placed at SDRAM, right after .bss section. */ | ||
74 | .stack . : | ||
75 | { | ||
76 | *(.stack) | ||
77 | stackbegin = .; | ||
78 | . += STACKSIZE; | ||
79 | stackend = .; | ||
80 | } | ||
81 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/adc-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/adc-lyre_proto1.c new file mode 100644 index 0000000000..3734d6d1b1 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/adc-lyre_proto1.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | void adc_init(void) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | /* Called to get the recent ADC reading */ | ||
27 | inline unsigned short adc_read(int channel) | ||
28 | { | ||
29 | (void)channel; | ||
30 | return 0; | ||
31 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/adc-target.h b/firmware/target/arm/at91sam/lyre_proto1/adc-target.h new file mode 100644 index 0000000000..3712e476ea --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/adc-target.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _ADC_TARGET_H_ | ||
23 | #define _ADC_TARGET_H_ | ||
24 | |||
25 | void adc_init(void); | ||
26 | inline unsigned short adc_read(int channel); | ||
27 | |||
28 | #endif | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/backlight-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/backlight-lyre_proto1.c new file mode 100644 index 0000000000..fabf8aa041 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/backlight-lyre_proto1.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | void _backlight_set_brightness(int brightness) | ||
23 | { | ||
24 | (void)brightness; | ||
25 | } | ||
26 | |||
27 | void _backlight_on(void) | ||
28 | { | ||
29 | |||
30 | } | ||
31 | |||
32 | void _backlight_off(void) | ||
33 | { | ||
34 | |||
35 | } | ||
36 | |||
37 | void _buttonlight_on(void) | ||
38 | { | ||
39 | |||
40 | } | ||
41 | |||
42 | void _buttonlight_off(void) | ||
43 | { | ||
44 | |||
45 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/backlight-target.h b/firmware/target/arm/at91sam/lyre_proto1/backlight-target.h new file mode 100644 index 0000000000..f4e253abbe --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/backlight-target.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef BACKLIGHT_TARGET_H | ||
23 | #define BACKLIGHT_TARGET_H | ||
24 | |||
25 | |||
26 | #endif | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c new file mode 100644 index 0000000000..2d38803115 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/button-lyre_proto1.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "at91sam9260.h" | ||
23 | #include "button.h" | ||
24 | |||
25 | #define BUTTON_01 AT91C_PIO_PB4 | ||
26 | #define BUTTON_02 AT91C_PIO_PB5 | ||
27 | #define BUTTON_03 AT91C_PIO_PB27 | ||
28 | #define BUTTON_04 AT91C_PIO_PB26 | ||
29 | #define BUTTON_05 AT91C_PIO_PB25 | ||
30 | #define BUTTON_06 AT91C_PIO_PB24 | ||
31 | #define BUTTON_07 AT91C_PIO_PB22 | ||
32 | #define BUTTON_08 AT91C_PIO_PB23 | ||
33 | |||
34 | void button_init_device(void) | ||
35 | { | ||
36 | /* Enable the periph clock for the PIO controller */ | ||
37 | /* This is mandatory when PIO are configured as input */ | ||
38 | AT91C_PMC_PCER = (1 << AT91C_ID_PIOB); | ||
39 | |||
40 | /* Set the PIO line in input */ | ||
41 | AT91C_PIOB_ODR = (BUTTON_01 | | ||
42 | BUTTON_02 | | ||
43 | BUTTON_03 | | ||
44 | BUTTON_04 | | ||
45 | BUTTON_05 | | ||
46 | BUTTON_06 | | ||
47 | BUTTON_07 | | ||
48 | BUTTON_08); | ||
49 | |||
50 | /* Set the PIO controller in PIO mode instead of peripheral mode */ | ||
51 | AT91C_PIOB_PER = (BUTTON_01 | | ||
52 | BUTTON_02 | | ||
53 | BUTTON_03 | | ||
54 | BUTTON_04 | | ||
55 | BUTTON_05 | | ||
56 | BUTTON_06 | | ||
57 | BUTTON_07 | | ||
58 | BUTTON_08); | ||
59 | } | ||
60 | |||
61 | bool button_hold(void) | ||
62 | { | ||
63 | return (0); | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | * Get button pressed from hardware | ||
68 | */ | ||
69 | int button_read_device(void) | ||
70 | { | ||
71 | uint32_t buttons = AT91C_PIOB_PDSR; | ||
72 | uint32_t ret = 0; | ||
73 | |||
74 | if ((buttons & BUTTON_01) == 0) | ||
75 | ret |= BUTTON_UP; | ||
76 | |||
77 | if ((buttons & BUTTON_02) == 0) | ||
78 | ret |= BUTTON_RIGHT; | ||
79 | |||
80 | if ((buttons & BUTTON_03) == 0) | ||
81 | ret |= BUTTON_PLAY; | ||
82 | |||
83 | if ((buttons & BUTTON_04) == 0) | ||
84 | ret |= BUTTON_SELECT; | ||
85 | |||
86 | if ((buttons & BUTTON_05) == 0) | ||
87 | ret |= BUTTON_LEFT; | ||
88 | |||
89 | if ((buttons & BUTTON_06) == 0) | ||
90 | ret |= BUTTON_DOWN; | ||
91 | |||
92 | if ((buttons & BUTTON_07) == 0) | ||
93 | ret |= BUTTON_STOP; | ||
94 | |||
95 | if ((buttons & BUTTON_08) == 0) | ||
96 | ret |= BUTTON_MENU; | ||
97 | |||
98 | return ret; | ||
99 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/button-target.h b/firmware/target/arm/at91sam/lyre_proto1/button-target.h new file mode 100644 index 0000000000..e05f9f294f --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/button-target.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _BUTTON_TARGET_H_ | ||
23 | #define _BUTTON_TARGET_H_ | ||
24 | |||
25 | #include <stdbool.h> | ||
26 | #include "config.h" | ||
27 | |||
28 | #define BUTTON_SELECT 0x00000001 | ||
29 | #define BUTTON_MENU 0x00000002 | ||
30 | #define BUTTON_PLAY 0x00000004 | ||
31 | #define BUTTON_STOP 0x00000008 | ||
32 | |||
33 | #define BUTTON_LEFT 0x00000010 | ||
34 | #define BUTTON_RIGHT 0x00000020 | ||
35 | #define BUTTON_UP 0x00000040 | ||
36 | #define BUTTON_DOWN 0x00000080 | ||
37 | |||
38 | #define BUTTON_MAIN (BUTTON_UP|BUTTON_DOWN|BUTTON_RIGHT|BUTTON_LEFT \ | ||
39 | |BUTTON_SELECT|BUTTON_MENU|BUTTON_PLAY \ | ||
40 | |BUTTON_STOP) | ||
41 | bool button_hold(void); | ||
42 | void button_init_device(void); | ||
43 | int button_read_device(void); | ||
44 | |||
45 | /* No Remote control */ | ||
46 | #define BUTTON_REMOTE 0 | ||
47 | |||
48 | #endif /* _BUTTON_TARGET_H_ */ | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/crt0.S b/firmware/target/arm/at91sam/lyre_proto1/crt0.S new file mode 100644 index 0000000000..0146a8409c --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/crt0.S | |||
@@ -0,0 +1,274 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "at91sam9260.h" | ||
23 | |||
24 | #define DRAMORIG AT91C_EBI_SDRAM_32BIT | ||
25 | #define DRAMSIZE (MEMORYSIZE * 0x100000) | ||
26 | #define IRAM0ORIG AT91C_IRAM_1 | ||
27 | #define IRAM0SIZE AT91C_IRAM_1_SIZE | ||
28 | #define TOP_OF_MEMORY (IRAM0ORIG + IRAM0SIZE) | ||
29 | #define ABT_STACK_SIZE 8*3*4 | ||
30 | #define IRQ_STACK_SIZE 8*3*4 | ||
31 | |||
32 | #define ARM_MODE_ABT 0x17 | ||
33 | #define ARM_MODE_FIQ 0x11 | ||
34 | #define ARM_MODE_IRQ 0x12 | ||
35 | #define ARM_MODE_SVC 0x13 | ||
36 | |||
37 | #define I_BIT 0x80 | ||
38 | #define F_BIT 0x40 | ||
39 | |||
40 | |||
41 | /* Application startup entry point */ | ||
42 | .globl reset_handler | ||
43 | |||
44 | .align 4 | ||
45 | |||
46 | .section .vectors | ||
47 | .arm | ||
48 | |||
49 | |||
50 | /* Exception vectors (should be a branch to be detected as a valid code | ||
51 | * by the rom) */ | ||
52 | _exception_vectors: | ||
53 | reset_vector: | ||
54 | ldr pc, =reset_handler | ||
55 | undef_vector: | ||
56 | b undef_vector /* Undefined Instruction */ | ||
57 | swi_vector: | ||
58 | b swi_vector /* Software Interrupt */ | ||
59 | pabt_vector: | ||
60 | ldr pc, =pabt_handler /* Prefetch Abort */ | ||
61 | dabt_vector: | ||
62 | ldr pc, =dabt_handler /* Data Abort */ | ||
63 | rsvd_vector: | ||
64 | b rsvd_vector /* reserved */ | ||
65 | irq_vector: | ||
66 | b irq_handler /* IRQ : read the AIC */ | ||
67 | fiq_vector: | ||
68 | /*----------------------------------------------------------------------------- | ||
69 | *- Function : fiq_handler | ||
70 | *- Treatments : FIQ (Fast Interrupt) Interrupt Handler. | ||
71 | *- Called Functions : | ||
72 | *---------------------------------------------------------------------------*/ | ||
73 | fiq_handler: | ||
74 | pabt_handler: | ||
75 | dabt_handler: | ||
76 | b fiq_handler | ||
77 | |||
78 | /*----------------------------------------------------------------------------- | ||
79 | *- Function : irq_handler | ||
80 | *- Treatments : IRQ Controller Interrupt Handler. | ||
81 | *- Called Functions : AIC_IVR[interrupt] | ||
82 | *---------------------------------------------------------------------------*/ | ||
83 | irq_handler: | ||
84 | /*- Manage Exception Entry */ | ||
85 | /*- Adjust and save LR_irq in IRQ stack - (LR - Link Register) */ | ||
86 | sub lr, lr, #4 | ||
87 | stmfd sp!, {lr} | ||
88 | /*- Save r0 and SPSR (Saved Program Status Register) in IRQ stack */ | ||
89 | mrs r14, SPSR | ||
90 | stmfd sp!, {r0,r14} | ||
91 | |||
92 | /*- Write in the IVR (Interrupt Vector Register) to support Protect Mode */ | ||
93 | /*- No effect in Normal Mode */ | ||
94 | /*- De-assert the NIRQ and clear the source in Protect Mode */ | ||
95 | ldr r14, =AT91C_BASE_AIC | ||
96 | ldr r0 , [r14, #AIC_IVR] | ||
97 | str r14, [r14, #AIC_IVR] | ||
98 | |||
99 | /*- Enable Interrupt and Switch in Supervisor Mode */ | ||
100 | msr CPSR_c, #ARM_MODE_SVC | ||
101 | |||
102 | /*- Save scratch/used registers and LR in User Stack */ | ||
103 | stmfd sp!, {r1-r3, r12, r14} | ||
104 | |||
105 | /*- Branch to the routine pointed by the AIC_IVR */ | ||
106 | mov r14, pc | ||
107 | bx r0 | ||
108 | |||
109 | /*- Restore scratch/used registers and LR from User Stack */ | ||
110 | ldmia sp!, {r1-r3, r12, r14} | ||
111 | |||
112 | /*- Disable Interrupt and switch back in IRQ mode */ | ||
113 | msr CPSR_c, #ARM_MODE_IRQ | I_BIT | ||
114 | |||
115 | /*- Mark the End of Interrupt on the AIC */ | ||
116 | ldr r14, =AT91C_BASE_AIC | ||
117 | str r14, [r14, #AIC_EOICR] | ||
118 | |||
119 | /*- Restore SPSR_irq and r0 from IRQ stack */ | ||
120 | ldmia sp!, {r0,r14} | ||
121 | msr SPSR_cxsf, r14 | ||
122 | |||
123 | /*- Restore adjusted LR_irq from IRQ stack directly in the PC */ | ||
124 | ldmia sp!, {pc}^ | ||
125 | |||
126 | /*----------------------------------------------------------------------------- | ||
127 | *- Function : reset_handler | ||
128 | *- Treatments : Reset Interrupt Handler. | ||
129 | *- Called Functions : lowlevel_init | ||
130 | * main | ||
131 | *---------------------------------------------------------------------------*/ | ||
132 | .section .text | ||
133 | reset_handler: | ||
134 | /*----------------------------------------------------------------------------- | ||
135 | *- Low level Init is performed in a C function: lowlevel_init | ||
136 | *- Init Stack Pointer to a valid memory area before calling lowlevel_init | ||
137 | * | ||
138 | * Put Stack Pointer on end of IRAM 1 and branches to lowlevel_init function. | ||
139 | *---------------------------------------------------------------------------*/ | ||
140 | /*- Temporary stack in internal RAM for Low Level Init execution */ | ||
141 | _low_level_init: | ||
142 | ldr r2, =_litteral_pool_lowlevel_init /* Load r2 with the address of | ||
143 | * _litteral_pool_lowlevel_init | ||
144 | */ | ||
145 | ldmia r2, {r0, r1} /* r0 = lowlevel_init and r1 = TOP_OF_MEMORY */ | ||
146 | mov sp, r1 /* sp (Stack Pointer) = TOP_OF_MEMORY (end of IRAM 1) */ | ||
147 | mov lr, pc /* lr (Link register) = pc (Program Counter) */ | ||
148 | bx r0 /* Branch on C function (interworking) -- branch to | ||
149 | * lowlevel_init | ||
150 | */ | ||
151 | |||
152 | /*----------------------------------------------------------------------------- | ||
153 | *- Setup the stack for each mode | ||
154 | * | ||
155 | * Executes this code after returning from lowlevel_init fucntion. | ||
156 | * Configures Abort Mode Stack + Interrupt Mode Stack + Supervisor Mode Stack, | ||
157 | * reserves 3 blocks, one for each mode and they start at end of IRAM 1. | ||
158 | *---------------------------------------------------------------------------*/ | ||
159 | _stack_init: | ||
160 | ldr r2, =_litteral_pool_stack_init | ||
161 | ldmia r2, {r0, r1, r2} /* r0 = TOP_OF_MEMORY (end of IRAM 1); | ||
162 | * r1 = ABT_STACK_SIZE; | ||
163 | * r2 = IRQ_STACK_SIZE | ||
164 | */ | ||
165 | |||
166 | /*- Set up Abort Mode and set ABT Mode Stack */ | ||
167 | msr CPSR_c, #ARM_MODE_ABT | I_BIT | F_BIT /* Enter in Mode Abort | ||
168 | * and disable IRQ (Interrupt) and FIQ (Fast Interrupt) | ||
169 | */ | ||
170 | |||
171 | mov sp, r0 /* sp (ABT Mode Stack Pointer) = TOP_OF_MEMORY | ||
172 | * (end of IRAM 1) | ||
173 | */ | ||
174 | |||
175 | /* put r0 with value of the new address for next Stack */ | ||
176 | sub r0, r0, r1 /* r0 = r0 - r1 --> r0 = (end of IRAM 1) - | ||
177 | * (ABT_STACK_SIZE) | ||
178 | */ | ||
179 | |||
180 | /*- Set up Interrupt Mode and set IRQ Mode Stack */ | ||
181 | msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT /* Enter in Mode Interrupt | ||
182 | * and disable IRQ (Interrupt) and FIQ (Fast Interrupt) | ||
183 | */ | ||
184 | |||
185 | mov sp, r0 /* sp (Interrupt Mode Stack Pointer) = | ||
186 | * TOP_OF_MEMORY (end of IRAM 1) - (ABT_STACK_SIZE) | ||
187 | */ | ||
188 | |||
189 | sub r0, r0, r2 /* Put on r0 the new address for next | ||
190 | * Stack (Supervisor Mode) | ||
191 | */ | ||
192 | |||
193 | /*- Enable interrupt & Set up Supervisor Mode and set Supervisor Mode Stack */ | ||
194 | msr CPSR_c, #ARM_MODE_SVC | F_BIT | ||
195 | mov sp, r0 | ||
196 | |||
197 | /*----------------------------------------------------------------------------- | ||
198 | *- Segments initialization | ||
199 | *---------------------------------------------------------------------------*/ | ||
200 | /* Copy the vectors section code from the LMA address to the LVA address */ | ||
201 | _init_vectors: | ||
202 | ldr r1, =_litteral_pool_vectors /* Load r1 with the address of | ||
203 | * _litteral_pool_vectors | ||
204 | */ | ||
205 | ldmia r1, {r2, r3, r4} /* r2 = DRAMORIG; r3 = _start_vectors_section; | ||
206 | * r4 = _end_vectors_section; | ||
207 | */ | ||
208 | 1: | ||
209 | cmp r3, r4 /* Compare r3 with r4 (r3 - r4) */ | ||
210 | ldrcc r5, [r2], #4 /* if (_start_vectors_section < _end_vectors_section) | ||
211 | * { r5 = [r2]; r2 = r2 + 4; } | ||
212 | */ | ||
213 | strcc r5, [r3], #4 /* if (_start_vectors_section < _end_vectors_section) | ||
214 | * { [r3] = r5; r3 = r3 + 4; } | ||
215 | */ | ||
216 | bcc 1b /* loop while (_start_vectors_section < _end_vectors_section) */ | ||
217 | |||
218 | /* Clear the bss segment */ | ||
219 | _init_bss: | ||
220 | ldr r2, =_litteral_pool_bss | ||
221 | ldmia r2, {r3, r4} /* r3 = _start_bss_section; r4 = _end_bss_section */ | ||
222 | mov r2, #0 /* r2 = 0 */ | ||
223 | 1: | ||
224 | cmp r3, r4 /* Compare --> (_start_bss_section - _end_bss_section) */ | ||
225 | strcc r2, [r3], #4 /* if (_start_bss_section < _end_bss_section) { | ||
226 | * [r3] = 0; r3 = r3 + 4; } | ||
227 | */ | ||
228 | bcc 1b /* loop while _start_bss_section < _end_bss_section */ | ||
229 | |||
230 | /* Set up some stack and munge it with 0xdeadbeef */ | ||
231 | ldr sp, =stackend | ||
232 | mov r3, sp | ||
233 | ldr r2, =stackbegin | ||
234 | ldr r4, =0xdeadbeef | ||
235 | |||
236 | stackmunge: | ||
237 | cmp r3, r2 | ||
238 | strhi r4, [r2], #4 | ||
239 | bhi stackmunge | ||
240 | |||
241 | /*----------------------------------------------------------------------------- | ||
242 | *- Branch to the main | ||
243 | *---------------------------------------------------------------------------*/ | ||
244 | _branch_main: | ||
245 | ldr r0, =main | ||
246 | mov lr, pc | ||
247 | bx r0 | ||
248 | |||
249 | /*----------------------------------------------------------------------------- | ||
250 | *- Litteral pools | ||
251 | *---------------------------------------------------------------------------*/ | ||
252 | _litteral_pool_lowlevel_init: | ||
253 | .word lowlevel_init | ||
254 | .word TOP_OF_MEMORY /* Default SVC stack after power up */ | ||
255 | |||
256 | _litteral_pool_stack_init: | ||
257 | .word TOP_OF_MEMORY /* Top of the stack */ | ||
258 | .word ABT_STACK_SIZE /* ABT stack size */ | ||
259 | .word IRQ_STACK_SIZE /* IRQ stack size */ | ||
260 | |||
261 | _litteral_pool_bss: | ||
262 | .word _start_bss_section | ||
263 | .word _end_bss_section | ||
264 | |||
265 | _litteral_pool_vectors: | ||
266 | #if defined(BOOTLOADER) | ||
267 | .word (DRAMORIG + DRAMSIZE - 0x100000) /* LMA address of vectors are at | ||
268 | * end of DRAM minus 1MByte | ||
269 | */ | ||
270 | #else | ||
271 | .word DRAMORIG /* LMA address of vectors are at DRAMORIG */ | ||
272 | #endif | ||
273 | .word _start_vectors_section | ||
274 | .word _end_vectors_section | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/debug-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/debug-lyre_proto1.c new file mode 100644 index 0000000000..54a262a9ff --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/debug-lyre_proto1.c | |||
@@ -0,0 +1,34 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "at91sam9260.h" | ||
23 | #include <stdbool.h> | ||
24 | #include "debug-target.h" | ||
25 | |||
26 | bool __dbg_ports(void) | ||
27 | { | ||
28 | return false; | ||
29 | } | ||
30 | |||
31 | bool __dbg_hw_info(void) | ||
32 | { | ||
33 | return false; | ||
34 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/debug-target.h b/firmware/target/arm/at91sam/lyre_proto1/debug-target.h new file mode 100644 index 0000000000..140feafe67 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/debug-target.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdbool.h> | ||
23 | |||
24 | bool __dbg_ports(void); | ||
25 | bool __dbg_hw_info(void); | ||
26 | |||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/kernel-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/kernel-lyre_proto1.c new file mode 100644 index 0000000000..4d7167b3ba --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/kernel-lyre_proto1.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "system.h" | ||
24 | #include "kernel.h" | ||
25 | #include "timer.h" | ||
26 | #include "thread.h" | ||
27 | #include "at91sam9260.h" | ||
28 | |||
29 | /*----------------------------------------------------------------------------- | ||
30 | * Function Name : pitc_handler | ||
31 | * Object : Handler for PITC interrupt | ||
32 | *---------------------------------------------------------------------------*/ | ||
33 | void pitc_handler(void) | ||
34 | { | ||
35 | unsigned long pivr = 0; | ||
36 | unsigned long pisr = 0; | ||
37 | |||
38 | /* Read the PISR */ | ||
39 | pisr = AT91C_PITC_PISR & AT91C_PITC_PITS; | ||
40 | |||
41 | /* Read the PIVR. It acknowledges the IT */ | ||
42 | pivr = AT91C_PITC_PIVR; | ||
43 | |||
44 | /* Run through the list of tick tasks */ | ||
45 | call_tick_tasks(); | ||
46 | } | ||
47 | |||
48 | void tick_start(unsigned int interval_in_ms) | ||
49 | { | ||
50 | volatile unsigned long pimr = 0; | ||
51 | |||
52 | /* Configure a resolution of 1 ms */ | ||
53 | AT91C_PITC_PIMR = MCK_FREQ / (((16 * 1000) - 1) / interval_in_ms); | ||
54 | |||
55 | /* Enable interrupts */ | ||
56 | /* Disable the interrupt on the interrupt controller */ | ||
57 | AT91C_AIC_IDCR = (1 << AT91C_ID_SYS); | ||
58 | |||
59 | /* Save the interrupt handler routine pointer and the interrupt priority */ | ||
60 | AT91C_AIC_SVR(AT91C_ID_SYS) = (unsigned long) pitc_handler; | ||
61 | |||
62 | /* Store the Source Mode Register */ | ||
63 | AT91C_AIC_SMR(AT91C_ID_SYS) = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE | \ | ||
64 | AT91C_AIC_PRIOR_LOWEST; | ||
65 | /* Clear the interrupt on the interrupt controller */ | ||
66 | AT91C_AIC_ICCR = (1 << AT91C_ID_SYS); | ||
67 | |||
68 | /* Enable the interrupt on the interrupt controller */ | ||
69 | AT91C_AIC_IECR = (1 << AT91C_ID_SYS); | ||
70 | |||
71 | /* Enable the interrupt on the pit */ | ||
72 | pimr = AT91C_PITC_PIMR; | ||
73 | AT91C_PITC_PIMR = pimr | AT91C_PITC_PITIEN; | ||
74 | |||
75 | /* Enable the pit */ | ||
76 | pimr = AT91C_PITC_PIMR; | ||
77 | AT91C_PITC_PIMR = pimr | AT91C_PITC_PITEN; | ||
78 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/lcd-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/lcd-lyre_proto1.c new file mode 100644 index 0000000000..3ace8e791d --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/lcd-lyre_proto1.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | /* Update the display. | ||
23 | This must be called after all other LCD functions that change the display */ | ||
24 | void lcd_update(void) | ||
25 | { | ||
26 | |||
27 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/lcd-target.h b/firmware/target/arm/at91sam/lyre_proto1/lcd-target.h new file mode 100644 index 0000000000..5008bd861d --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/lcd-target.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | void lcd_update_rect(int x, int y, int width, int height); | ||
23 | |||
24 | |||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/system-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/system-lyre_proto1.c new file mode 100644 index 0000000000..e91ef7a918 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/system-lyre_proto1.c | |||
@@ -0,0 +1,150 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | /* Include Standard files */ | ||
23 | #include "at91sam9260.h" | ||
24 | #include "debug-target.h" | ||
25 | #include "config.h" | ||
26 | |||
27 | /*----------------------------------------------------------------------------- | ||
28 | * Function Name : default_spurious_handler | ||
29 | * Object : default handler for spurious interrupt | ||
30 | *---------------------------------------------------------------------------*/ | ||
31 | void default_spurious_handler(void) | ||
32 | { | ||
33 | while (1); | ||
34 | } | ||
35 | |||
36 | /*----------------------------------------------------------------------------- | ||
37 | * Function Name : default_fiq_handler | ||
38 | * Object : default handler for fast interrupt | ||
39 | *---------------------------------------------------------------------------*/ | ||
40 | void default_fiq_handler(void) | ||
41 | { | ||
42 | while (1); | ||
43 | } | ||
44 | |||
45 | /*----------------------------------------------------------------------------- | ||
46 | * Function Name : default_irq_handler | ||
47 | * Object : default handler for irq | ||
48 | *---------------------------------------------------------------------------*/ | ||
49 | void default_irq_handler(void) | ||
50 | { | ||
51 | #if defined(BOOTLOADER) | ||
52 | while (1); | ||
53 | #endif | ||
54 | } | ||
55 | |||
56 | /*----------------------------------------------------------------------------- | ||
57 | * Function Name : lowlevel_init | ||
58 | * Object : This function performs very low level HW initialization | ||
59 | * this function can use a Stack, depending the compilation | ||
60 | * optimization mode | ||
61 | *---------------------------------------------------------------------------*/ | ||
62 | void lowlevel_init(void) | ||
63 | { | ||
64 | unsigned char i = 0; | ||
65 | |||
66 | /* void default_fiq_handler(void) | ||
67 | * Init PMC Step 1. Enable Main Oscillator | ||
68 | * Main Oscillator startup time is board specific: | ||
69 | * Main Oscillator Startup Time worst case (3MHz) corresponds to 15ms | ||
70 | * (0x40 for AT91C_CKGR_OSCOUNT field) | ||
71 | */ | ||
72 | AT91C_PMC_MOR = (((AT91C_CKGR_OSCOUNT & (0x40 << 8)) | AT91C_CKGR_MOSCEN)); | ||
73 | /* Wait Main Oscillator stabilization */ | ||
74 | while (!(AT91C_PMC_SR & AT91C_PMC_MOSCS)); | ||
75 | |||
76 | /* Init PMC Step 2. | ||
77 | * Set PLLA to 198,608MHz | ||
78 | * PLL Startup time depends on PLL RC filter: worst case is choosen. | ||
79 | * | ||
80 | * Crystal frequency = 18.432MHz; PLLA = (18.432 * 96) / 9 = 198,608MHz. | ||
81 | */ | ||
82 | |||
83 | AT91C_PMC_PLLAR = (1 << 29) | | ||
84 | (0x60 << 16) | /* MULA = 96 */ | ||
85 | (0x2 << 14) | | ||
86 | (0x3f << 8) | | ||
87 | (0x09); /* DIVA = 9 */ | ||
88 | |||
89 | /* Wait for PLLA stabilization */ | ||
90 | while (!(AT91C_PMC_SR & AT91C_PMC_LOCKA)); | ||
91 | /* Wait until the master clock is established for the case we already */ | ||
92 | /* turn on the PLLA */ | ||
93 | while (!(AT91C_PMC_SR & AT91C_PMC_MCKRDY)); | ||
94 | |||
95 | /* Init PMC Step 3. | ||
96 | * Processor Clock = 198,608MHz (PLLA); Master clock = | ||
97 | * (198,608MHz (PLLA))/2 = 98,304MHz. | ||
98 | * The PMC_MCKR register must not be programmed in a single write operation | ||
99 | * (see. Product Errata Sheet) | ||
100 | */ | ||
101 | AT91C_PMC_MCKR = AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2; | ||
102 | /* Wait until the master clock is established */ | ||
103 | while (!(AT91C_PMC_SR & AT91C_PMC_MCKRDY)); | ||
104 | |||
105 | AT91C_PMC_MCKR |= AT91C_PMC_CSS_PLLA_CLK; | ||
106 | /* Wait until the master clock is established */ | ||
107 | while (!(AT91C_PMC_SR & AT91C_PMC_MCKRDY)); | ||
108 | |||
109 | /* Reset AIC: assign default handler for each interrupt source | ||
110 | */ | ||
111 | |||
112 | /* Disable the interrupt on the interrupt controller */ | ||
113 | AT91C_AIC_IDCR = (1 << AT91C_ID_SYS); | ||
114 | |||
115 | /* Assign default handler for each IRQ source */ | ||
116 | AT91C_AIC_SVR(AT91C_ID_FIQ) = (int) default_fiq_handler; | ||
117 | for (i = 1; i < 31; i++) | ||
118 | { | ||
119 | AT91C_AIC_SVR(i) = (int) default_irq_handler; | ||
120 | } | ||
121 | AT91C_AIC_SPU = (unsigned int) default_spurious_handler; | ||
122 | |||
123 | /* Perform 8 IT acknoledge (write any value in EOICR) */ | ||
124 | |||
125 | /* The End of Interrupt Command Register (AIC_EOICR) must be written in order | ||
126 | to indicate to the AIC that the current interrupt is finished. This causes the | ||
127 | current level to be popped from the stack, restoring the previous current level | ||
128 | if one exists on the stack. If another interrupt is pending, with lower or | ||
129 | equal priority than the old current level but with higher priority than the new | ||
130 | current level, the nIRQ line is re-asserted, but the interrupt sequence does | ||
131 | not immediately start because the āIā bit is set in the core. | ||
132 | SPSR_irq is restored. Finally, the saved value of the link register is restored | ||
133 | directly into the PC. This has the effect of returning from the interrupt to | ||
134 | whatever was being executed before, and of loading the CPSR with the stored | ||
135 | SPSR, masking or unmasking the interrupts depending on the state saved in | ||
136 | SPSR_irq. */ | ||
137 | for (i = 0; i < 8 ; i++) | ||
138 | { | ||
139 | AT91C_AIC_EOICR = 0; | ||
140 | } | ||
141 | |||
142 | /* Enable the interrupt on the interrupt controller */ | ||
143 | AT91C_AIC_IECR = (1 << AT91C_ID_SYS); | ||
144 | |||
145 | /* Disable Watchdog */ | ||
146 | AT91C_WDTC_WDMR = AT91C_WDTC_WDDIS; | ||
147 | |||
148 | /* Remap */ | ||
149 | AT91C_MATRIX_MRCR = AT91C_MATRIX_RCA926I | AT91C_MATRIX_RCA926D; | ||
150 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/system-target.h b/firmware/target/arm/at91sam/lyre_proto1/system-target.h new file mode 100644 index 0000000000..479614f634 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/system-target.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef SYSTEM_TARGET_H | ||
23 | #define SYSTEM_TARGET_H | ||
24 | |||
25 | #include "system-arm.h" | ||
26 | |||
27 | void system_init(void); | ||
28 | |||
29 | #endif /* SYSTEM_TARGET_H */ | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/timer-lyre_proto1.c b/firmware/target/arm/at91sam/lyre_proto1/timer-lyre_proto1.c new file mode 100644 index 0000000000..5924438d10 --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/timer-lyre_proto1.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "timer.h" | ||
26 | #include "logf.h" | ||
27 | #include "at91sam9260.h" | ||
28 | |||
29 | /*----------------------------------------------------------------------------- | ||
30 | * Function Name : pitc_handler | ||
31 | * Object : Handler for PITC interrupt | ||
32 | *---------------------------------------------------------------------------*/ | ||
33 | void pitc_handler(void) | ||
34 | { | ||
35 | unsigned long pivr = 0; | ||
36 | unsigned long pisr = 0; | ||
37 | |||
38 | /* Read the PISR */ | ||
39 | pisr = AT91C_PITC_PISR & AT91C_PITC_PITS; | ||
40 | |||
41 | if (pisr != 0) | ||
42 | { | ||
43 | /* Read the PIVR. It acknowledges the IT */ | ||
44 | pivr = AT91C_PITC_PIVR; | ||
45 | |||
46 | if (pfn_timer != NULL) | ||
47 | pfn_timer(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | bool __timer_set(long cycles, bool start) | ||
52 | { | ||
53 | if (cycles < 1000) /* Max value on PITC?? */ | ||
54 | { | ||
55 | if (start && pfn_unregister != NULL) | ||
56 | { | ||
57 | pfn_unregister(); | ||
58 | pfn_unregister = NULL; | ||
59 | } | ||
60 | |||
61 | /* Configure a resolution of <cycles> ms */ | ||
62 | AT91C_PITC_PIMR = MCK_FREQ / ( 16 * cycles) - 1; | ||
63 | |||
64 | return true; | ||
65 | } | ||
66 | |||
67 | return false; | ||
68 | } | ||
69 | |||
70 | bool __timer_register(void) | ||
71 | { | ||
72 | bool retval = true; | ||
73 | volatile unsigned long pimr = 0; | ||
74 | |||
75 | /* Configure a resolution of 1 ms */ | ||
76 | AT91C_PITC_PIMR = MCK_FREQ / (16 * 1000) - 1; | ||
77 | |||
78 | /* Enable interrupts */ | ||
79 | /* Disable the interrupt on the interrupt controller */ | ||
80 | AT91C_AIC_IDCR = (1 << AT91C_ID_SYS); | ||
81 | |||
82 | /* Save the interrupt handler routine pointer and the interrupt priority */ | ||
83 | AT91C_AIC_SVR(AT91C_ID_SYS) = (unsigned long) pitc_handler; | ||
84 | /* Store the Source Mode Register */ | ||
85 | AT91C_AIC_SMR(AT91C_ID_SYS) = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE | \ | ||
86 | AT91C_AIC_PRIOR_LOWEST; | ||
87 | /* Clear the interrupt on the interrupt controller */ | ||
88 | AT91C_AIC_ICCR = (1 << AT91C_ID_SYS); | ||
89 | |||
90 | /* Enable the interrupt on the interrupt controller */ | ||
91 | AT91C_AIC_IECR = (1 << AT91C_ID_SYS); | ||
92 | |||
93 | /* Enable the interrupt on the pit */ | ||
94 | pimr = AT91C_PITC_PIMR; | ||
95 | AT91C_PITC_PIMR = pimr | AT91C_PITC_PITIEN; | ||
96 | |||
97 | /* Enable the pit */ | ||
98 | pimr = AT91C_PITC_PIMR; | ||
99 | AT91C_PITC_PIMR = pimr | AT91C_PITC_PITEN; | ||
100 | |||
101 | return retval; | ||
102 | } | ||
103 | |||
104 | void __timer_unregister(void) | ||
105 | { | ||
106 | volatile unsigned long pimr = 0; | ||
107 | |||
108 | /* Disable the interrupt on the interrupt controller */ | ||
109 | AT91C_AIC_IDCR = (1 << AT91C_ID_SYS); | ||
110 | |||
111 | /* Clear the interrupt on the interrupt controller */ | ||
112 | AT91C_AIC_ICCR = (1 << AT91C_ID_SYS); | ||
113 | |||
114 | /* Disable the interrupt on the pit */ | ||
115 | pimr = AT91C_PITC_PIMR; | ||
116 | pimr &= ~AT91C_PITC_PITIEN; | ||
117 | AT91C_PITC_PIMR = pimr; | ||
118 | |||
119 | /* Disable the pit */ | ||
120 | pimr = AT91C_PITC_PIMR; | ||
121 | pimr &= ~AT91C_PITC_PITEN; | ||
122 | AT91C_PITC_PIMR = pimr; | ||
123 | } | ||
diff --git a/firmware/target/arm/at91sam/lyre_proto1/timer-target.h b/firmware/target/arm/at91sam/lyre_proto1/timer-target.h new file mode 100644 index 0000000000..d16577b0de --- /dev/null +++ b/firmware/target/arm/at91sam/lyre_proto1/timer-target.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jorge Pinto | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef TIMER_TARGET_H | ||
23 | #define TIMER_TARGET_H | ||
24 | |||
25 | /* timer is based on PCLK and minimum division is 2 */ | ||
26 | #define TIMER_FREQ (49156800/2) | ||
27 | |||
28 | bool __timer_set(long cycles, bool set); | ||
29 | bool __timer_register(void); | ||
30 | void __timer_unregister(void); | ||
31 | |||
32 | #define __TIMER_SET(cycles, set) \ | ||
33 | __timer_set(cycles, set) | ||
34 | |||
35 | #define __TIMER_REGISTER(reg_prio, unregister_callback, cycles, \ | ||
36 | int_prio, timer_callback) \ | ||
37 | __timer_register() | ||
38 | |||
39 | #define __TIMER_UNREGISTER(...) \ | ||
40 | __timer_unregister() | ||
41 | |||
42 | #endif /* TIMER_TARGET_H */ | ||