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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [orpmon/] [common/] [common.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 809 simons
#include "common.h"
2
#include "uart.h"
3
#include "screen.h"
4
#include "support.h"
5 855 markom
#include "keyboard.h"
6 858 markom
#include "spr_defs.h"
7
#include "int.h"
8 809 simons
 
9 1312 jurem
#include "build.h"
10
 
11 809 simons
#define MAX_COMMANDS  100
12
 
13 817 simons
extern unsigned long src_addr;
14
 
15 809 simons
bd_t bd;
16
 
17
int num_commands = 0;
18
 
19 878 rherveille
command_struct command[MAX_COMMANDS];
20 809 simons
 
21
void putc (const char c)
22
{
23 858 markom
  debug ("putc %i, %i = %c\n", bd.bi_console_type, c, c);
24 809 simons
  switch (bd.bi_console_type) {
25
  case CT_NONE:
26
    break;
27
  case CT_UART:
28
    uart_putc (c);
29
    break;
30 855 markom
#ifdef CRT_ENABLED
31 809 simons
  case CT_CRT:
32 855 markom
#endif
33 809 simons
    screen_putc (c);
34
    break;
35
  case CT_SIM:
36
    __printf ("%c", c);
37
    break;
38
  }
39
}
40
 
41
int getc ()
42
{
43 855 markom
  int ch = 0;
44 809 simons
  debug ("getc %i\n", bd.bi_console_type);
45
  switch (bd.bi_console_type) {
46 855 markom
#if KBD_ENABLED
47 809 simons
  case CT_CRT:
48 855 markom
    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 809 simons
  case CT_UART:
54
    return uart_getc ();
55 1312 jurem
    break;
56
  case CT_NONE: /* just to satisfy the compiler */
57
  case CT_SIM:
58
    break;
59 809 simons
  }
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 855 markom
#if KBD_ENABLED
68 809 simons
  case CT_CRT:
69 855 markom
    if (kbd_head == kbd_tail) return 0;
70
    else return getc ();
71
#endif
72 809 simons
  case CT_UART:
73
    return uart_testc ();
74 1312 jurem
    break;
75
  case CT_NONE: /* just to satisfy the compiler */
76
  case CT_SIM:
77
    break;
78 809 simons
  }
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 812 markom
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 809 simons
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 855 markom
#if CRT_ENABLED
129 809 simons
    screen_init ();
130 855 markom
#endif
131
#if KBD_ENABLED
132
    kbd_init ();
133
#endif
134 809 simons
    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 1312 jurem
  printf ("\n" BOARD_DEF_NAME"> ");
168 809 simons
#endif
169 878 rherveille
 
170 809 simons
  /* 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 878 rherveille
 
188 809 simons
  /* Get command from the string */
189
  command_str = pstr;
190 878 rherveille
 
191 817 simons
  while (1) {
192 809 simons
    /* Go to next argument */
193 817 simons
    while (*pstr != ' ' && *pstr != '\0') pstr++;
194
    if (*pstr) {
195
      *pstr++ = '\0';
196
      while (*pstr == ' ') pstr++;
197
      argv[argc++] = pstr;
198
    }
199 878 rherveille
    else
200 817 simons
      break;
201 809 simons
  }
202 878 rherveille
 
203 809 simons
  {
204
    int i, found = 0;
205 878 rherveille
 
206 809 simons
    for (i = 0; i < num_commands; i++)
207 878 rherveille
      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 809 simons
        }
215 878 rherveille
 
216
        found++;
217 809 simons
        break;
218
      }
219 1312 jurem
    /* '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 809 simons
  }
227 1312 jurem
 
228 809 simons
}
229
 
230
#if HELP_ENABLED
231
/* Displays help screen */
232
int help_cmd (int argc, char *argv[])
233
{
234
  int i;
235
  for (i = 0; i < num_commands; i++)
236
    printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
237
  return 0;
238
}
239
#endif /* HELP_ENABLED */
240
 
241
void module_cpu_init (void);
242
void module_memory_init (void);
243
void module_eth_init (void);
244 816 markom
void module_dhry_init (void);
245 809 simons
void module_camera_init (void);
246 816 markom
void module_load_init (void);
247 809 simons
void tick_init(void);
248 872 simons
void module_touch_init (void);
249 878 rherveille
void module_ata_init (void);
250 921 rherveille
void module_hdbug_init (void);
251 809 simons
 
252 1312 jurem
 
253 809 simons
/* List of all initializations */
254
void mon_init (void)
255
{
256 816 markom
  /* Set defaults */
257
  global.erase_method = 2; /* as needed */
258 833 simons
  global.src_addr = (unsigned long)&src_addr;
259 816 markom
  global.dst_addr = FLASH_BASE_ADDR;
260 833 simons
  global.eth_add[0] = ETH_MACADDR0;
261
  global.eth_add[1] = ETH_MACADDR1;
262
  global.eth_add[2] = ETH_MACADDR2;
263
  global.eth_add[3] = ETH_MACADDR3;
264
  global.eth_add[4] = ETH_MACADDR4;
265
  global.eth_add[5] = ETH_MACADDR5;
266 817 simons
  global.ip = BOARD_DEF_IP;
267 833 simons
  global.gw_ip = BOARD_DEF_GW;
268
  global.mask = BOARD_DEF_MASK;
269 816 markom
 
270
  /* Init modules */
271 809 simons
  module_cpu_init ();
272
  module_memory_init ();
273
  module_eth_init ();
274 816 markom
  module_dhry_init ();
275 809 simons
  module_camera_init ();
276 816 markom
  module_load_init ();
277 872 simons
  module_touch_init ();
278 878 rherveille
  module_ata_init ();
279 921 rherveille
  module_hdbug_init ();
280 817 simons
 
281 833 simons
  tick_init();
282 809 simons
}
283
 
284
/* Main shell loop */
285
int main(int argc, char **argv)
286
{
287 828 markom
  extern unsigned long calc_mycrc32 (void);
288 1312 jurem
#if 0
289 822 markom
  extern unsigned long mycrc32, mysize;
290 828 markom
#endif
291 878 rherveille
 
292 858 markom
  int_init ();
293
  change_console_type (CONSOLE_TYPE);
294
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
295 878 rherveille
 
296 829 markom
#if SELF_CHECK
297 820 markom
  printf ("Self check... ");
298 878 rherveille
  if ((t = calc_mycrc32 ()))
299
      printf ("FAILED!!!\n");
300
  else
301
      printf ("OK\n");
302 829 markom
#endif /* SELF_CHECK */
303
 
304 809 simons
  mon_init ();
305 878 rherveille
 
306 809 simons
  if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
307
 
308
#ifdef XESS
309
  printf ("\nORP-XSV Monitor (type 'help' for help)\n");
310
#else
311 1312 jurem
  printf ("\n" BOARD_DEF_NAME " Monitor (type 'help' for help)\n");
312 809 simons
#endif
313
 
314
  while(1) mon_command();
315
}

powered by: WebSVN 2.1.0

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