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

Subversion Repositories openrisc

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

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
void putc (const char c)
24
{
25
  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 2 marcus.erl
  case CT_CRT:
34
    screen_putc (c);
35
    break;
36 140 julius
#endif
37 2 marcus.erl
  case CT_SIM:
38
    __printf ("%c", c);
39
    break;
40
  }
41
}
42
 
43
int getc ()
44
{
45
  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 2 marcus.erl
  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
#endif
55
  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
}
64
 
65
int testc ()
66
{
67
  debug ("testc %i\n", bd.bi_console_type);
68
  switch (bd.bi_console_type) {
69
#if KBD_ENABLED
70
  case CT_CRT:
71
    if (kbd_head == kbd_tail) return 0;
72
    else return getc ();
73
#endif
74
  case CT_UART:
75
    return uart_testc ();
76
    break;
77
  case CT_NONE: /* just to satisfy the compiler */
78
  case CT_SIM:
79
    break;
80
  }
81
  return -1;
82
}
83
 
84
int ctrlc ()
85
{
86
  if (testc ()) {
87
    switch (getc ()) {
88
      case 0x03:    /* ^C - Control C */
89
        return 1;
90
      default:
91
        break;
92
    }
93
  }
94
  return 0;
95
}
96
 
97 246 julius
void
98
print_or1k_cache_info()
99
{
100
  // Read out UPR, check what modules we have
101
  unsigned long upr = mfspr(SPR_UPR);
102
  printf("Instruction cache:\t");
103
  if (upr & SPR_UPR_ICP)
104
    {
105
      // We have instruction cache, read out ICCFGR
106
 
107
      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
 
115
      printf("%dkB (BS: %d Sets: %d)\n",
116
             (cbs * ncs)/1024, cbs, ncs);
117
 
118
    }
119
  else
120
    printf(" not present\n");
121
 
122
  printf("Data cache:\t\t");
123
  if (upr & SPR_UPR_DCP)
124
    {
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
    }
139
  else
140
    printf(" not present\n");
141
 
142
}
143
 
144 2 marcus.erl
unsigned long parse_ip (char *ip)
145
{
146
  unsigned long num;
147
  num = strtoul (ip, &ip, 10) & 0xff;
148
  if (*ip++ != '.') return 0;
149
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
150
  if (*ip++ != '.') return 0;
151
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
152
  if (*ip++ != '.') return 0;
153
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
154
  return num;
155
}
156
 
157
void change_console_type (enum bi_console_type_t con_type)
158
{
159
  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 2 marcus.erl
    screen_init ();
179
#endif
180
#if KBD_ENABLED
181
    kbd_init ();
182
#endif
183
    break;
184
  case CT_SIM:
185
    break;
186
  }
187
}
188
 
189
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]))
190
{
191
  debug ("register_command '%s'\n", name);
192
  if (num_commands < MAX_COMMANDS) {
193
    command[num_commands].name = name;
194
    command[num_commands].params = params;
195
    command[num_commands].help = help;
196
    command[num_commands].func = func;
197
    num_commands++;
198
  } else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name);
199
}
200
 
201
/* Process command and arguments by executing
202
   specific function. */
