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

📄 mcf5206.cpp

📁 coldfire5206芯片的boot程序
💻 CPP
字号:
//#include  "nucleus.h"
#include  "bastype.h"
//#include  "systypes.h"
#include  "stdio.h"
#include  "mcf5206.h"

/*
FileName:      mcf5206.cpp
Description:   Initialization and timers' ISR for MCF5206E.
Version:       v1.0
Function List:

History:
   <author>           <time>                <desc>
  Li Linghua        2001/6/20            The file was created today.
*/

//extern VOID AnalogOutput( VOID  );


INT  gCpuFreePercent = 0;


/*
 Function Name: MCF5206Init
 Description:   initialize 5206
 Parameters:    None
 Return:        Nothing
 Test&Revision: done
*/
VOID  MCF5206Init( VOID )
{
   MCF5206InitInterrupts( );
   Init5206Timer1( );
   Init5206Timer2( );
}

/**
 *  a operation for writing one byte to the given register
 *
 *  @param  reg    the register to be written
 *  @param  value  a UCHAR value to be written
 */
VOID WriteByte(UINT32 reg,  UCHAR value)
{
	 *(UCHAR*)reg = value;
}


/**
 *  a operation for reading one byte from the given register
 *
 *  @param  reg    the register to be read
 */
UCHAR  ReadByte(UINT32 reg)
{
   return *(UCHAR*)reg;
}


/**
 *  make Interrupt Control Register context from interrupt level, priority
 *  and autovect flag
 *
 *  @param   intLevel     interrupt level
 *  @param   intPriority  interrupt priority
 *  @param   autoVect     auto-vector flag
 */
UCHAR MakeICR(UCHAR intLevel, UCHAR intPriority, UCHAR autoVect )
{
	 return  (autoVect | (intLevel << 2) | intPriority) ;
}


/**
 *  Enable hardware interrupt.
 *
 *  @see  <code>MCF5206</code> which give the define of interrupt mask
 *        bit for all interrupt
 */
VOID EnableSysInterrupt( UINT16 intMask )
{
	 *(UINT16*)MCF5206::IMR = ( *(UINT16*)MCF5206::IMR ) & ~intMask;
}


/**
 *  Disable hardware interrupt
 */
VOID DisableSysInterrupt( UINT16 intMask )
{
	 *(UINT16*)MCF5206::IMR = ( *(UINT16*)MCF5206::IMR ) | intMask;
}


/**
 *  MCf5206 system integration module initialize, include ICRs and IMR
 */
VOID  MCF5206InitInterrupts( VOID )
{
	UCHAR  icr;

    // =======================  ICR initialize ============================ //

   // External interrupt 1 to 7
   icr = MakeICR(MCF5206::IL_EINT1, MCF5206::IP_EINT1, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR1, icr);

   icr = MakeICR(MCF5206::IL_EINT2, MCF5206::IP_EINT2, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR2, icr);

   icr = MakeICR(MCF5206::IL_EINT3, MCF5206::IP_EINT3, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR3, icr);

   icr = MakeICR(MCF5206::IL_EINT4, MCF5206::IP_EINT4, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR4, icr);

   icr = MakeICR(MCF5206::IL_EINT5, MCF5206::IP_EINT5, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR5, icr);

   icr = MakeICR(MCF5206::IL_EINT6, MCF5206::IP_EINT6, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR6, icr);

   icr = MakeICR(MCF5206::IL_EINT7, MCF5206::IP_EINT7, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR7, icr);

   // Software Watchdog
   icr = MakeICR(MCF5206::IL_SWT, MCF5206::IP_SWT, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR8, icr);

   // Timer 1
   icr = MakeICR(MCF5206::IL_TIMER1, MCF5206::IP_TIMER1, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR9, icr);

   // Timer 2
   icr = MakeICR(MCF5206::IL_TIMER2, MCF5206::IP_TIMER2, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR10, icr);

   // MBUS
	 icr = MakeICR(MCF5206::IL_MBUS, MCF5206::IP_MBUS, MCF5206::IAV_YES);
   WriteByte(MCF5206::ICR11, icr);

   // UART 1
   icr = MakeICR(MCF5206::IL_UART1, MCF5206::IP_UART1, MCF5206::IAV_NO);
   WriteByte(MCF5206::ICR12, icr);

   // UART 2
   icr = MakeICR(MCF5206::IL_UART2, MCF5206::IP_UART2, MCF5206::IAV_NO);
   WriteByte(MCF5206::ICR13, icr);

   // =======================  IMR initialize ============================ //
   DisableSysInterrupt( MCF5206::IM_ALL );
}

/*
 Function Name:  Init5206Timer1
 Description:    Initialize 5206 timer1 to 4ms interrupt as Nucleus time tick,
                 note: interrupt status will not be changed.
 Parameters:     No
 Return:         Nothing
 Output:         Nothing
 Test&Revision:  Done
*/
VOID  Init5206Timer1( VOID )
{
   // Timer Mode
   *(UINT16*)MCF5206::TMR1 =  0xFF00 // b15~b8: Prescaler = 256
                            | 0x0010 // b4: Enable reference interrupt
                            | 0x0008 // b3: Restart timer after reference reached
                            | 0x0004 // b2~b1: System clock / 16
                            | 0x0001 // b0: Enable timer
                            ;
   // How to calculate Timer Reference:
   //  1. one LSB in reference represent for:
   //     LSB_INTERVAL = 1000000us / (system clock / (16 * (Prescaler + 1)))(us);
   //  2. so, if you want a 4 milliseconds timer interrupt, the TRR is:
   //     Timer Reference = 4 millisecond / LSB_INTERVAL
   //  3. example:
   //     system clock = 54MHz, System clock / 16 enabled, prescaler is 255,
   //     the LSB_INTERVAL = 1000000 / (54 * 1000000 / (16 * 256));
   //     the Timer Reference for a 4ms interrupt is: 1024000 / LSB_INTERVAL = 13500

   // Timer Reference for a 1.024s interrupt
   // System clock is 54Mhz
	*(UINT16*)MCF5206::TRR1 = 13500;
}


/*
 Function Name:  Init5206Timer2
 Description:    Initialize 5206 timer2 to 2ms interrupt,
                 note: interrupt status will not be changed.
 Parameters:     No
 Return:         Nothing
 Output:         Nothing
 Test&Revision:  Done
*/
VOID  Init5206Timer2( VOID )
{
   // Timer Mode
   *(UINT16*)MCF5206::TMR2 =  0x0000 // b15~b8: Prescaler = 0
                            | 0x0000 // b4: Disenable reference interrupt
                            | 0x0008 // b3: Restart timer after reference reached
                            | 0x0004 // b2~b1: System clock / 16
                            | 0x0001 // b0: Enable timer
                            ;
   // How to calculate Timer Reference: see Init5206Timer1

   // Timer Reference for 1ms delaying
   // System clock is 54hz
   //     system clock = 54MHz, System clock / 16 enabled, prescaler is 0,
   //     the LSB_INTERVAL = 1000000 / (54 * 1000000 / (16 * 1));
   //     the Timer Reference for a 1.024ms interrupt is: 1024 / LSB_INTERVAL = 3375
   // System clock is 54Mhz
	*(UINT16*)MCF5206::TRR2 = 3456;
}

/*
 Function Name:  FirstTimerLisr
 Description:    MCF5206 timer1 ISR, for reseting watchdog
 Parameters:     No
 Return:         Nothing
 Output:         Nothing
 Test&Revision:  Done
*/

extern ResetWatchdog();
extern "C" VOID  FirstTimerLisr()
{
	ResetWatchdog();
}

/*
 Function Name:  SecondTimerLisr
 Description:    MCF5206 timer2 ISR
 Parameters:     No
 Return:         Nothing
 Output:         Nothing
 Test&Revision:  Done
*/
extern "C" VOID  SecondTimerLisr( VOID )
{
}


/*
 Function Name:  Delay
 Description:    delay 1 ms, using timer2
 Parameters:     No
 Return:         Nothing
 Test&Revision:  Done
*/
void Sleep(UINT32 tmSize)	// size: ms 
{
	UINT16 x, y;

	if ( tmSize == 0)
		tmSize = 1;
	while (tmSize)
	{
		x = *((UINT16*)(MCF5206::TCN2));
		while (1)
		{ 
//			y = (0xffff + *((UINT16*)(MCF5206::TCN2)) - x) % 0xffff;
			y = *((UINT16*)(MCF5206::TCN2));
			if (y >= x && (y - x) >= *((UINT16*)MCF5206::TRR2))
				break;
			if (y < x && (y + 0xffff - x) >= *((UINT16*)MCF5206::TRR2))
				break;
		}
		tmSize--;
	}
	return;
}
/*
 Function Name:  ShutDownSystem
 Description:    shut down the minitor system
 Parameters:     No
 Return:         Nothing
 Test&Revision:  Done
*/
VOID  ShutDownSystem( VOID )
{
   WriteByte( MCF5206::PPDAT, 0xf6 );
}


⌨️ 快捷键说明

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