📄 bsp.c
字号:
/*
*********************************************************************************************************
* Philips LPC214x
* LPC2148 Kick Start Card Board Support Package
*
* (c) Copyright 2006, Micrium, Weston, FL
* All Rights Reserved
*
*
* File : BSP.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#define BSP_GLOBALS
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define LED_1_BIT (CPU_INT32U)(1 << 25)
#define LCD_BIT_RW (CPU_INT32U)(1 << 29)
#define LCD_BIT_E (CPU_INT32U)(1 << 28)
#define LCD_BIT_RS (CPU_INT32U)(1 << 22)
#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)
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef void (*PFNCT)(void);
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
CPU_INT32U Tmr_ReloadCnts;
CPU_INT32U VIC_SpuriousInt;
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_PLL_Init (void);
static void BSP_IO_Init(void);
static void BSP_MAM_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);
static void Ext0_Init (void);
/*
*********************************************************************************************************
* 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
/* Configure PLL0, which determines the CPU clock */
PLLCFG = 0x00000023; /* Use PLL values of M = 4 and P = 2 */
PLLCON = 0x01; /* Set the PLL Enable bit */
#if (CPU_FCCO_FREQ / CPU_FCCLK_FREQ) == 2
PLLCFG = ((CPU_FCCLK_FREQ / CPU_OSC_FREQ) - 1) | (0 << 5);
#endif
#if (CPU_FCCO_FREQ / CPU_FCCLK_FREQ) == 4
PLLCFG = ((CPU_FCCLK_FREQ / CPU_OSC_FREQ) - 1) | (1 << 5);
#endif
#if (CPU_FCCO_FREQ / CPU_FCCLK_FREQ) == 8
PLLCFG = ((CPU_FCCLK_FREQ / CPU_OSC_FREQ) - 1) | (2 << 5);
#endif
#if (CPU_FCCO_FREQ / CPU_FCCLK_FREQ) == 16
PLLCFG = ((CPU_FCCLK_FREQ / CPU_OSC_FREQ) - 1) | (3 << 5);
#endif
OS_ENTER_CRITICAL();
PLLFEED = 0xAA; /* Write to the PLL Feed register */
PLLFEED = 0x55;
OS_EXIT_CRITICAL();
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
OS_ENTER_CRITICAL();
PLLFEED = 0xaa;
PLLFEED = 0x55;
OS_EXIT_CRITICAL();
VPBDIV = 0x00000004; /* Set the VPB frequency to one-half of the CPU clock */
}
/*
*********************************************************************************************************
* Get the CPU Clock Frequency
*
* Description: This function reads CPU registers to determine the CPU clock frequency of the chip.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreq (void)
{
CPU_INT32U msel;
CPU_INT32U cpu_clk_freq;
cpu_clk_freq = CPU_FCCLK_FREQ;
return (cpu_clk_freq);
}
/*
*********************************************************************************************************
* Get the Peripheral Clock Frequency
*
* Description: This function reads CPU registers to determine the peripheral clock frequency of the chip.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreqPeripheral (void)
{
CPU_INT32U cpu_clk_freq;
CPU_INT32U cpu_peripheral_clk_freq;
cpu_clk_freq = BSP_CPU_ClkFreq();
cpu_peripheral_clk_freq = cpu_clk_freq / 4;
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 and the VPB Divider Register */
BSP_MAM_Init(); /* Initialize the Memory Acceleration Module */
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 */
UART0_Ini();
//Tmr1_Init();
RTCInit();
//Ext0_Init();
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
VICIntEnClr = 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
*********************************************************************************************************
*/
static void BSP_IO_Init (void)
{
CPU_INT32U value;
SCS = 0x00000001; /* Fast GPIO registers will be used */
value = (1 << 16) | (1 << 15); /* Push buttons B2 and B1 */
FIO0DIR &= ~value;
/* LCD control lines */
value = ~((3 << 20) | (3 << 22) | (3 << 24) | (3 << 26));
PINSEL0 &= value;
/* LCD data lines */
value = ~((3 << 12) | (3 << 24) | (3 << 26));
PINSEL1 &= value;
value = LCD_BIT_DATA3 | LCD_BIT_DATA2 | LCD_BIT_DATA1 | LCD_BIT_DATA0 | LCD_BIT_E | LCD_BIT_RS | LCD_BIT_RW | LED_1_BIT;
FIO0DIR |= value;
PINSEL2 = 0x00000004;
}
/*$PAGE*/
/*
*********************************************************************************************************
* GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments : push_button is the number of the push button to probe
* 1 probe the push button B1
* 2 probe the push button B2
*********************************************************************************************************
*/
CPU_BOOLEAN PB_GetStatus (CPU_INT08U push_button_id)
{
CPU_BOOLEAN status;
status = DEF_FALSE;
switch (push_button_id)
{
case 1:
if ((FIO0PIN & (1 << 15)) == 0)
{
return (DEF_TRUE);
}
break;
case 2:
if ((FIO0PIN & (1 << 16)) == 0)
{
return (DEF_TRUE);
}
break;
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
* LED INITIALIZATION
*
* Description : This function initializes the board's LEDs
*
* Arguments : none
*********************************************************************************************************
*/
const unsigned int LED=(1<<24); //P1.24--LED, low level is on
void LED_Init (void)
{
PINSEL2=PINSEL2&(~0x08); /* Turn OFF all the LEDs */
IO1DIR=LED;
}
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
static INT8U LedFlag = 0;
void LED_Off (CPU_INT08U led)
{
IO1SET = LED;
LedFlag = 0;
}
/*
*********************************************************************************************************
* 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_On (CPU_INT08U led)
{
IO1CLR = LED;
LedFlag = 1;
}
/*
*********************************************************************************************************
* LED TOGGLE
*
* Description : This function is used to toggle any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to control
* 0 indicates that you want to toggle ALL the LEDs
* 1 toggles LED1 on the board
* .
* .
* 16 toggles LED16 on the board
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
}
INT8U LED_Status(void)
{
return LedFlag;
}
/*
*********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -