?? bsp.c
字號:
/*
*********************************************************************************************************
* MICIRUM BOARD SUPPORT PACKAGE
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* BOARD SUPPORT PACKAGE
*
* NXP LPC2138
*
* Filename : bsp.c
* Version : V1.00
* Programmer(s) : JJL
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define BSP_GLOBALS
#include <includes.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/* ---------------------- GPIO0 PINS ---------------------- */
#define GPIO0_TXD0 DEF_BIT_00 /* (TXD (UART0) )(01): UART0 TX */
#define GPIO0_RXD0 DEF_BIT_01 /* (RXD (UART0) )(01): UART0 RX */
#define GPIO0_TXD1 DEF_BIT_08 /* (TXD (UART1) )(01): UART1 TX */
#define GPIO0_RXD1 DEF_BIT_09 /* (RXD (UART1) )(01): UART1 RX */
#define GPIO0_LCD_DATA4 DEF_BIT_10 /* (GPIO Port 0.10)(00): LCD Data 4 */
#define GPIO0_LCD_DATA5 DEF_BIT_11 /* (GPIO Port 0.11)(00): LCD Data 5 */
#define GPIO0_LCD_DATA6 DEF_BIT_12 /* (GPIO Port 0.12)(00): LCD Data 6 */
#define GPIO0_LCD_DATA7 DEF_BIT_13 /* (GPIO Port 0.13)(00): LCD Data 7 */
#define GPIO0_B1 DEF_BIT_15 /* (GPIO Port 0.15)(00): PB1 */
#define GPIO0_B2 DEF_BIT_16 /* (GPIO Port 0.16)(00): PB2 */
#define GPIO0_PWM5 DEF_BIT_21 /* ( )( ): PWM5 [LCD backlight] */
#define GPIO0_LCD_RS DEF_BIT_23 /* (GPIO Port 0.23)(00): LCD RS */
#define GPIO0_AOUT DEF_BIT_25 /* ( )( ): AOUT [LCD backlight] */
#define GPIO0_LCD_E DEF_BIT_26 /* (GPIO Port 0.26)(00): LCD E */
#define GPIO0_AD0 DEF_BIT_27 /* (AD0.0 )(01): AD0.0 [Potentiometer] */
#define GPIO0_LCD_RW DEF_BIT_31 /* (GPIO Port 0.31)(00): LCD RW */
#define GPIO0_LCD_DATA (GPIO0_LCD_DATA7 | GPIO0_LCD_DATA6 | GPIO0_LCD_DATA5 | GPIO0_LCD_DATA4)
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
CPU_INT32U VIC_SpuriousInt;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void ADC_Init (void);
static void LED_Init (void);
static void BSP_IO_Init (void);
static void BSP_PLL_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_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);
/*
*********************************************************************************************************
* 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)
{
MEMMAP = 2; /* Remap 64 bytes of int. RAM to 0x00 */
OS_CPU_InitExceptVect();
BSP_PLL_Init(); /* Initialize PLL0 and the VPB Divider Register */
BSP_IO_Init(); /* Initialize the board's I/Os */
VIC_Init(); /* Initialize the Vectored Interrupt Controller */
LED_Init(); /* Initialize the LED controls */
ADC_Init(); /* Intiialize the ADC control */
Tmr_TickInit(); /* Initialize the uC/OS-II tick interrupt */
}
/*
*********************************************************************************************************
* 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 cpu_clk_freq;
msel = (CPU_INT32U)(PLLCFG & 0x1F);
cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);
return (cpu_clk_freq);
}
/*
*********************************************************************************************************
* BSP_CPU_PclkFreq()
*
* Description : Get the peripheral clock frequency.
*
* Argument(s) : none.
*
* Return(s) : The peripheral clock frequency, in Hz.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_PclkFreq (void)
{
CPU_INT32U msel;
CPU_INT32U vpbdiv;
CPU_INT32U clk_freq;
CPU_INT32U pclk_freq;
msel = (CPU_INT32U)(PLLCFG & 0x1F);
clk_freq = CPU_OSC_FREQ * (msel + 1);
vpbdiv = (CPU_INT32U)(VPBDIV & 0x03);
switch (vpbdiv) {
case 0:
pclk_freq = clk_freq / 4;
break;
case 1:
pclk_freq = clk_freq;
break;
case 2:
pclk_freq = clk_freq / 2;
break;
default:
pclk_freq = clk_freq / 4;
break;
}
return (pclk_freq);
}
/*
*********************************************************************************************************
* OS_CPU_ExceptHndlr()
*
* Description : Handle any exceptions.
*
* Argument(s) : except_id ARM exception type:
*
* OS_CPU_ARM_EXCEPT_RESET 0x00
* OS_CPU_ARM_EXCEPT_UNDEF_INSTR 0x01
* OS_CPU_ARM_EXCEPT_SWI 0x02
* OS_CPU_ARM_EXCEPT_PREFETCH_ABORT 0x03
* OS_CPU_ARM_EXCEPT_DATA_ABORT 0x04
* OS_CPU_ARM_EXCEPT_ADDR_ABORT 0x05
* OS_CPU_ARM_EXCEPT_IRQ 0x06
* OS_CPU_ARM_EXCEPT_FIQ 0x07
*
* Return(s) : none.
*
* Caller(s) : OS_CPU_ARM_EXCEPT_HANDLER(), which is declared in os_cpu_a.s.
*********************************************************************************************************
*/
void OS_CPU_ExceptHndlr (CPU_INT32U except_id)
{
CPU_FNCT_VOID pfnct;
if (except_id == OS_CPU_ARM_EXCEPT_IRQ) {
pfnct = (CPU_FNCT_VOID)VICVectAddr; /* Read the interrupt vector from the VIC */
while (pfnct != (CPU_FNCT_VOID)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
VICVectAddr = 1; /* Acknowlege the VIC interrupt */
pfnct = (CPU_FNCT_VOID)VICVectAddr; /* Read the interrupt vector from the VIC */
}
} else {
/* Infinite loop on other exceptions. */
/* Should be replaced by other behavior (reboot, etc.) */
while (DEF_TRUE) {
;
}
}
}
/*
*********************************************************************************************************
* BSP_IntDisAll()
*
* Description : Disable ALL interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
VICIntEnClear = 0xFFFFFFFFL; /* Disable ALL interrupts */
}
/*
*********************************************************************************************************
*********************************************************************************************************
** uC/LCD FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DispInitPort()
*
* Description : Initializes the I/O ports used by the display driver.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Note(s) : (1) The I/Os for the LCD module are initialized in BSP_IO_Init().
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
void DispInitPort (void)
{
;
}
#endif
/*
*********************************************************************************************************
* DispDataWr()
*
* Description : Sends a single byte to the display device.
*
* Argument(s) : 'data' Data to send to the display device
*
* Return(s) : none.
*
* Note(s) : (1) The LPC2148 evaluation board uses a 4 bit interface.
* If an 8 bit interface is used. BSP_IO_Init() and DispDataWr() will need
* to be modified to reflect the new databus. In 8 bit mode, DispDataWrOneNibble()
* is not necessary.
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
void DispDataWr (CPU_INT08U data)
{
CPU_INT32U value;
DispRW_Low(); /* Set R/W write LOW to write to the LCD module */
DispE_High(); /* Write the UPPER nibble to the LCD module */
value = ((data >> 4) & 0x0F) << 10;
IO0SET = value;
value = (~(data >> 4) & 0x0F) << 10;
IO0CLR = value;
DispDly_uS(100);
DispE_Low();
DispDly_uS(100); /* Write the LOWER nibble to the LCD module */
DispE_High();
value = (data & 0x0F) << 10;
IO0SET = value;
value = (~data & 0x0F) << 10;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -