OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [common/] [common.c] - Blame information for rev 447

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
#include "common.h"
2
#include "uart.h"
3
#include "screen.h"
4
#include "support.h"
5
#include "keyboard.h"
6 246 julius
#include "spr-defs.h"
7
#include "spincursor.h"
8 2 marcus.erl
#include "int.h"
9
 
10
#include "build.h"
11
 
12
#define MAX_COMMANDS  100
13
 
14 246 julius
// Value from linker script
15 375 julius
extern unsigned long _src_addr;
16 2 marcus.erl
 
17
bd_t bd;
18
 
19
int num_commands = 0;
20
 
21
command_struct command[MAX_COMMANDS];
22
 
23 406 julius
void putc(const char c)
24 2 marcus.erl
{
25 406 julius
        debug("putc %i, %i = %c\n", bd.bi_console_type, c, c);
26
        switch (bd.bi_console_type) {
27
        case CT_NONE:
28
                break;
29
        case CT_UART:
30
                uart_putc(c);
31
                break;
32 140 julius
#if CRT_ENABLED==1
33 406 julius
        case CT_CRT:
34
                screen_putc(c);
35
                break;
36 140 julius
#endif
37 406 julius
        case CT_SIM:
38
                __printf("%c", c);
39
                break;
40
        }
41 2 marcus.erl
}
42
 
43 406 julius
int getc()
44 2 marcus.erl
{
45 406 julius
        int ch = 0;
46
        debug("getc %i\n", bd.bi_console_type);
47
        switch (bd.bi_console_type) {
48 140 julius
#if KBD_ENABLED==1
49 406 julius
        case CT_CRT:
50
                while ((volatile int)kbd_head == (volatile int)kbd_tail) ;
51
                ch = kbd_buf[kbd_tail];
52
                kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE;
53
                return ch;
54 2 marcus.erl
#endif
55 406 julius
        case CT_UART:
56
                return uart_getc();
57
                break;
58
        case CT_NONE:           /* just to satisfy the compiler */
59
        case CT_SIM:
60
                break;
61
        }
62
        return -1;
63 2 marcus.erl
}
64
 
65 406 julius
int testc()
66 2 marcus.erl
{
67 406 julius
        debug("testc %i\n", bd.bi_console_type);
68
        switch (bd.bi_console_type) {
69 2 marcus.erl
#if KBD_ENABLED
70 406 julius
        case CT_CRT:
71
                if (kbd_head == kbd_tail)
72
                        return 0;
73
                else
74
                        return getc();
75 2 marcus.erl
#endif
76 406 julius
        case CT_UART:
77
                return uart_testc();
78
                break;
79
        case CT_NONE:           /* just to satisfy the compiler */
80
        case CT_SIM:
81
                break;
82
        }
83
        return -1;
84 2 marcus.erl
}
85
 
86 406 julius
int ctrlc()
87 2 marcus.erl
{
88 406 julius
        if (testc()) {
89
                switch (getc()) {
90
                case 0x03:      /* ^C - Control C */
91
                        return 1;
92
                default:
93
                        break;
94
                }
95
        }
96
        return 0;
97 2 marcus.erl
}
98
 
99 406 julius
void print_or1k_cache_info()
100 246 julius
{
101 406 julius
        // Read out UPR, check what modules we have
102
        unsigned long upr = mfspr(SPR_UPR);
103
        printf("Instruction cache:\t");
104
        if (upr & SPR_UPR_ICP) {
105
                // We have instruction cache, read out ICCFGR
106 246 julius
 
107 406 julius
                unsigned long iccfgr = mfspr(SPR_ICCFGR);
108
                unsigned int cbs;       // cache block size
109
                unsigned long ncs = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
110
                if (iccfgr & SPR_ICCFGR_CBS)
111
                        cbs = 32;
112
                else
113
                        cbs = 16;
114 246 julius
 
115 406 julius
                printf("%dkB (BS: %d Sets: %d)\n",
116
                       (cbs * ncs) / 1024, cbs, ncs);
117 246 julius
 
118 406 julius
        } else
119
                printf(" not present\n");
120
 
121
        printf("Data cache:\t\t");
122
        if (upr & SPR_UPR_DCP) {
123
                // We have instruction cache, read out DCCFGR
124
 
125
                unsigned long iccfgr = mfspr(SPR_DCCFGR);
126
                unsigned int cbs;       // cache block size
127
                unsigned long ncs = 1 << ((iccfgr & SPR_DCCFGR_NCS) >> 3);
128
                if (iccfgr & SPR_DCCFGR_CBS)
129
                        cbs = 32;
130
                else
131
                        cbs = 16;
132
 
133
                printf("%dkB (BS: %d Sets: %d)\n",
134
                       (cbs * ncs) / 1024, cbs, ncs);
135
 
136
        } else
137
                printf(" not present\n");
138
 
139 246 julius
}
140
 
141 406 julius
unsigned long parse_ip(char *ip)
142 2 marcus.erl
{
143 406 julius
        unsigned long num;
144
        num = strtoul(ip, &ip, 10) & 0xff;
145
        if (*ip++ != '.')
146
                return 0;
147
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
148
        if (*ip++ != '.')
149
                return 0;
150
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
151
        if (*ip++ != '.')
152
                return 0;
153
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
154
        return num;
155 2 marcus.erl
}
156
 
157 406 julius
void change_console_type(enum bi_console_type_t con_type)
158 2 marcus.erl
{
159 406 julius
        debug("Console change %i -> %i\n", bd.bi_console_type, con_type);
160
        /* Close previous */
161
        switch (bd.bi_console_type) {
162
        case CT_NONE:
163
        case CT_UART:
164
        case CT_CRT:
165
        case CT_SIM:
166
                break;
167
        }
168
        bd.bi_console_type = con_type;
169
        /* Initialize new */
170
        switch (bd.bi_console_type) {
171
        case CT_NONE:
172
                break;
173
        case CT_UART:
174
                uart_init();
175
                break;
176
        case CT_CRT:
177 140 julius
#if CRT_ENABLED==1
178 406 julius
                screen_init();
179 2 marcus.erl
#endif
180
#if KBD_ENABLED
181 406 julius
                kbd_init();
182 2 marcus.erl
#endif
183 406 julius
                break;
184
        case CT_SIM:
185
                break;
186
        }
187 2 marcus.erl
}
188
 
189 406 julius
void register_command_func(const char *name, const char *params,
190
                           const char *help, int (*func) (int argc,
191
                                                          char *argv[]))
192 2 marcus.erl
{
193 406 julius
        debug("register_command '%s'\n", name);
194
        if (num_commands < MAX_COMMANDS) {
195
                command[num_commands].name = name;
196
                command[num_commands].params = params;
197
                command[num_commands].help = help;
198
                command[num_commands].func = func;
199
                num_commands++;
200
        } else
201
                printf("Command '%s' ignored; MAX_COMMANDS limit reached\n",
202
                       name);
203 2 marcus.erl
}
204
 
205
/* Process command and arguments by executing
206
   specific function. */
