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 313

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 2 marcus.erl
extern unsigned long src_addr;
16
 
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
      if (c == '\r' || c == '\f' || c == '\n')
220
        {
221
          // Mark end of string
222
          *pstr = '\0';
223
          putc('\n');
224
          break;
225
        }
226
      else if (c == '\b') // Backspace
227
        {
228
          if (chcnt > 0)
229
            {
230
              putc(c);
231
              putc(' '); // cover char with space
232
              putc(c);
233
              pstr--;
234
              chcnt--;
235
            }
236
        }
237
      else
238
        {
239
          putc(c);
240
          *pstr++ = c;
241
          chcnt++;
242
        }
243
    }
244 2 marcus.erl
 
245
  /* Skip leading blanks */
246
  pstr = str;
247
  while (*pstr == ' ' && *pstr != '\0') pstr++;
248
 
249
  /* Get command from the string */
250
  command_str = pstr;
251
 
252
  while (1) {
253
    /* Go to next argument */
254
    while (*pstr != ' ' && *pstr != '\0') pstr++;
255
    if (*pstr) {
256
      *pstr++ = '\0';
257
      while (*pstr == ' ') pstr++;
258
      argv[argc++] = pstr;
259
    }
260
    else
261
      break;
262
  }
263
 
264
  {
265
    int i, found = 0;
266
 
267
    for (i = 0; i < num_commands; i++)
268
      if (strcmp (command_str, command[i].name) == 0)
269
      {
270
        switch ( command[i].func(argc, &argv[0]) )
271
        {
272
          case -1:
273 246 julius
            printf ("Missing/wrong parameters, usage: %s %s\n",
274
                    command[i].name, command[i].params);
275 2 marcus.erl
            break;
276
        }
277
 
278
        found++;
279
        break;
280
      }
281
    /* 'built-in' build command */
282
    if(strcmp(command_str, "build") == 0) {
283
      printf("Build tag: %s", BUILD_VERSION);
284
      found++;
285
    }
286
    if (!found)
287
      printf ("Unknown command. Type 'help' for help.\n");
288
  }
289
 
290
}
291
 
292
#if HELP_ENABLED
293 246 julius
extern unsigned long src_addr; // Stack section ends here, will print it out
294 2 marcus.erl
/* Displays help screen */
295
int help_cmd (int argc, char *argv[])
296
{
297
  int i;
298
  for (i = 0; i < num_commands; i++)
299
    printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
300 140 julius
 
301
  // Build info....
302
  printf("\n");
303 246 julius
  printf("CPU info\n");
304
  printf("Frequency\t\t%dMHz\n", IN_CLK/1000000);
305
  print_or1k_cache_info();
306
  printf("\n");
307 140 julius
  printf("Info: Stack section addr 0x%x\n",(unsigned long) &src_addr);
308
  printf("Build tag: %s", BUILD_VERSION);
309
 
310 2 marcus.erl
  return 0;
311
}
312
#endif /* HELP_ENABLED */
313
 
314
void module_cpu_init (void);
315
void module_memory_init (void);
316
void module_eth_init (void);
317
void module_dhry_init (void);
318
void module_camera_init (void);
319
void module_load_init (void);
320
void tick_init(void);
321
void module_touch_init (void);
322
void module_ata_init (void);
323
void module_hdbug_init (void);
324
 
325
 
326
/* List of all initializations */
327
void mon_init (void)
328
{
329
  /* Set defaults */
330
  global.erase_method = 2; /* as needed */
331
  global.src_addr = (unsigned long)&src_addr;
332
  global.dst_addr = FLASH_BASE_ADDR;
333
  global.eth_add[0] = ETH_MACADDR0;
334
  global.eth_add[1] = ETH_MACADDR1;
335
  global.eth_add[2] = ETH_MACADDR2;
336
  global.eth_add[3] = ETH_MACADDR3;
337
  global.eth_add[4] = ETH_MACADDR4;
338
  global.eth_add[5] = ETH_MACADDR5;
339
  global.ip = BOARD_DEF_IP;
340
  global.gw_ip = BOARD_DEF_GW;
341
  global.mask = BOARD_DEF_MASK;
342 140 julius
 
343
#define CPU_CMDS
344
#define MEM_CMDS
345
#define DHRY_CMDS
346
  //#define CAMERA_CMDS
347
#define LOAD_CMDS
348
    //#define TOUCHSCREEN_CMDS
349
    //#define ATA_CMDS
350
    //#define HDBUG_CMDS
351
#define TICK_CMDS
352
#define ETH_CMDS
353
#define LOAD_CMDS
354 2 marcus.erl
 
355
  /* Init modules */
356 140 julius
#ifdef CPU_CMDS
357 2 marcus.erl
  module_cpu_init ();
358 140 julius
#endif
359
#ifdef MEM_CMDS
360 2 marcus.erl
  module_memory_init ();
361 140 julius
#endif
362
#ifdef ETH_CMDS
363 2 marcus.erl
  module_eth_init ();
364 140 julius
#endif
365
#ifdef DHRY_CMDS
366 2 marcus.erl
  module_dhry_init ();
367 140 julius
#endif
368
#ifdef CAMERA_CMDS
369 2 marcus.erl
  module_camera_init ();
370 140 julius
#endif
371
#ifdef LOAD_CMDS
372 2 marcus.erl
  module_load_init ();
373 140 julius
#endif
374
#ifdef TOUCHSCREEN_CMDS
375 2 marcus.erl
  module_touch_init ();
376 140 julius
#endif
377
#ifdef ATA_CMDS
378 2 marcus.erl
  module_ata_init ();
379 140 julius
#endif
380
#ifdef HDBUG_CMDS
381 2 marcus.erl
  module_hdbug_init ();
382 140 julius
#endif
383 2 marcus.erl
 
384 246 julius
#ifdef TICK_CMDS
385
#endif
386 140 julius
 
387 2 marcus.erl
}
388 140 julius
int tboot_cmd (int argc, char *argv[]);
389 2 marcus.erl
/* Main shell loop */
390
int main(int argc, char **argv)
391
{
392
  extern unsigned long calc_mycrc32 (void);
393 246 julius
 
394 2 marcus.erl
#if 0
395
  extern unsigned long mycrc32, mysize;
396
#endif
397 246 julius
 
398 140 julius
  timestamp = 0; // clear timer counter
399 2 marcus.erl
 
400
  int_init ();
401 246 julius
 
402 2 marcus.erl
  change_console_type (CONSOLE_TYPE);
403 246 julius
 
404 2 marcus.erl
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
405
 
406
#if SELF_CHECK
407
  printf ("Self check... ");
408
  if ((t = calc_mycrc32 ()))
409
      printf ("FAILED!!!\n");
410
  else
411
      printf ("OK\n");
412
#endif /* SELF_CHECK */
413 246 julius
 
414 140 julius
  num_commands=0;
415 2 marcus.erl
  mon_init ();
416
 
417 246 julius
  disable_spincursor();
418
 
419
  tick_init();
420
 
421
 
422 2 marcus.erl
  if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
423
 
424 140 julius
  printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
425
  printf("\tbuild: %s", BUILD_VERSION);
426 2 marcus.erl
 
427 246 julius
  // Loop forever, accepting commands
428
  while(1)
429
    {
430
      mon_command();
431
    }
432
 
433 2 marcus.erl
}

powered by: WebSVN 2.1.0

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