blob: e5762083fca29445adab217759890b1c46bbf39a [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <stdarg.h>
24#include <reg.h>
25#include <debug.h>
26#include <printf.h>
27#include <kernel/thread.h>
28#include <platform/debug.h>
29#include <arch/ops.h>
30#include <platform/omap5912.h>
31
32static void write_uart_reg(int uart, int reg, unsigned char data)
33{
34 unsigned long base;
35 int mul = 4;
36
37 switch(uart) {
38 case 0: base = UART0_BASE; break;
39 case 1: base = UART1_BASE; break;
40 case 2: base = UART2_BASE; break;
41 default: return;
42 }
43
44 *(volatile unsigned char *)(base + reg * mul) = data;
45}
46
47static unsigned char read_uart_reg(int uart, int reg)
48{
49 unsigned long base;
50 int mul = 4;
51
52 switch(uart) {
53 case 0: base = UART0_BASE; break;
54 case 1: base = UART1_BASE; break;
55 case 2: base = UART2_BASE; break;
56 default: return 0;
57 }
58
59 return *(volatile unsigned char *)(base + reg * mul);
60}
61
62static int uart_init(void)
63{
64 /* clear the tx & rx fifo and disable */
65 write_uart_reg(0, UART_FCR, 0x6);
66
67 return 0;
68}
69
70static int uart_putc(int port, char c )
71{
72 while (!(read_uart_reg(port, UART_LSR) & (1<<6))) // wait for the shift register to empty
73 ;
74 write_uart_reg(port, UART_THR, c);
75 return 0;
76}
77
78static int uart_getc(int port, bool wait) /* returns -1 if no data available */
79{
80 if (wait) {
81 while (!(read_uart_reg(port, UART_LSR) & (1<<0))) // wait for data to show up in the rx fifo
82 ;
83 } else {
84 if (!(read_uart_reg(port, UART_LSR) & (1<<0)))
85 return -1;
86 }
87 return read_uart_reg(port, UART_RHR);
88}
89
Travis Geiselbrechteb946052008-09-07 22:32:49 -070090void _dputc(char c)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070091{
92 if (c == '\n')
93 uart_putc(0, '\r');
94 uart_putc(0, c);
95}
96
Travis Geiselbrecht28da92a2009-06-28 11:12:40 -070097int dgetc(char *c, bool wait)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070098{
99 int _c;
100
Travis Geiselbrecht28da92a2009-06-28 11:12:40 -0700101 while ((_c = uart_getc(0, false)) < 0) {
102 if (!wait) {
103 return -1;
104 }
105 }
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700106
107 *c = _c;
108 return 0;
109}
110
111void debug_dump_regs(void)
112{
113 PANIC_UNIMPLEMENTED;
114}
115
Travis Geiselbrechteb946052008-09-07 22:32:49 -0700116void platform_halt(void)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700117{
Travis Geiselbrechteb946052008-09-07 22:32:49 -0700118 dprintf(ALWAYS, "HALT: spinning forever...\n");
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700119 for(;;);
120}
121
122void debug_dump_memory_bytes(void *mem, int len)
123{
124 PANIC_UNIMPLEMENTED;
125}
126
127void debug_dump_memory_halfwords(void *mem, int len)
128{
129 PANIC_UNIMPLEMENTED;
130}
131
132void debug_dump_memory_words(void *mem, int len)
133{
134 PANIC_UNIMPLEMENTED;
135}
136
137void debug_set_trace_level(int trace_type, int level)
138{
139 PANIC_UNIMPLEMENTED;
140}
141
142uint32_t debug_cycle_count(void)
143{
144// PANIC_UNIMPLEMENTED;
145 return 0;
146}