1 /*=============================================================================
5 // HAL diagnostic output via the DCC interface.
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 // Copyright (C) 2008 FSF
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //=============================================================================
42 //#####DESCRIPTIONBEGIN####
44 // Author(s): Andrew Lunn
45 // Contributors:jskov, gthomas
47 // Purpose: HAL diagnostic output via DCC.
48 // Description: Implementations of HAL diagnostic output support.
50 //####DESCRIPTIONEND####
52 //===========================================================================*/
54 #include <pkgconf/hal.h>
55 #include CYGBLD_HAL_PLATFORM_H
57 #include <cyg/infra/cyg_type.h> // base types
59 #include <cyg/hal/hal_arch.h> // SAVE/RESTORE GP macros
60 #include <cyg/hal/hal_io.h> // IO macros
61 #include <cyg/hal/hal_if.h> // interface API
62 #include <cyg/hal/hal_intr.h> // HAL_ENABLE/MASK/UNMASK_INTERRUPTS
63 #include <cyg/hal/hal_misc.h> // Helper functions
64 #include <cyg/hal/hal_diag.h>
67 #define DCC_RX_READY 1
69 //-----------------------------------------------------------------------------
72 cyg_hal_plf_dcc_putc(void * __ch_data, char ch)
75 CYG_UNUSED_PARAM(void *, __ch_data);
80 __asm__ volatile ( "mrc p14,0, %0, c0, c0\n" : "=r" (status));
81 } while ( status & DCC_TX_BUSY );
82 __asm__( "mcr p14,0, %0, c1, c0\n" : : "r" (ch));
84 CYGARC_HAL_RESTORE_GP();
88 cyg_hal_plf_dcc_getc_nonblock(cyg_uint8* ch)
93 __asm__( "mrc p14,0, %0, c0, c0\n" : "=r" (status));
95 if (status & DCC_RX_READY) {
96 __asm__( "mrc p14,0, %0, c1, c0\n" : "=r" (c));
104 cyg_hal_plf_dcc_getc(void* __ch_data)
107 CYG_UNUSED_PARAM(void *, __ch_data);
108 CYGARC_HAL_SAVE_GP();
110 while(!cyg_hal_plf_dcc_getc_nonblock(&ch));
112 CYGARC_HAL_RESTORE_GP();
117 cyg_hal_plf_dcc_write(void* __ch_data, const cyg_uint8* __buf,
120 CYG_UNUSED_PARAM(void *, __ch_data);
121 CYGARC_HAL_SAVE_GP();
124 cyg_hal_plf_dcc_putc(NULL, *__buf++);
126 CYGARC_HAL_RESTORE_GP();
130 cyg_hal_plf_dcc_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
132 CYG_UNUSED_PARAM(void *, __ch_data);
133 CYGARC_HAL_SAVE_GP();
136 *__buf++ = cyg_hal_plf_dcc_getc(NULL);
138 CYGARC_HAL_RESTORE_GP();
142 cyg_hal_plf_dcc_getc_timeout(void* __ch_data, cyg_uint8* ch)
146 CYG_UNUSED_PARAM(void *, __ch_data);
148 CYGARC_HAL_SAVE_GP();
150 delay_count = 100010; // delay in .1 ms steps
153 res = cyg_hal_plf_dcc_getc_nonblock(ch);
154 if (res || 0 == delay_count--)
157 CYGACC_CALL_IF_DELAY_US(100);
160 CYGARC_HAL_RESTORE_GP();
165 cyg_hal_plf_dcc_control(void *__ch_data, __comm_control_cmd_t __func, ...)
167 CYG_UNUSED_PARAM(void *, __ch_data);
168 CYG_UNUSED_PARAM(__comm_control_cmd_t, __func);
174 cyg_hal_plf_dcc_register(const int channel)
176 hal_virtual_comm_table_t* comm;
179 cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
180 // Setup procs in the vector table
182 CYGACC_CALL_IF_SET_CONSOLE_COMM(channel);
183 comm = CYGACC_CALL_IF_CONSOLE_PROCS();
184 CYGACC_COMM_IF_CH_DATA_SET(*comm, NULL);
185 CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_dcc_write);
186 CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_dcc_read);
187 CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_dcc_putc);
188 CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_dcc_getc);
189 CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_dcc_control);
190 CYGACC_COMM_IF_DBG_ISR_SET(*comm, NULL);
191 CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_dcc_getc_timeout);
193 // Restore to original console.
194 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
198 cyg_hal_plf_dcc_init(const int channel)
200 static int initialized = 0;
207 cyg_hal_plf_dcc_register(channel);
210 //-----------------------------------------------------------------------------
211 // End of hal_diag_dcc.c