⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp.c

📁 9260的ucos源码
💻 C
📖 第 1 页 / 共 3 页
字号:
*
* Returns     : none
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    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;
             }
             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;
    }
}


/*
*********************************************************************************************************
*                                         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     = 0x01 << AT91C_ID_PIOA;       /* Enable peripheral clock                                  */
    AT91C_BASE_PIOA->PIO_PER     = BSP_PB2 | BSP_PB1;           /* Enable register                                          */
    AT91C_BASE_PIOA->PIO_ODR     = BSP_PB2 | BSP_PB1;           /* Output disable                                           */
    AT91C_BASE_PIOA->PIO_IER     = BSP_PB2 | BSP_PB1;
    AT91C_BASE_PIOA->PIO_PPUER   = BSP_PB2 | BSP_PB1;

}


/*
*********************************************************************************************************
*                                         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)
{
    switch (pb) {
        case 1:
            if (AT91C_BASE_PIOA->PIO_PDSR & (CPU_INT32U)BSP_PB1) {
                return (DEF_FALSE);
            }
            break;
        case 2:
            if (AT91C_BASE_PIOA->PIO_PDSR & (CPU_INT32U)BSP_PB2) {
                return (DEF_FALSE);
            }
            break;
        default:
            break;
    }
    return (DEF_TRUE);
}

/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                          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 << 17);          /* Enable the peripheral clk                                */
    AT91C_BASE_TCB0->TCB_TC0.TC_CCR      =  (1 <<  1);          /* TC0 timer disabled                                       */
    AT91C_BASE_TCB0->TCB_TC0.TC_CMR     &= ~(7 <<  0);          /* TIMER_CLOCK1 is input clk                                */
    AT91C_BASE_TCB0->TCB_TC0.TC_CCR      =  (1 <<  0);          /* TC0 timer enabled                                        */
    AT91C_BASE_TCB0->TCB_TC0.TC_CCR      =  (1 <<  2);          /* SWTRG to reset and start                                 */
#endif

#if OS_VIEW_TIMER_SEL == 1
    AT91C_BASE_PMC->PMC_PCER             =  (1 << 18);          /* Enable the peripheral clk                                */
    AT91C_BASE_TCB0->TCB_TC1.TC_CCR      =  (1 <<  1);          /* TC1 timer disabled                                       */
    AT91C_BASE_TCB0->TCB_TC1.TC_CMR     &= ~(7 <<  0);          /* TIMER_CLOCK1 is input clk                                */
    AT91C_BASE_TCB0->TCB_TC1.TC_CCR      =  (1 <<  0);          /* TC1 timer enabled                                        */
    AT91C_BASE_TCB0->TCB_TC1.TC_CCR      =  (1 <<  2);          /* SWTRG to reset and start                                 */
#endif

#if OS_VIEW_TIMER_SEL == 2
    AT91C_BASE_PMC->PMC_PCER             =  (1 << 19);          /* Enable the peripheral clk                                */
    AT91C_BASE_TCB0->TCB_TC2.TC_CCR      =  (1 <<  1);          /* TC2 timer disabled                                       */
    AT91C_BASE_TCB0->TCB_TC2.TC_CMR     &= ~(7 <<  0);          /* TIMER_CLOCK1 is input clk                                */
    AT91C_BASE_TCB0->TCB_TC2.TC_CCR      =  (1 <<  0);          /* TC2 timer enabled                                        */
    AT91C_BASE_TCB0->TCB_TC2.TC_CCR      =  (1 <<  2);          /* 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 = (INT32U)(AT91C_BASE_TCB0->TCB_TC0.TC_CV & 0x0000FFFF);   /* Read timer 0                                         */
#endif

#if OS_VIEW_TIMER_SEL == 1
    cnts = (INT32U)(AT91C_BASE_TCB0->TCB_TC1.TC_CV & 0x0000FFFF);   /* Read timer 1                                         */
#endif

#if OS_VIEW_TIMER_SEL == 2
    cnts = (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_ClkFreq();

    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;
    AT91C_BASE_AIC->AIC_EOICR = 0;                              /* Signal end of interrupt                                  */
}

/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                       Serial Port Communications
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                                   Ser_Init
*
* Description :   This function prepares UART0.
*
* Arguments   :   None.
*
* Returns     :   None.
*********************************************************************************************************
*/

void  Ser_Init (void)
{
    CPU_INT32U     peripheral_clk_freq;


    peripheral_clk_freq       = BSP_CPU_ClkFreq();              /* peripheral_clk_freq = MCLK (set in US_MR)                */

#if SER_COMM_SEL == SER_UART_0
    AT91C_BASE_PIOB->PIO_PDR  = 0x0C000030;                     /* Enable USART0 control of pins 5, 6, 7, 8                 */
    AT91C_BASE_PIOB->PIO_ASR  = 0x0C000030;                     /* Select GPIOA attached peripheral (USART0)                */

    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)((peripheral_clk_freq / 38400) / 16);

    AT91C_BASE_PMC->PMC_PCER  = (1 << AT91C_ID_US0);            /* Enable the USART0 peripheral clock                       */
#endif
}

/*
*********************************************************************************************************
*                                                Ser_WrByte
*
* Description :   Transmit a single byte using UART0
*
* Arguments   :   The byte that should be transmitted.
*
* Returns     :   None.
*********************************************************************************************************
*/

void  Ser_WrByte (CPU_INT08U tx_byte)
{
#if SER_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_US0->US_THR = tx_byte;
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -