📄 bsp.c
字号:
break;
}
if ((PLLSTAT & (1 << 25)) > 0) { /* If the PLL is currently enabled and connected. */
msel = (CPU_INT32U)(PLLSTAT & 0x3FFF) + 1; /* Obtain the PLL multiplier. */
nsel = (CPU_INT32U)((PLLSTAT >> 16) & 0x0F) + 1; /* Obtain the PLL divider. */
pll_clk_feq = (2 * msel * (fin / nsel)); /* Compute the PLL output frequency. */
} else {
pll_clk_feq = (fin); /* The PLL is bypassed. */
}
clk_div = (CPU_INT32U)(CCLKCFG & 0xFF) + 1; /* Obtain the CPU core clock divider. */
clk_freq = (CPU_INT32U)(pll_clk_feq / clk_div); /* Compute the ARM Core clock frequency. */
return (clk_freq);
}
/*
*********************************************************************************************************
* BSP_CPU_PclkFreq()
*
* Description : Get the peripheral clock frequency for a specific peripheral.
*
* Argument(s) : pclk The peripheral clock ID, one of PCLK_??? defined in bsp.h.
*
* Return(s) : The peripheral's clock in Hz
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_PclkFreq (CPU_INT08U pclk)
{
CPU_INT32U clk_freq;
CPU_INT32U pclk_freq;
CPU_INT32U selection;
clk_freq = BSP_CPU_ClkFreq();
switch (pclk) {
case PCLK_WDT:
case PCLK_TIMER0:
case PCLK_TIMER1:
case PCLK_UART0:
case PCLK_UART1:
case PCLK_PWM0:
case PCLK_PWM1:
case PCLK_I2C0:
case PCLK_SPI:
case PCLK_RTC:
case PCLK_SSP1:
case PCLK_DAC:
case PCLK_ADC:
case PCLK_CAN1:
case PCLK_CAN2:
case PCLK_ACF:
selection = ((PCLKSEL0 >> (pclk * 2)) & 0x03);
if (selection == 0) {
pclk_freq = clk_freq / 4;
} else if (selection == 1) {
pclk_freq = clk_freq;
} else if (selection == 2) {
pclk_freq = clk_freq / 2;
} else {
pclk_freq = clk_freq / 8;
}
break;
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) {
pclk_freq = clk_freq / 4;
} else if (selection == 1) {
pclk_freq = clk_freq;
} else if (selection == 2) {
pclk_freq = clk_freq / 2;
} else {
pclk_freq = clk_freq / 8;
}
break;
default:
pclk_freq = 0;
break;
}
return (pclk_freq);
}
/*
*********************************************************************************************************
* OS_CPU_ExceptHndlr()
*
* Description : Handle any exceptions.
*
* Argument(s) : except_type ARM exception type:
*
* 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
*
* Return(s) : none.
*
* Caller(s) : OS_CPU_ARM_EXCEPT_HANDLER(), which is declared in os_cpu_a.s.
*********************************************************************************************************
*/
void OS_CPU_ExceptHndlr (CPU_INT32U except_type)
{
CPU_FNCT_VOID pfnct;
CPU_INT32U *sp;
if (except_type == OS_CPU_ARM_EXCEPT_IRQ) { /* If this exception is an IRQ. */
pfnct = (CPU_FNCT_VOID)VICAddress; /* Read the interrupt vector from the VIC. */
if (pfnct != (CPU_FNCT_VOID)0) { /* Make sure we don't have a NULL pointer. */
OS_CPU_SR_INT_En(); /* Enable IRQs & FIQs. */
(*pfnct)(); /* Execute the ISR for the interrupting device. */
OS_CPU_SR_INT_Dis(); /* Disable IRQs & FIQs. */
VICAddress = 1; /* Acknowlege the VIC interrupt. */
}
} else if (except_type == OS_CPU_ARM_EXCEPT_FIQ) { /* If this exception is a FIQ. */
pfnct = (CPU_FNCT_VOID)VICAddress; /* Read the interrupt vector from the VIC. */
if (pfnct != (CPU_FNCT_VOID)0) { /* Make sure we don't have a NULL pointer. */
(*pfnct)(); /* Execute the ISR for the interrupting device. */
VICAddress = 1; /* Acknowlege the VIC interrupt. */
}
} else {
if (OSIntNesting == 1) {
sp = (CPU_INT32U *)OSTCBCur->OSTCBStkPtr;
} else {
sp = (CPU_INT32U *)OS_CPU_ExceptStkPtr;
}
APP_TRACE_INFO(("\nCPU_ARM_EXCEPTION #%d trapped.\n", except_type));
APP_TRACE_INFO(("R0 : 0x%08x\n", *(sp + 0x01)));
APP_TRACE_INFO(("R1 : 0x%08x\n", *(sp + 0x02)));
APP_TRACE_INFO(("R2 : 0x%08x\n", *(sp + 0x03)));
APP_TRACE_INFO(("R3 : 0x%08x\n", *(sp + 0x04)));
APP_TRACE_INFO(("R4 : 0x%08x\n", *(sp + 0x05)));
APP_TRACE_INFO(("R5 : 0x%08x\n", *(sp + 0x06)));
APP_TRACE_INFO(("R6 : 0x%08x\n", *(sp + 0x07)));
APP_TRACE_INFO(("R7 : 0x%08x\n", *(sp + 0x08)));
APP_TRACE_INFO(("R8 : 0x%08x\n", *(sp + 0x09)));
APP_TRACE_INFO(("R9 : 0x%08x\n", *(sp + 0x0A)));
APP_TRACE_INFO(("R10 : 0x%08x\n", *(sp + 0x0B)));
APP_TRACE_INFO(("R11 : 0x%08x\n", *(sp + 0x0C)));
APP_TRACE_INFO(("R12 : 0x%08x\n", *(sp + 0x0D)));
APP_TRACE_INFO(("SP : 0x%08x\n", sp));
APP_TRACE_INFO(("LR : 0x%08x\n", *(sp + 0x0E)));
APP_TRACE_INFO(("PC : 0x%08x\n", *(sp + 0x0F)));
APP_TRACE_INFO(("CPSR: 0x%08x\n", *(sp + 0x00)));
/* Infinite loop on other exceptions. */
/* Should be replaced by other behavior (reboot, etc.). */
while (DEF_TRUE) {
;
}
}
}
/*
*********************************************************************************************************
* BSP_IntDisAll()
*
* Description : Disable ALL interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
VICIntEnClear = 0xFFFFFFFFL; /* Disable ALL interrupts. */
}
/*
*********************************************************************************************************
* ADC_Init()
*
* Description : Initializes the board's ADC.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
static void ADC_Init (void)
{
CPU_INT08U divisor;
CPU_INT32U pinsel;
PCONP |= DEF_BIT_12;
divisor = (BSP_CPU_PclkFreq(PCLK_ADC) / 4500000) + 1;
/* Configure ADC ... */
AD0CR = (CPU_INT32U)(0x04 << 0) /* ... Sample/convert pin AD0.0 and AD0.1 ... */
| (CPU_INT32U)(divisor << 8) /* ... Set divider so sample freq. < 4.5 MHz ... */
| (CPU_INT32U)(DEF_BIT_16 ) /* ... Use burst mode for continuous conversion ... */
| (CPU_INT32U)(0x00 << 17) /* ... Use 11 clks per conversion for 10-bit ... */
| (CPU_INT32U)(DEF_BIT_21 ); /* ... Power up the ADC. */
/* Select AD0.0, AD0.1 function for P0.23, P0.24. */
pinsel = PINSEL1;
pinsel &= 0xFFF3FFFF;
pinsel |= 0x00040000;
PINSEL1 = pinsel;
}
/*
*********************************************************************************************************
* ADC_GetStatus()
*
* Description : This function initializes the board's ADC
*
* Argument(s) : adc The ID of the ADC to probe:
*
* 0 Probe AD0.0, the right-hand potentiometer.
* 1 Probe AD0.1, the left-hand potentiometer.
*
* Return(s) : The numerator of the binary fraction representing the result of the latest ADC conversion.
* This value will be a 10-bit value between 0x0000 and 0x03FF, inclusive.
*********************************************************************************************************
*/
CPU_INT16U ADC_GetStatus (CPU_INT08U adc)
{
if (adc == 2) {
return ((ADDR2 >> 6) & 0x03FF);
}
else {
return (0);
}
}
/*
*********************************************************************************************************
*********************************************************************************************************
* 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_COM_MODULE == DEF_ENABLED) && (OS_PROBE_HOOKS_EN == 1)
void OSProbe_TmrInit (void)
{
T1PR = 256;
T1TCR = 0x00000001; /* Enable the timer. */
}
#endif
/*
*********************************************************************************************************
* OSProbe_TmrRd()
*
* Description : Read the current counts of a 32-bit free running timer.
*
* Argument(s) : none.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -