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 858

Go to most recent revision | 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
#define MAX_COMMANDS  100
10
 
11 817 simons
extern unsigned long src_addr;
12
 
13 809 simons
bd_t bd;
14
 
15
int num_commands = 0;
16
 
17
struct command_struct {
18
  const char *name;
19
  const char *params;
20
  const char *help;
21
  int (*func)(int argc, char *argv[]);
22
} command[MAX_COMMANDS];
23
 
24
void putc (const char c)
25
{
26 858 markom
  debug ("putc %i, %i = %c\n", bd.bi_console_type, c, c);
27 809 simons
  switch (bd.bi_console_type) {
28
  case CT_NONE:
29
    break;
30
  case CT_UART:
31
    uart_putc (c);
32
    break;
33 855 markom
#ifdef CRT_ENABLED
34 809 simons
  case CT_CRT:
35 855 markom
#endif
36 809 simons
    screen_putc (c);
37
    break;
38
  case CT_SIM:
39
    __printf ("%c", c);
40
    break;
41
  }
42
}
43
 
44
int getc ()
45
{
46 855 markom
  int ch = 0;
47 809 simons
  debug ("getc %i\n", bd.bi_console_type);
48
  switch (bd.bi_console_type) {
49 855 markom
#if KBD_ENABLED
50 809 simons
  case CT_CRT:
51 855 markom
    while ((volatile int)kbd_head == (volatile int)kbd_tail);
52
    ch = kbd_buf[kbd_tail];
53
    kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE;
54
    return ch;
55
#endif
56 809 simons
  case CT_UART:
57
    return uart_getc ();
58
  }
59
  return -1;
60
}
61
 
62
int testc ()
63
{
64
  debug ("testc %i\n", bd.bi_console_type);
65
  switch (bd.bi_console_type) {
66 855 markom
#if KBD_ENABLED
67 809 simons
  case CT_CRT:
68 855 markom
    if (kbd_head == kbd_tail) return 0;
69
    else return getc ();
70
#endif
71 809 simons
  case CT_UART:
72
    return uart_testc ();
73
  }
74
  return -1;
75
}
76
 
77
int ctrlc ()
78
{
79
  if (testc ()) {
80
    switch (getc ()) {
81
      case 0x03:    /* ^C - Control C */
82
        return 1;
83
      default:
84
        break;
85
    }
86
  }
87
  return 0;
88
}
89
 
90 812 markom
unsigned long parse_ip (char *ip)
91
{
92
  unsigned long num;
93
  num = strtoul (ip, &ip, 10) & 0xff;
94
  if (*ip++ != '.') return 0;
95
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
96
  if (*ip++ != '.') return 0;
97
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
98
  if (*ip++ != '.') return 0;
99
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
100
  return num;
101
}
102
 
103 809 simons
void change_console_type (enum bi_console_type_t con_type)
104
{
105
  debug ("Console change %i -> %i\n", bd.bi_console_type, con_type);
106
  /* Close previous */
107
  switch (bd.bi_console_type) {
108
  case CT_NONE:
109
  case CT_UART:
110
  case CT_CRT:
111
  case CT_SIM:
112
    break;
113
  }
114
  bd.bi_console_type = con_type;
115
  /* Initialize new */
116
  switch (bd.bi_console_type) {
117
  case CT_NONE:
118
    break;
119
  case CT_UART:
120
    uart_init ();
121
    break;
122
  case CT_CRT:
123 855 markom
#if CRT_ENABLED
124 809 simons
    screen_init ();
125 855 markom
#endif
126
#if KBD_ENABLED
127
    kbd_init ();
128
#endif
129 809 simons
    break;
130
  case CT_SIM:
131
    break;
132
  }
133
}
134
 
135
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]))
136
{
137
  debug ("register_command '%s'\n", name);
138
  if (num_commands < MAX_COMMANDS) {
139
    command[num_commands].name = name;
140
    command[num_commands].params = params;
141
    command[num_commands].help = help;
142
    command[num_commands].func = func;
143
    num_commands++;
144
  } else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name);
145
}
146
 
147
/* Process command and arguments by executing
148
   specific function. */
149
void mon_command(void)
150
{
151
  char c = '\0';
152
  char str[1000];
153
  char *pstr = str;
154
  char *command_str;
155
  char *argv[20];
156
  int argc = 0;
157
 
158
  /* Show prompt */
159
#ifdef XESS
160
  printf ("\norp-xsv> ");
161
#else
162
  printf ("\nbender> ");
163
#endif
164
 
165
  /* Get characters from UART */
166
  c = getc();
167
  while (c != '\r' && c != '\f' && c != '\n')
168
  {
169
    if (c == '\b')
170
      pstr--;
171
    else
172
      *pstr++ = c;
173
    putc(c);
174
    c = getc();
175
  }
176
  *pstr = '\0';
177
  printf ("\n");
178
 
179
  /* Skip leading blanks */
180
  pstr = str;
181
  while (*pstr == ' ' && *pstr != '\0') pstr++;
182
 
183
  /* Get command from the string */
184
  command_str = pstr;
185
 
186 817 simons
  while (1) {
187 809 simons
    /* Go to next argument */
188 817 simons
    while (*pstr != ' ' && *pstr != '\0') pstr++;
189
    if (*pstr) {
190
      *pstr++ = '\0';
191
      while (*pstr == ' ') pstr++;
192
      argv[argc++] = pstr;
193
    }
194
    else
195
      break;
196 809 simons
  }
197
 
198
  {
199
    int i, found = 0;
200
    for (i = 0; i < num_commands; i++)
201
      if (strcmp (command_str, command[i].name) == 0) {
202
        switch (command[i].func (argc, &argv[0])) {
203
        case -1:
204
          printf ("Missing/wrong parameters, usage: %s %s\n", command[i].name, command[i].params);
205
          break;
206
        }
207
        found = 1;
208
        break;
209
      }
210
    if (!found) printf ("Unknown command. Type 'help' for help.\n");
211
  }
212
}
213
 
214
#if HELP_ENABLED
215
/* Displays help screen */
216
int help_cmd (int argc, char *argv[])
217
{
218
  int i;
219
  for (i = 0; i < num_commands; i++)
220
    printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
221
  return 0;
222
}
223
#endif /* HELP_ENABLED */
224
 
225
void module_cpu_init (void);
226
void module_memory_init (void);
227
void module_eth_init (void);
228 816 markom
void module_dhry_init (void);
229 809 simons
void module_camera_init (void);
230 816 markom
void module_load_init (void);
231 809 simons
void tick_init(void);
232
 
233
/* List of all initializations */
234
void mon_init (void)
235
{
236 816 markom
  /* Set defaults */
237
  global.erase_method = 2; /* as needed */
238 833 simons
  global.src_addr = (unsigned long)&src_addr;
239 816 markom
  global.dst_addr = FLASH_BASE_ADDR;
240 833 simons
  global.eth_add[0] = ETH_MACADDR0;
241
  global.eth_add[1] = ETH_MACADDR1;
242
  global.eth_add[2] = ETH_MACADDR2;
243
  global.eth_add[3] = ETH_MACADDR3;
244
  global.eth_add[4] = ETH_MACADDR4;
245
  global.eth_add[5] = ETH_MACADDR5;
246 817 simons
  global.ip = BOARD_DEF_IP;
247 833 simons
  global.gw_ip = BOARD_DEF_GW;
248
  global.mask = BOARD_DEF_MASK;
249 816 markom
 
250
  /* Init modules */
251 809 simons
  module_cpu_init ();
252
  module_memory_init ();
253
  module_eth_init ();
254 816 markom
  module_dhry_init ();
255 809 simons
  module_camera_init ();
256 816 markom
  module_load_init ();
257 817 simons
 
258 833 simons
  tick_init();
259 809 simons
}
260
 
261
/* Main shell loop */
262
int main(int argc, char **argv)
263
{
264 828 markom
  extern unsigned long calc_mycrc32 (void);
265 822 markom
  unsigned long t;
266 858 markom
#if 1
267 822 markom
  extern unsigned long mycrc32, mysize;
268 828 markom
#endif
269 858 markom
  int_init ();
270
  change_console_type (CONSOLE_TYPE);
271
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
272
 
273 829 markom
#if SELF_CHECK
274 820 markom
  printf ("Self check... ");
275 828 markom
  if ((t = calc_mycrc32 ())) printf ("FAILED!!!\n");
276 820 markom
  else printf ("OK\n");
277 829 markom
#endif /* SELF_CHECK */
278
 
279 809 simons
  mon_init ();
280
 
281
  if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
282
 
283
#ifdef XESS
284
  printf ("\nORP-XSV Monitor (type 'help' for help)\n");
285
#else
286
  printf ("\nBender Monitor (type 'help' for help)\n");
287
#endif
288
 
289
  while(1) mon_command();
290
}

powered by: WebSVN 2.1.0

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