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

Subversion Repositories openrisc

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

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
#include "spr_defs.h"
7
#include "int.h"
8
 
9
#include "build.h"
10
 
11
#define MAX_COMMANDS  100
12
 
13
extern unsigned long src_addr;
14
 
15
bd_t bd;
16
 
17
int num_commands = 0;
18
 
19
command_struct command[MAX_COMMANDS];
20
 
21
void putc (const char c)
22
{
23
  debug ("putc %i, %i = %c\n", bd.bi_console_type, c, c);
24
  switch (bd.bi_console_type) {
25
  case CT_NONE:
26
    break;
27
  case CT_UART:
28
    uart_putc (c);
29
    break;
30 140 julius
#if CRT_ENABLED==1
31 2 marcus.erl
  case CT_CRT:
32
    screen_putc (c);
33
    break;
34 140 julius
#endif
35 2 marcus.erl
  case CT_SIM:
36
    __printf ("%c", c);
37
    break;
38
  }
39
}
40
 
41
int getc ()
42
{
43
  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 2 marcus.erl
  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
#endif
53
  case CT_UART:
54
    return uart_getc ();
55
    break;
56
  case CT_NONE: /* just to satisfy the compiler */
57
  case CT_SIM:
58
    break;
59
  }
60
  return -1;
61
}
62
 
63
int testc ()
64
{
65
  debug ("testc %i\n", bd.bi_console_type);
66
  switch (bd.bi_console_type) {
67
#if KBD_ENABLED
68
  case CT_CRT:
69
    if (kbd_head == kbd_tail) return 0;
70
    else return getc ();
71
#endif
72
  case CT_UART:
73
    return uart_testc ();
74
    break;
75
  case CT_NONE: /* just to satisfy the compiler */
76
  case CT_SIM:
77
    break;
78
  }
79
  return -1;
80
}
81
 
82
int ctrlc ()
83
{
84
  if (testc ()) {
85
    switch (getc ()) {
86
      case 0x03:    /* ^C - Control C */
87
        return 1;
88
      default:
89
        break;
90
    }
91
  }
92
  return 0;
93
}
94
 
95
unsigned long parse_ip (char *ip)
96
{
97
  unsigned long num;
98
  num = strtoul (ip, &ip, 10) & 0xff;
99
  if (*ip++ != '.') return 0;
100
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
101
  if (*ip++ != '.') return 0;
102
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
103
  if (*ip++ != '.') return 0;
104
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
105
  return num;
106
}
107
 
108
void change_console_type (enum bi_console_type_t con_type)
109
{
110
  debug ("Console change %i -> %i\n", bd.bi_console_type, con_type);
111
  /* Close previous */
112
  switch (bd.bi_console_type) {
113
  case CT_NONE:
114
  case CT_UART:
115
  case CT_CRT:
116
  case CT_SIM:
117
    break;
118
  }
119
  bd.bi_console_type = con_type;
120
  /* Initialize new */
121
  switch (bd.bi_console_type) {
122
  case CT_NONE:
123
    break;
124
  case CT_UART:
125
    uart_init ();
126
    break;
127
  case CT_CRT:
128 140 julius
#if CRT_ENABLED==1
129 2 marcus.erl
    screen_init ();
130
#endif
131
#if KBD_ENABLED
132
    kbd_init ();
133
#endif
134
    break;
135
  case CT_SIM:
136
    break;
137
  }
138
}
139
 
140
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]))
141
{
142
  debug ("register_command '%s'\n", name);
143
  if (num_commands < MAX_COMMANDS) {
144
    command[num_commands].name = name;
145
    command[num_commands].params = params;
146
    command[num_commands].help = help;
147
    command[num_commands].func = func;
148
    num_commands++;
149
  } else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name);
150
}
151
 
152
/* Process command and arguments by executing
153
   specific function. */
154
void mon_command(void)
155
{
156
  char c = '\0';
157
  char str[1000];
158
  char *pstr = str;
159
  char *command_str;
160
  char *argv[20];
161
  int argc = 0;
162
 
163
  /* Show prompt */
164
#ifdef XESS
165
  printf ("\norp-xsv> ");
166
#else
167
  printf ("\n" BOARD_DEF_NAME"> ");
168
#endif
169
 
170
  /* Get characters from UART */
171
  c = getc();
172
  while (c != '\r' && c != '\f' && c != '\n')
173
  {
174
    if (c == '\b')
175
      pstr--;
176
    else
177
      *pstr++ = c;
178
    putc(c);
179
    c = getc();
180
  }
181
  *pstr = '\0';
182
  printf ("\n");
183
 
184
  /* Skip leading blanks */
185
  pstr = str;
186
  while (*pstr == ' ' && *pstr != '\0') pstr++;
187
 
188
  /* Get command from the string */
189
  command_str = pstr;
190
 
191
  while (1) {
192
    /* Go to next argument */
193
    while (*pstr != ' ' && *pstr != '\0') pstr++;
194
    if (*pstr) {
195
      *pstr++ = '\0';
196
      while (*pstr == ' ') pstr++;
197
      argv[argc++] = pstr;
198
    }
199
    else
200
      break;
201
  }
202
 
203
  {
204
    int i, found = 0;
205
 
206
    for (i = 0; i < num_commands; i++)
207
      if (strcmp (command_str, command[i].name) == 0)
208
      {
209
        switch ( command[i].func(argc, &argv[0]) )
210
        {
211
          case -1:
212
            printf ("Missing/wrong parameters, usage: %s %s\n", command[i].name, command[i].params);
213
            break;
214
        }
215
 
216
        found++;
217
        break;
218
      }
219
    /* 'built-in' build command */
220
    if(strcmp(command_str, "build") == 0) {
221
      printf("Build tag: %s", BUILD_VERSION);
222
      found++;
223
    }
224
    if (!found)
225
      printf ("Unknown command. Type 'help' for help.\n");
226
  }
227
 
228
}
229
 
230
#if HELP_ENABLED
231 140 julius
extern unsigned long src_addr; // Stack section ends here
232 2 marcus.erl
/* Displays help screen */
233
int help_cmd (int argc, char *argv[])
234
{
235
  int i;
236
  for (i = 0; i < num_commands; i++)
237
    printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
238 140 julius
 
239
  // Build info....
240
  printf("Info: CPU@ %dMHz", IN_CLK/1000000);
241
#if IC_ENABLE==1
242
  printf(" IC=%dB",IC_SIZE);
243
#endif
244
#if DC_ENABLE==1
245
  printf(" DC=%dB",DC_SIZE);
246
#endif
247
  printf("\n");
248
  printf("Info: Stack section addr 0x%x\n",(unsigned long) &src_addr);
249
  printf("Build tag: %s", BUILD_VERSION);
250
 
251 2 marcus.erl
  return 0;
252
}
253
#endif /* HELP_ENABLED */
254
 
255
void module_cpu_init (void);
256
void module_memory_init (void);
257
void module_eth_init (void);
258
void module_dhry_init (void);
259
void module_camera_init (void);
260
void module_load_init (void);
261
void tick_init(void);
262
void module_touch_init (void);
263
void module_ata_init (void);
264
void module_hdbug_init (void);
265
 
266
 
267
/* List of all initializations */
268
void mon_init (void)
269
{
270
  /* Set defaults */
271
  global.erase_method = 2; /* as needed */
272
  global.src_addr = (unsigned long)&src_addr;
273
  global.dst_addr = FLASH_BASE_ADDR;
274
  global.eth_add[0] = ETH_MACADDR0;
275
  global.eth_add[1] = ETH_MACADDR1;
276
  global.eth_add[2] = ETH_MACADDR2;
277
  global.eth_add[3] = ETH_MACADDR3;
278
  global.eth_add[4] = ETH_MACADDR4;
279
  global.eth_add[5] = ETH_MACADDR5;
280
  global.ip = BOARD_DEF_IP;
281
  global.gw_ip = BOARD_DEF_GW;
282
  global.mask = BOARD_DEF_MASK;
283 140 julius
 
284
#define CPU_CMDS
285
#define MEM_CMDS
286
#define DHRY_CMDS
287
  //#define CAMERA_CMDS
288
#define LOAD_CMDS
289
    //#define TOUCHSCREEN_CMDS
290
    //#define ATA_CMDS
291
    //#define HDBUG_CMDS
292
#define TICK_CMDS
293
#define ETH_CMDS
294
#define LOAD_CMDS
295 2 marcus.erl
 
296
  /* Init modules */
297 140 julius
#ifdef CPU_CMDS
298 2 marcus.erl
  module_cpu_init ();
299 140 julius
#endif
300
#ifdef MEM_CMDS
301 2 marcus.erl
  module_memory_init ();
302 140 julius
#endif
303
#ifdef ETH_CMDS
304 2 marcus.erl
  module_eth_init ();
305 140 julius
#endif
306
#ifdef DHRY_CMDS
307 2 marcus.erl
  module_dhry_init ();
308 140 julius
#endif
309
#ifdef CAMERA_CMDS
310 2 marcus.erl
  module_camera_init ();
311 140 julius
#endif
312
#ifdef LOAD_CMDS
313 2 marcus.erl
  module_load_init ();
314 140 julius
#endif
315
#ifdef TOUCHSCREEN_CMDS
316 2 marcus.erl
  module_touch_init ();
317 140 julius
#endif
318
#ifdef ATA_CMDS
319 2 marcus.erl
  module_ata_init ();
320 140 julius
#endif
321
#ifdef HDBUG_CMDS
322 2 marcus.erl
  module_hdbug_init ();
323 140 julius
#endif
324 2 marcus.erl
 
325
  tick_init();
326 140 julius
 
327 2 marcus.erl
}
328 140 julius
int tboot_cmd (int argc, char *argv[]);
329 2 marcus.erl
/* Main shell loop */
330
int main(int argc, char **argv)
331
{
332
  extern unsigned long calc_mycrc32 (void);
333
#if 0
334
  extern unsigned long mycrc32, mysize;
335
#endif
336 140 julius
  timestamp = 0; // clear timer counter
337 2 marcus.erl
 
338
  int_init ();
339
  change_console_type (CONSOLE_TYPE);
340
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
341
 
342
#if SELF_CHECK
343
  printf ("Self check... ");
344
  if ((t = calc_mycrc32 ()))
345
      printf ("FAILED!!!\n");
346
  else
347
      printf ("OK\n");
348
#endif /* SELF_CHECK */
349 140 julius
  num_commands=0;
350 2 marcus.erl
  mon_init ();
351
 
352
  if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
353
 
354
#ifdef XESS
355
  printf ("\nORP-XSV Monitor (type 'help' for help)\n");
356
#else
357 140 julius
  printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
358
  printf("\tbuild: %s", BUILD_VERSION);
359 2 marcus.erl
#endif
360
 
361
  while(1) mon_command();
362 140 julius
  // Run tboot in sim for now:  tboot_cmd (0,0);
363 2 marcus.erl
}

powered by: WebSVN 2.1.0

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