📄 bsp.c
字号:
} else if (selection == 2) {
return (clk_freq / 2);
} else {
return (clk_freq / 8);
}
case PCLK_BAT_RAM:
case PCLK_GPIO:
case PCLK_PCB:
case PCLK_I2C1:
case PCLK_SSP0:
case PCLK_TIMER2:
case PCLK_TIMER3:
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
*
* Returns : 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 = 1; /* Acknowlege the VIC interrupt */
}
}
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** PB, LED, 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_INT08U reg;
CPU_INT08U data;
CPU_BOOLEAN status;
status = DEF_FALSE;
if (pb >= 1 && pb <= 4) {
reg = 0x00;
data = 0xFF;
I2C_ReadReg(&data, 1, reg);
}
switch (pb) {
case 1:
if ((data & 0x01) == 0) {
status = DEF_TRUE;
}
break;
case 2:
if ((data & 0x02) == 0) {
status = DEF_TRUE;
}
break;
case 3:
if ((data & 0x04) == 0) {
status = DEF_TRUE;
}
break;
case 4:
if ((data & 0x08) == 0) {
status = DEF_TRUE;
}
break;
case 5:
if ((FIO2PIN & DEF_BIT_10) == 0) {
status = DEF_TRUE;
}
break;
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
* 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
* .
* .
* 4 turns ON LED4 on the board
*
* Returns : None
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
CPU_INT08U reg;
CPU_INT08U data;
CPU_INT08U buf[2];
reg = 0x08;
data = 0xFF;
I2C_ReadReg(&data, 1, reg);
switch (led) {
case 0:
data = 0x55;
break;
case 1:
data &= ~0x03;
data |= 0x01;
break;
case 2:
data &= ~0x0C;
data |= 0x04;
break;
case 3:
data &= ~0x30;
data |= 0x10;
break;
case 4:
data &= ~0xC0;
data |= 0x40;
break;
default:
return;
}
buf[0] = 0x08;
buf[1] = data;
I2C_Write(buf, 2);
}
/*
*********************************************************************************************************
* 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
* .
* .
* 4 turns OFF LED4 on the board
*
* Returns : None
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
CPU_INT08U reg;
CPU_INT08U data;
CPU_INT08U buf[2];
reg = 0x08;
data = 0xFF;
I2C_ReadReg(&data, 1, reg);
switch (led) {
case 0:
data = 0x00;
break;
case 1:
data &= ~0x03;
break;
case 2:
data &= ~0x0C;
break;
case 3:
data &= ~0x30;
break;
case 4:
data &= ~0xC0;
break;
default:
return;
}
buf[0] = 0x08;
buf[1] = data;
I2C_Write(buf, 2);
}
/*
*********************************************************************************************************
* 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
* .
* .
* 8 toggles LED8 on the board
*
* Returns : None
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
CPU_INT08U reg;
CPU_INT08U data;
CPU_INT08U buf[2];
reg = 0x08;
data = 0xFF;
I2C_ReadReg(&data, 1, reg);
switch (led) {
case 0:
data ^= 0x55;
break;
case 1:
if ((data & 0x03) == 0) {
data &= ~0x03;
data |= 0x01;
} else {
data &= ~0x03;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -