📄 bsp.c
字号:
/*
*********************************************************************************************************
* IRQ ISR HANDLER
*
* Description : This function is called by OS_CPU_IRQ_ISR() to determine the source of the interrupt
* and process it accordingly.
*
* Arguments : none
*********************************************************************************************************
*/
void OS_CPU_IRQ_ISR_Handler (void)
{
BSP_FNCT_PTR pfnct;
INT32U VecNum;
VecNum = (NIVECSR >> 16); /* Get the vector number from the status register */
pfnct = BSP_IRQ[VecNum]; /* Get the function pointer from the array */
if (pfnct != (BSP_FNCT_PTR)0) { /* Make sure we dont have a null pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
}
}
/*
*********************************************************************************************************
* FIQ ISR HANDLER
*
* Description : This function is called by OS_CPU_FIQ_ISR() to determine the source of the interrupt
* and process it accordingly.
*
* Arguments : none
*********************************************************************************************************
*/
void OS_CPU_FIQ_ISR_Handler (void)
{
BSP_FNCT_PTR pfnct;
INT32U VecNum;
VecNum = (FIVECSR >> 16); /* Get the vector number from the status register */
pfnct = BSP_FIQ[VecNum]; /* Get the function pointer from the array */
if (pfnct != (BSP_FNCT_PTR)0) { /* Make sure we dont have a null pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
}
}
/*
*********************************************************************************************************
* 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.
*
* Arguments : none
*
* Returns ; none
*
* Note(s) :
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
void OSView_TmrInit (void)
{
#if OSView_Uses_Own_Timer == 1
PCCR1 |= 1 << 26; /* Enable the clock input for GPT2 */
GPT2_TCTL1 = 0; /* Set the control register to its reset value */
GPT2_TCTL1 |= 1 << 1; /* Timer clock source = perclk1 to prescaler */
GPT2_TCTL1 |= 1 << 8; /* Set timer freerun mode */
GPT2_TCTL1 |= 1 << 0; /* Enable the timer */
#endif
}
#endif
/*
*********************************************************************************************************
* READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 32 bit free running timer.
*
* Timer #0 of the LPC2000 is used. This is an UP-timer.
*
* Arguments : none
*
* Returns ; The 16 bit counts of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
INT32U OSView_TmrRd (void)
{
INT32U cnts;
#if OSView_Uses_Own_Timer == 0
cnts = (INT32U)GPT1_TCN1; /* OSView shares the OS ticker timer */
#else
cnts = (INT32U)GPT2_TCN1; /* OSView uses its own free-running timer */
#endif
return (cnts);
}
#endif
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
* interrupts every 1 to 100 mS).
*
* Arguments : none
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
GPT1_TCTL1 = 0; /* Set control reg to its reset value (GPT stopped) */
PCCR1 |= 1 << 25; /* Enable the clock input for GPT1 */
GPT1_TCTL1 |= 1 << 1; /* Timer clock source = perclk1 into prescaler */
GPT1_TCTL1 |= 1 << 4; /* Enable compare interrupts */
#if BSP_TickMode == 0
GPT1_TCTL1 &= ~(1 << 8); /* Set timer to reset to 0 after a compare */
GPT1_TCMP1 = GPT1CLK / OS_TICKS_PER_SEC; /* Set initial compare value to desired ticks */
#else
GPT1_TCTL1 |= 1 << 8; /* Set timer freerun mode */
GPT1_TCMP1 = GPT1_TCN1 + (GPT1CLK / OS_TICKS_PER_SEC); /* Set initial comp val to CNTR + ticks */
#endif
BSP_Set_IRQ_Vector(INT_GPT1, Tmr_TickISR_Handler);
BSP_IntEn(INT_GPT1);
GPT1_TCTL1 |= 1 << 0; /* Enable the timer */
}
/*
*********************************************************************************************************
* TIMER #0 IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : none
*********************************************************************************************************
*/
void Tmr_TickISR_Handler (void)
{
GPT1_TSTAT1 |= 1; /* Clear the interrupt flag */
#if BSP_TickMode == 1 /* Set initial compare value to counter + ticks */
GPT1_TCMP1 = GPT1_TCN1 + (GPT1CLK / OS_TICKS_PER_SEC);
#endif
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() */
}
/*
*********************************************************************************************************
* Central Interrupt Manager Initialization
*********************************************************************************************************
*/
static void AITC_Init (void)
{
INT8U i;
BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 0xEAFFFFFE;
BSP_SWI_VECTOR_ADDR = 0xEAFFFFFE;
BSP_PREFETCH_ABORT_VECTOR_ADDR = 0xEAFFFFFE;
BSP_DATA_ABORT_VECTOR_ADDR = 0xEAFFFFFE;
BSP_IRQ_VECTOR_ADDR = (INT32U)OS_CPU_IRQ_ISR;
BSP_FIQ_VECTOR_ADDR = (INT32U)OS_CPU_FIQ_ISR;
for (i = 0; i < 64; i++) {
BSP_IRQ[i] = Normal_ISR_AITC_Dummy;
BSP_FIQ[i] = Fast_ISR_AITC_Dummy;
}
NIMASK = 0x1F; /* Unmask all interrupts */
}
/*
*********************************************************************************************************
* ATIC - Set IRQ Vector
*********************************************************************************************************
*/
void BSP_Set_IRQ_Vector (INT8U VecNum, BSP_FNCT_PTR BSP_IRQ_VEC)
{
if (VecNum < 64) {
BSP_IRQ[VecNum] = BSP_IRQ_VEC;
}
}
/*
*********************************************************************************************************
* ATIC - Set FIQ Vector
*********************************************************************************************************
*/
void BSP_Set_FIQ_Vector (INT8U VecNum, BSP_FNCT_PTR BSP_FIQ_VEC)
{
if (VecNum < 64) {
BSP_FIQ[VecNum] = BSP_FIQ_VEC;
}
}
/*
*********************************************************************************************************
* ATIC - Enable Interrupt
*********************************************************************************************************
*/
void BSP_IntEn (INT8U VecNum)
{
if (VecNum < 64) {
INTENNUM = VecNum;
}
}
/*
*********************************************************************************************************
* ATIC - Disable Interrupt
*********************************************************************************************************
*/
void BSP_IntDis (INT8U VecNum)
{
if (VecNum < 64) {
INTDISNUM = VecNum;
}
}
/*
*********************************************************************************************************
* ISR code called when a spurious interrupt occurs
*
* Note: Check AITC_SpurousInt for interrupt source vector number
*********************************************************************************************************
*/
static void Fast_ISR_AITC_Dummy (void)
{
AITC_SpuriousInt = NIVECSR;
while (TRUE)
{
;
}
}
static void Normal_ISR_AITC_Dummy (void)
{
AITC_SpuriousInt = FIVECSR;
while (TRUE)
{
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -