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

📄 bsp.c

📁 MCB2300_ucgui_LCD320240.rar LPC2368的uc/gui的移植
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
*********************************************************************************************************
*   								  MICRIUM BOARD SUPPORT SUPPORT
*
*   						  (c) Copyright 2006; Micrium, Inc.; Weston, FL
*
*   			All rights reserved.  Protected by international copyright laws.
*   			Knowledge of the source code may NOT be used to develop a similar product.
*   			Please help us continue to provide the Embedded community with the finest
*   			software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*   									 BOARD SUPPORT PACKAGE
*
*   										  NXP LPC2378
*   											 on the
*   								   Keil MCB2300 Evaluation Board
*
* Filename  	: bsp.c
* Version   	: V1.00
* Programmer(s) : EFS
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*   										  INCLUDE FILES
*********************************************************************************************************
*/

#define  BSP_GLOBALS
#include <includes.h>


/*
*********************************************************************************************************
*   										 LOCAL DEFINES
*********************************************************************************************************
*/

#define  HW_REV_0   								0			/* LCD E bit is pin 30 for early MCB2300 revisions  		*/
/* For later hardware revisions, define to 0, pin 31.   	*/

/* ---------------------- GPIO0 Pins ---------------------- */
#define  GPIO0_CAN_RX1  					  DEF_BIT_00
#define  GPIO0_CAN_TX1  					  DEF_BIT_01
#define  GPIO0_TXD0 						  DEF_BIT_02
#define  GPIO0_RXD0 						  DEF_BIT_03
#define  GPIO0_CAN_RX2  					  DEF_BIT_04
#define  GPIO0_CAN_TX2  					  DEF_BIT_05
#define  GPIO0_TXD1 						  DEF_BIT_15
#define  GPIO0_RXD1 						  DEF_BIT_16
#define  GPIO0_MCICLK   					  DEF_BIT_19
#define  GPIO0_MCICMD   					  DEF_BIT_20
#define  GPIO0_MCIDAT0  					  DEF_BIT_22
#define  GPIO0_POT  						  DEF_BIT_23
#define  GPIO0_SPEAKER  					  DEF_BIT_26

/* ---------------------- GPIO1 Pins ---------------------- */
#define  GPIO1_E_TXD0   					  DEF_BIT_00
#define  GPIO1_E_TXD1   					  DEF_BIT_01
#define  GPIO1_E_TX_EN  					  DEF_BIT_04
#define  GPIO1_E_CRS0   					  DEF_BIT_08
#define  GPIO1_E_RXD0   					  DEF_BIT_09
#define  GPIO1_E_RXD1   					  DEF_BIT_10
#define  GPIO1_E_RX_ER  					  DEF_BIT_14
#define  GPIO1_E_RX_CLK 					  DEF_BIT_15
#define  GPIO1_E_MDC						  DEF_BIT_16
#define  GPIO1_E_MDIO   					  DEF_BIT_17
#define  GPIO1_LCD_DB4  					  DEF_BIT_24
#define  GPIO1_LCD_DB5  					  DEF_BIT_25
#define  GPIO1_LCD_DB6  					  DEF_BIT_26
#define  GPIO1_LCD_DB7  					  DEF_BIT_27
#define  GPIO1_LCD_RS   					  DEF_BIT_28
#define  GPIO1_LCD_RW   					  DEF_BIT_29
#if HW_REV_0
#define  GPIO1_LCD_E						  DEF_BIT_30
#else
#define  GPIO1_LCD_E						  DEF_BIT_31
#endif

/* ---------------------- GPIO2 Pins ---------------------- */
#define  GPIO2_LED0 						  DEF_BIT_00
#define  GPIO2_LED1 						  DEF_BIT_01
#define  GPIO2_LED2 						  DEF_BIT_02
#define  GPIO2_LED3 						  DEF_BIT_03
#define  GPIO2_LED4 						  DEF_BIT_04
#define  GPIO2_LED5 						  DEF_BIT_05
#define  GPIO2_LED6 						  DEF_BIT_06
#define  GPIO2_LED7 						  DEF_BIT_07
#define  GPIO2_PB1  						  DEF_BIT_10
#define  GPIO2_MCIDAT1  					  DEF_BIT_11
#define  GPIO2_MCIDAT2  					  DEF_BIT_12
#define  GPIO2_MCIDAT3  					  DEF_BIT_13

/*
*********************************************************************************************************
*   										LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*   									   LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*   										 LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*   									LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/

CPU_INT32U  VIC_SpuriousInt;


/*
*********************************************************************************************************
*   								   LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void PLL_Init(void);
static  void MAM_Init(void);
static  void GPIO_Init(void);
static  void VIC_Init(void);
static  void ADC_Init(void);
static  void LED_Init(void);

#ifdef DISP_MODULE_PRESENT
static  void DispE_High(void);
static  void DispE_Low(void);
static  void DispRW_High(void);
static  void DispRW_Low(void);
#endif

static  void Tmr_TickInit(void);

static  void VIC_Dummy(void);   					  /* Prototypes for dummy interrupt handlers				  */
static  void VIC_DummyWDT(void);
static  void VIC_DummySW(void);
static  void VIC_DummyDEBUGRX(void);
static  void VIC_DummyDEBUGTX(void);
static  void VIC_DummyTIMER0(void);
static  void VIC_DummyTIMER1(void);
static  void VIC_DummyUART0(void);
static  void VIC_DummyUART1(void);
static  void VIC_DummyPWM01(void);
static  void VIC_DummyI2C0(void);
static  void VIC_DummySPI(void);
static  void VIC_DummySSP1(void);
static  void VIC_DummyPLL(void);
static  void VIC_DummyRTC(void);
static  void VIC_DummyEINT0(void);
static  void VIC_DummyEINT1(void);
static  void VIC_DummyEINT2(void);
static  void VIC_DummyEINT3(void);
static  void VIC_DummyAD0(void);
static  void VIC_DummyI2C1(void);
static  void VIC_DummyBOD(void);
static  void VIC_DummyETHERNET(void);
static  void VIC_DummyUSB(void);
static  void VIC_DummyCAN01(void);
static  void VIC_DummyMMC(void);
static  void VIC_DummyGP_DMA(void);
static  void VIC_DummyTIMER2(void);
static  void VIC_DummyTIMER3(void);
static  void VIC_DummyUART2(void);
static  void VIC_DummyUART3(void);
static  void VIC_DummyI2C2(void);
static  void VIC_DummyI2S(void);


/*
*********************************************************************************************************
*   								  LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*********************************************************************************************************
**  									   GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*   										  BSP_Init()
*
* Description : Initialize the Board Support Package (BSP).
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Note(s)     : (1) This function SHOULD be called before any other BSP function is called.
*********************************************************************************************************
*/

void BSP_Init(void)
{
	PLL_Init(); 								   				/* Initialize the PLL   									*/
	MAM_Init(); 											  	/* Initialize the Memory Acceleration Module				*/
	GPIO_Init();											 	/* Initialize the board's I/Os                              */
	ADC_Init(); 												/* Initialize the board's ADC                               */
	VIC_Init(); 												/* Initialize the Vectored Interrupt Controller 			*/
	LED_Init(); 											   	/* Initialize the I/Os for the LED controls 				*/

	Tmr_TickInit(); 											/* Initialize the uC/OS-II tick interrupt   				*/

	SCS = 1;

	PINSEL0 = 0;
	PINSEL1 = 0;
	PINSEL2 = 0;

	PINMODE0 = 0;
	PINMODE1 = 0;
	PINMODE2 = 0;

	FIO0DIR = 0xffffffff;
	FIO1DIR = 0xffffffff;
	FIO2DIR = 0xffffffff;
}


/*
*********************************************************************************************************
*   										 BSP_CPU_ClkFreq()
*
* Description : Get the CPU clock frequency.
*
* Argument(s) : none.
*
* Return(s)   : The CPU clock frequency, in Hz.
*********************************************************************************************************
*/

CPU_INT32U BSP_CPU_ClkFreq(void)
{
	CPU_INT32U  msel;
	CPU_INT32U  nsel;
	CPU_INT32U  fin;
	CPU_INT32U  pll_clk_feq;									/* When the PLL is enabled, this is Fcco					*/
	CPU_INT32U  clk_div;
	CPU_INT32U  clk_freq;


	switch (CLKSRCSEL & 0x03)
	{
			/* Determine the current clock source   					*/
		case 0:
			fin = IRC_OSC_FRQ;
			break;

		case 1:
			fin = MAIN_OSC_FRQ;
			break;

		case 2:
			fin = RTC_OSC_FRQ;
			break;

		default:
			fin = IRC_OSC_FRQ;
			break;
	}

	if ((PLLSTAT & (1 << 25)) > 0)
	{
		/* If the PLL is currently enabled and connected		*/
		msel = (CPU_INT32U) (PLLSTAT & 0x3FFF) + 1; 		  		/* Obtain the PLL multiplier  						  */
		nsel = (CPU_INT32U) ((PLLSTAT >> 16) & 0x0F) + 1;   		/* Obtain the PLL divider   							*/
		pll_clk_feq = (2 * msel * (fin / nsel));					/* Compute the PLL output frequency 					*/
	}
	else
	{
		pll_clk_feq = (fin);										/* The PLL is bypassed  								*/
	}

	clk_div = (CPU_INT32U) (CCLKCFG & 0xFF) + 1;			 		/* Obtain the CPU core clock divider   				 */
	clk_freq = (CPU_INT32U) (pll_clk_feq / clk_div);		  		/* Compute the ARM Core clock frequency   			  */

	return (clk_freq);
}

/*
*********************************************************************************************************
*   										 BSP_CPU_PclkFreq()
*
* Description : Get the peripheral clock frequency for a specific peripheral.
*
* Argument(s) : pclk		The peripheral clock ID, one of PCLK_??? defined in bsp.h.
*
* Return(s)   : The peripheral's clock in Hz
*********************************************************************************************************
*/


CPU_INT32U BSP_CPU_PclkFreq(CPU_INT08U  pclk)
{
	CPU_INT32U  clk_freq;
	CPU_INT32U  selection;


	clk_freq = BSP_CPU_ClkFreq();

	switch (pclk)
	{
		case PCLK_WDT:
		case PCLK_TIMER0:
		case PCLK_TIMER1:
		case PCLK_UART0:
		case PCLK_UART1:
		case PCLK_PWM0:
		case PCLK_PWM1:
		case PCLK_I2C0:
		case PCLK_SPI:
		case PCLK_RTC:
		case PCLK_SSP1:
		case PCLK_DAC:
		case PCLK_ADC:
		case PCLK_CAN1:
		case PCLK_CAN2:
		case PCLK_ACF:
			selection = ((PCLKSEL0 >> (pclk * 2)) & 0x03);
			if (selection == 0)
			{
				return (clk_freq / 4);
			}
			else if (selection == 1)
			{
				return (clk_freq);
			}
			else if (selection == 2)
			{
				return (clk_freq / 2);
			}
			else
			{
				return (clk_freq / 8);
			}

		case PCLK_BAT_RAM:
		case PCLK_GPIO:
		case PCLK_PCB:
		case PCLK_I2C1:
		case PCLK_SSP0:
		case PCLK_TIMER2:
		case PCLK_TIMER3:
		case PCLK_UART2:
		case PCLK_UART3:
		case PCLK_I2C2:
		case PCLK_MCI:
		case PCLK_SYSCON:
			selection = ((PCLKSEL1 >> ((pclk - 16) * 2)) & 0x03);
			if (selection == 0)
			{
				return (clk_freq / 4);
			}
			else if (selection == 1)
			{
				return (clk_freq);
			}
			else if (selection == 2)
			{
				return (clk_freq / 2);
			}
			else
			{
				return (clk_freq / 8);
			}

		default:
			return (0);
	}
}

⌨️ 快捷键说明

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