📄 bsp.c
字号:
/*
*********************************************************************************************************
* Atmel AT91 SAM7
* Board Support Package
*
* (c) Copyright 2004, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : BSP.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_DummyISR_Handler(void);
static void Tmr_TickISR_Handler(void);
/*
*********************************************************************************************************
* DUMMY IRQ HANDLER
*
* Description : This function is called to handle invalid IRQs
*
* Arguments : none
*********************************************************************************************************
*/
static void BSP_DummyISR_Handler (void)
{
}
/*
*********************************************************************************************************
* INITIALIZE THE INTERRUPT CONTROLLER
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntCtrlInit (void)
{
int i;
AT91C_BASE_AIC->AIC_EOICR = 0x00000000; /* End-of-interrupt command */
for (i = 0; i < 32; i++) { /* Disable all ISRs */
AT91C_BASE_AIC->AIC_SVR[i] = (INT32U)BSP_DummyISR_Handler;
AT91C_BASE_AIC->AIC_SMR[i] = 0;
}
}
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source which uses the PIT
* (typically a timer generating interrupts every 1 to 100 mS).
*
* Arguments : none
*
* Note(s) : 1) PIT Interrupt frequency:
*
* MCLK 1
* Freq = ---- * -----------
* 16 (PIV + 1)
*
*
* MCLK 1
* PIV = ( ---- * ------ ) - 1
* 16 Freq
*
* Where:
* MCLK = 48 MHz (i.e 48,000,000)
* Freq = Desired frequency (i.e. OS_TICKS_PER_SEC)
*********************************************************************************************************
*/
void Tmr_TickInit (void)
{
INT32U counts;
/* Set the vector address for PIT */
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (INT32U)Tmr_TickISR_Handler;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE
| AT91C_AIC_PRIOR_LOWEST;
// clear any pending interrupt for this AIC input and then enable the interrupt.
AT91C_BASE_AIC->AIC_ICCR = 1 << AT91C_ID_SYS;
AT91C_BASE_AIC->AIC_IECR = 1 << AT91C_ID_SYS;
counts = (48000000 / 16 / OS_TICKS_PER_SEC) - 1;
AT91C_BASE_PITC->PITC_PIMR = AT91C_PITC_PITEN | AT91C_PITC_PITIEN | counts;
}
/*
*********************************************************************************************************
* PIT IRQ HANDLER
*
* Description : This function handles the PIT interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : none
*********************************************************************************************************
*/
static void Tmr_TickISR_Handler (void)
{
volatile INT32U status;
if (AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS)
{
status = AT91C_BASE_PITC->PITC_PIVR; /* Clear PIT interrupt */
OSTimeTick(); /* Tell uC/OS-II about clock tick */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -