#include "common.h"
|
#include "common.h"
|
#include "uart.h"
|
#include "uart.h"
|
#include "screen.h"
|
#include "screen.h"
|
#include "support.h"
|
#include "support.h"
|
|
|
#define MAX_COMMANDS 100
|
#define MAX_COMMANDS 100
|
|
|
bd_t bd;
|
bd_t bd;
|
|
|
int num_commands = 0;
|
int num_commands = 0;
|
|
|
struct command_struct {
|
struct command_struct {
|
const char *name;
|
const char *name;
|
const char *params;
|
const char *params;
|
const char *help;
|
const char *help;
|
int (*func)(int argc, char *argv[]);
|
int (*func)(int argc, char *argv[]);
|
} command[MAX_COMMANDS];
|
} command[MAX_COMMANDS];
|
|
|
unsigned long strtoul(char *s)
|
unsigned long strtoul(char *s)
|
{
|
{
|
int base = 10;
|
int base = 10;
|
char *ptmp;
|
char *ptmp;
|
unsigned long val = 0;
|
unsigned long val = 0;
|
unsigned long digit = 1;
|
unsigned long digit = 1;
|
|
|
ptmp = s;
|
ptmp = s;
|
while (*ptmp != '\0')
|
while (*ptmp != '\0')
|
if (*ptmp++ == 'x')
|
if (*ptmp++ == 'x')
|
base = 16;
|
base = 16;
|
|
|
while (ptmp-- != s)
|
while (ptmp-- != s)
|
if ((*ptmp >= '0') &&
|
if ((*ptmp >= '0') &&
|
(*ptmp <= '9'))
|
(*ptmp <= '9'))
|
{
|
{
|
val += (*ptmp - '0') * digit;
|
val += (*ptmp - '0') * digit;
|
digit *= base;
|
digit *= base;
|
}
|
}
|
else
|
else
|
if ((*ptmp >= 'a') &&
|
if ((*ptmp >= 'a') &&
|
(*ptmp <= 'f'))
|
(*ptmp <= 'f'))
|
{
|
{
|
val += (*ptmp - 'a' + 10) * digit;
|
val += (*ptmp - 'a' + 10) * digit;
|
digit *= base;
|
digit *= base;
|
}
|
}
|
|
|
return val;
|
return val;
|
}
|
}
|
|
|
void putc (const char c)
|
void putc (const char c)
|
{
|
{
|
debug ("getc %i, %i = %c\n", bd.bi_console_type, c, c);
|
debug ("getc %i, %i = %c\n", bd.bi_console_type, c, c);
|
switch (bd.bi_console_type) {
|
switch (bd.bi_console_type) {
|
case CT_NONE:
|
case CT_NONE:
|
break;
|
break;
|
case CT_UART:
|
case CT_UART:
|
uart_putc (c);
|
uart_putc (c);
|
break;
|
break;
|
case CT_CRT:
|
case CT_CRT:
|
screen_putc (c);
|
screen_putc (c);
|
break;
|
break;
|
case CT_SIM:
|
case CT_SIM:
|
__printf ("%c", c);
|
__printf ("%c", c);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
int getc ()
|
int getc ()
|
{
|
{
|
debug ("getc %i\n", bd.bi_console_type);
|
debug ("getc %i\n", bd.bi_console_type);
|
switch (bd.bi_console_type) {
|
switch (bd.bi_console_type) {
|
case CT_NONE:
|
case CT_NONE:
|
case CT_CRT:
|
case CT_CRT:
|
case CT_SIM:
|
case CT_SIM:
|
return -1;
|
return -1;
|
case CT_UART:
|
case CT_UART:
|
return uart_getc ();
|
return uart_getc ();
|
}
|
}
|
return -1;
|
return -1;
|
}
|
}
|
|
|
int testc ()
|
int testc ()
|
{
|
{
|
debug ("testc %i\n", bd.bi_console_type);
|
debug ("testc %i\n", bd.bi_console_type);
|
switch (bd.bi_console_type) {
|
switch (bd.bi_console_type) {
|
case CT_NONE:
|
case CT_NONE:
|
case CT_CRT:
|
case CT_CRT:
|
case CT_SIM:
|
case CT_SIM:
|
return -1;
|
return -1;
|
case CT_UART:
|
case CT_UART:
|
return uart_testc ();
|
return uart_testc ();
|
}
|
}
|
return -1;
|
return -1;
|
}
|
}
|
|
|
int ctrlc ()
|
int ctrlc ()
|
{
|
{
|
if (testc ()) {
|
if (testc ()) {
|
switch (getc ()) {
|
switch (getc ()) {
|
case 0x03: /* ^C - Control C */
|
case 0x03: /* ^C - Control C */
|
return 1;
|
return 1;
|
default:
|
default:
|
break;
|
break;
|
}
|
}
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
void change_console_type (enum bi_console_type_t con_type)
|
void change_console_type (enum bi_console_type_t con_type)
|
{
|
{
|
debug ("Console change %i -> %i\n", bd.bi_console_type, con_type);
|
debug ("Console change %i -> %i\n", bd.bi_console_type, con_type);
|
/* Close previous */
|
/* Close previous */
|
switch (bd.bi_console_type) {
|
switch (bd.bi_console_type) {
|
case CT_NONE:
|
case CT_NONE:
|
case CT_UART:
|
case CT_UART:
|
case CT_CRT:
|
case CT_CRT:
|
case CT_SIM:
|
case CT_SIM:
|
break;
|
break;
|
}
|
}
|
bd.bi_console_type = con_type;
|
bd.bi_console_type = con_type;
|
/* Initialize new */
|
/* Initialize new */
|
switch (bd.bi_console_type) {
|
switch (bd.bi_console_type) {
|
case CT_NONE:
|
case CT_NONE:
|
break;
|
break;
|
case CT_UART:
|
case CT_UART:
|
uart_init ();
|
uart_init ();
|
break;
|
break;
|
case CT_CRT:
|
case CT_CRT:
|
screen_init ();
|
screen_init ();
|
break;
|
break;
|
case CT_SIM:
|
case CT_SIM:
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]))
|
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]))
|
{
|
{
|
debug ("register_command '%s'\n", name);
|
debug ("register_command '%s'\n", name);
|
if (num_commands < MAX_COMMANDS) {
|
if (num_commands < MAX_COMMANDS) {
|
command[num_commands].name = name;
|
command[num_commands].name = name;
|
command[num_commands].params = params;
|
command[num_commands].params = params;
|
command[num_commands].help = help;
|
command[num_commands].help = help;
|
command[num_commands].func = func;
|
command[num_commands].func = func;
|
num_commands++;
|
num_commands++;
|
} else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name);
|
} else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name);
|
}
|
}
|
|
|
/* Process command and arguments by executing
|
/* Process command and arguments by executing
|
specific function. */
|
specific function. */
|
void mon_command(void)
|
void mon_command(void)
|
{
|
{
|
char c = '\0';
|
char c = '\0';
|
char str[1000];
|
char str[1000];
|
char *pstr = str;
|
char *pstr = str;
|
char *command_str;
|
char *command_str;
|
char *argv[20];
|
char *argv[20];
|
int argc = 0;
|
int argc = 0;
|
int end = 0;
|
int end = 0;
|
|
|
/* Show prompt */
|
/* Show prompt */
|
#ifdef XESS
|
#ifdef XESS
|
printf ("\norp-xsv> ");
|
printf ("\norp-xsv> ");
|
#else
|
#else
|
printf ("\nbender> ");
|
printf ("\nbender> ");
|
#endif
|
#endif
|
|
|
/* Get characters from UART */
|
/* Get characters from UART */
|
c = getc();
|
c = getc();
|
while (c != '\r' && c != '\f' && c != '\n')
|
while (c != '\r' && c != '\f' && c != '\n')
|
{
|
{
|
if (c == '\b')
|
if (c == '\b')
|
pstr--;
|
pstr--;
|
else
|
else
|
*pstr++ = c;
|
*pstr++ = c;
|
putc(c);
|
putc(c);
|
c = getc();
|
c = getc();
|
}
|
}
|
*pstr = '\0';
|
*pstr = '\0';
|
printf ("\n");
|
printf ("\n");
|
|
|
/* Skip leading blanks */
|
/* Skip leading blanks */
|
pstr = str;
|
pstr = str;
|
while (*pstr == ' ' && *pstr != '\0') pstr++;
|
while (*pstr == ' ' && *pstr != '\0') pstr++;
|
|
|
/* Get command from the string */
|
/* Get command from the string */
|
command_str = pstr;
|
command_str = pstr;
|
while (*pstr != '\0' && *pstr != ' ') pstr++;
|
while (*pstr != '\0' && *pstr != ' ') pstr++;
|
if (*pstr == '\0') end = 1;
|
if (*pstr == '\0') end = 1;
|
*pstr = '\0';
|
*pstr = '\0';
|
|
|
while (!end) {
|
while (!end) {
|
/* Go to next argument */
|
/* Go to next argument */
|
while (*pstr == ' ' && *pstr != '\0') pstr++;
|
while (*pstr == ' ' && *pstr != '\0') pstr++;
|
if (*pstr) argv[argc++] = pstr;
|
if (*pstr) argv[argc++] = pstr;
|
else end = 1;
|
else end = 1;
|
}
|
}
|
|
|
{
|
{
|
int i, found = 0;
|
int i, found = 0;
|
for (i = 0; i < num_commands; i++)
|
for (i = 0; i < num_commands; i++)
|
if (strcmp (command_str, command[i].name) == 0) {
|
if (strcmp (command_str, command[i].name) == 0) {
|
switch (command[i].func (argc, &argv[0])) {
|
switch (command[i].func (argc, &argv[0])) {
|
case -1:
|
case -1:
|
printf ("Missing/wrong parameters, usage: %s %s\n", command[i].name, command[i].params);
|
printf ("Missing/wrong parameters, usage: %s %s\n", command[i].name, command[i].params);
|
break;
|
break;
|
}
|
}
|
found = 1;
|
found = 1;
|
break;
|
break;
|
}
|
}
|
if (!found) printf ("Unknown command. Type 'help' for help.\n");
|
if (!found) printf ("Unknown command. Type 'help' for help.\n");
|
}
|
}
|
}
|
}
|
|
|
#if HELP_ENABLED
|
#if HELP_ENABLED
|
/* Displays help screen */
|
/* Displays help screen */
|
int help_cmd (int argc, char *argv[])
|
int help_cmd (int argc, char *argv[])
|
{
|
{
|
int i;
|
int i;
|
for (i = 0; i < num_commands; i++)
|
for (i = 0; i < num_commands; i++)
|
printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
|
printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
|
return 0;
|
return 0;
|
}
|
}
|
#endif /* HELP_ENABLED */
|
#endif /* HELP_ENABLED */
|
|
|
void module_cpu_init (void);
|
void module_cpu_init (void);
|
void module_memory_init (void);
|
void module_memory_init (void);
|
void module_eth_init (void);
|
void module_eth_init (void);
|
//void module_dhry_init (void);
|
//void module_dhry_init (void);
|
void module_camera_init (void);
|
void module_camera_init (void);
|
void module_tftp_init (void);
|
void module_tftp_init (void);
|
void tick_init(void);
|
void tick_init(void);
|
|
|
/* List of all initializations */
|
/* List of all initializations */
|
void mon_init (void)
|
void mon_init (void)
|
{
|
{
|
module_cpu_init ();
|
module_cpu_init ();
|
module_memory_init ();
|
module_memory_init ();
|
module_eth_init ();
|
module_eth_init ();
|
// module_dhry_init ();
|
// module_dhry_init ();
|
module_camera_init ();
|
module_camera_init ();
|
module_tftp_init ();
|
module_tftp_init ();
|
|
|
// tick_init();
|
// tick_init();
|
}
|
}
|
|
|
/* Main shell loop */
|
/* Main shell loop */
|
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
{
|
{
|
/* Initialize controller */
|
/* Initialize controller */
|
change_console_type (CT_UART);
|
change_console_type (CT_UART);
|
mon_init ();
|
mon_init ();
|
|
|
if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
|
if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
|
|
|
#ifdef XESS
|
#ifdef XESS
|
printf ("\nORP-XSV Monitor (type 'help' for help)\n");
|
printf ("\nORP-XSV Monitor (type 'help' for help)\n");
|
#else
|
#else
|
printf ("\nBender Monitor (type 'help' for help)\n");
|
printf ("\nBender Monitor (type 'help' for help)\n");
|
#endif
|
#endif
|
|
|
while(1) mon_command();
|
while(1) mon_command();
|
}
|
}
|
|
|