📄 bsp.c
字号:
//===============================================================================================
//===============================================================================================
#define ext extern
#include "data.h"
#include "bsp.h"
#include <stdarg.h>
#include <stdio.h>
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef void (*BSP_PFNCT)(void);
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_DummyISR_Handler(void);
static void BSP_IntCtrlInit(void);
extern void Tmr_TickInit(void);
static void Tmr_TickISR_Handler(void);
extern void LED_On (INT8U);
extern void LED_Off (INT8U);
//*----------------------------------------------------------------------------
//* \fn AT91F_US_Get
//* \brief Get a Char to USART
//*----------------------------------------------------------------------------
int AT91F_DBGU_Get( char *val)
{
if ((AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU)) == 0) return (FALSE);
else
{
*val= AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU);
return (TRUE);
}
}
//*--------------------------1--------------------------------------------------
//* \fn AT91F_DBGU_Printk
//* \brief This function is used to send a string through the DBGU channel
//*----------------------------------------------------------------------------
void AT91F_DBGU_Ready(void)
{
while (!(AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY));
}
//*----------------------------------------------------------------------------
//* \fn AT91F_DBGU_Frame
//* \brief This function is used to send a string through the DBGU channel
//*----------------------------------------------------------------------------
void AT91F_DBGU_Frame( char *buffer)
{
unsigned char len;
for (len =0; buffer[len] != '\0'; len++){}
AT91F_US_SendFrame((AT91PS_USART)AT91C_BASE_DBGU, buffer,len,0,0);
}
//*----------------------------------------------------------------------------
//* Function Name : Send_reset
//* Object : Acknoledeg AIC and send reset
//*----------------------------------------------------------------------------
void Send_reset(void)
{
void(*pfct)(void) = (void (*)(void) ) 0x00000000;
// Acknoledge the interrupt
// Mark the End of Interrupt on the AIC
AT91C_BASE_AIC->AIC_EOICR=0;
AT91F_DBGU_Ready();
// Jump in reset
pfct();
}
//*----------------------------------------------------------------------------
//* Function Name : DBGU_irq_handler
//* Object : C handler interrupt function called by the interrupts
//* assembling routine
//*----------------------------------------------------------------------------
void DBGU_irq_handler(void)
{
/* char value;
AT91PS_DBGU USART_pt = AT91C_BASE_DBGU;
unsigned int status;
INT16U rec;
// get Usart status register
//int *val;
//val = AT91F_DBGU_Get(USART_pt);
status = USART_pt->DBGU_CSR;
if ( status & AT91C_US_RXRDY){
rec = AT91F_US_GetChar(USART_pt);
DBBuffer[dbcount] = rec;
// Get byte and send
AT91F_US_PutChar (USART_pt,DBBuffer);
}
AT91F_DBGU_Get(&value);
switch (value) {
case '0': // info
AT91F_DBGU_Frame("\n\rSet Pull up\n\r");
// Set
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA,AT91C_PIO_PA16);
break;
case '1': // info
AT91F_PIO_SetOutput(AT91C_BASE_PIOA,AT91C_PIO_PA16);
AT91F_DBGU_Printk("\n\rClear Pull up\n\r");
// Reset Application
Send_reset();
break;
default:
AT91F_DBGU_Printk("\n\r");
break;
}// end switch
*/
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
}
//========================================================
void AT91F_DBGU_Init(void)
{
//* Open PIO for DBGU
AT91F_DBGU_CfgPIO();
AT91F_DBGU_CfgPMC();
//* Enable Transmitter & receivier
((AT91PS_USART)AT91C_BASE_DBGU)->US_CR = AT91C_US_RSTTX |AT91C_US_RSTRX;
//* Configure DBGU
AT91F_US_Configure (
(AT91PS_USART) AT91C_BASE_DBGU, // DBGU base address
MCK,
AT91C_US_ASYNC_MODE , // Mode Register to be programmed
AT91C_USAR_BAUD , // Baudrate to be programmed
0); // Timeguard to be programmed
//* Enable Transmitter & receivier
((AT91PS_USART)AT91C_BASE_DBGU)->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
//* Enable USART IT error and AT91C_US_ENDRX
// AT91F_US_EnableIt((AT91PS_USART) AT91C_BASE_DBGU,AT91C_US_RXRDY);
//* open interrupt
//AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_SYS, USART_SYS_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, DBGU_irq_handler);
// AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_SYS);
//AT91F_PDC_DisableRx ((AT91PS_PDC) AT91C_BASE_PDC_DBGU); // \arg pointer to a PDC controller
//AT91F_PDC_DisableTx ((AT91PS_PDC) AT91C_BASE_PDC_DBGU);
//AT91F_DBGU_Printk(S0Buffer);
}
/*
*********************************************************************************************************
* 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();
AT91F_DBGU_Init();
LED_Init();
}
//------------------------------------------------
void AT91F_DBGU_Printk( char *buffer)
{
while(*buffer != '\0')
{
while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *buffer++);
}
}
void uprintf(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
AT91F_DBGU_Printk(string);
va_end(ap);
}
//================================================================================================
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)
{
// First, enable the clock of the PIO
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
// then, we configure the PIO Lines corresponding to LED1 to LED4
// to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
AT91F_PIO_CfgOutput( AT91D_BASE_PIO_LED, LED_MASK );
// Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, LED_MASK );
// Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, LED_MASK );
// Turn off LEDs
AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, LED_MASK );
}
/*
*********************************************************************************************************
* LED ON
*
* Description : This function is used to control any or all the LEDs on the board.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -