comparison target-utils/libcommon/uartsel.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 2942c5ef76ed
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * uart_select_init() figures out which UART was used to load us
3 * through the boot ROM, and sets things up for us to use the same
4 * UART for our communication.
5 */
6
7 #include "types.h"
8 #include "romvars.h"
9 #include "ns16550.h"
10 #include "halt.h"
11
12 extern struct ns16550_regs *uart_base;
13
14 static u16 rom_version;
15 static struct boot_rom_vars *rom_vars;
16 static char *uart_name;
17
18 uart_select_init()
19 {
20 rom_version = *(u16 *)0x1FFE;
21
22 switch (rom_version) {
23 case 0x0200:
24 rom_vars = (struct boot_rom_vars *) 0x800504;
25 break;
26 case 0x0300:
27 rom_vars = (struct boot_rom_vars *) 0x800518;
28 break;
29 default:
30 _exit(HALTCODE_BOOTROMVER);
31 }
32
33 switch (rom_vars->uart_id) {
34 case 0:
35 uart_base = (struct ns16550_regs *) 0xFFFF5800;
36 uart_name = "MODEM";
37 break;
38 case 1:
39 uart_base = (struct ns16550_regs *) 0xFFFF5000;
40 uart_name = "IrDA";
41 break;
42 default:
43 _exit(HALTCODE_INVALIDUART);
44 }
45 }
46
47 print_boot_rom_info()
48 {
49 printf("Loaded via boot ROM v%04X, UART %d (%s) at baud rate #%d\n",
50 rom_version, rom_vars->uart_id, uart_name,
51 rom_vars->baud_rate_code);
52 printf("CLKTCXO input autodetected to be %d MHz\n",
53 rom_vars->clktcxo_13mhz ? 13 : 26);
54 }