annotate frbl/reconst/boot.c @ 315:bc3391aa3d35

frbl/reconst/boot.c: import from TI's FLUID package with defenestrated line endings
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 04 Mar 2020 23:17:27 +0000
parents
children 2ceb1f263e19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
315
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /******************************************************************************
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * FLUID (Flash Loader Utility Independent of Device)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * (C) Delta Technologies 2001.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Cleanup, modifications and extensions by Mads Meisner-Jensen, mmj@ti.com.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * Target Bootloader
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * $Id: boot.c 1.18 Mon, 28 Apr 2003 08:49:16 +0200 tsj $
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 *
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 ******************************************************************************/
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "chipset.cfg"
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "target.h"
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #define DEBUG_TRACE 0
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 // Protocol version of this bootloader
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 // Version 0: Original, unmodified Delta Technology Bootloader.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 // Version 1: First Fluid Bootloader. 'B'audrate command and 'V'ersion
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 // command. Backward compatibly with version 0.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 // Version 2: 'H'ardware chipset query command. Debug/Trace
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 // functionality. Backward compatibly with version 0, 1. Fixed bug where
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 // IND$CALL was used to start command interpreter instead of private jump()
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 // function
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 // Version 3: Generic 'Q'uery command. Discontinued 'H'ardware query command
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 // from version 2.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #define BOOTLOADER_VERSION '3'
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /******************************************************************************
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * Bootstrap/Init
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 ******************************************************************************/
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 // Initialize stackpointer according to chipset. Note that we ALWAYS do
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 // this, no matter if we were laoded with JTAG or if we were compiled-in.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 #if (CHIPSET == 3)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 asm("STACK_INIT .equ 03000000h");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 asm("STACK_ADD .equ 00020000h ; 128kB");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 #elif (CHIPSET == 7)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 asm("STACK_INIT .equ 00800000h");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 asm("STACK_ADD .equ 00020000h ; 128kB");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 #elif (CHIPSET == 12)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 asm("STACK_INIT .equ 08000000h");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 asm("STACK_ADD .equ 00020000h ; 128kB");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 #else
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 #error Unknown target hardware selected
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 #ifdef FLUID_BOOT_STAND_ALONE
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 asm(" .def _c_int00 ");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 asm("_c_int00:");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 asm(" .state32 ");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 asm(" mov sp,#STACK_INIT");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 asm(" add sp,sp,#STACK_ADD");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 asm(" adr lr,start_end + 1 ; module end address with lsb set");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 asm(" bx lr ; branch to start");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 asm(" nop");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 asm("start_end:");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 /******************************************************************************
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 * Main
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 ******************************************************************************/
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 uint32 uart;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 void jump(uint32, uint32);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 void putchar(uint8 ch);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 uint8 getchar(void);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 void uart_init(UBYTE dlh, UBYTE dll);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 void hardware_init(uint16 *code);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 void fluid_bootloader(void)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 uint8 ch;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 uint16 *mem;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 union32_t addr;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 union16_t size;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 union16_t data;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 uint8 uart_dlh, uart_dll;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 uint16 chip_id_code;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 hardware_init(&chip_id_code);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 uart = UART_MODEM;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 uart_init(0, 0x07); // baudrate = 115200kbps
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 uart = UART_IRDA;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 uart_init(0, 0x07); // baudrate = 115200kbps
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 #ifdef TESTBOOT
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 while (1) {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 uart = UART_MODEM;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if ((REGISTER_8_READ(uart + UART_LSR) & STAT_RXRDY))
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 uart = UART_IRDA;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if ((REGISTER_8_READ(uart + UART_LSR) & STAT_RXRDY))
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 while (getchar() != 0xAA)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 ;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 while (getchar() != 0x01)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 ;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 while (getchar() != 0xDD)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 ;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 while (1) {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 uart = UART_MODEM;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 putchar(PROTO_HELLO);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if ((REGISTER_8_READ(uart + UART_LSR) & STAT_RXRDY))
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 uart = UART_IRDA;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 putchar(PROTO_HELLO);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 if ((REGISTER_8_READ(uart + UART_LSR) & STAT_RXRDY))
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 while (1) {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 ch = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 switch (ch) {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 case PROTO_VERSION:
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 putchar(BOOTLOADER_VERSION);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 case PROTO_QUERY:
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 ch = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (ch == PROTO_QUERY_CHIP) {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 data.i = chip_id_code;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 putchar(data.b[0]);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 putchar(data.b[1]);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 putchar(0);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 putchar(0);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 else {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 putchar(PROTO_ERROR);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 case PROTO_BAUDRATE:
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 ch = getchar(); // Get DLH
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 case 0:
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 uart_init(ch, getchar());
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 case PROTO_DOWNLOAD:
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 addr.b[0] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 addr.b[1] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 addr.b[2] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 addr.b[3] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 size.b[0] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 size.b[1] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 putchar(PROTO_READY);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 mem = (uint16 *) addr.i;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 while (size.i--) {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 // Data bytes arrive in reverse order due to little endian mode
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 data.b[1] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 data.b[0] = getchar();
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 *mem++ = data.i;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 #if DEBUG_TRACE
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 // Insert convenient tracing here...
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 // Start the program we loaded.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 jump(uart, addr.i);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 break;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 default:
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 putchar(PROTO_ERROR);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 // Little assembly function that makes a jump to the address/argument,
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 // similar to the compiler's IND$CALL. We do not use the compiler's IND$CALL
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 // because when we compile for non-standalone, IND$CALL is already
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 // defined. We expect that the base address of the UART is in R0, so it can
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 // be properly passed on to the command interpreter.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 asm("$jump:");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 asm(" bx r1");
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 void putchar(uint8 ch)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 PUTCHAR_FUNCTION_CODE(uart)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 uint8 getchar(void)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 GETCHAR_FUNCTION_CODE(uart)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 /******************************************************************************
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 * Initialization
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 ******************************************************************************/
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 #if (CHIPSET == 3)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 #define IQ_MASK (0xFFFFFA02) /* Mask Interrupt Register */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 #elif (CHIPSET == 7) || (CHIPSET == 12)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 #define IQ_MASK1 (0xFFFFFA08) /* Mask Interrupt Register 1 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 #define IQ_MASK2 (0xFFFFFA0A) /* Mask Interrupt Register 2 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 #else
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 #error Unknown target hardware selected
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 void hardware_init(uint16 *chip_id_code)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 uint16 clk;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 char chip_set = 0;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 // We read the chipset version directly from the hardware because
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 // otherwise the stand-alone bootloader (to be downloaded with JTAG) is
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 // obviously not target independent!
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 *chip_id_code = *((volatile uint16 *) CHIP_ID_CODE);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 // We should only intialize the hardware if we were downloaded with JTAG
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 #ifdef FLUID_BOOT_STAND_ALONE
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 // FIXME: we should perhaps have different init depending on chipset
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 // detected?
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 // Mask all interrupts
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 #if (CHIPSET == 3)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 *((volatile uint16 *) IQ_MASK) = 0xFFFF;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 #elif (CHIPSET == 7)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 *((volatile uint16 *) IQ_MASK1) = 0xFFFF;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 *((volatile uint16 *) IQ_MASK2) = 0x001F;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 #elif (CHIPSET == 12)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 *((volatile uint16 *) IQ_MASK1) = 0xFFFF;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 *((volatile uint16 *) IQ_MASK2) = 0xFFFF; //BJO Check IRQ_29_MSK - should it be 0 ?
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 // Disable watchdog timer
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 *((volatile uint16 *) WATCHDOG_TIM_MODE) = 0xF5;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 *((volatile uint16 *) WATCHDOG_TIM_MODE) = 0xA0;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 #if (CHIPSET == 12) //BJO Check this (documented?)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 *((volatile uint16 *) WATCHDOG_TIM_MODE+80) = 0xF5; // Secure watchdog CALPLUS
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 *((volatile uint16 *) WATCHDOG_TIM_MODE+80) = 0xA0; // Secure watchdog CALPLUS
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 #if (CHIPSET == 3) || (CHIPSET == 7)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 // FIXME: Describe exactly how the CSs are initialized
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 *((volatile uint16 *) CS0_MEM_REG) = 0x2A1;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 *((volatile uint16 *) CS1_MEM_REG) = 0x2A1;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 *((volatile uint16 *) CS2_MEM_REG) = 0x2A1;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 *((volatile uint16 *) CS3_MEM_REG) = 0x283;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 *((volatile uint16 *) CS4_MEM_REG) = 0x283;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 *((volatile uint16 *) CS6_MEM_REG) = 0x2C0;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 #elif (CHIPSET == 12)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 *((volatile uint16 *) CS0_MEM_REG) = 0x2A3; //*BJO Check these settings
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 *((volatile uint16 *) CS1_MEM_REG) = 0x2A3;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 *((volatile uint16 *) CS2_MEM_REG) = 0x2A3;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 *((volatile uint16 *) CS3_MEM_REG) = 0x2A3;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 *((volatile uint16 *) CS4_MEM_REG) = 0x2A3;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 *((volatile uint16 *) CS5_MEM_REG) = 0x2A3;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 #if (CHIPSET == 3)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 clk = *(volatile uint16 *) CLKM_CNTL_ARM_CLK;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 clk &= ~(0x0C | 0x30);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 clk |= (2 << 4);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 *(volatile uint16 *) CLKM_CNTL_ARM_CLK = clk;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 #elif (CHIPSET == 7)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 // Reset DPLL register
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 * (volatile uint16 *) MEM_DPLL_ADDR = DPLL_RESET_VALUE;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 // Wait that DPLL is in BYPASS mode
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 while (((* (volatile uint16 *) MEM_DPLL_ADDR) & 1) != 1)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 ;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 // Reset CLKM register
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 *(volatile uint16 *) MEM_CLKM_ADDR = CLKM_CNTL_ARM_CLK_RST;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 #elif (CHIPSET == 12)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 *((volatile uint8*)CTNL_CLK) = 0x91; // Make sure we are set to 26MHz mode (div 2) // CALPLUS
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 *((volatile uint16 *) MEM_DPLL_ADDR) = 0x6012 | (8<<7) | (1<<5); // multiplyer=8, divider=2 (-1) 52MHz!!! // CALPLUS
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 // Wait that DPLL is locked
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 while (((* (volatile unsigned short *) MEM_DPLL_ADDR) & 1) != 1) ; // CALPLUS
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 #endif // ifdef FLUID_BOOT_STAND_ALONE
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 void uart_init(uint8 my_dlh, uint8 my_dll)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 {
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 uint8 ch;
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 * Transition from the DSP Rhea bus to the MCU Rhea bus.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 BIT_SET (UART_UIR, UART_MASK_IT);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 BIT_CLR (UART_UIR, UART_ACCESS);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 BIT_CLR (UART_UIR, UART_MASK_IT);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 * Set the UART in reset mode.
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 REGISTER_8_WRITE(uart + UART_MDR1, CMD_UART_RESET);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 * FIFO configuration
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 REGISTER_8_WRITE(uart + UART_LCR, CMD_EFR_EN);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 BIT_SET (uart + UART_EFR, ENHANCED_EN);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 REGISTER_8_WRITE(uart + UART_LCR, CMD_FCR_MCR_EN);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 REGISTER_8_WRITE(uart + UART_FCR, CMD_FIFO_EN);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 * Speed configuration
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 REGISTER_8_WRITE(uart + UART_LCR, CMD_EFR_EN);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 REGISTER_8_WRITE(uart + UART_DLL, my_dll);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 REGISTER_8_WRITE(uart + UART_DLH, my_dlh);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 * Character format configuration
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 REGISTER_8_WRITE(uart + UART_LCR, CMD_CHAR8_STOP1_NOPAR);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 * Modem configuration
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 REGISTER_8_WRITE(uart + UART_MDR1, CMD_UART_MODE);
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 /*
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 * Flush Rx buffer
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 */
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 while ((REGISTER_8_READ(uart + UART_LSR) & STAT_RXRDY))
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 ch = (REGISTER_8_READ(uart + UART_RHR));
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 }
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 /******************************************************************************
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 * Debug
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 ******************************************************************************/
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 #if (DEBUG_TRACE == 1)
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 #include "debug.c"
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 #endif
bc3391aa3d35 frbl/reconst/boot.c: import from TI's FLUID package
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357