1 |
27 |
unneback |
//=============================================================================
|
2 |
|
|
//
|
3 |
|
|
// hal_diag.c
|
4 |
|
|
//
|
5 |
|
|
// HAL diagnostic output code
|
6 |
|
|
//
|
7 |
|
|
//=============================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//=============================================================================
|
41 |
|
|
|
42 |
|
|
#include <pkgconf/hal.h>
|
43 |
|
|
|
44 |
|
|
#include <cyg/hal/hal_diag.h> // our header.
|
45 |
|
|
|
46 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
|
47 |
|
|
#include <cyg/hal/hal_stub.h> // hal_output_gdb_string
|
48 |
|
|
#endif
|
49 |
|
|
|
50 |
|
|
#include <cyg/infra/cyg_type.h> // base types, externC
|
51 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
52 |
|
|
#include <cyg/hal/hal_intr.h> // Interrupt macros
|
53 |
|
|
|
54 |
|
|
#include <cyg/hal/hal_arch.h>
|
55 |
|
|
|
56 |
|
|
#define CYG_KERNEL_DIAG_SERIAL
|
57 |
|
|
|
58 |
|
|
//-----------------------------------------------------------------------------
|
59 |
|
|
// Serial diag functions.
|
60 |
|
|
#ifdef CYG_KERNEL_DIAG_SERIAL
|
61 |
|
|
|
62 |
|
|
// Include the serial driver.
|
63 |
|
|
|
64 |
|
|
void hal_diag_init(void)
|
65 |
|
|
{
|
66 |
|
|
CYG_WORD16 clk_div;
|
67 |
|
|
|
68 |
|
|
/* We must first enable the UART output pins from the general-purpose */
|
69 |
|
|
/* I/O module. */
|
70 |
|
|
|
71 |
|
|
/* Enable the UART0 pins in the port B control register. */
|
72 |
|
|
|
73 |
|
|
MCF5272_SIM->gpio.pbcnt = ((MCF5272_SIM->gpio.pbcnt &
|
74 |
|
|
~(MCF5272_GPIO_PBCNT_URT0_MSK)) |
|
75 |
|
|
(MCF5272_GPIO_PBCNT_URT0_EN));
|
76 |
|
|
|
77 |
|
|
/* Before we do anything else, make sure we have enabled CTS (our */
|
78 |
|
|
/* RTS) in case the device we are using relies on hardware flow */
|
79 |
|
|
/* control. Note that this step is our only attempt at hardware flow */
|
80 |
|
|
/* control. */
|
81 |
|
|
|
82 |
|
|
MCF5272_SIM->uart[0].uop1 = 1;
|
83 |
|
|
|
84 |
|
|
/* Initialize UART0 */
|
85 |
|
|
|
86 |
|
|
/* Reset Transmitter */
|
87 |
|
|
MCF5272_SIM->uart[0].ucr = MCF5272_UART_UCR_RTX;
|
88 |
|
|
|
89 |
|
|
/* Reset Receiver */
|
90 |
|
|
MCF5272_SIM->uart[0].ucr = MCF5272_UART_UCR_RRX;
|
91 |
|
|
|
92 |
|
|
/* Reset Mode Register */
|
93 |
|
|
MCF5272_SIM->uart[0].ucr = MCF5272_UART_UCR_RMR;
|
94 |
|
|
|
95 |
|
|
MCF5272_SIM->uart[0].ucr = MCF5272_UART_UCR_RES;
|
96 |
|
|
MCF5272_SIM->uart[0].ucr = MCF5272_UART_UCR_RBC;
|
97 |
|
|
|
98 |
|
|
/* Mode register 1 sets the UART to 8 data bits with no parity, and */
|
99 |
|
|
/* mode register 2 forces 1 stop bit. Reading or write to the mode */
|
100 |
|
|
/* register switches it from umr1 to umr2. To set it to umr1, we must */
|
101 |
|
|
/* write a reset mode register command to the command register. */
|
102 |
|
|
|
103 |
|
|
MCF5272_SIM->uart[0].umr = MCF5272_UART_UMR_8BNP;
|
104 |
|
|
MCF5272_SIM->uart[0].umr = MCF5272_UART_UMR_1S;
|
105 |
|
|
|
106 |
|
|
/* Select a prescaled (by 1/32) CLKIN for the clock source. */
|
107 |
|
|
|
108 |
|
|
MCF5272_SIM->uart[0].usr_ucsr = MCF5272_UART_UCSR_CLKIN;
|
109 |
|
|
|
110 |
|
|
/* Calculate baud settings */
|
111 |
|
|
clk_div = (CYG_WORD16)
|
112 |
|
|
((CYGHWR_HAL_SYSTEM_CLOCK_MHZ*1000000)/
|
113 |
|
|
(CYGHWR_HAL_M68K_MCF52xx_MCF5272_MCF5272C3_DIAG_BAUD * 32));
|
114 |
|
|
MCF5272_SIM->uart[0].udu = clk_div >> 8;
|
115 |
|
|
MCF5272_SIM->uart[0].udl = clk_div & 0x00ff;
|
116 |
|
|
|
117 |
|
|
/* Enable the transmitter and receiver. */
|
118 |
|
|
MCF5272_SIM->uart[0].ucr = MCF5272_UART_UCR_TXRXEN;
|
119 |
|
|
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
void hal_diag_write_char(cyg_int8 ch)
|
123 |
|
|
{
|
124 |
|
|
|
125 |
|
|
/* Loop until the transmit data holding register is empty. */
|
126 |
|
|
while (!(MCF5272_SIM->uart[0].usr_ucsr & MCF5272_UART_USR_TXRDY));
|
127 |
|
|
|
128 |
|
|
/* Write the character to the transmit status register. */
|
129 |
|
|
MCF5272_SIM->uart[0].urb_utb = ch;
|
130 |
|
|
|
131 |
|
|
/* Loop until the transmit data FIFO and the shift register are */
|
132 |
|
|
/* empty. */
|
133 |
|
|
|
134 |
|
|
while ((MCF5272_SIM->uart[0].utf & MCF5272_UART_UTF_TXB) ||
|
135 |
|
|
(!(MCF5272_SIM->uart[0].usr_ucsr & MCF5272_UART_USR_TXEMP)));
|
136 |
|
|
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
cyg_int8 hal_diag_read_char(void)
|
140 |
|
|
{
|
141 |
|
|
|
142 |
|
|
return 0;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
#endif // ifdef CYG_KERNEL_DIAG_SERIAL
|
146 |
|
|
|
147 |
|
|
//-----------------------------------------------------------------------------
|
148 |
|
|
// End of hal_diag.c
|
149 |
|
|
|