]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/fr30/mb91301/v2_0/include/variant.inc
Initial revision
[karo-tx-redboot.git] / packages / hal / fr30 / mb91301 / v2_0 / include / variant.inc
1 #ifndef CYGONCE_HAL_VARIANT_INC
2 #define CYGONCE_HAL_VARIANT_INC
3 ##=============================================================================
4 ##
5 ##      variant.inc
6 ##
7 ##      MB91301 family assembler header file
8 ##
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.
14 ##
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.
18 ##
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
22 ## for more details.
23 ##
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.
27 ##
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.
34 ##
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.
37 ##
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####
44 ##
45 ## Author(s):   larsi
46 ## Contributors:larsi
47 ## Date:        2006-07-24
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.
51 ## Usage:
52 ##              #include <cyg/hal/variant.inc>
53 ##              ...
54 ##              
55 ##
56 ######DESCRIPTIONEND####
57 ##
58 ##=============================================================================
59
60 #include <pkgconf/hal.h>
61
62 #include <cyg/hal/fr30.inc>
63
64 #include <cyg/hal/platform.inc>
65
66 ##-----------------------------------------------------------------------------
67 ## Define CPU variant for architecture HAL.
68
69 #define CYG_HAL_FR30_MB91301
70
71 ##-----------------------------------------------------------------------------
72 ## Indicate that the ISR tables are defined in variant.S
73
74 #ifndef CYG_HAL_FR30_ISR_TABLES_DEFINED
75 #define CYG_HAL_FR30_ISR_TABLES_DEFINED
76 #endif
77
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.
81
82 #ifndef CYGPKG_HAL_FR30_CPU_INIT_DEFINED
83 #define CYGPKG_HAL_FR30_CPU_INIT_DEFINED
84 #
85 # busy wait loop
86 # pollutes r11, r12
87 #
88 .macro wait_loop no=0x1
89     ldi:20  #\no,   r12
90     ldi:8   #0x1,   r11
91 8:
92     sub     r11,    r12
93     bne     8b
94 .endm
95
96 ##-----------------------------------------------------------------------------
97 ## Clock Modulator control registers
98
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
116
117 ##-----------------------------------------------------------------------------
118 ## Registers for Clock Generation and Reset
119
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
128
129 ##-----------------------------------------------------------------------------
130 ## ext bus interface registers
131 ## part used for flash
132
133     .equ FR30_MB91301_ASR0,     0x640
134     .equ FR30_MB91301_ACR0,     0x642
135     .equ FR30_MB91301_AWR0,     0x660
136     .equ FR30_MB91301_CSER,     0x680
137
138     .equ FR30_MB91301_PDR9,     0x9
139     .equ FR30_MB91301_DDR9,     0x609
140     .equ FR30_MB91301_PFR9,     0x619
141     .equ FR30_MB91301_PCR9,     0x629
142
143     .equ FR30_MB91301_PDR8,     0x8
144     .equ FR30_MB91301_DDR8,     0x608
145     .equ FR30_MB91301_PFR8,     0x618
146     .equ FR30_MB91301_PCR8,     0x628
147
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
155
156
157 ##-----------------------------------------------------------------------------
158 ## registers for serial0 and U-timer settings
159 ##
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
172
173 ##-----------------------------------------------------------------------------
174 ## registers for clock settings
175 ##
176     .equ FR30_MB91301_RTC_TMRLR,      0x50
177     .equ FR30_MB91301_RTC_TMR,        0x52
178     .equ FR30_MB91301_RTC_TMCSR,      0x56
179
180
181
182 ##------------------------------------------------------------------------------
183 ## CPU initialisation macro
184 ## This is mainly for setting clock speeds.
185 ##------------------------------------------------------------------------------
186 .macro  hal_cpu_init
187
188     ldi:8   #0x00,  r0
189
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
193
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)
197
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
203
204     ldi:20  #FR30_MB91301_STCR, r13     ; set oscillation stabilisation time
205     ldi:8   #0x17,  r1                  ; to about 250 us
206     stb     r1,     @r13                ;
207
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
211
212     ldi:20  #FR30_MB91301_DIVR1, r13    ; CLKT divider
213     ldi:8   (CYGHWR_HAL_FR30_MB91301_CLKT_DIVIDER - 1) * 16,    r1
214     stb     r1,     @r13                ;
215
216     ldi:8   #0x80,  r2                  ; wait the rest
217 1:                                      ; of the
218     ldub    @r11,   r3                  ; time base counter time
219     and     r2,     r3                  ; (we set it to
220     beq     1b                          ; 60 ms above)
221
222     ldi:8   #0x36,  r1                  ; and now we are ready to
223     stb     r1,     @r10                ; switch clock to PLL
224
225 .endm
226
227 #endif /* !CYGPKG_HAL_FR30_CPU_INIT_DEFINED */
228
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
234
235
236 ##------------------------------------------------------------------------------
237 ## Diagnostics macros.
238 ## Indicate that the diagnostic macros are defined in variant.S / hal_diag.c
239
240 #ifndef CYGPKG_HAL_FR30_DIAG_DEFINED
241
242 ##-----------------------------------------------------------------------------
243 ## registers for led settings
244 ##
245
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
252
253
254 .macro hal_diag_init_led
255     ldi:8   #0xff,      r4
256     ldi:20  #FR30_MB91301_DDRG, r5
257     stb     r4,         @r5
258     ldi:8   #0x00,      r13
259     ldi:20  #FR30_MB91301_PFRG, r5
260     stb     r13,         @r5
261     dmovb   r13,        @FR30_MB91301_PDRG
262 .endm
263
264 ##
265 ## switch on led on "hardcoded" value supplied after this macro
266 ## pollutes r13
267 ##
268 .macro hal_diag_led led=0x0
269 ##st      r13, @-r15
270     ldi:8   #\led , r13
271     dmovb   r13,    @FR30_MB91301_PDRG
272 ##ld      @r15+,  r13
273 .endm
274
275 ##------------------------------------------------------------------------------
276 ## UARTa macros
277 ##
278
279 ## output a value to UART a
280 ## the value has to be in r4
281 ## register r1 will be polluted
282 .macro uarta_putc
283     ldi:8   #FR30_MB91301_SODR0,  r1
284     stb     r4, @r1
285 .endm
286
287
288 ## wait for the data in UART a SODR0 register to be drained
289 ## registers r1, r2, r3 will be polluted
290 .macro uarta_drain
291     ldi:8   #FR30_MB91301_SSR0,     r3  ;
292     ldi:8   #0x08,  r1                  ; TDRE bit of SSR0
293 1:                                      ;
294     ldub    @r3,    r2                  ;
295     and     r1,     r2                  ;
296     beq     1b
297 .endm
298
299 ## receive a value from UART a
300 ## value is returned in r4
301 ## register r1, r2 and r3 will be polluted
302 .macro uarta_getc
303     ldi:8   #FR30_MB91301_SSR0,     r3  ;
304     ldi:8   #0x10,  r1                  ; RDRF bit of SSR0
305 2:
306     ldub    @r3,    r2                  ;
307     and     r1,     r2                  ;
308     beq     2b                          ; wait until a byte is received
309
310     ldi:8   #FR30_MB91301_SIDR0,    r3  ;
311     ldub    @r3,    r4                  ; and get the value
312 .endm
313
314 #define CYGPKG_HAL_FR30_DIAG_DEFINED
315
316 #endif
317
318 #------------------------------------------------------------------------------
319 # Timer initialization.
320
321 #ifndef CYGPKG_HAL_FR30_TIMER_DEFINED
322
323     .macro  hal_timer_init
324
325     # load reload value into reload register
326         ldi:8   #FR30_MB91301_RTC_TMRLR,  r4
327         ldi:20  #CYGNUM_HAL_RTC_PERIOD, r5
328         sth     r5,     @r4
329     # set parameters to TODO
330         ldi:8   #FR30_MB91301_RTC_TMCSR,  r4
331         ldi:20  #0x0813,    r5
332         sth     r5,     @r4
333     .endm
334
335 #define CYGPKG_HAL_FR30_TIMER_DEFINED
336
337 #endif
338
339 #------------------------------------------------------------------------------
340 #endif // ifndef CYGONCE_HAL_VARIANT_INC
341 # end of variant.inc