?? 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 LPC2106
* on the
* IAR LPC210x Kickstart Card
*
* Filename : bsp.c
* Version : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* #DEFINE CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
typedef void (*BSP_PFNCT)(void);
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
CPU_INT32U VIC_SpuriousInt;
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void BSP_PLL_Init(void);
static void BSP_IO_Init(void);
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);
/*
*********************************************************************************************************
* Get the CPU Clock Frequency
*
* Description: This function reads CPU registers to determine the CPU clock frequency of the chip.
*
* Arguments : None
*
* Returns : The 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);
}
/*
*********************************************************************************************************
* Get the Peripheral Clock Frequency
*
* Description: This function reads CPU registers to determine the peripheral clock frequency of the chip.
*
* Arguments : None
*
* Returns : The 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
*********************************************************************************************************
*/
void BSP_Init (void)
{
MEMMAP = 2; /* Remap 64 bytes of int. RAM to 0x00 */
OS_CPU_InitExceptVect();
BSP_PLL_Init(); /* Initialize PLL0 */
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 */
}
/*
*********************************************************************************************************
* Set up the PLL
*
* Description: This function sets up and activates the PLL
*********************************************************************************************************
*/
static void BSP_PLL_Init (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
CPU_INT16U loop_ctr;
/* Configure PLL0, which determines the CPU clock */
PLLCFG = 0x00000023; /* Use PLL values of M = 4 and P = 2 */
PLLCON_bit.PLLE = 1; /* Set the PLL Enable bit */
OS_ENTER_CRITICAL();
PLLFEED = 0xAA; /* Write to the PLL Feed register */
PLLFEED = 0x55;
OS_EXIT_CRITICAL();
loop_ctr = 10000; /* Wait for the PLL to lock into the new frequency */
while (((PLLSTAT_bit.PLOCK) == 0) && (loop_ctr > 0)) {
loop_ctr--;
}
PLLCON_bit.PLLC = 1; /* Connect the PLL */
OS_ENTER_CRITICAL();
PLLFEED = 0xAA; /* Write to the PLL Feed register */
PLLFEED = 0x55;
OS_EXIT_CRITICAL();
VPBDIV = 0x00000002; /* Set the VPB frequency to one-half of the CPU clock */
}
/*
*********************************************************************************************************
* INITIALIZE I/Os
*
* Description : This function initializes the GPIO pins
*
* Arguments : none
*
* Note(s) :
* FUNCTION WHEN PINSEL0 bits are:
* ------------------------------------------------------
* BIT # PINSEL0 Bits 00 01 10 11
* ----- ------------ --------- --------- --------- ---------
* 0 1:0 GPIO P0.0 UART0 TxD PWM1
* 1 3:2 GPIO P0.1 UART0 RxD PWM3
* 2 5:4 GPIO P0.2 SCL (I2C) Capture 0.0
* 3 7:6 GPIO P0.3 SDA (I2C) Match 0.0
* 4 9:8 GPIO P0.4 SCK (I2C) Capture 0.1
* 5 11:10 GPIO P0.5 MISO (SPI) Match 0.1
* 6 13:12 GPIO P0.6 MOSI (SPI) Capture 0.2
* 7 15:14 GPIO P0.7 SSEL (SPI) PWM2
* 8 17:16 GPIO P0.8 UART1 TxD PWM4
* 9 19:18 GPIO P0.9 UART1 RxD PWM6
* 10 21:20 GPIO P0.10 UART1 RTS Capture 1.0
* 11 23:22 GPIO P0.11 UART1 CTS Capture 1.1
* 12 25:24 GPIO P0.12 UART1 DSR Match 1.0
* 13 27:26 GPIO P0.13 UART1 DTR Match 1.1
* 14 29:28 GPIO P0.14 UART1 CD EINT1
* 15 31:30 GPIO P0.15 UART1 RI EINT2
*********************************************************************************************************
*/
static void BSP_IO_Init (void)
{
#if OS_VIEW_MODULE == 0
PINSEL0 = 0xA0000000; /* Use GPIO pins P0.0 to P0.15 for LEDs */
PINSEL1 = 0x00000002;
IODIR = 0x00003FFF; /* Set GPIO pins as outputs */
#endif
#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_0)
PINSEL0 = 0xA0000005; /* Use GPIO pins P0.2 to P0.7 and P0.10 to P0.15 for LEDs */
PINSEL1 = 0x00000002;
IODIR = 0x00003FFD; /* Set GPIO pins as outputs except UART0, RxD */
#endif
#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
PINSEL0 = 0xA0050000; /* Use GPIO pins P0.0 to P0.15 for LEDs */
PINSEL1 = 0x00000002;
IODIR = 0x00003DFF; /* Set GPIO pins as outputs except UART1, RxD */
#endif
}
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
void LED_Init (void)
{
LED_Off(0); /* Turn OFF all the LEDs */
}
/*
*********************************************************************************************************
* LED ON
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to control
* 0 indicates that you want ALL the LEDs to be ON
* 1 turns ON LED1 on the board
* .
* .
* 16 turns ON LED16 on the board
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
IOSET = 0x0000FFFF;
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
IOSET = 1 << (led - 1);
break;
default:
break;
}
}
/*
*********************************************************************************************************
* LED OFF
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to turn OFF
* 0 indicates that you want ALL the LEDs to be OFF
* 1 turns OFF LED1 on the board
* .
* .
* 16 turns OFF LED16 on the board
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
IOCLR = 0x0000FFFF;
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -