📄 bsp.c
字号:
//=======================================================================================================
//=======================================================================================================
#include "../ucos/AT91SAM7S64.h"
#include "includes.h"
#include "bsp.h"
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef void (*BSP_PFNCT)(void);
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_DummyISR_Handler(void);
static void BSP_IntCtrlInit(void);
static void Tmr_TickInit(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)
{
AT91C_BASE_AIC->AIC_IVR = 0; /* Debug variant of vector read (protect mode is used) */
}
/*
*********************************************************************************************************
* BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
* functions found in this module.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_Init (void)
{
BSP_IntCtrlInit(); /* Initialize the Interrupt Controller */
Tmr_TickInit(); /* Initialize uC/OS-II's Tick Rate */
LED_Init(); /* Initialize the I/Os for the LEDs */
}
/*
*********************************************************************************************************
* INITIALIZE THE INTERRUPT CONTROLLER
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments : none
*********************************************************************************************************
*/
static void BSP_IntCtrlInit (void)
{
INT16U 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;
}
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF; /* Disable all interrupts */
}
/*
*********************************************************************************************************
* BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
* functions found in this module.
*
* Arguments : none
*********************************************************************************************************
*/
void LED_Init (void)
{
AT91C_BASE_PIOA->PIO_PER = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1; /* Enable register */
AT91C_BASE_PIOA->PIO_OER = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1; /* Output enable */
AT91C_BASE_PIOA->PIO_IDR = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
LED_Off(BSP_LED_ALL); /* Turn OFF all the LEDs */
}
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
void LED_On (INT8U led)
{
switch (led) {
case 0:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
break;
case 1:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
break;
case 2:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
break;
case 3:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED3;
break;
case 4:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED4;
break;
}
}
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
void LED_Off (INT8U led)
{
int i=0;
/*while( led & 0xF==0 )
{
i+=4;
led>>=4;
}*/
switch (led+i) {
case 0:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
break;
case 1:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
break;
case 2:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
break;
case 3:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED3;
break;
case 4:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED4;
break;
}
}
/*
*********************************************************************************************************
* 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 toggle
* 0 indicates that you want ALL the LEDs to be toggle
* 1 toggles LED1 on the board
* .
* .
* 4 toggles LED4 on the board
*********************************************************************************************************
*/
void LED_Toggle (INT8U led)
{
switch (led) {
case 0:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED1) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
}
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED2) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
}
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED3) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED3;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED3;
}
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED4) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED4;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED4;
}
break;
case 1:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED1) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
}
break;
case 2:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED2) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
}
break;
case 3:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED3) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED3;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED3;
}
break;
case 4:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED4) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED4;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED4;
}
break;
}
}
/*
*********************************************************************************************************
* 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_PFNCT pfnct;
#if 1
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR; /* Read the interrupt vector from the VIC */
if (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
}
#else
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR; /* Read the interrupt vector from the VIC */
while (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR; /* Read the interrupt vector from the VIC */
}
#endif
}
/*
*********************************************************************************************************
* 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_PFNCT pfnct;
#if 1
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR; /* Read the interrupt vector from the VIC */
if (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
}
#else
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR; /* Read the interrupt vector from the VIC */
while (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR; /* Read the interrupt vector from the VIC */
}
#endif
}
/*
*********************************************************************************************************
* 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)
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
INT32U counts;
/* Set the vector address for PIT */
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (INT32U)Tmr_TickISR_Handler;// OS_CPU_IRQ_ISR;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE
| AT91C_AIC_PRIOR_LOWEST;
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_SYSC_PITEN | AT91C_SYSC_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;
status = AT91C_BASE_PITC->PITC_PIVR;
AT91C_BASE_AIC->AIC_IVR = 0; /* Debug variant of vector read (protect mode is used) */
AT91C_BASE_AIC->AIC_ICCR = AT91C_ID_SYS; /* Clear timer #0 interrupt */
AT91C_BASE_AIC->AIC_EOICR = 0; /* Signal end of interrupt */
OSTimeTick(); /* Tell uC/OS-II about clock tick */
}
//-------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -