-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
271 lines (215 loc) · 6.67 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
* Copyright (C) 2022 (Unix69@github)
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include "uart.h"
#include "delays.h"
#include "system_timer.h"
#include "timer.h"
#include "spi.h"
#define BOOTMODE 64
void exception_handler(unsigned long type, unsigned long esr, unsigned long elr, unsigned long spsr, unsigned long far, unsigned long currel);
void print_uint64(uint64_t reg);
void print_uint32(uint32_t reg);
void delay_test();
void exception_handler(unsigned long type, unsigned long esr, unsigned long elr, unsigned long spsr, unsigned long far, unsigned long currel){
switch(type) {
case 0:
uart_puts("Synchronous from same EL using SP0 ");
break;
case 1:
uart_puts("IRQ from same EL using SP0 ");
break;
case 2:
uart_puts("FIQ from same EL using SP0 ");
break;
case 3:
uart_puts("SError from same EL using SP0 ");
break;
case 4:
uart_puts("Synchronous from same EL using current SP ");
break;
case 5:
uart_puts("IRQ from same EL using current SP ");
break;
case 6:
uart_puts("FIQ from same EL using current SP ");
break;
case 7:
uart_puts("SError from same EL using current SP ");
break;
case 8:
uart_puts("Synchronous from lower EL using SP0 ");
break;
case 9:
uart_puts("IRQ from lower EL using SP0 ");
break;
case 10:
uart_puts("FIQ from lower EL AArch64 ");
break;
case 11:
uart_puts("SError from lower EL AArch64 ");
break;
case 12:
uart_puts("Synchronous from lower EL AArch32 ");
break;
case 13:
uart_puts("IRQ from lower EL AArch32 ");
break;
case 14:
uart_puts("FIQ from lower EL AArch32 ");
break;
case 15:
uart_puts("SError from lower EL AArch32 ");
break;
}
uart_puts("Current Excpetion Level ");
uart_hex_uint64(currel);
uart_puts(" Excpetion Type ");
uart_hex_uint64(type);
uart_puts(" Excpetion Syndrome Register ");
uart_hex_uint64(esr);
uart_puts(" Excpetion Link Register ");
uart_hex_uint64(elr);
uart_puts(" Saved Program Status Register ");
uart_hex_uint64(spsr);
uart_puts(" Fault Register ");
uart_hex_uint64(far);
uart_puts("\n");
return;
}
void print_uint32(uint32_t reg){
wait_msec_st(1000000);
uart_puts("reg=");
uart_hex_uint32((unsigned int)reg);
uart_puts("\n");
return;
}
void print_uint64(uint64_t reg){
wait_msec_st(1000000);
uart_puts("reg=");
uart_hex_uint64((unsigned long long)reg);
uart_puts("\n");
return;
}
void Happy_Birthday_Mattia_By_PiiRace(){
int i = 0;
wait_msec_st(3000000);
uart_puts("Starting PiRace1.0\n");
wait_msec_st(3000000);
uart_puts("Happy Birdthday Mandino\n");
wait_msec_st(2000000);
uart_puts("By PiRace1.0 to Puntozer.0\n");
wait_msec_st(3000000);
uart_puts("Good Party guys :)\n");
for(;i < 200;i++)
uart_puts("Mandino\n");
wait_msec_st(2500000);
uart_puts("Ni viremu n´Sicilia Mandino!\n");
return;
}
void delay_test(){
uart_puts("Waiting 1000000 CPU cycles (ARM CPU): ");
wait_cycles(1000000);
uart_puts("OK\n");
uart_puts("Waiting 1000000 microsec (ARM CPU): ");
wait_msec(1000000);
uart_puts("OK\n");
uart_puts("Waiting 1000000 microsec (BCM System Timer): ");
if(get_system_timer()==0) {
uart_puts("Not available\n");
} else {
wait_msec_st(1000000);
uart_puts("OK\n");
}
}
char OS_NAME [] = "BrainOS";
char OS_LEVEL [] = "Root";
char DIRECTORY [] = "/Home/Desktop";
#define ROOT_ID 0
void timer_err_handler(){
uart_puts("Timer error");
}
void timer_fiq_handler(){
uart_puts("Timer fiq");
}
void timer_irq_handler(){
uart_puts("Timer irq");
}
void timer_sync_handler(){
uart_puts("Timer synch");
}
void main()
{
register uint32_t i;
register uint8_t t_owner = ROOT_ID;
register uint32_t t_load = 1024;
uart_puts("\n\n\n------------------------------------------------------------------\n");
uart_puts(" Bootstap Brain OS -\n");
uart_puts("------------------------------------------------------------------------\n");
// Timer initialization function: MUST BE CALLED BEFORE EVERY OPERATION
//timer_boot();
//Acquire timer
timer_boot();
timer_init(1, 1, 0x0000ffff, 1, 1, 0, 0, 0);
uart_puts("\nTimer control ");
uart_hex_uint32(timer_ctrl_get());
uart_puts("\n");
uart_puts("Timer load ");
uart_hex_uint32(timer_load_get());
uart_puts("\n");
uart_puts("Timer value ");
uart_hex_uint32(timer_val_get());
uart_puts("\n");
uart_puts("Timer raw irq ");
uart_hex_uint32(timer_irq_raw_get());
uart_puts("\n");
uart_puts("Timer irq mask ");
uart_hex_uint32(timer_irq_mask_get());
uart_puts("\n");
uart_puts("System timer value ");
uart_hex_uint64(sys_timer_cnt_get());
uart_puts("\n");
spi_init(0, 0, 0, 3, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0);
/*spi_open(ROOT_ID);
spi_write(ROOT_ID, 12000);
*/
uart_puts("\n\n\n------------------------------------------------------------------\n");
uart_puts(" Bootstap Brain OS Successfully Completed \n");
uart_puts("------------------------------------------------------------------------\n");
/*
while(1){
char uart_input;
uart_puts("@");
uart_puts(OS_LEVEL);
uart_puts("-");
uart_puts(OS_NAME);
uart_puts(":~");
uart_puts(DIRECTORY);
uart_puts("$ ");
while((uart_input = uart_getc()) != '\n'){
uart_send(((unsigned int)uart_input) - 32);
}
uart_puts("\n");
}*/
}