]> rtime.felk.cvut.cz Git - sysless.git/blob - arch/h8300/generic/bloader/bloader.c
ec637c0a863b89da7ef7c7fb1715b46017e8ba5d
[sysless.git] / arch / h8300 / generic / bloader / bloader.c
1 /* procesor H8S/2638 ver 1.1  */
2 #include <types.h>
3 #include <cpu_def.h>
4 #include <mcu_regs.h>
5 //#include <periph/chmod_lcd.h>
6 //#include <periph/sgm_lcd.h>
7 #include <system_def.h>
8 #include <string.h>
9
10
11 #ifndef DEB_LED_INIT
12 #define DEB_LED_INIT()
13 #define DEB_LED_OFF(num)
14 #define DEB_LED_ON(num)
15 #endif
16
17 #define BOOT_TEST
18 #define APPLICATION_START
19
20 /*#define USE_FONT_6x8*/
21
22 #ifndef HIT_LOAD_BAUD
23   #define HIT_LOAD_BAUD 0
24 #endif
25
26 /* hack for start of main, should use crt0.o instead */
27 /* Used in boot mode to start main(). */
28 __asm__ /*__volatile__*/(
29         ".global _start_hack\n\t"
30         "_start_hack : \n\t"
31         "mov.l  #0xffdffe,sp\n\t"
32         "jsr    _main\n"
33         "0: bra 0b\n"
34         );
35
36 void exit(int status)
37 {
38   while(1);
39 }
40
41 void deb_wr_hex(long hex, short digs);
42
43 char data_test[]={'D','A','T','A',0};
44
45  /*
46  *----------------------------------------------------------
47  */
48 void deb_wr_hex(long hex, short digs)
49 {
50   char c;
51   while(digs--){
52     c=((hex>>(4*digs))&0xf)+'0';
53     if(c>'9') c+='A'-'9'-1;  
54   }
55 }
56
57 static void deb_led_out(char val)
58 {
59   if (val&1)
60     DEB_LED_ON(0);
61   else
62     DEB_LED_OFF(0);
63   if (val&2)
64     DEB_LED_ON(1);
65   else
66     DEB_LED_OFF(1);
67   if (val&4)
68     DEB_LED_ON(2);
69   else
70     DEB_LED_OFF(2);
71   if (val&8)
72     DEB_LED_ON(3);
73   else
74     DEB_LED_OFF(3);
75 }
76
77
78 #ifdef BOOT_TEST
79
80 #include <boot_fn.h>
81
82 void boot_test()
83 {
84   /*set power on for SCI0 and SCI1 module*/
85   *SYS_MSTPCRB&=~MSTPCRB_SCI0m;
86   *SYS_MSTPCRB&=~MSTPCRB_SCI1m;
87
88  #if 0
89   SCIInit(HIT_LOAD_BAUD);
90
91   SCISend('B');
92   SCISend('B');
93   SCISend(':');
94
95  #endif
96
97   /* switch off SCI2 module*/
98   *SYS_MSTPCRB|=MSTPCRB_SCI2m;
99   
100   *DIO_PADR |= 0x0f;
101   *DIO_PADDR = 0x0f;
102
103   if(!HIT_LOAD_BAUD) {
104     long bauddet;   
105     bauddet=SCIAutoBaud();
106     deb_wr_hex(bauddet,4);
107   }
108
109  
110   ProgMode(HIT_LOAD_BAUD);
111 }
112
113 #endif /* BOOT_TEST */
114
115 inline int call_address(unsigned long addr)
116 {
117   typedef int (*my_call_t)(void);
118   my_call_t my_call=(my_call_t)addr;
119   return my_call();  
120 }
121
122 /*
123  *-----------------------------------------------------------
124  */
125
126
127 /* Only for debuging */
128 void deb_led_blink() {
129   while(1) {
130     deb_led_out(1);
131     FlWait(1*1000000);
132     deb_led_out(2);
133     FlWait(1*1000000);
134   };
135 };
136
137 int main()
138 {
139   __u8 *p;
140
141   _setup_board(); /* Provided in bspbase library of each board */
142
143   p=(__u8*)&deb_wr_hex;
144   if(p>=IRAM_START) p=" IRAM";
145 #ifdef SRAM_START
146   else if(p>=SRAM_START) p=" SRAM";
147 #endif
148 #ifdef XRAM_START
149   else if(p>=XRAM_START) p=" XRAM";
150 #endif
151   else if(p>(__u8*)0x4000l) p=" FLSHU";
152   else p=" FLSHB";
153
154
155 #if 0           /* FLASH timing test */
156   do{
157     deb_led_out(~0);
158     FlWait(1l);
159     deb_led_out(~1);
160     FlWait(2l);
161     deb_led_out(~2);
162     FlWait(10l);
163     deb_led_out(~3);
164     FlWait(20l);
165   }while(1);
166 #endif
167
168 #ifdef APPLICATION_START
169   if(((*FLM_FLMCR1) & FLMCR1_FWEm)==0) {
170     if (*((unsigned long *)0x4000)!=0xffffffff){
171       call_address(0x4000);
172     }
173   }
174 #endif /* APPLICATION_START */
175  
176   deb_led_out(15);
177   FlWait(1*100000);
178   deb_led_out(3);
179  
180 #ifdef BOOT_TEST
181   boot_test();
182 #endif /* BOOT_TEST */ 
183  
184   return 0;
185 };
186
187