203
void mon_command(void)
204
{
205
  char c = '\0';
206
  char str[1000];
207
  char *pstr = str;
208
  char *command_str;
209
  char *argv[20];
210
  int argc = 0;
211 246 julius
  int chcnt = 0;
212 2 marcus.erl
 
213
  /* Show prompt */
214
  printf ("\n" BOARD_DEF_NAME"> ");
215
 
216 246 julius
  while(1)
217
    {
218
      c=getc();
219 375 julius
 
220
      if (c == 0x7f) // Backspace on picocom is showing up as 0x7f
221
        c = '\b';
222
 
223 246 julius
      if (c == '\r' || c == '\f' || c == '\n')
224
        {
225
          // Mark end of string
226
          *pstr = '\0';
227
          putc('\n');
228
          break;
229
        }
230
      else if (c == '\b') // Backspace
231
        {
232
          if (chcnt > 0)
233
            {
234
              putc(c);
235
              putc(' '); // cover char with space
236
              putc(c);
237
              pstr--;
238
              chcnt--;
239
            }
240
        }
241
      else
242
        {
243
          putc(c);
244
          *pstr++ = c;
245
          chcnt++;
246
        }
247
    }
248 2 marcus.erl
 
249
  /* Skip leading blanks */
250
  pstr = str;
251
  while (*pstr == ' ' && *pstr != '\0') pstr++;
252
 
253
  /* Get command from the string */
254
  command_str = pstr;
255
 
256
  while (1) {
257
    /* Go to next argument */
258
    while (*pstr != ' ' && *pstr != '\0') pstr++;
259
    if (*pstr) {
260
      *pstr++ = '\0';
261
      while (*pstr == ' ') pstr++;
262
      argv[argc++] = pstr;
263
    }
264
    else
265
      break;
266
  }
267
 
268
  {
269
    int i, found = 0;
270
 
271
    for (i = 0; i < num_commands; i++)
272
      if (strcmp (command_str, command[i].name) == 0)
273
      {
274
        switch ( command[i].func(argc, &argv[0]) )
275
        {
276
          case -1:
277 246 julius
            printf ("Missing/wrong parameters, usage: %s %s\n",
278
                    command[i].name, command[i].params);
279 2 marcus.erl
            break;
280
        }
281
 
282
        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
}
295
 
296
#if HELP_ENABLED
297 375 julius
extern unsigned long _src_addr; // Stack section ends here, will print it out
298 2 marcus.erl
/* Displays help screen */
299
int help_cmd (int argc, char *argv[])
300
{
301
  int i;
302
  for (i = 0; i < num_commands; i++)
303
    printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
304 140 julius
 
305
  // Build info....
306
  printf("\n");
307 246 julius
  printf("CPU info\n");
308
  printf("Frequency\t\t%dMHz\n", IN_CLK/1000000);
309
  print_or1k_cache_info();
310
  printf("\n");
311 375 julius
  printf("Info: Stack section addr 0x%x\n",(unsigned long) &_src_addr);
312 140 julius
  printf("Build tag: %s", BUILD_VERSION);
313
 
314 2 marcus.erl
  return 0;
315
}
316
#endif /* HELP_ENABLED */
317
 
318
void module_cpu_init (void);
319
void module_memory_init (void);
320
void module_eth_init (void);
321
void module_dhry_init (void);
322 355 julius
void module_coremark_init (void);
323 2 marcus.erl
void module_camera_init (void);
324
void module_load_init (void);
325
void tick_init(void);
326
void module_touch_init (void);
327
void module_ata_init (void);
328
void module_hdbug_init (void);
329
 
330
 
331
/* List of all initializations */
332
void mon_init (void)
333
{
334
  /* Set defaults */
335
  global.erase_method = 2; /* as needed */
336 375 julius
  global.src_addr = (unsigned long)&_src_addr;
337 2 marcus.erl
  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 140 julius
  //#define CAMERA_CMDS
353
#define LOAD_CMDS
354
    //#define TOUCHSCREEN_CMDS
355
    //#define ATA_CMDS
356
    //#define HDBUG_CMDS
357
#define TICK_CMDS
358
#define ETH_CMDS
359
#define LOAD_CMDS
360 2 marcus.erl
 
361
  /* Init modules */
362 140 julius
#ifdef CPU_CMDS
363 2 marcus.erl
  module_cpu_init ();
364 140 julius
#endif
365
#ifdef MEM_CMDS
366 2 marcus.erl
  module_memory_init ();
367 140 julius
#endif
368
#ifdef ETH_CMDS
369 2 marcus.erl
  module_eth_init ();
370 140 julius
#endif
371
#ifdef DHRY_CMDS
372 2 marcus.erl
  module_dhry_init ();
373 140 julius
#endif
374 355 julius
#ifdef COREMARK_CMDS
375
  module_coremark_init ();
376
#endif
377 140 julius
#ifdef CAMERA_CMDS
378 2 marcus.erl
  module_camera_init ();
379 140 julius
#endif
380
#ifdef LOAD_CMDS
381 2 marcus.erl
  module_load_init ();
382 140 julius
#endif
383
#ifdef TOUCHSCREEN_CMDS
384 2 marcus.erl
  module_touch_init ();
385 140 julius
#endif
386
#ifdef ATA_CMDS
387 2 marcus.erl
  module_ata_init ();
388 140 julius
#endif
389
#ifdef HDBUG_CMDS
390 2 marcus.erl
  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 140 julius
int tboot_cmd (int argc, char *argv[]);
398 2 marcus.erl
/* Main shell loop */
399
int main(int argc, char **argv)
400
{
401
  extern unsigned long calc_mycrc32 (void);
402 246 julius
 
403 2 marcus.erl
#if 0
404
  extern unsigned long mycrc32, mysize;
405
#endif
406 246 julius
 
407 140 julius
  timestamp = 0; // clear timer counter
408 2 marcus.erl
 
409
  int_init ();
410 246 julius
 
411 2 marcus.erl
  change_console_type (CONSOLE_TYPE);
412 246 julius
 
413 2 marcus.erl
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
414
 
415
#if SELF_CHECK
416
  printf ("Self check... ");
417
  if ((t = calc_mycrc32 ()))
418
      printf ("FAILED!!!\n");
419
  else
420
      printf ("OK\n");
421
#endif /* SELF_CHECK */
422 246 julius
 
423 140 julius
  num_commands=0;
424 2 marcus.erl
  mon_init ();
425
 
426 246 julius
  disable_spincursor();
427
 
428
  tick_init();
429
 
430
 
431 2 marcus.erl
  if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
432
 
433 140 julius
  printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
434
  printf("\tbuild: %s", BUILD_VERSION);
435 2 marcus.erl
 
436 246 julius
  // Loop forever, accepting commands
437
  while(1)
438
    {
439
      mon_command();
440
    }
441
 
442 2 marcus.erl
}

powered by: WebSVN 2.1.0

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