📄 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
*********************************************************************************************************
*/
#define BSP_UNDEF_INSTRUCTION_VECTOR_ADDR (*(INT32U *)0x0C000004L)
#define BSP_SWI_VECTOR_ADDR (*(INT32U *)0x0C000008L)
#define BSP_PREFETCH_ABORT_VECTOR_ADDR (*(INT32U *)0x0C00000CL)
#define BSP_DATA_ABORT_VECTOR_ADDR (*(INT32U *)0x0C000010L)
#define BSP_IRQ_VECTOR_ADDR (*(INT32U *)0x0C000018L)
#define BSP_FIQ_VECTOR_ADDR (*(INT32U *)0x0C00001CL)
#define BSP_IRQ_ISR_ADDR (*(INT32U *)0x0C000038L)
#define BSP_FIQ_ISR_ADDR (*(INT32U *)0x0C00003CL)
/*
*********************************************************************************************************
* 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);
//static void EXT_Int3Init (void);
//static void EXT_INT3_ISR_Handler (void);
BSP_PFNCT ISR_Handler[32];
/*
*********************************************************************************************************
* 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 */
//EXT_Int3Init();
// Uart1Init(0,115200);
//Uart0Init(0,115200);
//NetInit();
// LcdInit();
// 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;
BSP_IRQ_VECTOR_ADDR = 0xE59FF018; /* LDR PC,[PC,#0x18] instruction */
BSP_IRQ_ISR_ADDR = (INT32U)OS_CPU_IRQ_ISR; /* IRQ exception vector address */
BSP_FIQ_VECTOR_ADDR = 0xE59FF018; /* LDR PC,[PC,#0x18] instruction */
BSP_FIQ_ISR_ADDR = (INT32U)OS_CPU_FIQ_ISR; /* FIQ exception vector address */
BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 0xEAFFFFFE; /* Jump to itself */
BSP_SWI_VECTOR_ADDR = 0xEAFFFFFE;
BSP_PREFETCH_ABORT_VECTOR_ADDR = 0xEAFFFFFE;
BSP_DATA_ABORT_VECTOR_ADDR = 0xEAFFFFFE;
// BSP_FIQ_VECTOR_ADDR = 0xEAFFFFFE;
/* - END CODE RUNNING OUT OF RAM -- */
rINTCON = 0x00000007;
rINTMOD = 0x00000000;
rI_ISPC = rINTPND;
//AT91C_BASE_AIC->AIC_EOICR = 0x00000000; /* End-of-interrupt command */
rINTCON = 0x00000004;
rINTMSK = 0x03FFFFFF;
for (i = 0; i < 32; i++) { /* Disable all ISRs */
ISR_Handler[i]=BSP_DummyISR_Handler;
}
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
rINTMSK = 0x03FFFFFF;
}
/*
*********************************************************************************************************
* 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_LED2; /* Enable register */
//AT91C_BASE_PIOA->PIO_OER = BSP_LED2; /* Output enable */
//AT91C_BASE_PIOA->PIO_IDR = BSP_LED2;
//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)
{
//AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
}
/*
*********************************************************************************************************
* 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)
{
//AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
}
/*
*********************************************************************************************************
* 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)
{
#if 0
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;
}
#endif
}
/*
*********************************************************************************************************
* 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)
{
unsigned int i,temp,temp1;
temp1=~rINTMSK;
temp=rI_ISPR&temp1;
for(i=0;i<26;i++)
{
if((temp>>i)&0x00000001)
{
if(ISR_Handler[i]!=(BSP_PFNCT)0)
{
(*ISR_Handler[i])();
}
rI_ISPC=0x01<<i;
break;
}
}
}
/*
*********************************************************************************************************
* FIQ ISR HANDLER
*
* Description : This function is called by OS_CPU_FIQ_ISR() to determine the source of the interrupt
* and process it accordingly.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -