1 |
786 |
skrzyp |
/*=============================================================================
|
2 |
|
|
//
|
3 |
|
|
// hal_diag_dcc.c
|
4 |
|
|
//
|
5 |
|
|
// HAL diagnostic output via the DCC interface.
|
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, 2008 Free Software Foundation, 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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//=============================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Andrew Lunn
|
43 |
|
|
// Contributors:jskov, gthomas
|
44 |
|
|
// Date: 2008-06-15
|
45 |
|
|
// Purpose: HAL diagnostic output via DCC.
|
46 |
|
|
// Description: Implementations of HAL diagnostic output support.
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//===========================================================================*/
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/hal.h>
|
53 |
|
|
#include CYGBLD_HAL_PLATFORM_H
|
54 |
|
|
|
55 |
|
|
#include <cyg/infra/cyg_type.h> // base types
|
56 |
|
|
|
57 |
|
|
#include <cyg/hal/hal_arch.h> // SAVE/RESTORE GP macros
|
58 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
59 |
|
|
#include <cyg/hal/hal_if.h> // interface API
|
60 |
|
|
#include <cyg/hal/hal_intr.h> // HAL_ENABLE/MASK/UNMASK_INTERRUPTS
|
61 |
|
|
#include <cyg/hal/hal_misc.h> // Helper functions
|
62 |
|
|
#include <cyg/hal/hal_diag.h>
|
63 |
|
|
|
64 |
|
|
#define DCC_TX_BUSY 2
|
65 |
|
|
#define DCC_RX_READY 1
|
66 |
|
|
|
67 |
|
|
//-----------------------------------------------------------------------------
|
68 |
|
|
|
69 |
|
|
static void
|
70 |
|
|
cyg_hal_plf_dcc_putc(void * __ch_data, char ch)
|
71 |
|
|
{
|
72 |
|
|
unsigned int status;
|
73 |
|
|
CYG_UNUSED_PARAM(void *, __ch_data);
|
74 |
|
|
|
75 |
|
|
CYGARC_HAL_SAVE_GP();
|
76 |
|
|
|
77 |
|
|
do {
|
78 |
|
|
__asm__ volatile ( "mrc p14,0, %0, c0, c0\n" : "=r" (status));
|
79 |
|
|
} while ( status & DCC_TX_BUSY );
|
80 |
|
|
__asm__( "mcr p14,0, %0, c1, c0\n" : : "r" (ch));
|
81 |
|
|
|
82 |
|
|
CYGARC_HAL_RESTORE_GP();
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
static cyg_bool
|
86 |
|
|
cyg_hal_plf_dcc_getc_nonblock(cyg_uint8* ch)
|
87 |
|
|
{
|
88 |
|
|
cyg_uint32 status;
|
89 |
|
|
cyg_uint32 c;
|
90 |
|
|
|
91 |
|
|
__asm__( "mrc p14,0, %0, c0, c0\n" : "=r" (status));
|
92 |
|
|
|
93 |
|
|
if (status & DCC_RX_READY) {
|
94 |
|
|
__asm__( "mrc p14,0, %0, c1, c0\n" : "=r" (c));
|
95 |
|
|
*ch = (char )c;
|
96 |
|
|
return true;
|
97 |
|
|
} else
|
98 |
|
|
return false;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
static cyg_uint8
|
102 |
|
|
cyg_hal_plf_dcc_getc(void* __ch_data)
|
103 |
|
|
{
|
104 |
|
|
cyg_uint8 ch;
|
105 |
|
|
CYG_UNUSED_PARAM(void *, __ch_data);
|
106 |
|
|
CYGARC_HAL_SAVE_GP();
|
107 |
|
|
|
108 |
|
|
while(!cyg_hal_plf_dcc_getc_nonblock(&ch));
|
109 |
|
|
|
110 |
|
|
CYGARC_HAL_RESTORE_GP();
|
111 |
|
|
return ch;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
static void
|
115 |
|
|
cyg_hal_plf_dcc_write(void* __ch_data, const cyg_uint8* __buf,
|
116 |
|
|
cyg_uint32 __len)
|
117 |
|
|
{
|
118 |
|
|
CYG_UNUSED_PARAM(void *, __ch_data);
|
119 |
|
|
CYGARC_HAL_SAVE_GP();
|
120 |
|
|
|
121 |
|
|
while(__len-- > 0)
|
122 |
|
|
cyg_hal_plf_dcc_putc(NULL, *__buf++);
|
123 |
|
|
|
124 |
|
|
CYGARC_HAL_RESTORE_GP();
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
static void
|
128 |
|
|
cyg_hal_plf_dcc_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
|
129 |
|
|
{
|
130 |
|
|
CYG_UNUSED_PARAM(void *, __ch_data);
|
131 |
|
|
CYGARC_HAL_SAVE_GP();
|
132 |
|
|
|
133 |
|
|
while(__len-- > 0)
|
134 |
|
|
*__buf++ = cyg_hal_plf_dcc_getc(NULL);
|
135 |
|
|
|
136 |
|
|
CYGARC_HAL_RESTORE_GP();
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
static cyg_bool
|
140 |
|
|
cyg_hal_plf_dcc_getc_timeout(void* __ch_data, cyg_uint8* ch)
|
141 |
|
|
{
|
142 |
|
|
int delay_count;
|
143 |
|
|
cyg_bool res;
|
144 |
|
|
CYG_UNUSED_PARAM(void *, __ch_data);
|
145 |
|
|
|
146 |
|
|
CYGARC_HAL_SAVE_GP();
|
147 |
|
|
|
148 |
|
|
delay_count = 100010; // delay in .1 ms steps
|
149 |
|
|
|
150 |
|
|
for(;;) {
|
151 |
|
|
res = cyg_hal_plf_dcc_getc_nonblock(ch);
|
152 |
|
|
if (res || 0 == delay_count--)
|
153 |
|
|
break;
|
154 |
|
|
|
155 |
|
|
CYGACC_CALL_IF_DELAY_US(100);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
CYGARC_HAL_RESTORE_GP();
|
159 |
|
|
return res;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
static int
|
163 |
|
|
cyg_hal_plf_dcc_control(void *__ch_data, __comm_control_cmd_t __func, ...)
|
164 |
|
|
{
|
165 |
|
|
CYG_UNUSED_PARAM(void *, __ch_data);
|
166 |
|
|
CYG_UNUSED_PARAM(__comm_control_cmd_t, __func);
|
167 |
|
|
|
168 |
|
|
return 0;
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
static void
|
172 |
|
|
cyg_hal_plf_dcc_register(const int channel)
|
173 |
|
|
{
|
174 |
|
|
hal_virtual_comm_table_t* comm;
|
175 |
|
|
int cur;
|
176 |
|
|
|
177 |
|
|
cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
178 |
|
|
// Setup procs in the vector table
|
179 |
|
|
|
180 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(channel);
|
181 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
182 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, NULL);
|
183 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_dcc_write);
|
184 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_dcc_read);
|
185 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_dcc_putc);
|
186 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_dcc_getc);
|
187 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_dcc_control);
|
188 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, NULL);
|
189 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_dcc_getc_timeout);
|
190 |
|
|
|
191 |
|
|
// Restore to original console.
|
192 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
void
|
196 |
|
|
cyg_hal_plf_dcc_init(const int channel)
|
197 |
|
|
{
|
198 |
|
|
static int initialized = 0;
|
199 |
|
|
|
200 |
|
|
if (initialized)
|
201 |
|
|
return;
|
202 |
|
|
|
203 |
|
|
initialized = 1;
|
204 |
|
|
|
205 |
|
|
cyg_hal_plf_dcc_register(channel);
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
//-----------------------------------------------------------------------------
|
209 |
|
|
// End of hal_diag_dcc.c
|