]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/mn10300/stb/v2_0/src/plf_misc.c
Initial revision
[karo-tx-redboot.git] / packages / hal / mn10300 / stb / v2_0 / src / plf_misc.c
1 //==========================================================================
2 //
3 //      plf_misc.c
4 //
5 //      HAL platform miscellaneous functions
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 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):    nickg
44 // Contributors: nickg, jlarmour, dhowells
45 // Date:         1999-01-21
46 // Purpose:      HAL miscellaneous functions
47 // Description:  This file contains miscellaneous functions provided by the
48 //               HAL.
49 //
50 //####DESCRIPTIONEND####
51 //
52 //========================================================================*/
53
54 #include <pkgconf/hal.h>
55
56 #include <cyg/infra/cyg_type.h>         // Base types
57 #include <cyg/infra/cyg_trac.h>         // tracing macros
58 #include <cyg/infra/cyg_ass.h>          // assertion macros
59
60 #include <cyg/hal/hal_arch.h>           // architectural definitions
61
62 #include <cyg/hal/hal_intr.h>           // Interrupt handling
63
64 #include <cyg/hal/hal_cache.h>          // Cache handling
65
66 #include <cyg/hal/hal_if.h>
67 #include <cyg/hal/hal_misc.h>
68
69 #include <cyg/hal/plf_io.h>
70
71 /*------------------------------------------------------------------------*/
72 /* LED support                                                            */
73 cyg_uint8 cyg_hal_plf_led_val(CYG_WORD hexdig)
74 {
75     static cyg_uint8 map[] = {
76         0x81, // 0
77         0xf3, // 1
78         0x49, // 2
79         0x61, // 3
80         0x33, // 4
81         0x25, // 5
82         0x05, // 6
83         0xf1, // 7
84         0x01, // 8
85         0x21, // 9
86         0x11, // A
87         0x07, // B
88         0x8d, // C
89         0x43, // D
90         0x0d, // E
91         0x1d  // F
92     };
93     return map[(hexdig & 0xF)];
94 }
95
96 /*------------------------------------------------------------------------*/
97
98 void hal_platform_init(void)
99 {
100     HAL_WRITE_UINT8(HAL_LED_ADDRESS, cyg_hal_plf_led_val(8));
101
102 #if defined(CYG_HAL_STARTUP_ROM)
103     // Note that the hardware seems to come up with the
104     // caches containing random data. Hence they must be
105     // invalidated before being enabled.
106     // However, we only do this if we are in ROM. If we are
107     // in RAM, then we leave the caches in the state chosen
108     // by the ROM monitor. If we enable them when the monitor
109     // is not expecting it, we can end up breaking things if the
110     // monitor is not doing cache flushes.
111
112     //HAL_ICACHE_INVALIDATE_ALL();    
113     //HAL_ICACHE_ENABLE();
114     //HAL_DCACHE_INVALIDATE_ALL();
115     //HAL_DCACHE_ENABLE();
116 #endif
117
118     // Set up eCos/ROM interfaces
119     hal_if_init();
120     
121 #if defined(CYGPKG_KERNEL)                      && \
122     defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT)   && \
123     defined(CYGSEM_HAL_USE_ROM_MONITOR_GDB_stubs)
124     {
125         extern void patch_dbg_syscalls(void * vector);
126         patch_dbg_syscalls( (void *)(&hal_virtual_vector_table[0]) );
127     }
128 #endif    
129 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
130     {
131         static void hal_ctrlc_isr_init(void);
132         hal_ctrlc_isr_init();
133     }
134 #endif    
135 }
136
137 /*------------------------------------------------------------------------*/
138 /* Control C ISR support                                                  */
139
140 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) && \
141     !defined(CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT)
142
143 #if CYGHWR_HAL_MN10300_AM33_STB_GDB_PORT == 0
144
145 // We use serial0 on AM33
146 #define SERIAL_CR       ((volatile cyg_uint16 *)0xd4002000)
147 #define SERIAL_ICR      ((volatile cyg_uint8 *) 0xd4002004)
148 #define SERIAL_TXR      ((volatile cyg_uint8 *) 0xd4002008)
149 #define SERIAL_RXR      ((volatile cyg_uint8 *) 0xd4002009)
150 #define SERIAL_SR       ((volatile cyg_uint16 *)0xd400200c)
151
152 // Timer 1 provided baud rate divisor
153 #define TIMER_MD       ((volatile cyg_uint8 *)0xd4003000)
154 #define TIMER_BR       ((volatile cyg_uint8 *)0xd4003010)
155 #define TIMER_CR       ((volatile cyg_uint8 *)0xd4003020)
156
157 #define SIO_LSTAT_TRDY  0x20
158 #define SIO_LSTAT_RRDY  0x10
159
160 #else
161
162 #error Unsupported GDB port
163
164 #endif
165
166 struct Hal_SavedRegisters *hal_saved_interrupt_state;
167
168 static void hal_ctrlc_isr_init(void)
169 {
170 //    cyg_uint16 cr;
171
172 //    HAL_READ_UINT16( SERIAL_CR, cr );
173 //    cr |= LCR_RXE;
174 //    HAL_WRITE_UINT16( SERIAL_CR, cr );
175     HAL_INTERRUPT_SET_LEVEL( CYGHWR_HAL_GDB_PORT_VECTOR, 4 );
176     HAL_INTERRUPT_UNMASK( CYGHWR_HAL_GDB_PORT_VECTOR ); 
177 }
178
179 cyg_uint32 hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
180 {
181     char c;
182     cyg_uint16 sr;
183     
184     HAL_INTERRUPT_ACKNOWLEDGE( CYGHWR_HAL_GDB_PORT_VECTOR ); 
185
186     HAL_READ_UINT16( SERIAL_SR, sr );
187
188     if( sr & SIO_LSTAT_RRDY )
189     {
190         HAL_READ_UINT8( SERIAL_RXR, c);
191
192         if( cyg_hal_is_break( &c , 1 ) )
193             cyg_hal_user_break( (CYG_ADDRWORD *)hal_saved_interrupt_state );
194
195         
196     }
197     return 1;
198 }
199
200 #endif
201
202 /*------------------------------------------------------------------------*/
203 /* End of plf_misc.c                                                      */