1 #ifndef CYGONCE_HAL_VARIANT_INC
2 #define CYGONCE_HAL_VARIANT_INC
3 ##=============================================================================
7 ## MB91301 family assembler header file
9 ##=============================================================================
10 #####ECOSGPLCOPYRIGHTBEGIN####
11 ## -------------------------------------------
12 ## This file is part of eCos, the Embedded Configurable Operating System.
13 ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 ## eCos is free software; you can redistribute it and/or modify it under
16 ## the terms of the GNU General Public License as published by the Free
17 ## Software Foundation; either version 2 or (at your option) any later version.
19 ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 ## You should have received a copy of the GNU General Public License along
25 ## with eCos; if not, write to the Free Software Foundation, Inc.,
26 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 ## As a special exception, if other files instantiate templates or use macros
29 ## or inline functions from this file, or you compile this file and link it
30 ## with other works to produce a work based on this file, this file does not
31 ## by itself cause the resulting work to be covered by the GNU General Public
32 ## License. However the source code for this file must still be made available
33 ## in accordance with section (3) of the GNU General Public License.
35 ## This exception does not invalidate any other reasons why a work based on
36 ## this file might be covered by the GNU General Public License.
38 ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 ## at http://sources.redhat.com/ecos/ecos-license/
40 ## -------------------------------------------
41 #####ECOSGPLCOPYRIGHTEND####
42 ##=============================================================================
43 #######DESCRIPTIONBEGIN####
48 ## Purpose: MB91301 family definitions.
49 ## Description: This file contains various definitions and macros that are
50 ## useful for writing assembly code for the TX39 CPU family.
52 ## #include <cyg/hal/variant.inc>
56 ######DESCRIPTIONEND####
58 ##=============================================================================
60 #include <pkgconf/hal.h>
62 #include <cyg/hal/fr30.inc>
64 #include <cyg/hal/platform.inc>
66 ##-----------------------------------------------------------------------------
67 ## Define CPU variant for architecture HAL.
69 #define CYG_HAL_FR30_MB91301
71 ##-----------------------------------------------------------------------------
72 ## Indicate that the ISR tables are defined in variant.S
74 #ifndef CYG_HAL_FR30_ISR_TABLES_DEFINED
75 #define CYG_HAL_FR30_ISR_TABLES_DEFINED
78 ##-----------------------------------------------------------------------------
79 ## CPU initialisation, we set the clock to PLL 48 Mhz (12 * 4Mhz) here.
80 ## PLL lock waiting time is implemented as a busy loop.
82 #ifndef CYGPKG_HAL_FR30_CPU_INIT_DEFINED
83 #define CYGPKG_HAL_FR30_CPU_INIT_DEFINED
88 .macro wait_loop no=0x1
96 ##-----------------------------------------------------------------------------
97 ## Clock Modulator control registers
99 .equ FR30_MB91301_CMCR, 0x164
100 .equ FR30_MB91301_CMCRH, 0x164
101 .equ FR30_MB91301_CMCRL, 0x165
102 .equ FR30_MB91301_CMPR, 0x166
103 .equ FR30_MB91301_CMLS0, 0x168
104 .equ FR30_MB91301_CMLS1, 0x16a
105 .equ FR30_MB91301_CMLS2, 0x16c
106 .equ FR30_MB91301_CMLT0, 0x170
107 .equ FR30_MB91301_CMLT1, 0x172
108 .equ FR30_MB91301_CMLT2, 0x174
109 .equ FR30_MB91301_CMAC, 0x176
110 .equ FR30_MB91301_CMACH, 0x178
111 .equ FR30_MB91301_CMACL, 0x179
112 .equ FR30_MB91301_CMTS, 0x17a
113 .equ FR30_MB91301_CMTSH, 0x17a
114 .equ FR30_MB91301_CMTSL, 0x17b
115 .equ FR30_MB91301_ICR31, 0x45f
117 ##-----------------------------------------------------------------------------
118 ## Registers for Clock Generation and Reset
120 .equ FR30_MB91301_RSRR, 0x480
121 .equ FR30_MB91301_STCR, 0x481
122 .equ FR30_MB91301_TBCR, 0x482
123 .equ FR30_MB91301_CTBR, 0x483
124 .equ FR30_MB91301_CLKR, 0x484
125 .equ FR30_MB91301_WPR, 0x485
126 .equ FR30_MB91301_DIVR0, 0x486
127 .equ FR30_MB91301_DIVR1, 0x487
129 ##-----------------------------------------------------------------------------
130 ## ext bus interface registers
131 ## part used for flash
133 .equ FR30_MB91301_ASR0, 0x640
134 .equ FR30_MB91301_ACR0, 0x642
135 .equ FR30_MB91301_AWR0, 0x660
136 .equ FR30_MB91301_CSER, 0x680
138 .equ FR30_MB91301_PDR9, 0x9
139 .equ FR30_MB91301_DDR9, 0x609
140 .equ FR30_MB91301_PFR9, 0x619
141 .equ FR30_MB91301_PCR9, 0x629
143 .equ FR30_MB91301_PDR8, 0x8
144 .equ FR30_MB91301_DDR8, 0x608
145 .equ FR30_MB91301_PFR8, 0x618
146 .equ FR30_MB91301_PCR8, 0x628
148 ## part used for sdram
149 .equ FR30_MB91301_ASR6, 0x658
150 .equ FR30_MB91301_ACR6, 0x65a
151 .equ FR30_MB91301_AWR6, 0x66c
152 .equ FR30_MB91301_MCRA, 0x670
153 .equ FR30_MB91301_MCRB, 0x671
154 .equ FR30_MB91301_RCR, 0x684
157 ##-----------------------------------------------------------------------------
158 ## registers for serial0 and U-timer settings
160 .equ FR30_MB91301_PDRJ, 0x13
161 .equ FR30_MB91301_DDRJ, 0x403
162 .equ FR30_MB91301_PFRJ, 0x413
163 .equ FR30_MB91301_UTIM0, 0x64
164 .equ FR30_MB91301_UTIMR0, 0x64
165 .equ FR30_MB91301_UTIMC0, 0x67
166 .equ FR30_MB91301_DRCL, 0x66
167 .equ FR30_MB91301_SMR0, 0x63
168 .equ FR30_MB91301_SCR0, 0x62
169 .equ FR30_MB91301_SIDR0, 0x61
170 .equ FR30_MB91301_SODR0, 0x61
171 .equ FR30_MB91301_SSR0, 0x60
173 ##-----------------------------------------------------------------------------
174 ## registers for clock settings
176 .equ FR30_MB91301_RTC_TMRLR, 0x50
177 .equ FR30_MB91301_RTC_TMR, 0x52
178 .equ FR30_MB91301_RTC_TMCSR, 0x56
182 ##------------------------------------------------------------------------------
183 ## CPU initialisation macro
184 ## This is mainly for setting clock speeds.
185 ##------------------------------------------------------------------------------
190 ldi:20 #FR30_MB91301_CLKR, r10 ; PLLx4 and enable it, still use source
191 ldi:8 (CYGHWR_HAL_FR30_MB91301_CLKR - 1) * 16 + 4, r1 ;
192 stb r1, @r10 ; oscillation as clock source
194 ldi:20 #FR30_MB91301_TBCR, r11 ; set time base counter to
195 ldi:8 #0x18, r1 ; about 60 ms and disable
196 stb r1, @r11 ; its interrupt (we poll below)
198 ldi:20 #FR30_MB91301_CTBR, r12 ; and
199 ldi:8 #0xa5, r2 ; start
200 ldi:8 #0x5a, r3 ; the
201 stb r2, @r12 ; time base
202 stb r3, @r12 ; counter
204 ldi:20 #FR30_MB91301_STCR, r13 ; set oscillation stabilisation time
205 ldi:8 #0x17, r1 ; to about 250 us
208 ldi:20 #FR30_MB91301_DIVR0, r12 ; set CLKB divider
209 ldi:8 (CYGHWR_HAL_FR30_MB91301_CLKB_DIVIDER - 1) * 16 + (CYGHWR_HAL_FR30_MB91301_CLKP_DIVIDER - 1), r1 ; and
210 stb r1, @r12 ; CLKP divider
212 ldi:20 #FR30_MB91301_DIVR1, r13 ; CLKT divider
213 ldi:8 (CYGHWR_HAL_FR30_MB91301_CLKT_DIVIDER - 1) * 16, r1
216 ldi:8 #0x80, r2 ; wait the rest
218 ldub @r11, r3 ; time base counter time
219 and r2, r3 ; (we set it to
220 beq 1b ; 60 ms above)
222 ldi:8 #0x36, r1 ; and now we are ready to
223 stb r1, @r10 ; switch clock to PLL
227 #endif /* !CYGPKG_HAL_FR30_CPU_INIT_DEFINED */
229 ##-----------------------------------------------------------------------------
230 ## FR30 interrupt handling.
231 ## nothing is here because the intc is initialized correctly by hardware reset
232 ## if something is needed it should be implemented in arch.inc with define'd
233 ## adresses to the registers. It should be the same for all FR30s
236 ##------------------------------------------------------------------------------
237 ## Diagnostics macros.
238 ## Indicate that the diagnostic macros are defined in variant.S / hal_diag.c
240 #ifndef CYGPKG_HAL_FR30_DIAG_DEFINED
242 ##-----------------------------------------------------------------------------
243 ## registers for led settings
246 .equ FR30_MB91301_PDRG, 0x10
247 .equ FR30_MB91301_DDRG, 0x400
248 .equ FR30_MB91301_PFRG, 0x410
249 ## our MB91301A does not have PCRG (pull up resistor register G)
250 ## but it is here anyway
251 .equ FR30_MB91301_PCRG, 0x420
254 .macro hal_diag_init_led
256 ldi:20 #FR30_MB91301_DDRG, r5
259 ldi:20 #FR30_MB91301_PFRG, r5
261 dmovb r13, @FR30_MB91301_PDRG
265 ## switch on led on "hardcoded" value supplied after this macro
268 .macro hal_diag_led led=0x0
271 dmovb r13, @FR30_MB91301_PDRG
275 ##------------------------------------------------------------------------------
279 ## output a value to UART a
280 ## the value has to be in r4
281 ## register r1 will be polluted
283 ldi:8 #FR30_MB91301_SODR0, r1
288 ## wait for the data in UART a SODR0 register to be drained
289 ## registers r1, r2, r3 will be polluted
291 ldi:8 #FR30_MB91301_SSR0, r3 ;
292 ldi:8 #0x08, r1 ; TDRE bit of SSR0
299 ## receive a value from UART a
300 ## value is returned in r4
301 ## register r1, r2 and r3 will be polluted
303 ldi:8 #FR30_MB91301_SSR0, r3 ;
304 ldi:8 #0x10, r1 ; RDRF bit of SSR0
308 beq 2b ; wait until a byte is received
310 ldi:8 #FR30_MB91301_SIDR0, r3 ;
311 ldub @r3, r4 ; and get the value
314 #define CYGPKG_HAL_FR30_DIAG_DEFINED
318 #------------------------------------------------------------------------------
319 # Timer initialization.
321 #ifndef CYGPKG_HAL_FR30_TIMER_DEFINED
323 .macro hal_timer_init
325 # load reload value into reload register
326 ldi:8 #FR30_MB91301_RTC_TMRLR, r4
327 ldi:20 #CYGNUM_HAL_RTC_PERIOD, r5
329 # set parameters to TODO
330 ldi:8 #FR30_MB91301_RTC_TMCSR, r4
335 #define CYGPKG_HAL_FR30_TIMER_DEFINED
339 #------------------------------------------------------------------------------
340 #endif // ifndef CYGONCE_HAL_VARIANT_INC