?? bsp.c
字號:
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* uC/Probe PLUG-IN FOR uC/OS-II FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* OSProbe_TmrInit()
*
* Description : Select & initialize a timer for use with the uC/Probe Plug-In for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
void OSProbe_TmrInit (void)
{
T1PR = 0;
T1TCR = 0x00000001; /* Enable the timer */
}
#endif
/*
*********************************************************************************************************
* OSProbe_TmrRd()
*
* Description : Read the current counts of a 32-bit free running timer.
*
* Argument(s) : none.
*
* Return(s) : The 32 bit counts of the timer.
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
CPU_INT32U OSProbe_TmrRd (void)
{
return ((CPU_INT32U)T1TC);
}
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
** uC/OS-II TIMER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Tmr_TickInit()
*
* Description : Initialize uC/OS-II's tick source.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
CPU_INT32U pclk_freq;
CPU_INT32U tmr_reload;
/* VIC TIMER #0 Initialization */
VICIntSelect &= ~(1 << VIC_TIMER0); /* Enable interrupts */
VICVectAddr2 = (CPU_INT32U)Tmr_TickISR_Handler; /* Set the vector address */
VICVectCntl2 = 0x20 | VIC_TIMER0; /* Enable vectored interrupts */
VICIntEnable = (1 << VIC_TIMER0); /* Enable Interrupts */
pclk_freq = BSP_CPU_PclkFreq();
tmr_reload = pclk_freq / OS_TICKS_PER_SEC;
T0TCR = 0; /* Disable timer 0. */
T0PC = 0; /* Prescaler is set to no division. */
T0MR0 = tmr_reload;
T0MCR = 3; /* Interrupt on MR0 (reset TC) */
T0CCR = 0; /* Capture is disabled. */
T0EMR = 0; /* No external match output. */
T0TCR = 1; /* Enable timer 0 */
}
/*
*********************************************************************************************************
* Tmr_TickISR_Handler()
*
* Description : Handle the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
void Tmr_TickISR_Handler (void)
{
T0IR = 0xFF; /* Clear timer #0 interrupt */
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() */
}
/*
*********************************************************************************************************
*********************************************************************************************************
** LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_PLL_Init()
*
* Description : Set up and activate the PLL
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
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 = 0x00000003; /* Use PLL values of M = 4 and P = 2 */
PLLCON |= 0x00000001; /* 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 |= 0x00000002; /* 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 */
}
/*
*********************************************************************************************************
* BSP_IO_Init()
*
* 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.
*
* Argument(s) : 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;
value = (1 << 16) | (1 << 15); /* Push buttons B2 and B1 */
IO0DIR &= ~value;
/* LCD control lines */
value = ~((3 << 20) | (3 << 22) | (3 << 24) | (3 << 26));
PINSEL0 &= value;
/* LCD data lines */
value = ~((3 << 10) | (3 << 14) | (3 << 20) | (3 << 30));
PINSEL1 &= value;
value = GPIO0_LCD_DATA | GPIO0_LCD_E | GPIO0_LCD_RS | GPIO0_LCD_RW;
IO0DIR |= value;
IO0DIR |= 1 << 21; /* LCD Backlight control */
#ifdef DISP_MODULE_PRESENT
DispRW_High();
#endif
}
/*
*********************************************************************************************************
*********************************************************************************************************
** VIC FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Vectored Interrupt Controller
*********************************************************************************************************
*/
static void VIC_Init (void)
{
VICIntEnClear = 0xFFFFFFFF; /* Disable ALL interrupts */
VICProtection = 0; /* Setup interrupt controller */
VICVectAddr1 = (CPU_INT32U)VIC_DummyWDT; /* Set the vector address */
VICVectAddr2 = (CPU_INT32U)VIC_DummyTIMER0;
VICVectAddr3 = (CPU_INT32U)VIC_DummyTIMER1;
VICVectAddr4 = (CPU_INT32U)VIC_DummyUART0;
VICVectAddr5 = (CPU_INT32U)VIC_DummyUART1;
VICVectAddr6 = (CPU_INT32U)VIC_DummyPWM0;
VICVectAddr7 = (CPU_INT32U)VIC_DummyI2C;
VICVectAddr8 = (CPU_INT32U)VIC_DummySPI;
VICVectAddr9 = (CPU_INT32U)VIC_DummyRTC;
VICVectAddr10 = (CPU_INT32U)VIC_DummyEINT0;
VICVectAddr11 = (CPU_INT32U)VIC_DummyEINT1;
VICVectAddr12 = (CPU_INT32U)VIC_DummyEINT2;
}
static void VIC_Dummy (void)
{
while (1) {
(void)VIC_SpuriousInt;
}
}
static void VIC_DummyWDT (void)
{
VIC_SpuriousInt = VIC_WDT;
VIC_Dummy();
}
static void VIC_DummyTIMER0 (void)
{
VIC_SpuriousInt = VIC_TIMER0;
VIC_Dummy();
}
static void VIC_DummyTIMER1 (void)
{
VIC_SpuriousInt = VIC_TIMER1;
VIC_Dummy();
}
static void VIC_DummyUART0 (void)
{
VIC_SpuriousInt = VIC_UART0;
VIC_Dummy();
}
static void VIC_DummyUART1 (void)
{
VIC_SpuriousInt = VIC_UART1;
VIC_Dummy();
}
static void VIC_DummyPWM0 (void)
{
VIC_SpuriousInt = VIC_UART1;
VIC_Dummy();
}
static void VIC_DummyI2C (void)
{
VIC_SpuriousInt = VIC_I2C;
VIC_Dummy();
}
static void VIC_DummySPI (void)
{
VIC_SpuriousInt = VIC_SPI;
VIC_Dummy();
}
static void VIC_DummyRTC (void)
{
VIC_SpuriousInt = VIC_RTC;
VIC_Dummy();
}
static void VIC_DummyEINT0 (void)
{
VIC_SpuriousInt = VIC_EINT0;
VIC_Dummy();
}
static void VIC_DummyEINT1 (void)
{
VIC_SpuriousInt = VIC_EINT1;
VIC_Dummy();
}
static void VIC_DummyEINT2 (void)
{
VIC_SpuriousInt = VIC_EINT2;
VIC_Dummy();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -