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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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