📄 mcf5307_hi.c
字号:
/*
* File: mcf5307_hi.c
* Purpose: Higher level processing for MCF5307 specifics.
*
* Notes:
*
*/
#include "src/include/dbug.h"
/********************************************************************/
/*
* CPU name string and source code version for display at boot-up.
*/
const char CPU_STR[] = "ColdFire MCF5307";
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 = MCF5307_ ## MOD ## _ ## RDREG; \
printf(FORMAT ## SIZE, #RDREG, #WRREG, rdata); \
\
pause(&displayed); \
\
if (!display_all) return; \
} \
} \
else \
{ \
if (strcasecmp(#WRREG,reg) == 0) \
{ \
MCF5307_ ## MOD ## _ ## WRREG = (uint ## SIZE) value; \
return; \
} \
}
#define IRMD_NOWR(MOD,RDREG,SIZE) \
if (regread) \
{ \
if ((strcasecmp(#RDREG,reg) == 0) || display_all) \
{ \
rdata = MCF5307_ ## MOD ## _ ## RDREG; \
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) \
{ \
MCF5307_ ## MOD ## _ ## WRREG = (uint ## SIZE) value; \
return; \
} \
}
static int display_all;
static int displayed;
static uint32 rdata;
/********************************************************************/
static void
irmd_sim (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);
if (!display_all)
printf(INVREG,reg);
}
/********************************************************************/
#if (defined (CPU_MCF5307))
static void
irmd_cs (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, CSBAR, CSBAR, 8);
IRMD(CS, CSBMR, CSBMR, 8);
IRMD(CS, CSMR2, CSMR2, 16);
IRMD(CS, CSCR2, CSCR2, 16);
IRMD(CS, CSMR3, CSMR3, 16);
IRMD(CS, CSCR3, CSCR3, 16);
IRMD(CS, CSMR4, CSMR4, 16);
IRMD(CS, CSCR4, CSCR4, 16);
IRMD(CS, CSMR5, CSMR5, 16);
IRMD(CS, CSCR5, CSCR5, 16);
IRMD(CS, CSMR6, CSMR6, 16);
IRMD(CS, CSCR6, CSCR6, 16);
IRMD(CS, CSMR7, CSMR7, 16);
IRMD(CS, CSCR7, CSCR7, 16);
if (!display_all)
printf(INVREG,reg);
}
#else /* J20C mask */
static void
irmd_cs (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);
}
#endif
/********************************************************************/
static void
irmd_pp (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 (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 (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 (char *reg, int regread, uint32 value)
{
IRMD(UART1, UMR, UMR, 8);
IRMD(UART1, USR, UCSR, 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 (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 (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 (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 (char *reg, int regread, uint32 value)
{
IRMD(DMA0, SAR, SAR, 32);
IRMD(DMA0, DAR, DAR, 32);
IRMD(DMA0, DCR, DCR, 16);
#if (defined(CPU_MCF5307j20))
IRMD(DMA0, BCR, BCR, 32);
#else
IRMD(DMA0, BCR, BCR, 16);
#endif
IRMD(DMA0, DSR, DSR, 8);
IRMD(DMA0, DIVR, DIVR, 8);
}
/********************************************************************/
static void
irmd_dma1 (char *reg, int regread, uint32 value)
{
IRMD(DMA1, SAR, SAR, 32);
IRMD(DMA1, DAR, DAR, 32);
IRMD(DMA1, DCR, DCR, 16);
#if (defined(CPU_MCF5307j20))
IRMD(DMA1, BCR, BCR, 32);
#else
IRMD(DMA1, BCR, BCR, 16);
#endif
IRMD(DMA1, DSR, DSR, 8);
IRMD(DMA1, DIVR, DIVR, 8);
}
/********************************************************************/
static void
irmd_dma2 (char *reg, int regread, uint32 value)
{
IRMD(DMA2, SAR, SAR, 32);
IRMD(DMA2, DAR, DAR, 32);
IRMD(DMA2, DCR, DCR, 16);
#if (defined(CPU_MCF5307j20))
IRMD(DMA2, BCR, BCR, 32);
#else
IRMD(DMA2, BCR, BCR, 16);
#endif
IRMD(DMA2, DSR, DSR, 8);
IRMD(DMA2, DIVR, DIVR, 8);
}
/********************************************************************/
static void
irmd_dma3 (char *reg, int regread, uint32 value)
{
IRMD(DMA3, SAR, SAR, 32);
IRMD(DMA3, DAR, DAR, 32);
IRMD(DMA3, DCR, DCR, 16);
#if (defined(CPU_MCF5307j20))
IRMD(DMA3, BCR, BCR, 32);
#else
IRMD(DMA3, BCR, BCR, 16);
#endif
IRMD(DMA3, DSR, DSR, 8);
IRMD(DMA3, DIVR, DIVR, 8);
}
/********************************************************************/
static const struct module_t
{
char *module;
void (*func)(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
mcf5307_ird (int argc, char **argv)
{
/*
* Display Internal Memory Mapped register contents
*/
char *rstr;
char mstr[20];
int mi;
(void)argc;
display_all = FALSE;
if (argv[1] == NULL)
{
printf("Internal Modules, MBAR, located at %#08X\n",MBAR_ADDRESS);
printf("Modules: ");
for (mi = 0; mi < MODULE_SIZE; ++mi)
{
printf("%s ",MODULE[mi].module);
}
printf("\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 == '.')
++rstr;
/*
* Display the module contents
*/
for (mi = 0; mi < MODULE_SIZE; ++mi)
{
if (strcasecmp(MODULE[mi].module,mstr) == 0)
{
if (rstr == NULL)
{
display_all = TRUE;
printf("Module: %s\n",MODULE[mi].module);
}
MODULE[mi].func(rstr, TRUE, 0);
return;
}
}
printf(INVMOD,argv[1]);
}
/********************************************************************/
void
mcf5307_irm (int argc, char **argv)
{
/*
* Modify Internal Memory Mapped register contents
*/
uint32 value;
int success;
char *rstr;
char mstr[20];
int mi;
(void)argc;
display_all = FALSE;
/*
* 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 == '.')
++rstr;
/*
* Get the new value
*/
value = get_value(argv[2],&success,16);
if(success == 0)
{
printf(INVALUE,argv[2]);
return;
}
/*
* Modify the module contents
*/
for (mi = 0; mi < MODULE_SIZE; ++mi)
{
if (strcasecmp(MODULE[mi].module,mstr) == 0)
{
MODULE[mi].func(rstr, FALSE, value);
return;
}
}
printf(INVMOD,argv[1]);
}
/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -