📄 bsp.c
字号:
* 0 indicates that you want ALL the LEDs to toggle
* 1 toggle LD 16 (located on the upper-left corner of the board)
* 2 toggle LD 12 (located next to LD 16)
* .
* 16 toggle LD 6 (the last of the 16 LEDs located at the top of the board)
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO0->PD ^= 0x100F;
GPIO1->PD ^= 0x8070;
GPIO2->PD ^= 0xFE00;
break;
case 1:
GPIO2->PD ^= 0x8000;
break;
case 2:
GPIO2->PD ^= 0x0800;
break;
case 3:
GPIO1->PD ^= 0x0040;
break;
case 4:
GPIO2->PD ^= 0x1000;
break;
case 5:
GPIO1->PD ^= 0x0020;
break;
case 6:
GPIO2->PD ^= 0x2000;
break;
case 7:
GPIO1->PD ^= 0x0010;
break;
case 8:
GPIO2->PD ^= 0x4000;
break;
case 9:
GPIO0->PD ^= 0x1000;
break;
case 10:
GPIO0->PD ^= 0x0008;
break;
case 11:
GPIO1->PD ^= 0x8000;
break;
case 12:
GPIO0->PD ^= 0x0004;
break;
case 13:
GPIO2->PD ^= 0x0200;
break;
case 14:
GPIO0->PD ^= 0x0002;
break;
case 15:
GPIO2->PD ^= 0x0400;
break;
case 16:
GPIO0->PD ^= 0x0001;
break;
}
}
/*
*********************************************************************************************************
* INITIALIZE THE EXTERNAL MEMORY INTERFACE
*
* Description : This initializes the External Memory Interface. Bank 2, which represents the board's
* LCD, is enabled.
*
* Arguments : none
*********************************************************************************************************
*/
static void EMI_Init (void)
{
EMI->BCON2 = 0x8024; /* Initialize the EMI bank corresponding to the LCD */
}
/*
*********************************************************************************************************
* WRITE DATA TO DISPLAY DEVICE
*
* Description : This function sends a single BYTE to the display device.
*
* Arguments : 'data' is the BYTE to send to the display device
*********************************************************************************************************
*/
void DispDataWr (CPU_INT08U data)
{
*BSP_LCD_Reg = data; /* Write the byte to the LCD module */
DispDly_uS(100); /* Delay for 100 us */
}
/*
*********************************************************************************************************
* DELAY
*
* Description : This function is called to delay for the specified number of microseconds. The delay is
* based on the peripheral clock frequency, so BSP_Set_CPU_ClkFreqPeripheral() must be
* called to set the variable representing this frequency before this function is used.
*
* Arguments : us Number of microseconds
*********************************************************************************************************
*/
void DispDly_uS (CPU_INT32U us)
{
CPU_INT32U us_per_tick;
CPU_INT32U ticks;
us_per_tick = 1000000L / OS_TICKS_PER_SEC;
ticks = us / us_per_tick + 1;
OSTimeDly(ticks);
}
/*
*********************************************************************************************************
* INITIALIZE DISPLAY DRIVER I/O PORTS
*
* Description : This function normally initializes the I/O ports used by the display driver. In this
* case, the ports are initialized by BSP_IO_Init(), so this function intitializes the
* pointer used to write to the LCD.
*
* Arguments : none
*********************************************************************************************************
*/
void DispInitPort (void)
{
BSP_LCD_Reg = (CPU_INT08U *)BSP_LCD_DATA_REG;
}
/*
*********************************************************************************************************
* SELECT COMMAND OR DATA REGISTER
*
* Description : This function manipulates the Register Select control line to the LCD controller.
*
* Arguments : none
*********************************************************************************************************
*/
void DispSel (CPU_INT08U sel)
{
if (sel == DISP_SEL_CMD_REG) {
BSP_LCD_Reg = (CPU_INT08U *)BSP_LCD_CTRL_REG; /* Select the command register (RS low) */
} else {
BSP_LCD_Reg = (CPU_INT08U *)BSP_LCD_DATA_REG; /* Select the data register (RS high) */
}
}
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer
* generating interrupts every 1 to 100 mS).
*
* We decided to use Timer #0 as the tick interrupt source.
*
* Arguments : none
*********************************************************************************************************
*/
static void Tmr_TickInit(void)
{
CPU_INT08U err;
/* Calculate the reset value for Timer 0 */
BSP_Tmr0_Rst_Value = (BSP_Peripheral_Clk2_Freq / (BSP_TMR0_PRESCALER + 1)) / OS_TICKS_PER_SEC;
/* Set up the IVR */
err = BSP_VectSet((CPU_INT16U)BSP_TMR0_INT, (BSP_PFNCT)Tmr_TickISR_Handler);
if (err == BSP_VECT_SET) {
EIC->SIR[BSP_TMR0_INT] |= 0x00000001; /* Set the priority for Timer 0 */
}
EIC->IER = 1 << BSP_TMR0_INT; /* Enable the interrupt */
TIM0->CR2 = 0x4000 | BSP_TMR0_PRESCALER; /* Set up the Timer 0 interrupt */
TIM0->CR1 = 0x8040; /* Enable the timer in Output Compare mode */
TIM0->OCAR = BSP_Tmr0_Rst_Value; /* Set the timer's period */
TIM0->CNTR = 0xFFF0; /* Reset the counter */
}
/*
*********************************************************************************************************
* TICK IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : none
*
* Note(s) : The TICK ISR uses Timer 0
*********************************************************************************************************
*/
static void Tmr_TickISR_Handler (void)
{
TIM0->SR &= ~0x4000; /* Clear the timer's interrupt pending bit */
EIC->IPR = 0x00000001; /* Clear the timer's interrupt pending bit in the EIC */
TIM0->OCAR = BSP_Tmr0_Rst_Value; /* Reset the timer's period */
TIM0->CNTR = 0xFFF0; /* Start the timer again */
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() to signal a tick */
}
/*
*********************************************************************************************************
* READ TIMER USED TO MEASURE INTERRUPT DISABLE TIME
*
* Description : This function is called to read the current counts of the interrupt disable time
* measurement timer. Timer 1 is used for this measurement.
*
* Arguments : none
*
* Returns : The 16 bit counts of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if OS_CPU_INT_DIS_MEAS_EN > 0
CPU_INT16U OS_CPU_IntDisMeasTmrRd (void)
{
CPU_INT16U cnts;
cnts = TIM1->CNTR;
return (cnts);
}
#endif
/*
*********************************************************************************************************
* INITIALIZE TIMER FOR uC/OS-View
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
* used to make time measurements.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
void OSView_TmrInit (void)
{
TIM1->CR2 = 0x0000 | BSP_TMR1_PRESCALER; /* Set up the timer to run continuously */
TIM1->CR1 = 0x8000; /* Start the timer */
}
#endif
/*
*********************************************************************************************************
* READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 16-bit free running timer.
*
* Arguments : none
*
* Returns : A 32-bit value representing the current time
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
CPU_INT32U OSView_TmrRd (void)
{
CPU_INT32U cycles;
cycles = (CPU_INT32U)(TIM1->CNTR); /* Get the current value of Timer 1 */
return (cycles);
}
#endif
/*
*********************************************************************************************************
* UART INITIALIZATION
*
* Description : This function is called by uC/OS-View to initialize the UART.
*
* Arguments : baud_rate The baud rate to which the UART will be initialized
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
void OSView_UARTInit (CPU_INT32U baud_rate)
{
CPU_INT08U err;
err = BSP_VectSet((CPU_INT16U)BSP_UART0_INT, (BSP_PFNCT)UART_ISR_Handler);
if (err == BSP_VECT_SET) {
EIC->SIR[BSP_UART0_INT] |= 0x00000003; /* Set the priority for UART 0 */
}
EIC->IER |= 1 << BSP_UART0_INT; /* Enable the interrupt */
/* Set the UART's baud rate */
UART0->BR = (CPU_INT16U)(BSP_Peripheral_Clk1_Freq / (16 * baud_rate));
UART0->TOR = 0x00FF; /* Set the UART's timeout register*/
UART0->GTR = 0x0080; /* Set the UART's Guard time */
UART0->IER = 0x0083; /* Enable RX and TX interrputs */
UART0->CR = 0x0189; /* Start the UART */
}
#endif
/*
*********************************************************************************************************
* UART IRQ HANDLER
*
* Description : This function handles the UART interrupt by calling the uC/OS-View handler
*
* Arguments : none
*********************************************************************************************************
*/
#if OS_VIEW_MODULE >0
void UART_ISR_Handler (void)
{
OSView_RxTxISRHandler();
EIC->IPR = 0x00000200; /* Clear the UART's bit in the EIC */
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -