?? m5272c3.c
字號:
/*
* File: board.c
* Purpose: Board specific routines for the M5272C3
*
* Notes:
*
*/
#include "src/include/dbug.h"
#include "src/dev/flash/amd_flash.h"
#ifdef DBUG_NETWORK
#include "src/uif/net/net.h"
#include "src/dev/mcf5272/fec.h"
#include "src/dev/mcf5272/timer.h"
extern uint8 TIMER_NETWORK;
extern NIF nif1;
#endif
/********************************************************************/
/*
* Global BSP variables referenced by dBUG
*/
const char BRD_STR[] = "M5272C3";
const int BRD_VER_MAJOR = 1;
const char BRD_VER_MINOR = 'b';
const char COPYRIGHT2[] = "";
/********************************************************************/
/*
* Compiler specific code relocation section
*/
#ifdef __DCC__
#pragma section CODE ".code_relocation"
#else
#error "Unsupported compiler option"
#endif
void relocate_putchar (char);
char relocate_getchar (void);
int relocate_getchar_present (void);
/*
* Return to standard text section
*/
#ifdef __DCC__
#pragma section CODE
#endif
/********************************************************************/
void
board_init (void)
{
extern uint32 __VECTOR_RAM[];
extern REGISTERS context;
/* Point VBR to the vector table which is copied to RAM in main() */
mcf5xxx_wr_vbr((uint32)__VECTOR_RAM);
/* Good for detecting NULL dereferences */
*(ADDRESS *)(0) = 0;
printf("\n\n");
switch (MCF5272_SIM_SCR & 0x3000)
{
case MCF5272_SIM_SCR_HRST:
printf("Hard Reset\n");
break;
case MCF5272_SIM_SCR_DRAMRST:
printf("Hard & SDRAM Controller Reset\n");
break;
case MCF5272_SIM_SCR_SWTR:
printf("Software Watchdog Reset\n");
break;
}
/* Allow interrupts from IRQ 6 (black button) */
MCF5272_SIM_ICR4 = MCF5272_SIM_ICR_INT6_IL(7);
printf("SDRAM Size: %dM\n", SDRAM_SIZE >> 20);
context.a7 = SDRAM_SIZE;
}
/********************************************************************/
void
board_init2 (void)
{
/*
* The Timer routines cannot be called until after isr_init()
* Check main() for calling order of xxxx_init() functions.
*/
/* Initialize the Network Timer */
#if (defined(DBUG_NETWORK))
timer_init(TIMER_NETWORK, TIMER_NETWORK_PERIOD,
SYSTEM_CLOCK, TIMER_NETWORK_LEVEL, NULL);
#endif
}
/********************************************************************/
void
board_init3 (void)
{
FLASH_INFO Am29PL160CB;
strcpy(Am29PL160CB.name,"Am29PL160CB (1 x 32-bit)");
Am29PL160CB.base = (ADDRESS) FLASH_ADDRESS;
Am29PL160CB.size = (int) FLASH_SIZE;
Am29PL160CB.erase = (void *) amd_flash_erase;
Am29PL160CB.program = (void *) amd_flash_program;
Am29PL160CB.sector_start = (void *) amd_flash_sector_start;
Am29PL160CB.sector_end = (void *) amd_flash_sector_end;
Am29PL160CB.putchar = (void *) relocate_putchar;
Am29PL160CB.protect_start = (ADDRESS) DBUG_ADDRESS;
Am29PL160CB.protect_size = (int) DBUG_SIZE;
/*
* Initialize AMD Flash device
*/
amd_flash_init(FLASH_ADDRESS);
/*
* Register AMD Flash with dBUG Flash Utilities
*/
flash_register_device(&Am29PL160CB);
}
/********************************************************************/
/*
* Character Input/Output support
*/
/********************************************************************/
char
board_getchar (void)
{
/* Wait until character has been received */
while (!(MCF5272_UART0_USR & MCF5272_UART_USR_RXRDY))
;
return MCF5272_UART0_URB;
}
char
relocate_getchar (void)
{
/* Wait until character has been received */
while (!(MCF5272_UART0_USR & MCF5272_UART_USR_RXRDY))
;
return MCF5272_UART0_URB;
}
/********************************************************************/
void
board_putchar (char ch)
{
/* Wait until space is available in the FIFO */
while (!(MCF5272_UART0_USR & MCF5272_UART_USR_TXRDY))
;
/* Send the character */
MCF5272_UART0_UTB = (uint8)ch;
}
void
relocate_putchar (char ch)
{
/* Wait until space is available in the FIFO */
while (!(MCF5272_UART0_USR & MCF5272_UART_USR_TXRDY))
;
/* Send the character */
MCF5272_UART0_UTB = (uint8)ch;
}
/********************************************************************/
int
board_getchar_present (void)
{
return (MCF5272_UART0_USR & 1);
}
int
relocate_getchar_present (void)
{
return (MCF5272_UART0_USR & 1);
}
/********************************************************************/
void
board_putchar_flush (void)
{
}
/********************************************************************/
int
board_dlio_init (void)
{
/*
* Download initialization routine
*/
#ifdef DBUG_NETWORK
uint8* board_get_ethaddr(uint8*);
if (uif_dlio == UIF_DLIO_NETWORK)
{
unsigned char mac[6];
/* Register interrupt handlers */
if (!isr_register_handler(ISR_DBUG_ISR, FEC_VECTOR,
(void *)fec_handler,NULL, (void *)&nif1))
{
printf("Error: Unable to register handler\n");
return -1;
}
/* Enable FEC interrupts to ColdFire core */
MCF5272_SIM_ICR3 = MCF5272_SIM_ICR_ERX_IL(FEC_LEVEL);
/* Initialize network device */
fec_init(&nif1);
/* Get user programmed MAC address */
board_get_ethaddr(mac);
/* Write ethernet address in the data structure */
nif1.hwa[0] = mac[0];
nif1.hwa[1] = mac[1];
nif1.hwa[2] = mac[2];
nif1.hwa[3] = mac[3];
nif1.hwa[4] = mac[4];
nif1.hwa[5] = mac[5];
printf("Ethernet Address is %02X:%02X:%02X:%02X:%02X:%02X\n",\
nif1.hwa[0], nif1.hwa[1], nif1.hwa[2],\
nif1.hwa[3], nif1.hwa[4], nif1.hwa[5]);
}
#endif
return TRUE;
}
/********************************************************************/
int
board_dlio_getchar (void)
{
/* Download character input routine */
int ch;
switch (uif_dlio)
{
#ifdef DBUG_NETWORK
case UIF_DLIO_NETWORK:
ch = tftp_in_char();
break;
#endif
case UIF_DLIO_CONSOLE:
default:
ch = board_getchar();
break;
}
return ch;
}
/********************************************************************/
int
board_dlio_vda (ADDRESS addr)
{
/* Determines if the given address is valid for downloads */
if (((addr >= USER_SPACE) &&
(addr < SDRAM_SIZE))
|| ((addr >= EXT_SRAM_ADDRESS) &&
(addr < (EXT_SRAM_ADDRESS + EXT_SRAM_SIZE)))
|| ((addr >= SRAM_ADDRESS) &&
(addr < (SRAM_ADDRESS + SRAM_SIZE))))
return 1;
else
return 0;
}
/********************************************************************/
void
board_dlio_done (void)
{
/*
* Download complete, clean up
*/
#ifdef DBUG_NETWORK
if (uif_dlio == UIF_DLIO_NETWORK)
{
/* Disable FEC interrupts to ColdFire core */
MCF5272_SIM_ICR3 = MCF5272_SIM_ICR_ERX_IL(0);
isr_remove_handler(ISR_DBUG_ISR,(void *)fec_handler);
}
#endif
}
/********************************************************************/
#ifdef DBUG_NETWORK
int
board_dlio_filetype (char *filename, char *ext)
{
(void)filename;
(void)ext;
return UIF_DLIO_UNKNOWN;
}
#endif
/********************************************************************/
void
board_reset (void)
{
int i;
MCF5272_SIM_SCR = MCF5272_SIM_SCR_SOFT_RES;
/* Pause */
for (i = 0; i < 0x100; i++)
;
}
/********************************************************************/
void
board_irq_enable (void)
{
asm_set_ipl(0);
}
/********************************************************************/
void
board_irq_disable (void)
{
asm_set_ipl(6);
}
/********************************************************************/
void ext_irq6_handler (void)
{
/* Clear the interrupt */
MCF5272_SIM_ICR4 = MCF5272_SIM_ICR_INT6_IL(7);
}
/********************************************************************/
void
update_board_params (uint8 *data, int length, uint32 offset)
{
/*
* This function copies the PARAM section of the Flash
* into SRAM, modifies the SRAM copy of PARAM with 'data'
* for 'length' bytes, then writes the updated copy into
* Flash again.
*/
extern uint8 __PARAMS_START[];
uint8 *target = (uint8 *)(__PARAMS_START + offset);
int index, pbytes;
int amd_flash_program(ADDRESS, ADDRESS, int, int,
void (*)(void), void (*)(char));
board_irq_disable();
memcpy((void*)__PARAMS_START,(void*)PARAMS_ADDRESS,(uint32)PARAMS_SIZE);
for (index = 0; index < length; ++index)
{
*target++ = *data++;
}
pbytes = amd_flash_program((ADDRESS)PARAMS_ADDRESS, (ADDRESS)__PARAMS_START,
(uint32)PARAMS_SIZE, TRUE, NULL, NULL);
if (pbytes != PARAMS_SIZE)
{
printf("Flash programming error: %#X bytes of %#X written!\n",
pbytes, PARAMS_SIZE);
}
}
/********************************************************************/
/*
* Additional commands and SET/SHOW options for this board.
*/
/********************************************************************/
const char MEM_STR[] = " %-14s %#08X %#08X %d-bit\n";
const char PRT_STR[] = " %-14s %#08X %#08X\n";
const char CS_STR[] = " CS%d %s\n";
void
mmap (int argc, char **argv)
{
(void)argc;
(void)argv;
printf("\n");
printf(" Type Start End Port Size\n");
printf(" ---------------------------------------------------\n");
printf(MEM_STR, "SDRAM", SDRAM_ADDRESS,
SDRAM_ADDRESS + SDRAM_SIZE - 1, 32);
printf(MEM_STR, "SRAM (Int)", SRAM_ADDRESS,
SRAM_ADDRESS + SRAM_SIZE - 1, 32);
printf(MEM_STR, "SRAM (Ext)", EXT_SRAM_ADDRESS,
EXT_SRAM_ADDRESS + EXT_SRAM_SIZE - 1, 32);
printf(MEM_STR, "MBAR", MBAR_ADDRESS,
MBAR_ADDRESS + 0x1800, 32);
printf(MEM_STR, "Flash", FLASH_ADDRESS,
FLASH_ADDRESS + FLASH_SIZE - 1, 16);
printf("\n");
printf(" Protected Start End\n");
printf(" ----------------------------------------\n");
printf(PRT_STR, "dBUG Code", DBUG_ADDRESS,
DBUG_ADDRESS + DBUG_SIZE - 1);
printf(PRT_STR, "dBUG Data", VECTOR_RAM,
USER_SPACE - 1);
printf("\n");
printf(" Chip Selects\n");
printf(" ----------------\n");
printf(CS_STR, 0, "Flash");
printf(CS_STR, 2, "Ext SRAM");
printf(CS_STR, 7, "SDRAM");
printf("\n");
}
/********************************************************************/
void
dldbug (int argc, char **argv)
{
char answer[UIF_MAX_LINE];
void download_dbug (void (*)(void));
(void)argc;
(void)argv;
/*
* Print message
*/
printf("Erase Flash, download and program new dBUG image to Flash...\n");
printf("Continue? ");
get_line(answer);
if (strncasecmp("yes",answer,3) != 0)
return;
/*
* Jump to USER_SPACE and begin serial download and programming
* of new dBUG image
*/
download_dbug((void*)(DBUG_ADDRESS + 0x100));
}
/********************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -