📄 bsp.c
字号:
/*
*********************************************************************************************************
* NXP LPC213x
* LPC2138 Kick Start Card Board Support Package
*
* (c) Copyright 2005, Micrium, Weston, FL
* All Rights Reserved
*
*
* File : BSP.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define LCD_BIT_E (CPU_INT32U)(1 << 26)
#define LCD_BIT_RS (CPU_INT32U)(1 << 23)
#define LCD_BIT_RW (CPU_INT32U)(1 << 31)
#define LCD_BIT_DATA3 (CPU_INT32U)(1 << 13)
#define LCD_BIT_DATA2 (CPU_INT32U)(1 << 12)
#define LCD_BIT_DATA1 (CPU_INT32U)(1 << 11)
#define LCD_BIT_DATA0 (CPU_INT32U)(1 << 10)
#define BSP_PLL_STATUS_LOCKED (CPU_INT32U)(1 << 10)
#define BSP_PLL_EN 1 /* Uses PLL when 1 */
#define BSP_PLL_MULTIPLIER 4 /* 1 .. 6 */
#define BSP_PLL_DIVIDER 1 /* 1, 2, 4 or 8 */
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
CPU_INT32U Tmr_ReloadCnts;
CPU_INT32U VIC_SpuriousInt;
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_IO_Init(void);
#if BSP_PLL_EN == 1
static void BSP_PLL_Init(void);
#endif
#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_Init(void);
static void VIC_Dummy(void);
static void VIC_DummyWDT(void);
static void VIC_DummyTIMER0(void);
static void VIC_DummyTIMER1(void);
static void VIC_DummyUART0(void);
static void VIC_DummyUART1(void);
static void VIC_DummyPWM0(void);
static void VIC_DummyI2C(void);
static void VIC_DummySPI(void);
static void VIC_DummyRTC(void);
static void VIC_DummyEINT0(void);
static void VIC_DummyEINT1(void);
static void VIC_DummyEINT2(void);
/*
*********************************************************************************************************
* Set the CPU Clock Frequency
*
* Description: This function sets up and activates the PLL
*********************************************************************************************************
*/
#if BSP_PLL_EN == 1
void BSP_PLL_Init (void)
{
PLLCFG = (BSP_PLL_MULTIPLIER - 1); /* Set the multiplier */
PLLCFG |= (BSP_PLL_DIVIDER - 1) << 5; /* Set the divider */
PLLCON = 0x01; /* Activate the PLL */
PLLFEED = 0xAA; /* Validation sequence, 0xAA */
PLLFEED = 0x55; /* Validation sequence, 0x55 */
/* Wait, then verify that the PLL locks */
while ((PLLSTAT & BSP_PLL_STATUS_LOCKED) != BSP_PLL_STATUS_LOCKED) {
;
}
PLLCON = 0x03; /* Connect the PLL so cclk is driven by the PLL */
PLLFEED = 0xAA; /* Validation sequence, 0xAA */
PLLFEED = 0x55; /* Validation sequence, 0x55 */
}
#endif
/*
*********************************************************************************************************
* Get the CPU Clock Frequency
*
* Description: This function reads CPU registers to determine the CPU clock frequency of the chip.
*
* Argument(s): none
*
* Returns : Clock frequency in KHz.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreq (void)
{
CPU_INT32U msel;
CPU_INT32U cpu_clk_freq;
msel = (CPU_INT32U)(PLLCFG & 0x1F);
cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);
return (cpu_clk_freq);
}
/*
*********************************************************************************************************
* Get the Peripheral Clock Frequency
*
* Description: This function reads CPU registers to determine the peripheral clock frequency of the chip.
*
* Argument(s): none
*
* Returns : Peripheral clock frequency in Hz.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreqPeripheral (void)
{
CPU_INT32U msel;
CPU_INT32U vpbdiv;
CPU_INT32U cpu_clk_freq;
CPU_INT32U cpu_peripheral_clk_freq;
msel = (CPU_INT32U)(PLLCFG & 0x1F);
cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);
vpbdiv = (CPU_INT32U)(VPBDIV & 0x03);
switch (vpbdiv) {
case 0:
cpu_peripheral_clk_freq = cpu_clk_freq / 4;
break;
case 1:
cpu_peripheral_clk_freq = cpu_clk_freq;
break;
case 2:
cpu_peripheral_clk_freq = cpu_clk_freq / 2;
break;
default:
cpu_peripheral_clk_freq = cpu_clk_freq / 4;
break;
}
return (cpu_peripheral_clk_freq);
}
/*
*********************************************************************************************************
* BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
* functions found in this module.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void BSP_Init (void)
{
MEMMAP = 2; /* Remap 64 bytes of int. RAM to 0x00 */
BSP_InitExceptVect();
#if BSP_PLL_EN == 1
BSP_PLL_Init(); /* Initialize the PLL */
#endif
BSP_IO_Init(); /* Initialize the board's I/Os */
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 */
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
VICIntEnClear = 0xFFFFFFFFL; /* Disable ALL interrupts */
}
/*
*********************************************************************************************************
* INITIALIZE I/Os
*
* Description : This function initializes the GPIO pins. All the I/O pins are initialized in this function
* so you don't have to look at multiple places for I/O initialization.
*
* Arguments : none
*
* Note(s) : 1) PINSEL0 and PINSEL1 assignments for the LPC2138:
*
* FUNCTION WHEN PINSEL0 bits are:
* ------------------------------------------------------
* BIT # PINSEL0 Bits 00 01 10 11
* ----- ------------ --------- --------- --------- ---------
* 0 1:0 GPIO P0.0 UART0 TxD PWM1 Reserved
* 1 3:2 GPIO P0.1 UART0 RxD PWM3 EINT0
* 2 5:4 GPIO P0.2 SCL (I2C) Capture 0.0 Reserved
* 3 7:6 GPIO P0.3 SDA (I2C) Match 0.0 EINT1
* 4 9:8 GPIO P0.4 SCK (I2C) Capture 0.1 AD 0.6
* 5 11:10 GPIO P0.5 MISO (SPI) Match 0.1 AD 0.7
* 6 13:12 GPIO P0.6 MOSI (SPI) Capture 0.2 AD 1.0
* 7 15:14 GPIO P0.7 SSEL (SPI) PWM2 EINT2
*
* 8 17:16 GPIO P0.8 UART1 TxD PWM4 AD 1.1
* 9 19:18 GPIO P0.9 UART1 RxD PWM6 EINT3
* 10 21:20 GPIO P0.10 UART1 RTS Capture 1.0 AD 1.2
* 11 23:22 GPIO P0.11 UART1 CTS Capture 1.1 SCL1 (IIC #1)
* 12 25:24 GPIO P0.12 UART1 DSR Match 1.0 AD 1.3
* 13 27:26 GPIO P0.13 UART1 DTR Match 1.1 AD 1.4
* 14 29:28 GPIO P0.14 UART1 CD EINT1 SDA1 (IIC #1)
* 15 31:30 GPIO P0.15 UART1 RI EINT2 AD 1.5
*
* FUNCTION WHEN PINSEL1 bits are:
* ------------------------------------------------------
* BIT # PINSEL1 Bits 00 01 10 11
* ----- ------------ --------- --------- --------- ---------
* 0 1:0 GPIO P0.16 EINT0 Match 0.2 Capture 0.2
* 1 3:2 GPIO P0.17 Capture 1.2 SCLK (SSP) Match 1.2
* 2 5:4 GPIO P0.18 Capture 1.3 MISO (SSP) Match 1.3
* 3 7:6 GPIO P0.19 Match 1.3 MOSI (SSP) Capture 1.2
* 4 9:8 GPIO P0.20 Match 1.3 SSEL (SSP) EINT3
* 5 11:10 GPIO P0.21 PWM5 AD 1.6 Capture 1.3
* 6 13:12 GPIO P0.22 AD 1.7 Capture 0.0 Match 0.0
* 7 15:14 GPIO P0.23 Reserved Reserved Reserved
*
* 8 17:16 GPIO P0.24 Reserved Reserved Reserved
* 9 19:18 GPIO P0.25 AD 0.4 AOUT Reserved
* 10 21:20 GPIO P0.26 AD 0.5 Reserved Reserved
* 11 23:22 GPIO P0.27 AD 0.0 Capture 0.1 Match 0.1
* 12 25:24 GPIO P0.28 AD 0.1 Capture 0.2 Match 0.2
* 13 27:26 GPIO P0.29 AD 0.2 Capture 0.3 Match 0.3
* 14 29:28 GPIO P0.30 AD 0.3 EINT3 Capture 0.0
* 15 31:30 GPIO P0.31 Reserved Reserved Reserved
*
*
* 2) The 2x16 LCD is connected as follows on the LPC2138 Evaluation board:
*
* P0.31 R/W- Read (H) / Write (L)
* P0.26 E Enable
* P0.23 RS Register Select
* P0.21 LED LED Backlight
*
* P0.13 D7 LCD Data 7 \
* P0.12 D6 LCD Data 6 | 4-bit interface mode
* P0.11 D5 LCD Data 5 |
* P0.10 D4 LCD Data 4 /
*********************************************************************************************************
*/
static void BSP_IO_Init (void)
{
CPU_INT32U value;
#if OS_VIEW_MODULE == 0
PINSEL0 = 0x00000000;
#endif
#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_0)
PINSEL0 = 0x00000005; /* Enable UART0 I/Os */
#endif
#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
PINSEL0 = 0x00050000; /* Enable UART1 I/Os */
#endif
value = (1 << 16) | (1 << 15); /* Push buttons B2 and B1 */
#if __VER__ == 420
IODIR0 &= ~value;
#else
IO0DIR &= ~value;
#endif
/* LCD control lines */
value = ~((3 << 20) | (3 << 22) | (3 << 24) | (3 << 26));
PINSEL0 &= value;
/* LCD data lines */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -