annotate packages/hal/coldfire/mcf5272/current/src/hal_diag.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents a62600d0e7b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
1 //==========================================================================
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
2 //
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
3 // hal_diag.c
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
4 //
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
5 // HAL diagnostic I/O support routines for the MCF5272
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
6 //
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
16 // version.
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
21 // for more details.
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
33 // General Public License v2.
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2201
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
2201
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
39 //==========================================================================
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
41 //
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
42 // Author(s): Enrico Piria
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
43 // Contributors:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
44 // Date: 2005-25-06
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
45 // Purpose: Code to manage the serial ports for diagnostic output.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
46 // Description:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
47 //
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
48 //####DESCRIPTIONEND####
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
49 //==========================================================================
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
50
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
51
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
52 #include <pkgconf/hal.h>
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
53 #include <cyg/infra/cyg_type.h>
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
54 #include <cyg/hal/hal_intr.h> // CYGNUM_HAL_INTERRUPT_UART1
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
55 #include <cyg/hal/hal_if.h> // __comm_control_cmd_t
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
56 #include <cyg/hal/hal_io.h> // HAL I/O macros
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
57 #include <cyg/hal/hal_misc.h> // cyg_hal_is_break
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
58 #include <cyg/hal/drv_api.h> // CYG_ISR_HANDLED
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
59
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
60 #include <cyg/hal/plf_serial.h>
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
61
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
62
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
63 typedef struct {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
64 CYG_ADDRWORD base; // [Pointer] to Port base address
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
65 unsigned int vector; // UART interrupt vector
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
66 CYG_WORD msec_timeout; // Timeout in msec
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
67 } channel_data_t;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
68
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
69 static channel_data_t ports[] = {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
70 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
71 (CYG_ADDRWORD) (&((mcf5272_devs_t *) 0)->uart[0]),
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
72 CYGNUM_HAL_INTERRUPT_UART1,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
73 1000
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
74 },
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
75
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
76 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
77 (CYG_ADDRWORD) (&((mcf5272_devs_t *) 0)->uart[1]),
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
78 CYGNUM_HAL_INTERRUPT_UART2,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
79 1000
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
80 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
81 };
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
82
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
83
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
84 static cyg_uint8
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
85 cyg_hal_plf_serial_getc(void* __ch_data);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
86
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
87 static void
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
88 cyg_hal_plf_serial_putc(void* __ch_data, cyg_uint8 ch);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
89
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
90 static void
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
91 cyg_hal_plf_serial_init_channel(channel_data_t *port);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
92
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
93 static cyg_bool
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
94 cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
95
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
96 static cyg_bool
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
97 cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
98
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
99 static void
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
100 cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
101 cyg_uint32 __len);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
102 static void
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
103 cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
104
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
105 static int
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
106 cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
107 CYG_ADDRWORD __vector, CYG_ADDRWORD __data);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
108 static int
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
109 cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
110
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
111
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
112 // ----------------------------------------------------------------------------
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
113 // Early initialization of comm. channels.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
114 void
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
115 cyg_hal_plf_comms_init(void)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
116 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
117 hal_virtual_comm_table_t* comm;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
118 int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
119 cyg_uint32 portcnt;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
120 static int initialized = 0;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
121
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
122 if (initialized)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
123 return;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
124 initialized = 1;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
125
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
126 #if (defined(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL) && \
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
127 CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL == 0) || \
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
128 (defined(CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL) && \
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
129 CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 0)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
130
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
131 // UART0 pins are multplexed with GPIO port B. Enable them in
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
132 // port B control register.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
133 HAL_READ_UINT32(&MCF5272_DEVS->gpio.pbcnt, portcnt);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
134 HAL_WRITE_UINT32(&MCF5272_DEVS->gpio.pbcnt, ((portcnt &
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
135 ~(MCF5272_GPIO_PBCNT_URT0_MSK)) |
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
136 (MCF5272_GPIO_PBCNT_URT0_EN)));
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
137
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
138 // Init channel 0
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
139 cyg_hal_plf_serial_init_channel(&ports[0]);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
140
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
141 // Setup procs in the vector table for channel 0
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
142 CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
143 comm = CYGACC_CALL_IF_CONSOLE_PROCS();
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
144 CYGACC_COMM_IF_CH_DATA_SET(*comm, &ports[0]);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
145 CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
146 CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
147 CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
148 CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
149 CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
150 CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
151 CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
152 #endif
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
153
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
154 #if (defined(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL) && \
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
155 CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL == 1) || \
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
156 (defined(CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL) && \
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
157 CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 1)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
158
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
159 // UART1 pins need to be enabled in port D control register.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
160 HAL_READ_UINT32(&MCF5272_DEVS->gpio.pdcnt, portcnt);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
161 HAL_WRITE_UINT32(&MCF5272_DEVS->gpio.pdcnt, ((portcnt &
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
162 ~(MCF5272_GPIO_PDCNT_URT1_MSK)) |
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
163 (MCF5272_GPIO_PDCNT_URT1_EN)));
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
164
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
165 // Init channel 1
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
166 cyg_hal_plf_serial_init_channel(&ports[1]);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
167
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
168 // Setup procs in the vector table for channel 0
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
169 CYGACC_CALL_IF_SET_CONSOLE_COMM(1);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
170 comm = CYGACC_CALL_IF_CONSOLE_PROCS();
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
171 CYGACC_COMM_IF_CH_DATA_SET(*comm, &ports[1]);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
172 CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
173 CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
174 CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
175 CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
176 CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
177 CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
178 CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
179 #endif
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
180
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
181 // Restore original console
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
182 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
183 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
184
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
185
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
186 void cyg_hal_plf_serial_init_channel(channel_data_t *port)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
187 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
188 CYG_WORD16 clk_div;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
189 volatile mcf5272_uart_t *base =
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
190 (volatile mcf5272_uart_t *)((char *)MCF5272_DEVS + port->base);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
191 // Initialize variable to prevent compiler warnings
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
192 unsigned int baud_rate = 1200;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
193
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
194
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
195 #ifdef CYGPRI_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_CONFIGURABLE
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
196 if( (port-&ports[0]) == CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL )
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
197 baud_rate = CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_BAUD;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
198 #endif
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
199 #ifdef CYGPRI_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_CONFIGURABLE
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
200 if( (port-&ports[0]) == CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL )
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
201 baud_rate = CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
202 #endif
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
203
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
204 // Before we do anything else, make sure we have enabled RTS in case
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
205 // the device we are using relies on hardware flow control.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
206 // Note that this step is our only attempt at hardware flow control.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
207 HAL_WRITE_UINT8(&base->uop1, MCF5272_UART_UOP1_RTS);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
208
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
209 // Initialize UART
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
210
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
211 // Reset Transmitter
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
212 HAL_WRITE_UINT8(&base->ucr, MCF5272_UART_UCR_RTX);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
213
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
214 // Reset Receiver
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
215 HAL_WRITE_UINT8(&base->ucr, MCF5272_UART_UCR_RRX);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
216
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
217 // Reset Mode Register
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
218 HAL_WRITE_UINT8(&base->ucr, MCF5272_UART_UCR_RMR);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
219
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
220 HAL_WRITE_UINT8(&base->ucr, MCF5272_UART_UCR_RES);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
221 HAL_WRITE_UINT8(&base->ucr, MCF5272_UART_UCR_RBC);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
222
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
223 // Mode register 1 sets the UART to 8 data bits with no parity, and
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
224 // mode register 2 forces 1 stop bit. Also, interrupt generation
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
225 // on RxRDY signal is enabled by default.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
226 // Reading or write to the mode register switches it from umr1 to umr2.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
227 // To set it to umr1, we must write a reset mode register command to the
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
228 // command register.
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
229 HAL_WRITE_UINT8(&base->umr, MCF5272_UART_UMR_8BNP);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
230 HAL_WRITE_UINT8(&base->umr, MCF5272_UART_UMR_1S);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
231
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
232 // Select a prescaled (by 1/16) CLKIN for the clock source
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
233 HAL_WRITE_UINT8(&base->usr_ucsr, MCF5272_UART_UCSR_CLKIN);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
234
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
235 // Calculate baud settings
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
236 clk_div = (CYG_WORD16)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
237 ((CYGHWR_HAL_SYSTEM_CLOCK_MHZ*1000000)/
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
238 (baud_rate * 32));
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
239 HAL_WRITE_UINT8(&base->udu, clk_div >> 8);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
240 HAL_WRITE_UINT8(&base->udl, clk_div & 0x00ff);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
241
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
242 // Enable the transmitter and receiver
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
243 HAL_WRITE_UINT8(&base->ucr, MCF5272_UART_UCR_TXRXEN);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
244
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
245 // Set interrupt priority to highest maskable level
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
246 HAL_INTERRUPT_SET_LEVEL(port->vector, 6);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
247 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
248
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
249
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
250 cyg_uint8 cyg_hal_plf_serial_getc(void* __ch_data)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
251 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
252 cyg_uint8 ch;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
253
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
254
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
255 while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
256
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
257 return ch;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
258 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
259
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
260
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
261 void cyg_hal_plf_serial_putc(void *__ch_data, cyg_uint8 ch)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
262 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
263 channel_data_t *port = (channel_data_t *) __ch_data;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
264 volatile mcf5272_uart_t *base =
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
265 (volatile mcf5272_uart_t *)((char *)MCF5272_DEVS + port->base);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
266 cyg_uint8 usr_ucsr, utf;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
267
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
268
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
269 // Loop until the transmit data holding register is empty
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
270 do
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
271 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
272 HAL_READ_UINT8(&base->usr_ucsr, usr_ucsr);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
273 } while (!(usr_ucsr & MCF5272_UART_USR_TXRDY));
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
274
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
275 // Write the character to the transmit buffer
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
276 HAL_WRITE_UINT8(&base->urb_utb, ch);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
277
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
278 // Loop until the transmit data FIFO and the shift register are empty
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
279 do
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
280 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
281 HAL_READ_UINT8(&base->utf, utf);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
282 HAL_READ_UINT8(&base->usr_ucsr, usr_ucsr);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
283 } while ((utf & MCF5272_UART_UTF_TXB) ||
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
284 (!(usr_ucsr & MCF5272_UART_USR_TXEMP)));
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
285 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
286
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
287 static void cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
288 cyg_uint32 __len)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
289 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
290 while(__len-- > 0)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
291 cyg_hal_plf_serial_putc(__ch_data, *__buf++);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
292 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
293
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
294
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
295 static void cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
296 cyg_uint32 __len)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
297 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
298 while(__len-- > 0)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
299 *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
300 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
301
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
302
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
303 static cyg_bool cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
304 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
305 channel_data_t *port = (channel_data_t *) __ch_data;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
306 volatile mcf5272_uart_t *base =
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
307 (volatile mcf5272_uart_t *)((char *)MCF5272_DEVS + port->base);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
308 cyg_uint8 usr_ucsr;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
309
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
310
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
311 // Read status
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
312 HAL_READ_UINT8(&base->usr_ucsr, usr_ucsr);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
313
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
314 // Check if a character is present
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
315 if (usr_ucsr & MCF5272_UART_USR_RRDY)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
316 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
317 // Read character
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
318 HAL_READ_UINT8(&base->urb_utb, *ch);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
319 return true;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
320 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
321
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
322 return false;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
323 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
324
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
325
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
326 static cyg_bool cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
327 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
328 int delay_count;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
329 cyg_bool res;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
330
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
331
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
332 delay_count = ((channel_data_t *)__ch_data)->msec_timeout;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
333
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
334 for(;;) {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
335 res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
336 if (res || 0 == delay_count--)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
337 break;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
338
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
339 CYGACC_CALL_IF_DELAY_US(100);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
340 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
341
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
342 return res;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
343 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
344
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
345
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
346 static int cyg_hal_plf_serial_control(void *__ch_data,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
347 __comm_control_cmd_t __func, ...)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
348 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
349 static int irq_state = 0;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
350 channel_data_t *port = (channel_data_t *) __ch_data;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
351 volatile mcf5272_uart_t *base =
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
352 (volatile mcf5272_uart_t *)((char *)MCF5272_DEVS + port->base);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
353 int ret = 0;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
354
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
355
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
356 switch (__func) {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
357 case __COMMCTL_IRQ_ENABLE:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
358 irq_state = 1;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
359
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
360 HAL_WRITE_UINT8(&base->uisr_uimr, MCF5272_UART_UIMR_FFULL);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
361 HAL_INTERRUPT_UNMASK(port->vector);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
362 break;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
363 case __COMMCTL_IRQ_DISABLE:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
364 ret = irq_state;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
365 irq_state = 0;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
366
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
367 HAL_INTERRUPT_MASK(port->vector);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
368 HAL_WRITE_UINT8(&base->uisr_uimr, 0);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
369 break;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
370 case __COMMCTL_DBG_ISR_VECTOR:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
371 ret = port->vector;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
372 break;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
373 case __COMMCTL_SET_TIMEOUT:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
374 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
375 va_list ap;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
376
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
377 va_start(ap, __func);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
378
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
379 ret = port->msec_timeout;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
380 port->msec_timeout = va_arg(ap, cyg_uint32);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
381
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
382 va_end(ap);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
383 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
384 default:
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
385 break;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
386 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
387
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
388 return ret;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
389 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
390
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
391
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
392 static int cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
393 CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
394 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
395 channel_data_t *port = (channel_data_t *) __ch_data;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
396 volatile mcf5272_uart_t *base =
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
397 (volatile mcf5272_uart_t *)((char *)MCF5272_DEVS + port->base);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
398 char c;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
399
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
400
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
401 // Disable the interrupt temporarily
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
402 HAL_WRITE_UINT8(&base->uisr_uimr, 0);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
403
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
404 *__ctrlc = 0;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
405
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
406 // Read character
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
407 HAL_READ_UINT8(&base->urb_utb, c);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
408 if( cyg_hal_is_break( &c , 1 ) )
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
409 {
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
410 *__ctrlc = 1;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
411 }
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
412
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
413 // Re-enable RxRDY interrupt
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
414 HAL_WRITE_UINT8(&base->uisr_uimr, MCF5272_UART_UIMR_FFULL);
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
415
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
416 return CYG_ISR_HANDLED;
a62600d0e7b5 Import of the new ColdFire architecture HAL and M52272C port, with
asl
parents:
diff changeset
417 }