📄 bsp_ram.c
字号:
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 */
BSP_IRQ_VECTOR_ADDR = 0xE59FF018; /* LDR PC,[PC,#0x18] instruction */
BSP_IRQ_ISR_ADDR = (INT32U)OS_CPU_IRQ_ISR; /* IRQ exception vector address */
BSP_FIQ_VECTOR_ADDR = 0xE59FF018; /* LDR PC,[PC,#0x18] instruction */
BSP_FIQ_ISR_ADDR = (INT32U)OS_CPU_FIQ_ISR; /* FIQ exception vector address */
BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 0xEAFFFFFE; /* Jump to itself */
BSP_SWI_VECTOR_ADDR = 0xEAFFFFFE;
BSP_PREFETCH_ABORT_VECTOR_ADDR = 0xEAFFFFFE;
BSP_DATA_ABORT_VECTOR_ADDR = 0xEAFFFFFE;
BSP_FIQ_VECTOR_ADDR = 0xEAFFFFFE;
BSP_PLL_Init(); /* Initialize the PLL */
BSP_GPIO_Init(); /* Initialize the board's I/Os */
VIC_Init(); /* Initialize the Vectored Interrupt Controller */
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 /
*********************************************************************************************************
*/
void BSP_GPIO_Init( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Initialises the GPIO module. Only sets those registers with
** values not equal to the power-on reset values.
**
** Parameters:
** None
**
** Returns:
** None
**
**---------------------------------------------------------------------------
*/
{
/*--- Init GPIO registers ---*/
IO0DIR = BSP_IO0DIR_GPIO;
IO1DIR = BSP_IO1DIR_GPIO;
IO2DIR = BSP_IO2DIR_GPIO;
IO3DIR = BSP_IO3DIR_GPIO;
IO3CLR |= A20_GPIO_OFF;
} /* BSP_Init_GPIO */
INT8S BSP_SetPortIn_GPIO( INT8U PortNr, INT32U BitMask )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Reprograms selected GPIO pins as input pins.
**
** Parameters:
** PortNr The port to reprogram.
** BitMask Set a bit to program the corresponding pin to input
**
** Returns:
** BSP_OK if the function could be executed successfully.
** BSP_ERROR if an illegal port number was used.
**
**---------------------------------------------------------------------------
*/
{
/*--- Set some pins as input pins ---*/
switch( PortNr )
{
case 0x00:
/*--- Port 0 ---*/
IO0DIR &= ~BitMask;
break;
case 0x01:
/*--- Port 1 ---*/
IO1DIR &= ~BitMask;
break;
case 0x02:
/*--- Port 2 ---*/
IO2DIR &= ~BitMask;
break;
case 0x03:
/*--- Port 3 ---*/
IO3DIR &= ~BitMask;
break;
default:
/*--- Handle user code on function exit ---*/
return BSP_ERROR;
}
return BSP_OK;
} /* BSP_SetPortIn_GPIO */
INT8S BSP_SetPortOut_GPIO( INT8U PortNr, INT32U BitMask )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Reprograms selected GPIO pins as output pins.
**
** Parameters:
** PortNr The port to reprogram.
** BitMask Set a bit to program the corresponding pin to output
**
** Returns:
** BSP_OK if the function could be executed successfully.
** BSP_ERROR if an illegal port number was used.
**
**---------------------------------------------------------------------------
*/
{
/*--- Set some pins as input pins ---*/
switch( PortNr )
{
case 0x00:
/*--- Port 0 ---*/
IO0DIR |= BitMask;
break;
case 0x01:
/*--- Port 1 ---*/
IO1DIR |= BitMask;
break;
case 0x02:
/*--- Port 2 ---*/
IO2DIR |= BitMask;
break;
case 0x03:
/*--- Port 3 ---*/
IO3DIR |= BitMask;
break;
default:
return BSP_ERROR;
}
return BSP_OK;
} /* BSP_SetPortOut_GPIO */
INT32U BSP_ReadPort_GPIO( INT8U PortNr )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Reads GPIO port. Each port pin will be mapped to the corresponding
** bit in the return value.
**
** Parameters:
** PortNr The GPIO port to read from.
**
** Returns:
** The read data if a valid port number is used.
** BSP_ERROR if an illegal port number was used.
**
**---------------------------------------------------------------------------
*/
{
INT32U Data;
/*--- Read port ---*/
switch( PortNr )
{
case 0x00:
/*--- Port 0 ---*/
Data = IO0PIN;
break;
case 0x01:
/*--- Port 1 ---*/
Data = IO1PIN;
break;
case 0x02:
/*--- Port 2 ---*/
Data = IO2PIN;
break;
case 0x03:
/*--- Port 3 ---*/
Data = IO3PIN;
break;
default:
return (INT32U)BSP_ERROR;
}
/*--- Return read port value ---*/
return Data;
} /* BSP_ReadPort_GPIO */
INT8S BSP_WritePort_GPIO( INT8U PortNr, INT32U Value, INT32U BitMask )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Writes data to the selected GPIO port. Each bit in the selected
** port which has a corresponding bit set in the bitmask, will
** output the bit value that are defined in the 'Value' parameter.
**
** Parameters:
** PortNr The GPIO port to write to.
** Value The data to write
** BitMask Bitmask which selects the bits in the port to change
**
** Returns:
** BSP_OK if a valid port number is used.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -