📄 bsp.c
字号:
case 1:
if ((AT91C_BASE_PIOC->PIO_ODSR & GPIOC_PWM2) == GPIOC_PWM2) {
AT91C_BASE_PIOC->PIO_CODR = GPIOC_PWM2;
} else {
AT91C_BASE_PIOC->PIO_SODR = GPIOC_PWM2;
}
break;
case 2:
if ((AT91C_BASE_PIOB->PIO_ODSR & GPIOB_PWM1) == GPIOB_PWM1) {
AT91C_BASE_PIOB->PIO_CODR = GPIOB_PWM1;
} else {
AT91C_BASE_PIOB->PIO_SODR = GPIOB_PWM1;
}
break;
default:
break;
}
}
/*
*********************************************************************************************************
* PB INITIALIZATION
*
* Description : This function initializes the I/O for the PBs.
*
* Argument(s) : none
*
* Returns : none
*********************************************************************************************************
*/
static void PB_Init (void)
{
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOCDE; /* Enable peripheral clock */
AT91C_BASE_PIOC->PIO_PER = GPIOC_RIGHTCLICK
| GPIOC_LEFTCLICK; /* Enable register */
AT91C_BASE_PIOC->PIO_ODR = GPIOC_RIGHTCLICK
| GPIOC_LEFTCLICK; /* Output disable */
AT91C_BASE_PIOC->PIO_IDR = GPIOC_RIGHTCLICK
| GPIOC_LEFTCLICK;
}
/*
*********************************************************************************************************
* GET PUSH BUTTON STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Argument(s) : pb is the number of the push button to probe
* 1 probe the push button B1
* 2 probe the push button B2
*
* Returns : DEF_FALSE if the push button is pressed
* DEF_TRUE if the push button is not pressed
*********************************************************************************************************
*/
CPU_BOOLEAN PB_GetStatus (CPU_INT08U pb)
{
CPU_BOOLEAN status;
status = DEF_TRUE;
switch (pb) {
case 1:
if (AT91C_BASE_PIOC->PIO_PDSR & GPIOC_RIGHTCLICK) {
status = DEF_FALSE;
}
break;
case 2:
if (AT91C_BASE_PIOC->PIO_PDSR & GPIOC_LEFTCLICK) {
status = DEF_FALSE;
}
break;
default:
break;
}
return (status);
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** OS-View Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* OSView Timer Initialization
*
* Description : This function selects and initializes a timer for use with OSView and the Statistics Task
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
void OSView_TmrInit (void)
{
#if OS_VIEW_TIMER_SEL == 0
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC012;/* Enable the peripheral clk */
AT91C_BASE_TCB0->TCB_TC0.TC_CCR = DEF_BIT_01; /* TC0 timer disabled */
AT91C_BASE_TCB0->TCB_TC0.TC_CMR &= ~(7 << 0); /* TIMER_CLOCK1 is input clk */
AT91C_BASE_TCB0->TCB_TC0.TC_CCR = DEF_BIT_00; /* TC0 timer enabled */
AT91C_BASE_TCB0->TCB_TC0.TC_CCR = DEF_BIT_02; /* SWTRG to reset and start */
#endif
#if OS_VIEW_TIMER_SEL == 1
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC012;/* Enable the peripheral clk */
AT91C_BASE_TCB0->TCB_TC1.TC_CCR = DEF_BIT_01; /* TC1 timer disabled */
AT91C_BASE_TCB0->TCB_TC1.TC_CMR &= ~(7 << 0); /* TIMER_CLOCK1 is input clk */
AT91C_BASE_TCB0->TCB_TC1.TC_CCR = DEF_BIT_00; /* TC1 timer enabled */
AT91C_BASE_TCB0->TCB_TC1.TC_CCR = DEF_BIT_02; /* SWTRG to reset and start */
#endif
#if OS_VIEW_TIMER_SEL == 2
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC012;/* Enable the peripheral clk */
AT91C_BASE_TCB0->TCB_TC2.TC_CCR = DEF_BIT_01; /* TC2 timer disabled */
AT91C_BASE_TCB0->TCB_TC2.TC_CMR &= ~(7 << 0); /* TIMER_CLOCK1 is input clk */
AT91C_BASE_TCB0->TCB_TC2.TC_CCR = DEF_BIT_00; /* TC2 timer enabled */
AT91C_BASE_TCB0->TCB_TC2.TC_CCR = DEF_BIT_02; /* SWTRG to reset and start */
#endif
}
#endif
/*
*********************************************************************************************************
* READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 16 bit free running timer.
* This value is then used to compute CPU usage in uC/OS-View.
*
* Arguments : none
*
* Returns ; The 16 bit count (in a 32 bit variable) of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
CPU_INT32U OSView_TmrRd (void)
{
CPU_INT32U cnts;
#if OS_VIEW_TIMER_SEL == 0
cnts = (CPU_INT32U)(AT91C_BASE_TCB0->TCB_TC0.TC_CV & 0x0000FFFF); /* Read timer 0 */
#endif
#if OS_VIEW_TIMER_SEL == 1
cnts = (CPU_INT32U)(AT91C_BASE_TCB0->TCB_TC1.TC_CV & 0x0000FFFF); /* Read timer 1 */
#endif
#if OS_VIEW_TIMER_SEL == 2
cnts = (CPU_INT32U)(AT91C_BASE_TCB0->TCB_TC2.TC_CV & 0x0000FFFF); /* Read timer 2 */
#endif
return (cnts);
}
#endif
/*
******************************************************************************************************************************
******************************************************************************************************************************
** uC/OS-II Timer Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* 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
*
* Returns : 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)
{
CPU_INT32U counts;
CPU_INT32U cpu_frq;
/* Determine the number of counts per tick */
cpu_frq = BSP_CPU_MclkFreq();
counts = ((cpu_frq / 16) / OS_TICKS_PER_SEC) - 1;
/* Set the vector address for PIT */
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (CPU_INT32U)Tmr_TickISR_Handler;
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;
/* Enable the PIT with the correct compare value */
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
*
* Returns : none
*********************************************************************************************************
*/
static void Tmr_TickISR_Handler (void)
{
CPU_INT32U status;
AT91C_BASE_AIC->AIC_IVR = 0; /* Write IVR, 'Start of Handler', req by Protected Mode */
/* Clear the PIT interrupt */
status = AT91C_BASE_PITC->PITC_PIVR;
(void)status; /* Prevent a compiler warning that status was never used */
OSTimeTick(); /* Tell uC/OS-II about clock tick */
/* Clear System Interrupt */
AT91C_BASE_AIC->AIC_ICCR = 1 << AT91C_ID_SYS;
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** Serial Port Communications
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* Ser_Init
*
* Description : This function prepares UART0.
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_Init (void)
{
CPU_INT32U mclk_freq;
mclk_freq = BSP_CPU_MclkFreq(); /* Get peripheral clock frequency */
#if SER_COMM_SEL == SER_UART_0
/* Set GPIOB pins 26, 27, 28, & 29 as USART0 pins */
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA26_TXD0
| AT91C_PA27_RXD0
| AT91C_PA28_RTS0
| AT91C_PA29_CTS0;
/* Select GPIOB attached peripheral (USART0) */
AT91C_BASE_PIOA->PIO_ASR = AT91C_PA26_TXD0
| AT91C_PA27_RXD0
| AT91C_PA28_RTS0
| AT91C_PA29_CTS0;
AT91C_BASE_US0->US_IDR = AT91C_US_RXRDY /* Disable Rx interrupts */
| AT91C_US_TXRDY; /* Disable Tx interrupt */
AT91C_BASE_US0->US_CR = AT91C_US_RXEN /* Enable the receiver */
| AT91C_US_TXEN; /* Enable the transmitter */
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL /* RS232C mode selected */
| AT91C_US_CLKS_CLOCK /* USART input CLK is MCK */
| AT91C_US_CHRL_8_BITS /* 8 bit data to be sent */
| AT91C_US_PAR_NONE /* No parity bit selected */
| AT91C_US_NBSTOP_1_BIT; /* 1 stop bit selected */
/* Set the USART baud rate */
AT91C_BASE_US0->US_BRGR = (CPU_INT16U)((mclk_freq / 115200) / 16);
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US0); /* Enable the USART0 peripheral clock */
#endif
#if SER_COMM_SEL == SER_DBGU
/* Set GPIOC pins 30 and 31 as DBGU UART pins */
AT91C_BASE_PIOC->PIO_PDR = AT91C_PC30_DRXD
| AT91C_PC31_DTXD;
/* Select GPIOC attached peripheral (DBGU) */
AT91C_BASE_PIOC->PIO_ASR = AT91C_PC30_DRXD
| AT91C_PC31_DTXD;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -