]> rtime.felk.cvut.cz Git - sysless.git/blob - board/h8300/h8canusb/libs/bspbase/bsp0hwinit.c
1cb8668ca5ec777ab78edfbc8ec3490c20f10fb5
[sysless.git] / board / h8300 / h8canusb / libs / bspbase / bsp0hwinit.c
1 /* procesor H8S/2638 ver 1.1  */
2 #include <types.h>
3 #include <cpu_def.h>
4 #include <h8s2638h.h>
5 #include <system_def.h>
6 #include <string.h>
7 #include <boot_fn.h>
8
9 #ifdef XRAM_SUPPORT_ENABLED
10 #define FULL_XRAM_ADRBUS
11 #endif /*XRAM_SUPPORT_ENABLED*/
12 #define SMALL_ADRBUS 8
13
14 static void deb_led_out(char val)
15 {
16   if (val&1)
17     DEB_LED_ON(0);
18   else
19     DEB_LED_OFF(0);
20   if (val&2)
21     DEB_LED_ON(1);
22   else
23     DEB_LED_OFF(1);
24   if (val&4)
25     DEB_LED_ON(2);
26   else
27     DEB_LED_OFF(2);
28   if (val&8)
29     DEB_LED_ON(3);
30   else
31     DEB_LED_OFF(3);
32 }
33
34 /* Provided by linker script */
35 extern char __boot_fn_load;
36 extern char __boot_fn_start;
37 extern char __boot_fn_end;
38
39 static void relocate_boot_fn()
40 {
41   size_t reloc_size=&__boot_fn_end-&__boot_fn_start;
42
43   if(&__boot_fn_load != &__boot_fn_start) {
44     memcpy(&__boot_fn_start,&__boot_fn_load,reloc_size);
45   }
46 }
47
48 void _setup_board()
49 {
50   //int i, j;// POE-100
51
52 #if 1 /* registers setup */
53   /* Internal RAM enabled, advanced interrupt mode */
54   /* *SYS_SYSCR = 1*SYSCR_RAMEm | 1*SYSCR_INTM1m ; */
55
56   /* Remap 4kB of RAM from 0xffd000-0xffdfff to 0x0-0xfff */
57   /* *FLM_RAMER= 1*RAMER_RAMSm | 0&RAMER_RAMxm */
58   /* Sideefect - sets Flash software protection */
59
60   /* Enables access to flash control registers */
61   *IIC_SCRX |= SCRX_FLSHEm;
62
63   /* set shadow registers */
64   DIO_P1DDR_shadow=0;
65   DIO_P3DDR_shadow=0;
66   DIO_PFDDR_shadow=0;
67   DIO_PJDDR_shadow=0;
68
69   DEB_LED_INIT();
70
71   relocate_boot_fn();
72
73   /* show something on debug leds */
74   deb_led_out(0);
75   FlWait(1*100000);
76
77   SHADOW_REG_SET(DIO_P1DDR,0x03); /* A20 and A21 are outputs */
78
79   *DIO_P3DR=0x09;       /* Inactive value of TxD0 and TxD1 has to be log 1 */
80   SHADOW_REG_SET(DIO_P3DDR,0x09); /* TxD0 and TxD1 to outputs */
81
82   /* Setup system clock oscilator */
83   /* PLL mode x4, */
84   /* *SYS_LPWRCR=2&LPWRCR_STCxm; */
85   /* PLL mode x2, */
86   /* *SYS_LPWRCR=1&LPWRCR_STCxm; */
87   {
88     const char clkrat2stc[]={0,0/*1*/,1/*2*/,1,2/*4*/,2,2,2,3/*8*/};
89     *SYS_LPWRCR=LPWRCR_STCxm&(LPWRCR_STC0m*
90                               clkrat2stc[(CPU_SYS_HZ+CPU_REF_HZ/2)/CPU_REF_HZ]);
91   }
92   deb_led_out(1);
93   FlWait(1*100000);
94
95   /* No clock disable, immediate change, busmaster high-speed */
96   *SYS_SCKCR=(0*SCKCR_PSTOPm)|(1*SCKCR_STCSm)|(0&SCKCR_SCKxm);
97   // POE-100
98 #if 0
99   /* Setup chipselect outputs CS4 CS5 CS6 */
100   *DIO_P7DR |=1|2|4;
101   SHADOW_REG_SET(DIO_P7DDR,1|2|4);
102 #else
103   // SHADOW_REG_SET(DIO_P7DDR,0); not on 2638
104 #endif
105
106   /* Setup chipselect outputs CS3 CS2 CS1 CS0 */
107   // *DIO_PGDR |=2|4|8|0x10; no on 2638
108 #if 0
109   SHADOW_REG_SET(DIO_PGDDR,2|4|8|0x10);
110 #else
111   // SHADOW_REG_SET(DIO_PGDDR,2|4); no on 2638
112 #endif
113
114 #if 1
115   /* setup chipselect 0 - FLASH */
116   *BUS_ABWCR&=~ABWCR_ABW0m;     /* 16 bit width */
117   *BUS_ASTCR&=~ASTCR_AST0m;     /* 2 states access */
118   //*BUS_ASTCR|=ASTCR_AST0m;    /* 3 states access EDK 2638 */
119   *BUS_WCRL&=~(WCRL_W01m|WCRL_W00m);/* 0 additional wait states */
120
121   /* setup chipselect 1 - XRAM */
122   *BUS_ABWCR&=~ABWCR_ABW1m;     /* 16 bit width */
123   *BUS_ASTCR&=~ASTCR_AST1m;     /* 2 states access */
124   *BUS_WCRL&=~(WCRL_W11m|WCRL_W10m);/* 0 additional wait states */
125
126   /* setup chipselect 2 - USB */
127   *BUS_ABWCR|=ABWCR_ABW2m;      /* 8 bit width */
128   *BUS_ASTCR|=ASTCR_AST2m;      /* 3 states access */
129   *BUS_WCRL&=~(WCRL_W21m|WCRL_W20m);/* 0 additional wait states */
130   *BUS_WCRL|=1*WCRL_W21m;       /* 0/1 additional wait state */
131
132   /* setup chipselect 3 - KBD */
133   *BUS_ABWCR|=ABWCR_ABW3m;      /* 8 bit width */
134   *BUS_ASTCR|=ASTCR_AST3m;      /* 3 states access */
135   *BUS_WCRL|=(WCRL_W31m|WCRL_W30m);/* 0 additional wait states */
136 #endif
137
138 #if 0
139   /* setup chipselect 4 - IDE */
140   *BUS_ABWCR&=~ABWCR_ABW4m;     /* 16 bit width */
141   *BUS_ASTCR|=ASTCR_AST4m;      /* 3 states access */
142   *BUS_WCRH&=~(WCRH_W41m|WCRH_W40m);/* 0 additional wait states */
143
144   /* setup chipselect 5 - IDE */
145   *BUS_ABWCR&=~ABWCR_ABW5m;     /* 16 bit width */
146   *BUS_ASTCR|=ASTCR_AST5m;      /* 3 states access */
147   *BUS_WCRH&=~(WCRH_W51m|WCRH_W50m);/* 0 additional wait states */
148
149   /* setup chipselect 6 - KL41 */
150   *BUS_ABWCR|=ABWCR_ABW6m;      /* 8 bit width */
151   *BUS_ASTCR|=ASTCR_AST6m;      /* 3 states access */
152   *BUS_WCRH=WCRH_W61m|WCRH_W60m;        /* 3 additional wait states */
153 #endif
154
155   deb_led_out(2);
156   FlWait(1*100000);
157
158 #if 1
159   /*  cross cs wait| rd/wr wait    | no burst and DRAM */
160   *BUS_BCRH=0*BCRH_ICIS1m | 0*BCRH_ICIS0m;
161   /* release      | no DMAC buffer | no external wait */
162   *BUS_BCRL=0*BCRL_WDBEm; // 0*BCRL_BRLEm | 0*BCRL_WDBEm | 0*BCRL_WAITEm;  BRLE and WAITE not build in 2638
163   *DIO_PCDDR=0xff;              /* A0-A7 are outputs */
164 #ifndef SMALL_ADRBUS
165   *DIO_PBDDR=0xff;              /* A8-A15 are outputs */
166 #endif /*SMALL_ADRBUS*/
167 #ifndef FULL_XRAM_ADRBUS
168 #ifndef SMALL_ADRBUS
169   *SYS_PFCR=__val2mfld(PFCR_AExm,16-8); /* only 16 address lines */
170 #else /*SMALL_ADRBUS*/
171   *SYS_PFCR=__val2mfld(PFCR_AExm,SMALL_ADRBUS-8); /* only SMALL_ADRBUS address lines */
172 #endif /*SMALL_ADRBUS*/
173 #endif /* FULL_XRAM_ADRBUS */
174
175 #endif /* registers setup */
176
177   FlWait(1*100000);
178
179 #ifdef FULL_XRAM_ADRBUS
180   /* Setup full 22 address lines */
181   *DIO_PADR|=0x0f;
182   *DIO_PADDR=0x0f;              /* A16-A19 are outputs */
183   /* number of address output signals */
184   *SYS_PFCR=__val2mfld(PFCR_AExm,22-8);
185 #endif /*FULL_XRAM_ADRBUS*/
186 #endif
187
188 }
189