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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [common/] [common.c] - Diff between revs 464 and 467

Only display areas with differences | Details | Blame | View Log

Rev 464 Rev 467
#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 "spincursor.h"
 
#include "int.h"
#include "int.h"
 
 
#include "build.h"
#include "build.h"
 
 
#define MAX_COMMANDS  100
#define MAX_COMMANDS  100
 
 
// Value from linker script
 
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;
#if CRT_ENABLED==1
#if CRT_ENABLED==1
        case CT_CRT:
        case CT_CRT:
                screen_putc(c);
                screen_putc(c);
                break;
                break;
#endif
#endif
        case CT_SIM:
        case CT_SIM:
                __printf("%c", c);
                __printf("%c", c);
                break;
                break;
        default:
        default:
                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==1
#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:
 
        default:
                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)
                if (kbd_head == kbd_tail)
                        return 0;
                        return 0;
                else
                else
                        return getc();
                        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:
 
        default:
                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;
}
}
 
 
void print_or1k_cache_info()
void print_or1k_cache_info()
{
{
        // Read out UPR, check what modules we have
        // Read out UPR, check what modules we have
        unsigned long upr = mfspr(SPR_UPR);
        unsigned long upr = mfspr(SPR_UPR);
        printf("Instruction cache:\t");
        printf("Instruction cache:\t");
        if (upr & SPR_UPR_ICP) {
        if (upr & SPR_UPR_ICP) {
                // We have instruction cache, read out ICCFGR
                // We have instruction cache, read out ICCFGR
 
 
                unsigned long iccfgr = mfspr(SPR_ICCFGR);
                unsigned long iccfgr = mfspr(SPR_ICCFGR);
                unsigned int cbs;       // cache block size
                unsigned int cbs;       // cache block size
                unsigned long ncs = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
                unsigned long ncs = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
                if (iccfgr & SPR_ICCFGR_CBS)
                if (iccfgr & SPR_ICCFGR_CBS)
                        cbs = 32;
                        cbs = 32;
                else
                else
                        cbs = 16;
                        cbs = 16;
 
 
                printf("%dkB (BS: %d Sets: %d)\n",
                printf("%dkB (BS: %d Sets: %d)\n",
                       (cbs * ncs) / 1024, cbs, ncs);
                       (cbs * ncs) / 1024, cbs, ncs);
 
 
        } else
        } else
                printf(" not present\n");
                printf(" not present\n");
 
 
        printf("Data cache:\t\t");
        printf("Data cache:\t\t");
        if (upr & SPR_UPR_DCP) {
        if (upr & SPR_UPR_DCP) {
                // We have instruction cache, read out DCCFGR
                // We have instruction cache, read out DCCFGR
 
 
                unsigned long iccfgr = mfspr(SPR_DCCFGR);
                unsigned long iccfgr = mfspr(SPR_DCCFGR);
                unsigned int cbs;       // cache block size
                unsigned int cbs;       // cache block size
                unsigned long ncs = 1 << ((iccfgr & SPR_DCCFGR_NCS) >> 3);
                unsigned long ncs = 1 << ((iccfgr & SPR_DCCFGR_NCS) >> 3);
                if (iccfgr & SPR_DCCFGR_CBS)
                if (iccfgr & SPR_DCCFGR_CBS)
                        cbs = 32;
                        cbs = 32;
                else
                else
                        cbs = 16;
                        cbs = 16;
 
 
                printf("%dkB (BS: %d Sets: %d)\n",
                printf("%dkB (BS: %d Sets: %d)\n",
                       (cbs * ncs) / 1024, cbs, ncs);
                       (cbs * ncs) / 1024, cbs, ncs);
 
 
        } else
        } else
                printf(" not present\n");
                printf(" not present\n");
 
 
}
}
 
 
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++ != '.')
        if (*ip++ != '.')
                return 0;
                return 0;
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
        if (*ip++ != '.')
        if (*ip++ != '.')
                return 0;
                return 0;
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
        num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff);
        if (*ip++ != '.')
        if (*ip++ != '.')
                return 0;
                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==1
