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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orpmon/] [common/] [common.c] - Blame information for rev 921

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

powered by: WebSVN 2.1.0

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