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

📄 os_viewc.c

📁 AT91SAM7X256
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-View
*
*                                 (c) Copyright 2005, Micrium, Weston, FL
*                                           All Rights Reserved
*
*                                          Atmel AT91SAM7X256
*                                             IAR C Compiler
*
*
* Filename   : OS_VIEWc.C
* Version    : V1.20
* Programmer : Eric Shufro
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                              CONSTANTS
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                           EXIT uC/OS-View
*
* Description: This function is called if your target needs to 'uninstall' uC/OS-View.
*
* Note(s)    :
*********************************************************************************************************
*/

void  OSView_Exit (void)
{
}

/*
*********************************************************************************************************
*                                           Obtain CPU name
*********************************************************************************************************
*/

void  OSView_GetCPUName (INT8U *s)
{
    INT32U  cpu_clk_freq;


    cpu_clk_freq = BSP_CPU_ClkFreq();                           /* Get the CPU frequency in KHZ               */
    (void)OS_StrCopy(s, "AT91SAM7X256 (xx.x MHz)");
    s[14] = cpu_clk_freq / 10000         + '0';
    s[15] = cpu_clk_freq % 10000 / 1000  + '0';
    s[17] = cpu_clk_freq %  1000 /  100  + '0';
}

/*
*********************************************************************************************************
*                                  Obtain Interrupt Stack information
*********************************************************************************************************
*/

INT32U  OSView_GetIntStkBase (void)
{
    return (0);                                                 /* We are not using an ISR stack              */
}


INT32U  OSView_GetIntStkSize (void)
{
    return (0);                                                 /* We are not using an ISR stack              */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                    INITIALISE uC/OS-View COM PORT
*
* Description: Initialize the hardware required for the OS to run. This will work on any target hardware,
*              but may have to be tailored a little (regarding the clock frequency). Of course the same
*              holds true if for some reason you choose to use another timer.
*
* Note(s)    : 1) This function assumes that a free running timer has been initialized.  The timer can
*                 either be a 16 bits or 32 bits timer.  Your application needs to provide a function
*                 called OSView_TmrRd() that reads the current counts of this timer.  The free running
*                 timer is initialized by the BSP function OSView_TmrInit().
*********************************************************************************************************
*/

void  OSView_InitTarget (INT32U baud_rate)
{
    INT32U     peripheral_clk_freq;


    OSView_TmrInit();                                           /* Initialize the free running timer          */
    peripheral_clk_freq       = BSP_CPU_ClkFreq();              /* peripheral_clk_freq = MCLK (set in US_MR)  */

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_PIOA->PIO_PDR  = 0x0000001B;                     /* Set GPIOA pins 0, 1, 3, 4 as USART0 pins   */
    AT91C_BASE_PIOA->PIO_ASR  = 0x0000001B;                     /* 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   = (INT16U)((peripheral_clk_freq * 1000) / baud_rate / 16);

                                                                /* Set the vector address for USART0          */
    AT91C_BASE_AIC->AIC_SVR[AT91C_ID_US0] = (INT32U)OSView_RxTxISRHandler;
    AT91C_BASE_AIC->AIC_SMR[AT91C_ID_US0] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | AT91C_AIC_PRIOR_LOWEST;
    AT91C_BASE_AIC->AIC_ICCR              = 1 << AT91C_ID_US0;
    AT91C_BASE_AIC->AIC_IECR              = 1 << AT91C_ID_US0;

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

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Rx Interrupts
*********************************************************************************************************
*/

void  OSView_RxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_US0->US_IDR                 = AT91C_US_RXRDY;
#endif
}

/*
*********************************************************************************************************
*                                       Enable Rx Interrupts
*********************************************************************************************************
*/

void  OSView_RxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_US0->US_IER                 = AT91C_US_RXRDY;
#endif
}

/*
*********************************************************************************************************
*                                 Rx Communication handler for uC/OS-View
*
* Description: This function is called by OSView_RxISR (see OS_VIEWa.ASM) to process a received
*              character interrupt.
*
* Note(s)    : This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the UART
*              and thus this function is not needed.
*********************************************************************************************************
*/

void  OSView_RxISRHandler (void)
{
}

/*
*********************************************************************************************************
*                   Rx/Tx Communication handler for uC/OS-View ('combined' interrupt handler)
*********************************************************************************************************
*/

void  OSView_RxTxISRHandler (void)
{
    INT8U  rx_data;


#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
                                                                /* If we received a byte                      */
    if ((AT91C_BASE_US0->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY) {
        rx_data = (INT8U)(AT91C_BASE_US0->US_RHR & 0x00FF);     /* Remove the data from the holding register  */
        OSView_RxHandler(rx_data);                              /* Call the generic Rx handler                */
    }

                                                                /* If we completed transmitting a byte        */
    if ((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) == AT91C_US_TXRDY) {
        OSView_TxHandler();                                     /* Call the generic Tx handler                */
    }

    rx_data                     = AT91C_BASE_PITC->PITC_PIVR;   /* Read the interrupt source, ignore the value*/

    AT91C_BASE_AIC->AIC_IVR     = 0;                            /* Debug variant of IVR (protect mode is used)*/
    AT91C_BASE_AIC->AIC_ICCR    = AT91C_ID_US0;                 /* Clear  USART0 interrupt                    */
    AT91C_BASE_AIC->AIC_EOICR   = 0;                            /* Signal end of interrupt                    */

    if ((AT91C_BASE_US0->US_CSR  & AT91C_US_OVRE) == AT91C_US_OVRE) {
        AT91C_BASE_US0->US_CSR  = AT91C_US_RSTSTA;              /* If an overrun occurs, reset the OR flag    */
    }

#endif
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*********************************************************************************************************
*/

void  OSView_Tx1 (INT8U c)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_US0->US_THR = c;
#endif
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_US0->US_IDR                 = AT91C_US_TXRDY;
#endif
}

/*
*********************************************************************************************************
*                                       Enable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    AT91C_BASE_US0->US_IER                 = AT91C_US_TXRDY;
#endif
}

/*
*********************************************************************************************************
*                                 Tx Communication handler for uC/OS-View
*                                            (PORT SPECIFIC)
*
* Description: Handle transmission of a character
*
* Note(s)    : 1) This function is called by OSView_RxISR (see OS_VIEWa.ASM)
*              2) This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the
*                 UART and thus this function is not needed.
*********************************************************************************************************
*/

void  OSView_TxISRHandler (void)
{
}


⌨️ 快捷键说明

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