📄 bsp.c
字号:
* 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)
{
}
void LED_TurnOff(unsigned int led)
{
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, led) ;
}
/*
*********************************************************************************************************
* 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)
{
}
void LED_TurnOn(unsigned int led)
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, led);
}
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* 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)
*********************************************************************************************************
*/
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_POSITIVE_EDGE
| 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_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 static INT32U status;
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();
if((AT91PS_PITC)AT91C_BASE_PITC->PITC_PISR)
{
status = AT91C_BASE_PITC->PITC_PIVR;
OSTimeTick(); // Tell uC/OS-II about clock tick
}
else
{
if((int)((AT91PS_DBGU)AT91C_BASE_DBGU->DBGU_CSR) & (int)0x01)
{
if(pRxdt==&RXDT[19])
{
pRxdt=RXDT;
}
*(++pRxdt)=(int)(AT91PS_DBGU)AT91C_BASE_DBGU->DBGU_RHR;
OSSemPost (pE_Key);
}
}
}
//---------------------------------------------------------------------------------------------------------
void time_delay(int dly)
{
int i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
//--------------------------------------------------------
void pri_info(void)
{
AT91F_DBGU_Printk("\n\r ================================================");
AT91F_DBGU_Printk("\n\r | 欢迎使用深圳英贝德公司的产品 |");
AT91F_DBGU_Printk("\n\r | SAM7X256 uCOS-II的演示测试 |");
AT91F_DBGU_Printk("\n\r | 更多的帮助请到 http://www.szembed.com |");
AT91F_DBGU_Printk("\n\r ================================================\n\r\n\r");
}
//*----------------------------------------------------------------------------
//* 函数名: AT91F_DBGU_GetStatus_zzf
//* 功能:获得USART(DBGU,US0,US1)通道状态寄存器的值,供中断程序用
//*----------------------------------------------------------------------------
unsigned int AT91F_USART_GetStatus_zzf(AT91PS_USART pUSART )
{
return(pUSART->US_CSR);
}
//*----------------------------------------------------------------------------
//* 函数名: AT91F_DBGU_GetInterruptMaskStatus_zzf
//* 功能:中断屏蔽寄存器的值,供中断程序使用
//*----------------------------------------------------------------------------
unsigned int AT91F_USRT_GetInterruptMaskStatus_zzf(AT91PS_USART pUSART)
{
return(pUSART->US_IMR);
}
void US0_irq_handler(void)
{
unsigned int status; //变量定义
//禁止系统中断(DBGU属于系统中断)
AT91F_AIC_DisableIt(AT91C_BASE_AIC, AT91C_ID_US0);
//查看是那类中断,读取状态积存器/中断屏蔽积存器,以清除中断标志,
status=(AT91F_USART_GetStatus_zzf((AT91PS_USART)AT91C_BASE_US0)&AT91F_USRT_GetInterruptMaskStatus_zzf((AT91PS_USART)AT91C_BASE_US0));
if ( status & AT91C_US_RXRDY)
{
while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_US0));
AT91F_US_PutChar (AT91C_BASE_US0, AT91F_US_GetChar(AT91C_BASE_US0));
}
//* Clear the interrupt.
AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_US0);
//* End of interrupt
AT91C_BASE_AIC->AIC_EOICR = 0;
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_US0);
}
void prvSetupUARTInterrupt()
{
//* 允许接受缓冲区满中断
AT91F_US_EnableIt((AT91PS_USART)AT91C_BASE_US0,AT91C_US_RXRDY);
//* 允许接受缓冲区满中断
AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC,
AT91C_ID_US0,
US0_INT_LEVEL,
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
( void (*)( void ) ) US0_irq_handler );
//* 允许中断
AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_US0);
}
void US0_init()
{
//* 配置I/O
AT91F_US0_CfgPIO (); //调用库函数
//开US0时钟
AT91F_US0_CfgPMC();
//* 配置 US0
AT91F_US_Configure ( // 调用库函数
(AT91PS_USART) AT91C_BASE_US0, // US0 基地址
AT91B_MCK,
AT91C_US_ASYNC_MODE , // 模式积存器
AT91C_US0_BAUD , // 波特率
0); // 触发时间
//*允许串口接受发送
AT91F_US_EnableTxRx((AT91PS_USART)AT91C_BASE_US0);
//*中断设置
prvSetupUARTInterrupt();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -