📄 bsp.c
字号:
case PCLK_UART2:
case PCLK_UART3:
case PCLK_I2C2:
case PCLK_MCI:
case PCLK_SYSCON:
selection = ((PCLKSEL1 >> ((pclk - 16) * 2)) & 0x03);
if (selection == 0) {
return (clk_freq / 4);
} else if (selection == 1) {
return (clk_freq);
} else if (selection == 2) {
return (clk_freq / 2);
} else {
return (clk_freq / 8);
}
default:
return (0);
}
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
VICIntEnClear = 0xFFFFFFFFL; /* Disable ALL interrupts */
}
/*
*********************************************************************************************************
* EXCEPTION HANDLER
*
* Description : This function should be used to handle any exceptions. It is called by
* OS_CPU_ARM_EXCEPT_HANDLER(), which is declared in os_cpu_a.s
*
* Arguments : ID, an identifier used to indicate what type of ARM exception has been triggered
* Possible ID values are shown below.
* 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
*********************************************************************************************************
*/
void OS_CPU_ExceptHndlr (CPU_DATA ID)
{
BSP_FNCT_PTR pfnct;
/* If this exception is either an IRQ or FIQ */
if ((ID == OS_CPU_ARM_EXCEPT_IRQ) || (ID == OS_CPU_ARM_EXCEPT_FIQ)) {
pfnct = (BSP_FNCT_PTR)VICAddress; /* Read the interrupt vector from the VIC */
if (pfnct != (BSP_FNCT_PTR)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
VICAddress = 0; /* Acknowlege the VIC interrupt */
}
}
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** PB, Joystick, and ADC Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments : pb is the number of the push button to probe
* 1 probe the push button B1
*
* Returns : DEF_TRUE if the push button is pressed
* DEF_FALSE if the push button is not pressed
*********************************************************************************************************
*/
CPU_BOOLEAN PB_GetStatus (CPU_INT08U pb)
{
CPU_BOOLEAN status;
status = DEF_FALSE;
switch (pb) {
case 1:
if ((FIO0PIN & GPIO0_BUT1) == 0) {
status = (DEF_TRUE);
}
break;
case 2:
if ((FIO0PIN & GPIO0_BUT2) == 0) {
status = (DEF_TRUE);
}
break;
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
* INITIALIZE THE ADC
*
* Description : This function is used to initialize the ADC.
*
* Arguments : none
*
* Returns : none
*
*********************************************************************************************************
*/
static void ADC_Init (void)
{
CPU_INT08U div;
ADINTEN = 0x0000000000; /* Disable all ADC interrupts */
AD0CR &= ~(1 << 21); /* Power down the ADC */
PCONP |= (1 << 12); /* Enable the ADC clock */
/* Configure P1.31 for ADC potentiometer input */
PINSEL3 |= (CPU_INT32U)(0x03 << 30);
FIO1DIR &= ~(GPIO1_AIN5);
div = (BSP_CPU_PclkFreq(PCLK_ADC) / 4500000) + 1; /* Calculate divider */
/* Configure ADC ... */
AD0CR = (0x20 << 0) /* ... Sample/convert pin AD0.5 ... */
| (div << 8) /* ... Set divider so sample freq. < 4.5 MHz ... */
| ( 1 << 16) /* ... Use burst mode for continuous conversion ... */
| (0x04 << 17) /* ... Use 11 clocks per conversion for 10-bit accuracy ...*/
| ( 1 << 21) /* ... Power up the ADC. */
| (0x00 << 24); /* ... No start */
AD0CR |= (0x01 << 24); /* Start conversion */
}
/*
*********************************************************************************************************
* GET ADC STATUS
*
* Description : This function is used to get the status of any ADC on the board.
*
* Arguments : ADC is the number of the push button to probe
* 1 probe the potentiometer
*
* Returns : The 10-bit numerator of a binary fraction, where the numerator is 0x03FF. This is equal
* to the intput voltage divided reference voltage.
*
*********************************************************************************************************
*/
CPU_INT16U ADC_GetStatus (CPU_INT08U adc)
{
CPU_INT16U status;
status = 0;
switch (adc) {
case 1:
status = ((ADDR5 >> 6) & 0x03FF);
break;
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
* GET JOYSTICK STATUS
*
* Description : This function is used to get the status of the joystick on the board.
*
* Arguments : none
*
* Returns : JOYSTICK_CENTER if the joystick is being pressed.
* JOYSTICK_LEFT if the joystick is toggled left.
* JOYSTICK_RIGHT if the joystick is toggled right.
* JOYSTICK_UP if the joystick is toggled up.
* JOYSTICK_DOWN if the joystick is toggled down.
*
*********************************************************************************************************
*/
CPU_INT08U Joystick_GetStatus (void)
{
CPU_INT32U pins;
CPU_BOOLEAN status;
pins = FIO1PIN;
status = 0;
if ((pins & GPIO1_LEFT ) == 0) {
status |= JOYSTICK_LEFT;
}
if ((pins & GPIO1_RIGHT ) == 0) {
status |= JOYSTICK_RIGHT;
}
if ((pins & GPIO1_UP ) == 0) {
status |= JOYSTICK_UP;
}
if ((pins & GPIO1_DOWN ) == 0) {
status |= JOYSTICK_DOWN;
}
if ((pins & GPIO1_CENTER) == 0) {
status |= JOYSTICK_CENTER;
}
return (status);
}
/*
*********************************************************************************************************
* INITIALIZE THE LCD BACLIGHT
*
* Description : This function is used to initialize the PWM used for the LCD backlight.
*
* Arguments : none
*
* Returns : none
*
*********************************************************************************************************
*/
static void LCD_LightInit (void)
{
/* Configure P1.26 for PWM1 */
PINSEL3 |= (0x02 << 20);
PINSEL3 &= ~(0x01 << 20);
PCONP |= ( 1 << 6); /* Enable PWM1 clock */
PWM1TCR = ( 0 << 3) /* Disable PWM */
| ( 0 << 0) /* Disable counter */
| ( 1 << 1); /* Reset PWM */
PWM1CTCR = (0x00 << 0); /* Counter uses prescaler */
PWM1MCR = 2; /* Reset on PWMMR0 */
PWM1PCR = ( 0 << 6) /* Single-edged mode for PWM1.6 */
| ( 1 << 14); /* Enable PWM1.6 output */
PWM1PR = 0;
PWM1MR0 = 0xFF; /* 8-bit resolution */
PWM1LER = ( 1 << 0);
PWM1MR6 = 0;
PWM1LER |= ( 1 << 6);
PWM1TCR |= ( 1 << 3); /* Enable PWM */
PWM1TCR &= ~( 1 << 1); /* Release reset */
PWM1TCR |= ( 1 << 0); /* Enable counting */
}
/*
*********************************************************************************************************
* SET THE LCD LIGHT
*
* Description : This function is used to set the LCD backlight.
*
* Arguments : light is an 8-bit value that specifies the brightness of the LCD backlight.
*
* Returns : none
*
*********************************************************************************************************
*/
void LCD_LightSet (CPU_INT08U light)
{
PWM1MR6 = light;
PWM1LER_bit.EM6L = 1;
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** OS-View Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* INITIALIZE TIMER FOR uC/OS-View
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
* used to make time measurements.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -