#include "common.h"
|
#include "common.h"
|
#include "uart.h"
|
#include "uart.h"
|
#include "screen.h"
|
#include "screen.h"
|
#include "support.h"
|
#include "support.h"
|
#include "keyboard.h"
|
#include "keyboard.h"
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "int.h"
|
#include "int.h"
|
|
|
#include "build.h"
|
#include "build.h"
|
|
|
#define MAX_COMMANDS 100
|
#define MAX_COMMANDS 100
|
|
|
extern unsigned long src_addr;
|
extern unsigned long src_addr;
|
|
|
bd_t bd;
|
bd_t bd;
|
|
|
int num_commands = 0;
|
int num_commands = 0;
|
|
|
command_struct command[MAX_COMMANDS];
|
command_struct command[MAX_COMMANDS];
|
|
|
void putc (const char c)
|
void putc (const char c)
|
{
|
{
|
debug ("putc %i, %i = %c\n", bd.bi_console_type, c, c);
|
debug ("putc %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;
|
#ifdef CRT_ENABLED
|
#if CRT_ENABLED==1
|
case CT_CRT:
|
case CT_CRT:
|
#endif
|
|
screen_putc (c);
|
screen_putc (c);
|
break;
|
break;
|
|
#endif
|
case CT_SIM:
|
case CT_SIM:
|
__printf ("%c", c);
|
__printf ("%c", c);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
int getc ()
|
int getc ()
|
{
|
{
|
int ch = 0;
|
int ch = 0;
|
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) {
|
#if KBD_ENABLED
|
#if KBD_ENABLED==1
|
case CT_CRT:
|
case CT_CRT:
|
while ((volatile int)kbd_head == (volatile int)kbd_tail);
|
while ((volatile int)kbd_head == (volatile int)kbd_tail);
|
ch = kbd_buf[kbd_tail];
|
ch = kbd_buf[kbd_tail];
|
kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE;
|
kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE;
|
return ch;
|
return ch;
|
#endif
|
#endif
|
case CT_UART:
|
case CT_UART:
|
return uart_getc ();
|
return uart_getc ();
|
break;
|
break;
|
case CT_NONE: /* just to satisfy the compiler */
|
case CT_NONE: /* just to satisfy the compiler */
|
case CT_SIM:
|
case CT_SIM:
|
break;
|
break;
|
}
|
}
|
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) {
|
#if KBD_ENABLED
|
#if KBD_ENABLED
|
case CT_CRT:
|
case CT_CRT:
|
if (kbd_head == kbd_tail) return 0;
|
if (kbd_head == kbd_tail) return 0;
|
else return getc ();
|
else return getc ();
|
#endif
|
#endif
|
case CT_UART:
|
case CT_UART:
|
return uart_testc ();
|
return uart_testc ();
|
break;
|
break;
|
case CT_NONE: /* just to satisfy the compiler */
|
case CT_NONE: /* just to satisfy the compiler */
|
case CT_SIM:
|
case CT_SIM:
|
break;
|
break;
|
}
|
}
|
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;
|
}
|
}
|
|
|
unsigned long parse_ip (char *ip)
|
unsigned long parse_ip (char *ip)
|
{
|
{
|
unsigned long num;
|
unsigned long num;
|
num = strtoul (ip, &ip, 10) & 0xff;
|
num = strtoul (ip, &ip, 10) & 0xff;
|
if (*ip++ != '.') return 0;
|
if (*ip++ != '.') return 0;
|
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
|
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
|
if (*ip++ != '.') return 0;
|
if (*ip++ != '.') return 0;
|
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
|
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
|
if (*ip++ != '.') return 0;
|
if (*ip++ != '.') return 0;
|
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
|
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
|
return num;
|
return num;
|
}
|
}
|
|
|
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:
|
#if CRT_ENABLED
|
#if CRT_ENABLED==1
|
screen_init ();
|
screen_init ();
|
#endif
|
#endif
|
#if KBD_ENABLED
|
#if KBD_ENABLED
|
kbd_init ();
|
kbd_init ();
|
#endif
|
#endif
|
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;
|
|
|
/* Show prompt */
|
/* Show prompt */
|
#ifdef XESS
|
#ifdef XESS
|
printf ("\norp-xsv> ");
|
printf ("\norp-xsv> ");
|
#else
|
#else
|
printf ("\n" BOARD_DEF_NAME"> ");
|
printf ("\n" BOARD_DEF_NAME"> ");
|
#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 (1) {
|
while (1) {
|
/* Go to next argument */
|
/* Go to next argument */
|
while (*pstr != ' ' && *pstr != '\0') pstr++;
|
while (*pstr != ' ' && *pstr != '\0') pstr++;
|
if (*pstr) {
|
if (*pstr) {
|
*pstr++ = '\0';
|
*pstr++ = '\0';
|
while (*pstr == ' ') pstr++;
|
while (*pstr == ' ') pstr++;
|
argv[argc++] = pstr;
|
argv[argc++] = pstr;
|
}
|
}
|
else
|
else
|
break;
|
break;
|
}
|
}
|
|
|
{
|
{
|
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++;
|
found++;
|
break;
|
break;
|
}
|
}
|
/* 'built-in' build command */
|
/* 'built-in' build command */
|
if(strcmp(command_str, "build") == 0) {
|
if(strcmp(command_str, "build") == 0) {
|
printf("Build tag: %s", BUILD_VERSION);
|
printf("Build tag: %s", BUILD_VERSION);
|
found++;
|
found++;
|
}
|
}
|
if (!found)
|
if (!found)
|
printf ("Unknown command. Type 'help' for help.\n");
|
printf ("Unknown command. Type 'help' for help.\n");
|
}
|
}
|
|
|
}
|
}
|
|
|
#if HELP_ENABLED
|
#if HELP_ENABLED
|
|
extern unsigned long src_addr; // Stack section ends here
|
/* 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);
|
|
|
|
// Build info....
|
|
printf("Info: CPU@ %dMHz", IN_CLK/1000000);
|
|
#if IC_ENABLE==1
|
|
printf(" IC=%dB",IC_SIZE);
|
|
#endif
|
|
#if DC_ENABLE==1
|
|
printf(" DC=%dB",DC_SIZE);
|
|
#endif
|
|
printf("\n");
|
|
printf("Info: Stack section addr 0x%x\n",(unsigned long) &src_addr);
|
|
printf("Build tag: %s", BUILD_VERSION);
|
|
|
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_load_init (void);
|
void module_load_init (void);
|
void tick_init(void);
|
void tick_init(void);
|
void module_touch_init (void);
|
void module_touch_init (void);
|
void module_ata_init (void);
|
void module_ata_init (void);
|
void module_hdbug_init (void);
|
void module_hdbug_init (void);
|
|
|
|
|
/* List of all initializations */
|
/* List of all initializations */
|
void mon_init (void)
|
void mon_init (void)
|
{
|
{
|
/* Set defaults */
|
/* Set defaults */
|
global.erase_method = 2; /* as needed */
|
global.erase_method = 2; /* as needed */
|
global.src_addr = (unsigned long)&src_addr;
|
global.src_addr = (unsigned long)&src_addr;
|
global.dst_addr = FLASH_BASE_ADDR;
|
global.dst_addr = FLASH_BASE_ADDR;
|
global.eth_add[0] = ETH_MACADDR0;
|
global.eth_add[0] = ETH_MACADDR0;
|
global.eth_add[1] = ETH_MACADDR1;
|
global.eth_add[1] = ETH_MACADDR1;
|
global.eth_add[2] = ETH_MACADDR2;
|
global.eth_add[2] = ETH_MACADDR2;
|
global.eth_add[3] = ETH_MACADDR3;
|
global.eth_add[3] = ETH_MACADDR3;
|
global.eth_add[4] = ETH_MACADDR4;
|
global.eth_add[4] = ETH_MACADDR4;
|
global.eth_add[5] = ETH_MACADDR5;
|
global.eth_add[5] = ETH_MACADDR5;
|
global.ip = BOARD_DEF_IP;
|
global.ip = BOARD_DEF_IP;
|
global.gw_ip = BOARD_DEF_GW;
|
global.gw_ip = BOARD_DEF_GW;
|
global.mask = BOARD_DEF_MASK;
|
global.mask = BOARD_DEF_MASK;
|
|
|
|
#define CPU_CMDS
|
|
#define MEM_CMDS
|
|
#define DHRY_CMDS
|
|
//#define CAMERA_CMDS
|
|
#define LOAD_CMDS
|
|
//#define TOUCHSCREEN_CMDS
|
|
//#define ATA_CMDS
|
|
//#define HDBUG_CMDS
|
|
#define TICK_CMDS
|
|
#define ETH_CMDS
|
|
#define LOAD_CMDS
|
|
|
/* Init modules */
|
/* Init modules */
|
|
#ifdef CPU_CMDS
|
module_cpu_init ();
|
module_cpu_init ();
|
|
#endif
|
|
#ifdef MEM_CMDS
|
module_memory_init ();
|
module_memory_init ();
|
|
#endif
|
|
#ifdef ETH_CMDS
|
module_eth_init ();
|
module_eth_init ();
|
|
#endif
|
|
#ifdef DHRY_CMDS
|
module_dhry_init ();
|
module_dhry_init ();
|
|
#endif
|
|
#ifdef CAMERA_CMDS
|
module_camera_init ();
|
module_camera_init ();
|
|
#endif
|
|
#ifdef LOAD_CMDS
|
module_load_init ();
|
module_load_init ();
|
|
#endif
|
|
#ifdef TOUCHSCREEN_CMDS
|
module_touch_init ();
|
module_touch_init ();
|
|
#endif
|
|
#ifdef ATA_CMDS
|
module_ata_init ();
|
module_ata_init ();
|
|
#endif
|
|
#ifdef HDBUG_CMDS
|
module_hdbug_init ();
|
module_hdbug_init ();
|
|
#endif
|
|
|
tick_init();
|
tick_init();
|
}
|
|
|
|
|
}
|
|
int tboot_cmd (int argc, char *argv[]);
|
/* Main shell loop */
|
/* Main shell loop */
|
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
{
|
{
|
extern unsigned long calc_mycrc32 (void);
|
extern unsigned long calc_mycrc32 (void);
|
#if 0
|
#if 0
|
extern unsigned long mycrc32, mysize;
|
extern unsigned long mycrc32, mysize;
|
#endif
|
#endif
|
|
timestamp = 0; // clear timer counter
|
|
|
int_init ();
|
int_init ();
|
change_console_type (CONSOLE_TYPE);
|
change_console_type (CONSOLE_TYPE);
|
mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
|
mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
|
|
|
#if SELF_CHECK
|
#if SELF_CHECK
|
printf ("Self check... ");
|
printf ("Self check... ");
|
if ((t = calc_mycrc32 ()))
|
if ((t = calc_mycrc32 ()))
|
printf ("FAILED!!!\n");
|
printf ("FAILED!!!\n");
|
else
|
else
|
printf ("OK\n");
|
printf ("OK\n");
|
#endif /* SELF_CHECK */
|
#endif /* SELF_CHECK */
|
|
num_commands=0;
|
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 ("\n" BOARD_DEF_NAME " Monitor (type 'help' for help)\n");
|
printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
|
|
printf("\tbuild: %s", BUILD_VERSION);
|
#endif
|
#endif
|
|
|
while(1) mon_command();
|
while(1) mon_command();
|
|
// Run tboot in sim for now: tboot_cmd (0,0);
|
}
|
}
|
|
|