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

📄 m5282evb.c

📁 Coldfire MCF5282 DBug bootloader
💻 C
字号:
/*
 * File:		m5282evb.c
 * Purpose:		Board specific routines for the M5282EVB
 *
 * Notes:
 *
 */

#include "src/include/dbug.h"
#include "src/dev/flash/amd_flash.h"
#include "proj/common/relocate_io.h"

#ifdef DBUG_NETWORK
#include "src/dev/mcf5282/timer.h"
#include "src/uif/net/net.h"
#include "src/dev/mcf5282/fec.h"
extern uint8 TIMER_NETWORK;
extern NIF nif1;
#endif

/********************************************************************/
/* 
 * Global BSP variables referenced by dBUG 
 */
const char BRD_STR[]		= "M5282EVB";
const int  BRD_VER_MAJOR	= 1;
const char BRD_VER_MINOR	= 'b';
const char COPYRIGHT2[]		= "";

/********************************************************************/
void
board_init (void)
{
	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;

	/*
	 * Determine cause(s) of Reset
	 */
	printf("\n\n");
	if (MCF5282_SCM_CRSR & MCF5282_SCM_CRSR_CWDR)
		printf("Core Watchdog Time Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_EXT)
		printf("External Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_LOC)
		printf("Loss of Clock Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_LOL)
		printf("Loss of PLL Lock Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_LVD)
		printf("Low Voltage Detect Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_SOFT)
		printf("Software Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_WDR)
		printf("Watchdog Timer Reset\n");
	if (MCF5282_RESET_RSR & MCF5282_RESET_RSR_POR)
		printf("Power-on Reset\n");

	/* 
	 * Turn Instruction Cache ON
	 */
/*	
	mcf5xxx_wr_cacr(0
		| MCF5XXX_CACR_CENB
		| MCF5XXX_CACR_CINV
		| MCF5XXX_CACR_DISD
		| MCF5XXX_CACR_CEIB
		| MCF5XXX_CACR_CLNF_00);
*/

	/* 
	 * Allow interrupts from IRQ7 (black button) 
	 */
	MCF5282_EPORT_EPIER = MCF5282_EPORT_EPIER_EPIE7;
	MCF5282_INTC0_ICR7 = MCF5282_INTC_ICR_IL(7);
	MCF5282_INTC0_IMRL &= 	~(MCF5282_INTC_INTFRCL_INT7 
							| MCF5282_INTC_IMRL_MASKALL);
    /*
     * Set dBUG user stack to top of SDRAM
     */ 
	context.a7 = (SDRAM_ADDRESS + 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 Am29LV160DB;
	
	strcpy(Am29LV160DB.name,"Am29LV160DB (1 x 16-bit)");
	Am29LV160DB.base = (ADDRESS) AMD_FLASH_ADDRESS;
	Am29LV160DB.size = (int) AMD_FLASH_SIZE;
	Am29LV160DB.erase = (void *) amd_flash_erase;
	Am29LV160DB.program = (void *) amd_flash_program;
	Am29LV160DB.sector_start = (void *) amd_flash_sector_start;
	Am29LV160DB.sector_end = (void *) amd_flash_sector_end;
	Am29LV160DB.putchar = (void *) relocate_putchar;
	Am29LV160DB.protect_start = (ADDRESS) DBUG_ADDRESS;
	Am29LV160DB.protect_size = (int) DBUG_SIZE;

	/*
	 * Initialize AMD Flash device
	 */
	amd_flash_init(Am29LV160DB.base);
	
	/*
	 * Register AMD Flash with dBUG Flash Utilities
	 */
	flash_register_device(&Am29LV160DB);
}

/********************************************************************/
/*
 * Character Input/Output support
 */
/********************************************************************/
char
board_getchar (void)
{
	/* Wait until character has been received */
	while (!(MCF5282_UART0_USR & MCF5282_UART_USR_RXRDY))
		; 
	return MCF5282_UART0_URB;
}

/********************************************************************/
void
board_putchar (char ch)
{
	/* Wait until space is available in the FIFO */
	while (!(MCF5282_UART0_USR & MCF5282_UART_USR_TXRDY))
		;
	/* Send the character */
	MCF5282_UART0_UTB = (uint8)ch;
}

/********************************************************************/
int
board_getchar_present (void)
{
    return (MCF5282_UART0_USR & MCF5282_UART_USR_RXRDY);
}

/********************************************************************/
void
board_putchar_flush (void)
{
}

/********************************************************************/
int
board_dlio_init (void)
{
	/*	
	 * Download initialization routine 
	 */
	 
#ifdef DBUG_NETWORK
	int vector;
	uint8* board_get_ethaddr(uint8*);

	if (uif_dlio == UIF_DLIO_NETWORK)
	{
		unsigned char mac[6];

		/* 
		 * Register all FEC interrupt vectors with handler 
		 */
		for (vector = 87; vector <= 99; vector++)
		{
			if (!isr_register_handler(ISR_DBUG_ISR, vector,
					(void *)fec_handler,NULL, (void *)&nif1))
			{
				printf("Error: Unable to register handler\n");
				return FALSE;
			}
		}

		/* Enable FEC Rx Frame interrupts to ColdFire core */
		MCF5282_INTC0_ICR27 = MCF5282_INTC_ICR_IL(FEC_LEVEL);
		
		/* Set Timer Interrupt Mask Register */	
		MCF5282_INTC0_IMRL &= 	~(MCF5282_INTC_IMRL_INT27 
							| MCF5282_INTC_IMRL_MASKALL);

		/* 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;
}

/********************************************************************/
void
board_dlio_done (void)
{
	/*
	 * Download complete, clean up
	 */
#ifdef DBUG_NETWORK
	if (uif_dlio == UIF_DLIO_NETWORK)
	{
		/*	Disable FEC interrupts to ColdFire core */
		MCF5282_INTC0_ICR23 = MCF5282_INTC_ICR_IL(0);

		isr_remove_handler(ISR_DBUG_ISR,(void *)fec_handler);
    }
#endif
}

/********************************************************************/
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;
}

/********************************************************************/
#ifdef DBUG_NETWORK
int
board_dlio_filetype (char *filename, char *ext)
{
	(void)filename;
	(void)ext;

	return UIF_DLIO_UNKNOWN;
}
#endif

/********************************************************************/
void
board_reset (void)
{
	/*
	 * Initiate software reset
	 */
	MCF5282_RESET_RCR = 
		MCF5282_RESET_RCR_SOFTRST | MCF5282_RESET_RCR_FRCRSTOUT;
}

/********************************************************************/
void
board_irq_enable (void)
{
	asm_set_ipl(0);
}

/********************************************************************/
void
board_irq_disable (void)
{
	asm_set_ipl(6);
}

/********************************************************************/
void ext_irq7_handler (void) 
{
	/* Clear the interrupt */
	MCF5282_INTC0_ICR7 = MCF5282_INTC_ICR_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, "IPSBAR", 		IPSBAR_ADDRESS, 
									IPSBAR_ADDRESS + 0x3FFFFFFF, 32);

	printf(MEM_STR, "Flash (Int)",	FLASH_ADDRESS,	
									FLASH_ADDRESS + FLASH_SIZE - 1, 32);

	printf(MEM_STR, "Flash (Ext)",	EXT_FLASH_ADDRESS,	
									EXT_FLASH_ADDRESS + EXT_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, "Ext Flash");
	printf(CS_STR, 1, "Ext SRAM");
	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*)(AMD_FLASH_ADDRESS + 0x400));	 
}

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

⌨️ 快捷键说明

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