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

Subversion Repositories openrisc

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

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 2 marcus.erl
#include "int.h"
8
 
9
#include "build.h"
10
 
11
#define MAX_COMMANDS  100
12
 
13
bd_t bd;
14
 
15
int num_commands = 0;
16
 
17
command_struct command[MAX_COMMANDS];
18
 
19 406 julius
void putc(const char c)
20 2 marcus.erl
{
21 406 julius
        debug("putc %i, %i = %c\n", bd.bi_console_type, c, c);
22
        switch (bd.bi_console_type) {
23
        case CT_NONE:
24
                break;
25
        case CT_UART:
26
                uart_putc(c);
27
                break;
28 140 julius
#if CRT_ENABLED==1
29 406 julius
        case CT_CRT:
30
                screen_putc(c);
31
                break;
32 140 julius
#endif
33 406 julius
        case CT_SIM:
34
                __printf("%c", c);
35
                break;
36 464 julius
        default:
37
                break;
38 406 julius
        }
39 2 marcus.erl
}
40
 
41 406 julius
int getc()
42 2 marcus.erl
{
43 406 julius
        int ch = 0;
44
        debug("getc %i\n", bd.bi_console_type);
45
        switch (bd.bi_console_type) {
46 140 julius
#if KBD_ENABLED==1
47 406 julius
        case CT_CRT:
48
                while ((volatile int)kbd_head == (volatile int)kbd_tail) ;
49
                ch = kbd_buf[kbd_tail];
50
                kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE;
51
                return ch;
52 2 marcus.erl
#endif
53 406 julius
        case CT_UART:
54
                return uart_getc();
55
                break;
56
        case CT_NONE:           /* just to satisfy the compiler */
57
        case CT_SIM:
58 467 julius
        default:
59 406 julius
                break;
60
        }
61
        return -1;
62 2 marcus.erl
}
63
 
64 406 julius
int testc()
65 2 marcus.erl
{
66 406 julius
        debug("testc %i\n", bd.bi_console_type);
67
        switch (bd.bi_console_type) {
68 2 marcus.erl
#if KBD_ENABLED
69 406 julius
        case CT_CRT:
70
                if (kbd_head == kbd_tail)
71
                        return 0;
72
                else
73
                        return getc();
74 2 marcus.erl
#endif
75 406 julius
        case CT_UART:
76
                return uart_testc();
77
                break;
78
        case CT_NONE:           /* just to satisfy the compiler */
79
        case CT_SIM:
80 467 julius
        default:
81 406 julius
                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 467 julius
 
169 406 julius
        bd.bi_console_type = con_type;
170 467 julius
 
171
        /* Initialize new */
172 406 julius
        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 467 julius
 
299 2 marcus.erl
/* Displays help screen */
300 406 julius
int help_cmd(int argc, char *argv[])
301 2 marcus.erl
{
302 467 julius
#if HELP_ENABLED        
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 467 julius
        printf("Info: Stack section addr 0x%x\n", (unsigned long)&_stack_top);
315 406 julius
        printf("Build tag: %s", BUILD_VERSION);
316 467 julius
#endif /* HELP_ENABLED */
317 406 julius
        return 0;
318 2 marcus.erl
}
319
 
320 467 julius
 
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 467 julius
        global.src_addr = 0;
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 467 julius
 
405
 
406 2 marcus.erl
/* Main shell loop */
407
int main(int argc, char **argv)
408
{
409 406 julius
        timestamp = 0;           // clear timer counter
410 246 julius
 
411 467 julius
        /* Init. interface */
412 406 julius
        change_console_type(CONSOLE_TYPE);
413 2 marcus.erl
 
414 467 julius
        /* Init. processor interrupt handlers */
415
        int_init();
416
 
417
        /* Enable interrupts in processor */
418 406 julius
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
419
 
420 467 julius
        /* Initialise commands we'll handle */
421
        num_commands = 0;
422 246 julius
 
423 406 julius
        mon_init();
424 467 julius
 
425
        /* Init processor timers */
426 406 julius
        tick_init();
427 246 julius
 
428 406 julius
        if (HELP_ENABLED)
429
                register_command("help", "", "shows this help", help_cmd);
430 2 marcus.erl
 
431 406 julius
        printf("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
432
        printf("\tbuild: %s", BUILD_VERSION);
433 2 marcus.erl
 
434 406 julius
        // Loop forever, accepting commands
435
        while (1) {
436
                mon_command();
437
        }
438 246 julius
 
439 2 marcus.erl
}

powered by: WebSVN 2.1.0

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