blob: 3afb39ceda2056a141d6d1a05045339604a4b739 [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>
Travis Geiselbrecht2ce7b972009-06-28 12:33:13 -070028#include <kernel/timer.h>
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070029#include <platform/debug.h>
30#include <arch/ops.h>
31#include <platform/omap5912.h>
Travis Geiselbrecht2ce7b972009-06-28 12:33:13 -070032#include <lib/cbuf.h>
33
34static cbuf_t debug_buf;
35static timer_t debug_timer;
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070036
37static void write_uart_reg(int uart, int reg, unsigned char data)
38{
39 unsigned long base;
40 int mul = 4;
41
42 switch(uart) {
43 case 0: base = UART0_BASE; break;
44 case 1: base = UART1_BASE; break;
45 case 2: base = UART2_BASE; break;
46 default: return;
47 }
48
49 *(volatile unsigned char *)(base + reg * mul) = data;
50}
51
52static unsigned char read_uart_reg(int uart, int reg)
53{
54 unsigned long base;
55 int mul = 4;
56
57 switch(uart) {
58 case 0: base = UART0_BASE; break;
59 case 1: base = UART1_BASE; break;
60 case 2: base = UART2_BASE; break;
61 default: return 0;
62 }
63
64 return *(volatile unsigned char *)(base + reg * mul);
65}
66
67static int uart_init(void)
68{
69 /* clear the tx & rx fifo and disable */
70 write_uart_reg(0, UART_FCR, 0x6);
71
72 return 0;
73}
74
75static int uart_putc(int port, char c )
76{
77 while (!(read_uart_reg(port, UART_LSR) & (1<<6))) // wait for the shift register to empty
78 ;
79 write_uart_reg(port, UART_THR, c);
80 return 0;
81}
82
83static int uart_getc(int port, bool wait) /* returns -1 if no data available */
84{
85 if (wait) {
86 while (!(read_uart_reg(port, UART_LSR) & (1<<0))) // wait for data to show up in the rx fifo
87 ;
88 } else {
89 if (!(read_uart_reg(port, UART_LSR) & (1<<0)))
90 return -1;
91 }
92 return read_uart_reg(port, UART_RHR);
93}
94
Travis Geiselbrechteb946052008-09-07 22:32:49 -070095void _dputc(char c)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070096{
97 if (c == '\n')
98 uart_putc(0, '\r');
99 uart_putc(0, c);
100}
101
Travis Geiselbrecht2ce7b972009-06-28 12:33:13 -0700102static enum handler_return debug_timer_callback(timer_t *t, time_t now, void *arg)
103{
104 signed char c;
105 c = uart_getc(0, false);
106 if (c > 0) {
107 cbuf_write(&debug_buf, &c, 1, false);
108 return INT_RESCHEDULE;
109 } else {
110 return INT_NO_RESCHEDULE;
111 }
112}
113
Travis Geiselbrecht28da92a2009-06-28 11:12:40 -0700114int dgetc(char *c, bool wait)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700115{
Travis Geiselbrecht2ce7b972009-06-28 12:33:13 -0700116 ssize_t len;
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700117
Travis Geiselbrecht2ce7b972009-06-28 12:33:13 -0700118 len = cbuf_read(&debug_buf, c, 1, wait);
119 return len;
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700120}
121
122void debug_dump_regs(void)
123{
124 PANIC_UNIMPLEMENTED;
125}
126
Travis Geiselbrechteb946052008-09-07 22:32:49 -0700127void platform_halt(void)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700128{
Travis Geiselbrechteb946052008-09-07 22:32:49 -0700129 dprintf(ALWAYS, "HALT: spinning forever...\n");
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700130 for(;;);
131}
132
133void debug_dump_memory_bytes(void *mem, int len)
134{
135 PANIC_UNIMPLEMENTED;
136}
137
138void debug_dump_memory_halfwords(void *mem, int len)
139{
140 PANIC_UNIMPLEMENTED;
141}
142
143void debug_dump_memory_words(void *mem, int len)
144{
145 PANIC_UNIMPLEMENTED;
146}
147
148void debug_set_trace_level(int trace_type, int level)
149{
150 PANIC_UNIMPLEMENTED;
151}
152
Travis Geiselbrecht2ce7b972009-06-28 12:33:13 -0700153void platform_init_debug(void)
154{
155 cbuf_initialize(&debug_buf, 512);
156 timer_set_periodic(&debug_timer, 10, &debug_timer_callback, NULL);
157}