FreeCalypso > hg > freecalypso-sw
annotate target-utils/libcommon/uartsel.c @ 1023:cd6002e3aefb
doc/Freerunner-Howto: apparently some people still use SHR, so mention it too
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Tue, 03 May 2016 13:48:39 +0000 |
parents | a7b0b426f9ca |
children |
rev | line source |
---|---|
11
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * uart_select_init() figures out which UART was used to load us |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * through the boot ROM, and sets things up for us to use the same |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * UART for our communication. |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 */ |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include "types.h" |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include "romvars.h" |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "ns16550.h" |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "halt.h" |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 |
992
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
12 extern struct ns16550_regs *uart_base; |
11
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
992
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
14 static u16 rom_version; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
15 static struct boot_rom_vars *rom_vars; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
16 static char *uart_name; |
11
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 uart_select_init() |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
992
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
20 rom_version = *(u16 *)0x1FFE; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
21 |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
22 switch (rom_version) { |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
23 case 0x0200: |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
24 rom_vars = (struct boot_rom_vars *) 0x800504; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
25 break; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
26 case 0x0300: |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
27 rom_vars = (struct boot_rom_vars *) 0x800518; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
28 break; |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
29 default: |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
30 _exit(HALTCODE_BOOTROMVER); |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
31 } |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
32 |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
33 switch (rom_vars->uart_id) { |
11
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 case 0: |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 uart_base = (struct ns16550_regs *) 0xFFFF5800; |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 uart_name = "MODEM"; |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 break; |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 case 1: |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 uart_base = (struct ns16550_regs *) 0xFFFF5000; |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 uart_name = "IrDA"; |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 break; |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 default: |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 _exit(HALTCODE_INVALIDUART); |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
40f607bb0a2c
target-utils refactored
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 } |
992
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
46 |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
47 print_boot_rom_info() |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
48 { |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
49 printf("Loaded via boot ROM v%04X, UART %d (%s) at baud rate #%d\n", |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
50 rom_version, rom_vars->uart_id, uart_name, |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
51 rom_vars->baud_rate_code); |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
52 printf("CLKTCXO input autodetected to be %d MHz\n", |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
53 rom_vars->clktcxo_13mhz ? 13 : 26); |
a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
11
diff
changeset
|
54 } |