207
void mon_command(void)
208
{
209 406 julius
        char c = '\0';
210
        char str[1000];
211
        char *pstr = str;
212
        char *command_str;
213
        char *argv[20];
214
        int argc = 0;
215
        int chcnt = 0;
216 2 marcus.erl
 
217 406 julius
        /* Show prompt */
218
        printf("\n" BOARD_DEF_NAME "> ");
219 2 marcus.erl
 
220 406 julius
        while (1) {
221
                c = getc();
222 375 julius
 
223 406 julius
                if (c == 0x7f)  // Backspace on picocom is showing up as 0x7f
224
                        c = '\b';
225 375 julius
 
226 406 julius
                if (c == '\r' || c == '\f' || c == '\n') {
227
                        // Mark end of string
228
                        *pstr = '\0';
229
                        putc('\n');
230
                        break;
231
                } else if (c == '\b')   // Backspace
232
                {
233
                        if (chcnt > 0) {
234
                                putc(c);
235
                                putc(' ');      // cover char with space
236
                                putc(c);
237
                                pstr--;
238
                                chcnt--;
239
                        }
240
                } else {
241
                        putc(c);
242
                        *pstr++ = c;
243
                        chcnt++;
244
                }
245 246 julius
        }
246 2 marcus.erl
 
247 406 julius
        /* Skip leading blanks */
248
        pstr = str;
249
        while (*pstr == ' ' && *pstr != '\0')
250
                pstr++;
251 2 marcus.erl
 
252 406 julius
        /* Get command from the string */
253
        command_str = pstr;
254 2 marcus.erl
 
255 406 julius
        while (1) {
256
                /* Go to next argument */
257
                while (*pstr != ' ' && *pstr != '\0')
258
                        pstr++;
259
                if (*pstr) {
260
                        *pstr++ = '\0';
261
                        while (*pstr == ' ')
262
                                pstr++;
263
                        argv[argc++] = pstr;
264
                } else
265
                        break;
266
        }
267 2 marcus.erl
 
268 406 julius
        {
269
                int i, found = 0;
270 2 marcus.erl
 
271 406 julius
                for (i = 0; i < num_commands; i++)
272
                        if (strcmp(command_str, command[i].name) == 0) {
273
                                switch (command[i].func(argc, &argv[0])) {
274
                                case -1:
275
                                        printf
276
                                            ("Missing/wrong parameters, usage: %s %s\n",
277
                                             command[i].name,
278
                                             command[i].params);
279
                                        break;
280
                                }
281 2 marcus.erl
 
282 406 julius
                                found++;
283
                                break;
284
                        }
285
                /* 'built-in' build command */
286
                if (strcmp(command_str, "build") == 0) {
287
                        printf("Build tag: %s", BUILD_VERSION);
288
                        found++;
289
                }
290
                if (!found)
291
                        printf("Unknown command. Type 'help' for help.\n");
292
        }
293
 
294 2 marcus.erl
}
295
 
296
#if HELP_ENABLED
297 406 julius
extern unsigned long _src_addr; // Stack section ends here, will print it out
298 2 marcus.erl
/* Displays help screen */
299 406 julius
int help_cmd(int argc, char *argv[])
300 2 marcus.erl
{
301 406 julius
        int i;
302
        for (i = 0; i < num_commands; i++)
303
                printf("%-10s %-20s - %s\n", command[i].name, command[i].params,
304
                       command[i].help);
305 140 julius
 
306 406 julius
        // Build info....
307
        printf("\n");
308
        printf("CPU info\n");
309
        printf("Frequency\t\t%dMHz\n", IN_CLK / 1000000);
310
        print_or1k_cache_info();
311
        printf("\n");
312
        printf("Info: Stack section addr 0x%x\n", (unsigned long)&_src_addr);
313
        printf("Build tag: %s", BUILD_VERSION);
314 140 julius
 
315 406 julius
        return 0;
316 2 marcus.erl
}
317
#endif /* HELP_ENABLED */
318
 
319 406 julius
void module_cpu_init(void);
320
void module_memory_init(void);
321
void module_eth_init(void);
322
void module_dhry_init(void);
323
void module_coremark_init(void);
324
void module_camera_init(void);
325
void module_load_init(void);
326 2 marcus.erl
void tick_init(void);
327 406 julius
void module_touch_init(void);
328
void module_ata_init(void);
329
void module_hdbug_init(void);
330 2 marcus.erl
 
