⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcf5407_hi.c

📁 motorola 针对coldfire 5275 评估板的Dbug bootloader源程序
💻 C
字号:
/*
 * File:        mcf5407_hi.c
 * Purpose:     Higher level processing for MCF5407 specifics.
 *
 * Notes:
 *
 */

#include "src/include/dbug.h"

/********************************************************************/

/*
 * CPU name string and source code version for display at boot-up.
 */
const char CPU_STR[] = "ColdFire MCF5407";
const int  CPU_VER_MAJOR   = 1;
const char CPU_VER_MINOR   = 'a';

/********************************************************************/

static const char FORMAT8[]  = "%6s (%-6s): %02X\n";
static const char FORMAT16[] = "%6s (%-6s): %04X\n";
static const char FORMAT32[] = "%6s (%-6s): %08X\n";
static const char XFORMAT[]  = "%6s (%-6s): %6s\n";

static const char INVMOD[] = "Error: Invalid Module: %s\n";
static const char NOREG[]  = "XXXXXX";

#define IRMD(MOD,RDREG,WRREG,SIZE)  \
if (regread)                                            \
{                                                       \
    if ((strcasecmp(#RDREG,reg) == 0) || display_all)   \
    {                                                   \
        rdata = MCF5407_RD_ ## MOD ## _ ## RDREG(imm);  \
        printf(FORMAT ## SIZE, #RDREG, #WRREG, rdata);  \
                                                        \
        pause(&displayed);                              \
                                                        \
        if (!display_all) return;                       \
    }                                                   \
}                                                       \
else                                                    \
{                                                       \
    if (strcasecmp(#WRREG,reg) == 0)                    \
    {                                                   \
        MCF5407_WR_ ## MOD ## _ ## WRREG(imm,(uint ## SIZE) value); \
        return;                                         \
    }                                                   \
}

#define IRMD_NOWR(MOD,RDREG,SIZE)  \
if (regread)                                            \
{                                                       \
    if ((strcasecmp(#RDREG,reg) == 0) || display_all)   \
    {                                                   \
        rdata = MCF5407_RD_ ## MOD ## _ ## RDREG(imm);  \
        printf(FORMAT ## SIZE, #RDREG, NOREG, rdata);   \
                                                        \
        pause(&displayed);                              \
                                                        \
        if (!display_all) return;                       \
    }                                                   \
}

#define IRMD_NORD(MOD,WRREG,SIZE)  \
if (regread && display_all)                             \
{                                                       \
    printf(XFORMAT, NOREG, #WRREG, NOREG);              \
}                                                       \
else                                                    \
{                                                       \
    if (strcasecmp(#WRREG,reg) == 0)                    \
    {                                                   \
        MCF5407_WR_ ## MOD ## _ ## WRREG(imm,(uint ## SIZE) value); \
        return;                                         \
    }                                                   \
}

static int display_all;
static int displayed;
static uint32 rdata;

/********************************************************************/
static void
irmd_sim (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(SIM,   RSR,    RSR,    8);
    IRMD(SIM,   SYPCR,  SYPCR,  8);
    IRMD(SIM,   SWIVR,  SWIVR,  8);
    IRMD_NORD(  SIM,    SWSR,   8);
    IRMD(SIM,   PAR,    PAR,    16);
    IRMD(SIM,   IRQPAR, IRQPAR, 8);
    IRMD(SIM,   PLLCR,  PLLCR,  8);
    IRMD(SIM,   MPARK,  MPARK,  8);
    IRMD_NOWR(  SIM,    IPR,    32);
    IRMD(SIM,   IMR,    IMR,    32);
    IRMD(SIM,   AVCR,   AVCR,   8);
    IRMD(SIM,   ICR0,   ICR0,   8);
    IRMD(SIM,   ICR1,   ICR1,   8);
    IRMD(SIM,   ICR2,   ICR2,   8);
    IRMD(SIM,   ICR3,   ICR3,   8);
    IRMD(SIM,   ICR4,   ICR4,   8);
    IRMD(SIM,   ICR5,   ICR5,   8);
    IRMD(SIM,   ICR6,   ICR6,   8);
    IRMD(SIM,   ICR7,   ICR7,   8);
    IRMD(SIM,   ICR8,   ICR8,   8);
    IRMD(SIM,   ICR9,   ICR9,   8);
    IRMD(SIM,   ICR10,  ICR10,  8);
    IRMD(SIM,   ICR11,  ICR11,  8);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
 
static void
irmd_cs (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(CS,    CSAR0,  CSAR0,  16);
    IRMD(CS,    CSMR0,  CSMR0,  32);
    IRMD(CS,    CSCR0,  CSCR0,  16);
    IRMD(CS,    CSAR1,  CSAR1,  16);
    IRMD(CS,    CSMR1,  CSMR1,  32);
    IRMD(CS,    CSCR1,  CSCR1,  16);
    IRMD(CS,    CSAR2,  CSAR2,  16);
    IRMD(CS,    CSMR2,  CSMR2,  32);
    IRMD(CS,    CSCR2,  CSCR2,  16);
    IRMD(CS,    CSAR3,  CSAR3,  16);
    IRMD(CS,    CSMR3,  CSMR3,  32);
    IRMD(CS,    CSCR3,  CSCR3,  16);
    IRMD(CS,    CSAR4,  CSAR4,  16);
    IRMD(CS,    CSMR4,  CSMR4,  32);
    IRMD(CS,    CSCR4,  CSCR4,  16);
    IRMD(CS,    CSAR5,  CSAR5,  16);
    IRMD(CS,    CSMR5,  CSMR5,  32);
    IRMD(CS,    CSCR5,  CSCR5,  16);
    IRMD(CS,    CSAR6,  CSAR6,  16);
    IRMD(CS,    CSMR6,  CSMR6,  32);
    IRMD(CS,    CSCR6,  CSCR6,  16);
    IRMD(CS,    CSAR7,  CSAR7,  16);
    IRMD(CS,    CSMR7,  CSMR7,  32);
    IRMD(CS,    CSCR7,  CSCR7,  16);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_pp (void *imm, char *reg, int regread, uint32 value)
{

    IRMD(PP,    PADDR,  PADDR,  16);
    IRMD(PP,    PADAT,  PADAT,  16);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_dramc (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(DRAMC, DCR,    DCR,    16);
    IRMD(DRAMC, DACR0,  DACR0,  32);
    IRMD(DRAMC, DMR0,   DMR0,   32);
    IRMD(DRAMC, DACR1,  DACR1,  32);
    IRMD(DRAMC, DMR1,   DMR1,   32);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_uart0 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(UART0, UMR,    UMR,    8);
    IRMD(UART0, USR,    UCSR,   8);
    IRMD_NORD(UART0,    UCR,    8);
    IRMD(UART0, URB,    UTB,    8);
    IRMD(UART0, UIPCR,  UACR,   8);
    IRMD(UART0, UISR,   UIMR,   8);
    IRMD(UART0, UBG1,   UBG1,   8);
    IRMD(UART0, UBG2,   UBG2,   8);
    IRMD(UART0, UIVR,   UIVR,   8);
    IRMD_NOWR(UART0,    UIP,    8);
    IRMD_NORD(UART0,    UOP1,   8);
    IRMD_NORD(UART0,    UOP0,   8);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_uart1 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(UART1, UMR,    UMR,    8);
    IRMD(UART1, RXLVL,  RXLVL,  8);
    IRMD(UART1, MODCTL, MODCTL, 8);
    IRMD(UART1, TXLVL,  TXLVL,  8);
    IRMD(UART1, USR,    UCSR,   8);
    IRMD_NOWR(UART1,    RSMP,   8);
    IRMD_NOWR(UART1,    TSPC,   8);
    IRMD_NORD(UART1,    UCR,    8);
    IRMD(UART1, URB,    UTB,    8);
    IRMD(UART1, UIPCR,  UACR,   8);
    IRMD(UART1, UISR,   UIMR,   8);
    IRMD(UART1, UBG1,   UBG1,   8);
    IRMD(UART1, UBG2,   UBG2,   8);
    IRMD(UART1, UIVR,   UIVR,   8);
    IRMD_NOWR(UART1,    UIP,    8);
    IRMD_NORD(UART1,    UOP1,   8);
    IRMD_NORD(UART1,    UOP0,   8);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_i2c (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(I2C,   IADR,   IADR,   8);
    IRMD(I2C,   IFDR,   IFDR,   8);
    IRMD(I2C,   I2CR,   I2CR,   8);
    IRMD(I2C,   I2SR,   I2SR,   8);
    IRMD(I2C,   I2DR,   I2DR,   8);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_TIMER0 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(TIMER0,    TMR,    TMR,    16);
    IRMD(TIMER0,    TRR,    TRR,    16);
    IRMD_NOWR(TIMER0,       TCR,    16);
    IRMD(TIMER0,    TCN,    TCN,    16);
    IRMD(TIMER0,    TER,    TER,    8);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/
static void
irmd_TIMER1 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(TIMER1,    TMR,    TMR,    16);
    IRMD(TIMER1,    TRR,    TRR,    16);
    IRMD_NOWR(TIMER1,       TCR,    16);
    IRMD(TIMER1,    TCN,    TCN,    16);
    IRMD(TIMER1,    TER,    TER,    8);

    if (!display_all)
        printf(INVREG,reg);
}

/********************************************************************/

static void
irmd_dma0 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(DMA0,  SAR,    SAR,    32);
    IRMD(DMA0,  DAR,    DAR,    32);
    IRMD(DMA0,  DCR,    DCR,    32);
    IRMD(DMA0,  BCR,    BCR,    32);
    IRMD(DMA0,  DSR,    DSR,    8);
    IRMD(DMA0,  DIVR,   DIVR,   8);
}

/********************************************************************/
static void
irmd_dma1 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(DMA1,  SAR,    SAR,    32);
    IRMD(DMA1,  DAR,    DAR,    32);
    IRMD(DMA1,  DCR,    DCR,    32);
    IRMD(DMA1,  BCR,    BCR,    32);
    IRMD(DMA1,  DSR,    DSR,    8);
    IRMD(DMA1,  DIVR,   DIVR,   8);
}

/********************************************************************/
static void
irmd_dma2 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(DMA2,  SAR,    SAR,    32);
    IRMD(DMA2,  DAR,    DAR,    32);
    IRMD(DMA2,  DCR,    DCR,    32);
    IRMD(DMA2,  BCR,    BCR,    32);
    IRMD(DMA2,  DSR,    DSR,    8);
    IRMD(DMA2,  DIVR,   DIVR,   8);
}

/********************************************************************/
static void
irmd_dma3 (void *imm, char *reg, int regread, uint32 value)
{
    IRMD(DMA3,  SAR,    SAR,    32);
    IRMD(DMA3,  DAR,    DAR,    32);
    IRMD(DMA3,  DCR,    DCR,    32);
    IRMD(DMA3,  BCR,    BCR,    32);
    IRMD(DMA3,  DSR,    DSR,    8);
    IRMD(DMA3,  DIVR,   DIVR,   8);
}


/********************************************************************/
static const struct module_t
{
    char    *module;
    void    (*func)(void *, char *, int, uint32);
} MODULE[] =
{
    {"CS",      irmd_cs},
    {"DMA0",    irmd_dma0},
    {"DMA1",    irmd_dma1},
    {"DMA2",    irmd_dma2},
    {"DMA3",    irmd_dma3},
    {"DRAMC",   irmd_dramc},
    {"PP",      irmd_pp},
    {"I2C",     irmd_i2c},
    {"SIM",     irmd_sim},
    {"TIMER0",  irmd_TIMER0},
    {"TIMER1",  irmd_TIMER1},
    {"UART0",   irmd_uart0},
    {"UART1",   irmd_uart1},
} ;

#define MODULE_SIZE (int)(sizeof(MODULE)/sizeof(struct module_t))

/********************************************************************/
void
mcf5407_irmd (int argc, char **argv)
{
    uint32 value;
    char *rstr;
    char mstr[20];
    int mi, success;

    display_all = FALSE;
    displayed = 0;

    if (argc == 1)
    {
        printf("Internal Modules (MBAR = %#08X):",MBAR_ADDRESS);
        for (mi = 0; mi < MODULE_SIZE; ++mi)
        {
            if (!(mi % 8))
                printf("\n");
            printf("%-8s ",MODULE[mi].module);
        }
        printf("\n\n");
        return;
    }

    /*
     * Pick out module name and Point to register name
     */
    mi = 0;
    rstr = argv[1];
    while (*rstr != '.')
    {
        mstr[mi++] = *rstr;
        if (*++rstr == '\0')
        {
            rstr = NULL;
            break;
        }
    }
    mstr[mi] = '\0';
    if (rstr != NULL)
    {
        if (*rstr == '.')
            ++rstr;
    }

    /*
     * Get the new value
     */
    if (argc == 3)
    {
        if (rstr == NULL)
        {
            printf("Error:  Invalid Register:  %s\n",argv[1]);
            return;
        }
        value = get_value(argv[2],&success,16);
        if (success == 0)
        {
            printf(INVALUE,argv[2]);
            return;
        }
    }
    else
        value = 0;

    /*
     * Determine which module
     */
    for (mi = 0; mi < MODULE_SIZE; ++mi)
    {
        if (strcasecmp(MODULE[mi].module,mstr) == 0)
        {
            if (argc == 3)  /* modify operation */
            {
                MODULE[mi].func(rstr, REGWRITE, value);
            }
            else
            {
                /* display operation */
                if (rstr == NULL)
                {
                    display_all = TRUE;
                    printf("Module: %s\n",MODULE[mi].module);
                }
                MODULE[mi].func(rstr, REGREAD, 0);
            }
            return;
        }
    }

    printf(INVMOD,argv[1]);
}
/********************************************************************/
void
cpu_handle_interrupt (int vector)
{
    printf("User Defined Vector #%d\n",vector);
}
/********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -