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

📄 bsp.c

📁 ucOS_9263_Source ucOS-ii for 9263 port,from Micrium.com
💻 C
📖 第 1 页 / 共 4 页
字号:

    AT91C_BASE_DBGU->DBGU_IDR   = AT91C_US_RXRDY                /* Disable Rx interrupts                                    */
                                | AT91C_US_TXRDY;               /* Disable Tx interrupt                                     */

    AT91C_BASE_DBGU->DBGU_CR    = AT91C_US_RXEN                 /* Enable the receiver                                      */
                                | AT91C_US_TXEN;                /* Enable the transmitter                                   */

    AT91C_BASE_DBGU->DBGU_MR    = AT91C_US_USMODE_NORMAL        /* Normal mode selected                                     */
                                | AT91C_US_PAR_NONE;            /* No parity bit selected                                   */

                                                                /* Set the DBGU baud rate                                   */
    AT91C_BASE_DBGU->DBGU_BRGR = (CPU_INT16U)((mclk_freq / 115200) / 16);

    AT91C_BASE_PMC->PMC_PCER   = (1 << AT91C_ID_SYS);           /* Enable the DBGU 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 == SER_UART_0
    AT91C_BASE_US0->US_THR      = tx_byte;
#endif

#if SER_COMM_SEL == SER_DBGU
    AT91C_BASE_DBGU->DBGU_THR   = tx_byte;
#endif
}

/*
*********************************************************************************************************
*                                                Ser_WrStr
*
* Description :   Transmits a string using UART0
*
* Arguments   :   The string that will be transmitted.
*
* Returns     :   None.
*********************************************************************************************************
*/

void  Ser_WrStr (const CPU_CHAR * tx_str)
{
    while ((*tx_str) != 0) {
        Ser_WrByte(*tx_str++);

#if SER_COMM_SEL == SER_UART_0
        while ((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) != AT91C_US_TXRDY) {
            OSTimeDly(1);
        }
#endif

#if SER_COMM_SEL == SER_DBGU
        while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXRDY) != AT91C_US_TXRDY) {
            OSTimeDly(1);
        }
#endif
    }
}

/*
*********************************************************************************************************
*                                                Ser_RdByte
*
* Description :   Receive a single byte using UART0
*
* Arguments   :   None.
*
* Returns     :   The received byte
*********************************************************************************************************
*/

CPU_INT08U  Ser_RdByte (void)
{
    CPU_INT08U  rx_byte;


#if SER_COMM_SEL == SER_UART_0
    while ((AT91C_BASE_US0->US_CSR & AT91C_US_RXRDY) != AT91C_US_RXRDY) {
        OSTimeDly(1);
    }

    rx_byte = (CPU_INT08U)(AT91C_BASE_US0->US_RHR & 0x00FF);    /* Remove the data from the holding register                */
    return (rx_byte);
#endif

#if SER_COMM_SEL == SER_DBGU
    while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY) != AT91C_US_RXRDY) {
        OSTimeDly(1);
    }

    rx_byte = (CPU_INT08U)(AT91C_BASE_DBGU->DBGU_RHR & 0x00FF); /* Remove the data from the holding register                */
    return (rx_byte);
#endif

}

/*
*********************************************************************************************************
*                                                Ser_RdStr
*
* Description :   This function reads a string using Channel 0 of the UART.
*
* Arguments   :   s      A pointer to a buffer at which the string can be stored
*                 len    The size of the string that will be read
*
* Returns     :   None
*********************************************************************************************************
*/

void  Ser_RdStr (CPU_CHAR    *rx_str,
                 CPU_INT32U   len)
{
    CPU_CHAR  input;
    CPU_CHAR  input_ix;


    input_ix  = 0;
    rx_str[0] = 0;

    while (1)
    {
        input = Ser_RdByte();

        if ((input == '\r') ||
            (input == '\n')) {
            Ser_Printf("\n");
            rx_str[input_ix] = 0;
            break;
        }

        if (input == '\b') {
            if (input_ix > 0) {
                Ser_Printf("\b \b");
                input_ix--;
                rx_str[input_ix] = 0;
            }
        }

        if (Str_IsPrint(input)) {
            Ser_Printf("%c", input);
            rx_str[input_ix] = input;
            input_ix++;
            if (input_ix >= len) {
               input_ix = len;
            }
        }
    }
}

