]> rtime.felk.cvut.cz Git - sysless.git/blob - board/h8300/edk2638/libs/bspbase/bsp0hwinit.c
It is 12 years after C99 standardization - switch to stdint.h and its types.
[sysless.git] / board / h8300 / edk2638 / libs / bspbase / bsp0hwinit.c
1 /* procesor H8S/2638 board EDK2638 ver 1.1 */
2 #include <stdint.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
35 void _setup_board()
36 {
37   /* set shadow registers */
38   DIO_P1DDR_shadow=0;
39   DIO_P3DDR_shadow=0;
40   DIO_PFDDR_shadow=0;
41   DIO_PJDDR_shadow=0;
42
43   SHADOW_REG_SET(DIO_P1DDR,(P1DDR_P15DDRm|P1DDR_P14DDRm)); /* set P1.5 and P1.4 as output */
44   deb_led_out(1); /* _setup_board function entered */
45
46  #if 1 /* registers setup */
47   /* Internal RAM enabled, advanced interrupt mode */
48   /* *SYS_SYSCR = 1*SYSCR_RAMEm | 1*SYSCR_INTM1m ; */
49
50   /* Remap 4kB of RAM from 0xffd000-0xffdfff to 0x0-0xfff */
51   /* *FLM_RAMER= 1*RAMER_RAMSm | 0&RAMER_RAMxm */
52   /* Sideefect - sets Flash software protection */
53
54   /* Enables access to flash control registers */
55   *IIC_SCRX |= SCRX_FLSHEm;
56
57   //SHADOW_REG_SET(DIO_P3DDR,0xc4);
58   //SHADOW_REG_SET(DIO_P1DDR,0x03); /*A20 and A21 are outputs*/
59   *DIO_P3DR=0x09;       /* Inactive value of TxD0 and TxD1 has to be log 1 */
60   SHADOW_REG_SET(DIO_P3DDR,0x09); /* TxD0 and TxD1 to outputs */
61
62   /* Setup system clock oscilator */
63   /* PLL mode x4, */
64   /* *SYS_LPWRCR=2&LPWRCR_STCxm; */
65   /* PLL mode x2, */
66   /* *SYS_LPWRCR=1&LPWRCR_STCxm; */
67   { const char clkrat2stc[]={0,0/*1*/,1/*2*/,1,2/*4*/,2,2,2,3/*8*/};
68     *SYS_LPWRCR=LPWRCR_STCxm&(LPWRCR_STC0m*
69                 clkrat2stc[(CPU_SYS_HZ+CPU_REF_HZ/2)/CPU_REF_HZ]);
70   }
71
72   /* No clock disable, immediate change, busmaster high-speed */
73   *SYS_SCKCR=(0*SCKCR_PSTOPm)|(1*SCKCR_STCSm)|(0&SCKCR_SCKxm);
74 // POE-100
75  #if 0
76   /* Setup chipselect outputs CS4 CS5 CS6 */
77   *DIO_P7DR |=1|2|4;
78   SHADOW_REG_SET(DIO_P7DDR,1|2|4);
79  #else
80   // SHADOW_REG_SET(DIO_P7DDR,0); not on 2638
81  #endif
82
83   /* Setup chipselect outputs CS3 CS2 CS1 CS0 */
84   // *DIO_PGDR |=2|4|8|0x10; no on 2638
85  #if 0
86   SHADOW_REG_SET(DIO_PGDDR,2|4|8|0x10);
87  #else
88   // SHADOW_REG_SET(DIO_PGDDR,2|4); no on 2638
89  #endif
90
91  #if 0
92   /* setup chipselect 0 - FLASH */
93   *BUS_ABWCR&=~ABWCR_ABW0m;     /* 16 bit width */
94   *BUS_ASTCR&=~ASTCR_AST0m;     /* 2 states access */
95   *BUS_WCRL&=~(WCRL_W01m|WCRL_W00m);/* 0 additional wait states */
96
97   /* setup chipselect 1 - XRAM */
98   *BUS_ABWCR&=~ABWCR_ABW1m;     /* 16 bit width */
99   *BUS_ASTCR&=~ASTCR_AST1m;     /* 2 states access */
100   *BUS_WCRL&=~(WCRL_W11m|WCRL_W10m);/* 0 additional wait states */
101
102   /* setup chipselect 2 - SGM_LCD */
103   *BUS_ABWCR|=ABWCR_ABW2m;      /* 8 bit width */
104   *BUS_ASTCR|=ASTCR_AST2m;      /* 3 states access */
105   *BUS_WCRL&=~(WCRL_W21m|WCRL_W20m);/* 0 additional wait states */
106   *BUS_WCRL|=0*WCRL_W21m;       /* 0/1 additional wait state */
107   #endif
108
109   /* setup chipselect 3 - SRAM */
110   //*BUS_ABWCR|=ABWCR_ABW3m;    /* 8 bit width */
111   *BUS_ABWCR&=~ABWCR_ABW0m;     /* 16 bit width EDK 2638 */
112   //*BUS_ASTCR|=ASTCR_AST3m;    /* 3 states access */
113   *BUS_ASTCR|=ASTCR_AST0m;      /* 3 states access EDK 2638 */
114   //*BUS_WCRL&=~(WCRL_W31m|WCRL_W30m);  /* 0 additional wait states */
115   *BUS_WCRL&=~(WCRL_W01m|WCRL_W00m);    /* 0 additional wait states EDK 2638*/
116
117  #if 0
118   /* setup chipselect 4 - IDE */
119   *BUS_ABWCR&=~ABWCR_ABW4m;     /* 16 bit width */
120   *BUS_ASTCR|=ASTCR_AST4m;      /* 3 states access */
121   *BUS_WCRH&=~(WCRH_W41m|WCRH_W40m);/* 0 additional wait states */
122
123   /* setup chipselect 5 - IDE */
124   *BUS_ABWCR&=~ABWCR_ABW5m;     /* 16 bit width */
125   *BUS_ASTCR|=ASTCR_AST5m;      /* 3 states access */
126   *BUS_WCRH&=~(WCRH_W51m|WCRH_W50m);/* 0 additional wait states */
127
128   /* setup chipselect 6 - KL41 */
129   *BUS_ABWCR|=ABWCR_ABW6m;      /* 8 bit width */
130   *BUS_ASTCR|=ASTCR_AST6m;      /* 3 states access */
131   *BUS_WCRH=WCRH_W61m|WCRH_W60m;        /* 3 additional wait states */
132  #endif
133
134 #if 1
135          /*  cross cs wait| rd/wr wait    | no burst and DRAM */
136   *BUS_BCRH=0*BCRH_ICIS1m | 0*BCRH_ICIS0m;
137          /* release      | no DMAC buffer | no external wait */
138   *BUS_BCRL=0*BCRL_WDBEm; // 0*BCRL_BRLEm | 0*BCRL_WDBEm | 0*BCRL_WAITEm;  BRLE and WAITE not build in 2638
139   *DIO_PCDDR=0xff;              /* A0-A7 are outputs */
140  #ifndef SMALL_ADRBUS
141   *DIO_PBDDR=0xff;              /* A8-A15 are outputs */
142  #endif /*SMALL_ADRBUS*/
143  #ifndef FULL_XRAM_ADRBUS
144   #ifndef SMALL_ADRBUS
145    /* *SYS_PFCR=__val2mfld(PFCR_AExm,16-8);      only 16 address lines */
146    *SYS_PFCR=__val2mfld(PFCR_AExm,18-8);        /* only 18 address lines fer EDK238 Extend*/
147   #else /*SMALL_ADRBUS*/
148    *SYS_PFCR=__val2mfld(PFCR_AExm,SMALL_ADRBUS-8); /* only SMALL_ADRBUS address lines */
149   #endif /*SMALL_ADRBUS*/
150  #endif /* FULL_XRAM_ADRBUS */
151
152  #endif /* registers setup */
153
154   FlWait(1*1000000);
155
156  #ifdef FULL_XRAM_ADRBUS
157   /* Setup full 20 address lines */
158   *DIO_PADR|=0x0f;
159   *DIO_PADDR=0x0f;              /* A16-A19 are outputs */
160          /* number of address output signals */
161   /* *SYS_PFCR=__val2mfld(PFCR_AExm,20-8); */
162   *SYS_PFCR=__val2mfld(PFCR_AExm,18-8); /* only 18 address lines fer EDK238 Extend*/
163  #endif /*FULL_XRAM_ADRBUS*/
164 #endif
165 }
166