#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,
void register_command_func(const char *name, const char *params,
                           const char *help, int (*func) (int argc,
                           const char *help, int (*func) (int argc,
                                                          char *argv[]))
                                                          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
        } else
                printf("Command '%s' ignored; MAX_COMMANDS limit reached\n",
                printf("Command '%s' ignored; MAX_COMMANDS limit reached\n",
                       name);
                       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 chcnt = 0;
        int chcnt = 0;
 
 
        /* Show prompt */
        /* Show prompt */
        printf("\n" BOARD_DEF_NAME "> ");
        printf("\n" BOARD_DEF_NAME "> ");
 
 
        while (1) {
        while (1) {
                c = getc();
                c = getc();
 
 
                if (c == 0x7f)  // Backspace on picocom is showing up as 0x7f
                if (c == 0x7f)  // Backspace on picocom is showing up as 0x7f
                        c = '\b';
                        c = '\b';
 
 
                if (c == '\r' || c == '\f' || c == '\n') {
                if (c == '\r' || c == '\f' || c == '\n') {
                        // Mark end of string
                        // Mark end of string
                        *pstr = '\0';
                        *pstr = '\0';
                        putc('\n');
                        putc('\n');
                        break;
                        break;
                } else if (c == '\b')   // Backspace
                } else if (c == '\b')   // Backspace
                {
                {
                        if (chcnt > 0) {
                        if (chcnt > 0) {
                                putc(c);
                                putc(c);
                                putc(' ');      // cover char with space
                                putc(' ');      // cover char with space
                                putc(c);
                                putc(c);
                                pstr--;
                                pstr--;
                                chcnt--;
                                chcnt--;
                        }
                        }
                } else {
                } else {
                        putc(c);
                        putc(c);
                        *pstr++ = c;
                        *pstr++ = c;
                        chcnt++;
                        chcnt++;
                }
                }
        }
        }
 
 
        /* Skip leading blanks */
        /* Skip leading blanks */
        pstr = str;
        pstr = str;
        while (*pstr == ' ' && *pstr != '\0')
        while (*pstr == ' ' && *pstr != '\0')
                pstr++;
                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')
                while (*pstr != ' ' && *pstr != '\0')
                        pstr++;
                        pstr++;
                if (*pstr) {
                if (*pstr) {
                        *pstr++ = '\0';
                        *pstr++ = '\0';
                        while (*pstr == ' ')
                        while (*pstr == ' ')
                                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
                                        printf
                                            ("Missing/wrong parameters, usage: %s %s\n",
                                            ("Missing/wrong parameters, usage: %s %s\n",
                                             command[i].name,
                                             command[i].name,
                                             command[i].params);
                                             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
 
extern unsigned long _src_addr; // Stack section ends here, will print it out
 
/* Displays help screen */
/* Displays help screen */
int help_cmd(int argc, char *argv[])
int help_cmd(int argc, char *argv[])
{
{
 
#if HELP_ENABLED        
        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,
                printf("%-10s %-20s - %s\n", command[i].name, command[i].params,
                       command[i].help);
                       command[i].help);
 
 
        // Build info....
        // Build info....
        printf("\n");
        printf("\n");
        printf("CPU info\n");
        printf("CPU info\n");
        printf("Frequency\t\t%dMHz\n", IN_CLK / 1000000);
        printf("Frequency\t\t%dMHz\n", IN_CLK / 1000000);
        print_or1k_cache_info();
        print_or1k_cache_info();
        printf("\n");
        printf("\n");
        printf("Info: Stack section addr 0x%x\n", (unsigned long)&_src_addr);
        printf("Info: Stack section addr 0x%x\n", (unsigned long)&_stack_top);
        printf("Build tag: %s", BUILD_VERSION);
        printf("Build tag: %s", BUILD_VERSION);
 
#endif /* HELP_ENABLED */
        return 0;
        return 0;
}
}
#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_coremark_init(void);
void module_coremark_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 = 0;
#ifdef FLASH_BASE_ADDR
#ifdef FLASH_BASE_ADDR
        global.dst_addr = FLASH_BASE_ADDR;
        global.dst_addr = FLASH_BASE_ADDR;
#else
#else
        global.dst_addr = 0;
        global.dst_addr = 0;
#endif
#endif
        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 CPU_CMDS
#define MEM_CMDS
#define MEM_CMDS
#define DHRY_CMDS
#define DHRY_CMDS
#define COREMARK_CMDS
#define COREMARK_CMDS
        //#define CAMERA_CMDS
        //#define CAMERA_CMDS
#define LOAD_CMDS
#define LOAD_CMDS
        //#define TOUCHSCREEN_CMDS
        //#define TOUCHSCREEN_CMDS
        //#define ATA_CMDS
        //#define ATA_CMDS
        //#define HDBUG_CMDS
        //#define HDBUG_CMDS
#define TICK_CMDS
#define TICK_CMDS
#define ETH_CMDS
#define ETH_CMDS
#define LOAD_CMDS
#define LOAD_CMDS
 
 
        /* Init modules */
        /* Init modules */
#ifdef CPU_CMDS
#ifdef CPU_CMDS
        module_cpu_init();
        module_cpu_init();
#endif
#endif
#ifdef MEM_CMDS
#ifdef MEM_CMDS
        module_memory_init();
        module_memory_init();
#endif
#endif
#ifdef ETH_CMDS
#ifdef ETH_CMDS
        module_eth_init();
        module_eth_init();
#endif
#endif
#ifdef DHRY_CMDS
#ifdef DHRY_CMDS
        module_dhry_init();
        module_dhry_init();
#endif
#endif
#ifdef COREMARK_CMDS
#ifdef COREMARK_CMDS
        module_coremark_init();
        module_coremark_init();
#endif
#endif
#ifdef CAMERA_CMDS
#ifdef CAMERA_CMDS
        module_camera_init();
        module_camera_init();
#endif
#endif
#ifdef LOAD_CMDS
#ifdef LOAD_CMDS
        module_load_init();
        module_load_init();
#endif
#endif
#ifdef TOUCHSCREEN_CMDS
#ifdef TOUCHSCREEN_CMDS
        module_touch_init();
        module_touch_init();
#endif
#endif
#ifdef ATA_CMDS
#ifdef ATA_CMDS
        module_ata_init();
        module_ata_init();
#endif
#endif
#ifdef HDBUG_CMDS
#ifdef HDBUG_CMDS
        module_hdbug_init();
        module_hdbug_init();
#endif
#endif
 
 
#ifdef TICK_CMDS
#ifdef TICK_CMDS
#endif
#endif
 
 
}
}
 
 
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);
 
 
 
#if SELF_CHECK
 
        extern unsigned long mycrc32, mysize;
 
#endif
 
 
 
        timestamp = 0;           // clear timer counter
        timestamp = 0;           // clear timer counter
 
 
        int_init();
        /* Init. interface */
 
 
        change_console_type(CONSOLE_TYPE);
        change_console_type(CONSOLE_TYPE);
 
 
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
        /* Init. processor interrupt handlers */
 
        int_init();
 
 
#if SELF_CHECK
        /* Enable interrupts in processor */
        printf("Self check... ");
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
        if ((t = calc_mycrc32()))
 
                printf("FAILED!!!\n");
 
        else
 
                printf("OK\n");
 
#endif /* SELF_CHECK */
 
 
 
 
        /* Initialise commands we'll handle */
        num_commands = 0;
        num_commands = 0;
        mon_init();
 
 
 
        disable_spincursor();
        mon_init();
 
 
 
        /* Init processor timers */
        tick_init();
        tick_init();
 
 
        if (HELP_ENABLED)
        if (HELP_ENABLED)
                register_command("help", "", "shows this help", help_cmd);
                register_command("help", "", "shows this help", help_cmd);
 
 
        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);
        printf("\tbuild: %s", BUILD_VERSION);
 
 
        // Loop forever, accepting commands
        // Loop forever, accepting commands
        while (1) {
        while (1) {
                mon_command();
                mon_command();
        }
        }
 
 
}
}
 
 

powered by: WebSVN 2.1.0

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