/*
*********************************************************************************************************
*                                                Ser_Printf
*
* Description :   Formatted outout to the serial port.
*                 This funcion reads a string from a serial port. This call blocks until a
*                 character appears at the port and the last character is a Carriage
*                 Return (0x0D).
*
* Arguments   :   Format string follwing the C format convention.
*
* Returns     :   None.
*********************************************************************************************************
*/

void  Ser_Printf (const  CPU_CHAR *format, ...)
{
    static  CPU_CHAR  buffer[80 + 1];
            va_list   vArgs;


    va_start(vArgs, format);
    vsprintf((char *)buffer, (char const *)format, vArgs);
    va_end(vArgs);

    Ser_WrStr((CPU_CHAR*) buffer);
}


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                Static Board Support Initialization Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                           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)      */
}


/*
*********************************************************************************************************
*                                          PLL INITIALIZATION
*
* Description : This function initializes the AT91SAM7X256 PLL thereby setting the frequency of MCK
*               which is used by PIT to generate the OS tick interrupt.
*
* Arguments   : none
*
* Returns     : none
*********************************************************************************************************
*/

static  void  PLL_Init (void)
{
    CPU_INT32U  temp;


                                                                /* Enable the Main Oscillator                               */
    AT91C_BASE_PMC->PMC_MOR = AT91C_CKGR_OSCOUNT | AT91C_CKGR_MOSCEN;

                                                                /* Wait for the Main Oscillator to start up                 */
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS) == 0) {
        ;
    }

                                                                /* Conf PLLB assuming input frq BSP_XTAL_FREQ*/
                                                                /* Summary: PLLB CLK: 192MHZ, USB CLK: 48MHZ                */
    AT91C_BASE_PMC->PMC_PLLBR = ( 8   << 0)                     /* [07:00]  Divider     =  8                                */
                              | AT91C_CKGR_PLLBCOUNT            /* [13:08]  PLLACount startup dly: 63 SCLKs                 */
                              | AT91C_CKGR_OUTB_1
                              | ( 93  << 16)                    /* [26:16]  Multiplier  = (93 + 1) = 94                     */
                              | AT91C_CKGR_USBDIV_2;            /* [29:28]  USB Divider =  4                                */

                                                                /* Wait for the PLL to start up                             */
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKB) == 0) {
        ;
    }

    temp    =   AT91C_BASE_PMC->PMC_MCKR;
    temp   &= ~(AT91C_PMC_PRES       | AT91C_PMC_MDIV);
    temp   |=   AT91C_PMC_PRES_CLK   | AT91C_PMC_MDIV_2;

    AT91C_BASE_PMC->PMC_MCKR = temp;

                                                                /* Wait for the Master Clock (MCK) to start up              */
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) {
        ;
    }

    temp    =  AT91C_BASE_PMC->PMC_MCKR;
    temp   &= ~AT91C_PMC_CSS;
    temp   |=  AT91C_PMC_CSS_PLLB_CLK;

    AT91C_BASE_PMC->PMC_MCKR  = temp;

    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) {
        ;
    }

                                                                /* Conf PLLB assuming input frq BSP_XTAL_FREQ*/
                                                                /* Summary: PLLB CLK: 192MHZ, USB CLK: 48MHZ                */
    AT91C_BASE_PMC->PMC_PLLAR = ( 8   << 0)                     /* [07:00]  Divider     =  8                                */
                              | AT91C_CKGR_PLLACOUNT            /* [13:08]  PLLACount startup dly: 63 SCLKs                 */
                              | AT91C_CKGR_OUTA_2
                              | ( 93  << 16)                    /* [26:16]  Multiplier  = (93 + 1) = 94                     */
                              | AT91C_CKGR_SRCA;                /* [29:29]  Must be 1                                       */


                                                                 /* Wait for the PLL to start up                            */
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKA) == 0) {
        ;
    }

    temp    =  AT91C_BASE_PMC->PMC_MCKR;
    temp   &= ~AT91C_PMC_CSS;
    temp   |=  AT91C_PMC_CSS_PLLA_CLK;

    AT91C_BASE_PMC->PMC_MCKR  = temp;

    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) {
        ;
    }
}

/*
*********************************************************************************************************
*                                    INITIALIZE THE INTERRUPT CONTROLLER
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  BSP_IntCtrlInit (void)
{
    CPU_INT16U  i;


    OS_CPU_InitExceptVect();

    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] = (CPU_INT32U)BSP_DummyISR_Handler;
        AT91C_BASE_AIC->AIC_SMR[i] = 0;
    }
}

⌨️ 快捷键说明

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