331
/* List of all initializations */
332 406 julius
void mon_init(void)
333 2 marcus.erl
{
334 406 julius
        /* Set defaults */
335
        global.erase_method = 2;        /* as needed */
336
        global.src_addr = (unsigned long)&_src_addr;
337
        global.dst_addr = FLASH_BASE_ADDR;
338
        global.eth_add[0] = ETH_MACADDR0;
339
        global.eth_add[1] = ETH_MACADDR1;
340
        global.eth_add[2] = ETH_MACADDR2;
341
        global.eth_add[3] = ETH_MACADDR3;
342
        global.eth_add[4] = ETH_MACADDR4;
343
        global.eth_add[5] = ETH_MACADDR5;
344
        global.ip = BOARD_DEF_IP;
345
        global.gw_ip = BOARD_DEF_GW;
346
        global.mask = BOARD_DEF_MASK;
347 140 julius
 
348
#define CPU_CMDS
349
#define MEM_CMDS
350
#define DHRY_CMDS
351 355 julius
#define COREMARK_CMDS
352 406 julius
        //#define CAMERA_CMDS
353 140 julius
#define LOAD_CMDS
354 406 julius
        //#define TOUCHSCREEN_CMDS
355
        //#define ATA_CMDS
356
        //#define HDBUG_CMDS
357 140 julius
#define TICK_CMDS
358
#define ETH_CMDS
359
#define LOAD_CMDS
360 406 julius
 
361
        /* Init modules */
362 140 julius
#ifdef CPU_CMDS
363 406 julius
        module_cpu_init();
364 140 julius
#endif
365
#ifdef MEM_CMDS
366 406 julius
        module_memory_init();
367 140 julius
#endif
368
#ifdef ETH_CMDS
369 406 julius
        module_eth_init();
370 140 julius
#endif
371
#ifdef DHRY_CMDS
372 406 julius
        module_dhry_init();
373 140 julius
#endif
374 355 julius
#ifdef COREMARK_CMDS
375 406 julius
        module_coremark_init();
376 355 julius
#endif
377 140 julius
#ifdef CAMERA_CMDS
378 406 julius
        module_camera_init();
379 140 julius
#endif
380
#ifdef LOAD_CMDS
381 406 julius
        module_load_init();
382 140 julius
#endif
383
#ifdef TOUCHSCREEN_CMDS
384 406 julius
        module_touch_init();
385 140 julius
#endif
386
#ifdef ATA_CMDS
387 406 julius
        module_ata_init();
388 140 julius
#endif
389
#ifdef HDBUG_CMDS
390 406 julius
        module_hdbug_init();
391 140 julius
#endif
392 2 marcus.erl
 
393 246 julius
#ifdef TICK_CMDS
394
#endif
395 140 julius
 
396 2 marcus.erl
}
397 406 julius
 
398
int tboot_cmd(int argc, char *argv[]);
399 2 marcus.erl
/* Main shell loop */
400
int main(int argc, char **argv)
401
{
402 406 julius
        extern unsigned long calc_mycrc32(void);
403 246 julius
 
404 2 marcus.erl
#if 0
405 406 julius
        extern unsigned long mycrc32, mysize;
406 2 marcus.erl
#endif
407 246 julius
 
408 406 julius
        timestamp = 0;           // clear timer counter
409 246 julius
 
410 406 julius
        int_init();
411 246 julius
 
412 406 julius
        change_console_type(CONSOLE_TYPE);
413 2 marcus.erl
 
414 406 julius
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
415
 
416 2 marcus.erl
#if SELF_CHECK
417 406 julius
        printf("Self check... ");
418
        if ((t = calc_mycrc32()))
419
                printf("FAILED!!!\n");
420
        else
421
                printf("OK\n");
422 2 marcus.erl
#endif /* SELF_CHECK */
423 246 julius
 
424 406 julius
        num_commands = 0;
425
        mon_init();
426 2 marcus.erl
 
427 406 julius
        disable_spincursor();
428 246 julius
 
429 406 julius
        tick_init();
430 246 julius
 
431 406 julius
        if (HELP_ENABLED)
432
                register_command("help", "", "shows this help", help_cmd);
433 2 marcus.erl
 
434 406 julius
        printf("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
435
        printf("\tbuild: %s", BUILD_VERSION);
436 2 marcus.erl
 
437 406 julius
        // Loop forever, accepting commands
438
        while (1) {
439
                mon_command();
440
        }
441 246 julius
 
442 2 marcus.erl
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.