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

📄 st79_linuart.c

📁 st公司新出的一款8位单片机st79的lib库
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
  ********************************************************************************
  * @file st79_linuart.c
  * @brief This file contains all the functions for the LINUART peripheral.
  * @author STMicroelectronics - MCD & APG Car Body Application Labs
  * @version V0.01
  * @date 04-JUL-2007
  ******************************************************************************
  *
  * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2007 STMicroelectronics</center></h2>
  * @image html logo.bmp
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "st79_linuart.h"


/* LINKER SECTIONS DEFINITION FOR THIS FILE ONLY */
#pragma section (LINUART_CODE)
#pragma section const {LINUART_CONST}
#pragma section @near [LINUART_URAM]
#pragma section @near {LINUART_IRAM}
#pragma section @tiny [LINUART_UZRAM]
#pragma section @tiny {LINUART_IZRAM}

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/** @addtogroup LINUART_Private_Functions
  * @{
  */

/**
  * @}
  */

/* Public functions ----------------------------------------------------------*/

/** @}
  * @addtogroup LINUART_Public_Functions
  * @{
  */

/**
 * @brief Clears the LINUARTx's pending flags.
 * @par To be checked
 * 		- Check with designer the Clearing Procedure for TC and TXE flags
 * @par Full description:
 * Clears the LINUART's pending flags.
 * @param[in] LINUARTx can be only LINUART.
 * @param[in] LINUART_FLAG specifies the flag to clear
 *		This parameter can be one of the following values:
 *                       - LINUART_FLAG_LBD
 *                       - LINUART_FLAG_TXE
 *                       - LINUART_FLAG_TC
 *                       - LINUART_FLAG_RXNE
 *                       - LINUART_FLAG_IDLE
 *                       - LINUART_FLAG_ORE
 *                       - LINUART_FLAG_NE
 *                       - LINUART_FLAG_FE
 *                       - LINUART_FLAG_PE
 *		        - LINUART_FLAG_SBK
 *		        - LINUART_FLAG_LHDF     //FOR CUT 1.0 only
 *		        - LINUART_FLAG_LSF     //FOR CUT 1.0 only
  * @retval void None
  * @par Required preconditions:
  * None
  * @par Called functions:
  * None
  * @par Example:
  * Clear the LINUART TC flag
  * @code
  * LINUART_ClearFlag(LINUART, LINUART_FLAG_TC);
  * @endcode
  */

void LINUART_ClearFlag(LINUART_TypeDef* LINUARTx, LINUART_Flag_TypeDef LINUART_FLAG)
{
    u8 dummy=0xAA;
    assert(IS_LINUART_FLAG_VALUE_OK(LINUART_FLAG));

    switch (LINUART_FLAG)
    {
        /*< Clear the Transmit Register Empty flag    */
    case LINUART_FLAG_TXE:
        LINUARTx->DR = dummy;
        break;

        /*< Clear the Transmission Complete flag      */
    case LINUART_FLAG_TC:
        LINUARTx->SR |= LINUART_SR_TC;
        LINUARTx->SR |= LINUART_SR_TC;
        LINUARTx->DR = dummy;
        break;

        /*< Clear the LIN Header Error flag */
    case LINUART_FLAG_LHE:
        /*< Clear the Receive Register Not Empty flag */
    case LINUART_FLAG_RXNE:
        /*< Clear the Idle Detection flag             */
    case LINUART_FLAG_IDLE:
        /*< Clear the Overrun Error flag              */
    case LINUART_FLAG_ORE:
        /*< Clear the Noise Error flag                */
    case LINUART_FLAG_NE:
        /*< Clear the Framing Error flag              */
    case LINUART_FLAG_FE:
        /*< Clear the Parity Error flag               */
    case LINUART_FLAG_PE:
        dummy = LINUARTx->SR; /*< Read Status Register */
        dummy = LINUARTx->SR; /*< Read Status Register */  /*TBD*/
        dummy = LINUARTx->DR; /*< Read Data Register   */
        break;

        /*< Clear the LIN Break Detection flag */
    case LINUART_FLAG_LBD:
        LINUARTx->CR4 &= (u8)(~LINUART_CR4_LBDF);
        break;

    case LINUART_FLAG_SBK:
        LINUARTx->CR2 &= (u8)(~LINUART_CR2_SBK);
        break;
#ifdef  HW_PLATFORM_CUT10
    case LINUART_FLAG_LHDF:
        LINUARTx->CR5; /*TBD*/
        break;
    case LINUART_FLAG_LSF:
        LINUARTx->CR5 &= (u8)(~LINUART_CR5_LSF); /*TBD*/
        break;
#endif
    default:
        break;
    }
}

/**
  * @brief Enable the LINUART peripheral.
  * @par Full description:
  * Enable the LINUART peripheral.
  * @param[in] LINUARTx can be only LINUART.
  * @param[in] NewState new state of the LINUART Communication.
  *                    This parameter can be: ENABLE or DISABLE.
  * @retval void None
  * @par Required preconditions:
  * None
  * @par Called functions:
  * None
  * @par Example:
  * Enable LINUART peripheral.
  * @code
  * LINUART_Cmd(LINUART, ENABLE);
  * @endcode
  */
void LINUART_Cmd(LINUART_TypeDef* LINUARTx, FunctionalState NewState)
{
    /* Test if the LINUART is Enabled       */
    /* if(!(LINUART->CR1&LINUART_CR1_USARTD)) */
    /*  Wait for no Transmition before modifying the LINUART Enable bit */
    /* while(!(LINUART->SR&(LINUART_SR_TC|LINUART_SR_TC)));                  */

    if (NewState)
    {
        LINUARTx->CR1 &= (u8)(~LINUART_CR1_USARTD); /**< LINUART Enable */
    }
    else
    {
        LINUARTx->CR1 |= LINUART_CR1_USARTD;  /**< LINUART Disable (for low power consumption) */
    }
}

/**
  * @brief Deinitializes the LINUART peripheral.
  * @par Full description:
  * Set the LINUART peripheral registers to their default reset values.
  * @param[in] LINUARTx can be only LINUART.
  * @retval void None
  * @par Required preconditions:
  * None
  * @par Called functions:
  * None
  * @par Example:
  * Deinitialize LINUART peripheral.
  * @code
  * LINUART_DeInit(LINUART);
  * @endcode
  */

void LINUART_DeInit(LINUART_TypeDef* LINUARTx)
{
    u8 dummy;
    /*! Wait for no Transmition before DeInit process */
    /*! while(!(LINUARTx->SR&(LINUART_SR_TC|LINUART_SR_TC))); */

    /*< Clear the Idle Line Detected bit in the status rerister by a read
       to the LINUART_SR register followed by a Read to the LINUART_DR register */
    dummy = LINUARTx->SR;
    dummy = LINUARTx->DR;

    LINUARTx->BRR2 = LINUART_BRR2_RESET_VALUE;  /*< Set LINUART_BRR2 to reset value 0x00 */
    LINUARTx->BRR1 = LINUART_BRR1_RESET_VALUE;  /*< Set LINUART_BRR1 to reset value 0x00 */

    LINUARTx->CR1 = LINUART_CR1_RESET_VALUE; /*< Set LINUART_CR1 to reset value 0x00  */
    LINUARTx->CR2 = LINUART_CR2_RESET_VALUE; /*< Set LINUART_CR2 to reset value 0x00  */
    LINUARTx->CR3 = LINUART_CR3_RESET_VALUE;  /*< Set LINUART_CR3 to reset value 0x00  */
    LINUARTx->CR4 = LINUART_CR4_RESET_VALUE;  /*< Set LINUART_CR4 to reset value 0x00  */
    LINUARTx->CR5 = LINUART_CR5_RESET_VALUE; /*< Set LINUART_CR5 to reset value 0x00  */

}


/**
  * @brief Checks whether the specified LINUART flag is set or not.
  * @par Full description:
  * Checks whether the specified LINUART flag is set or not.
  * @param[in] LINUARTx can be LINUART or LINUART to select the peripheral.
  * @param[in] LINUART_FLAG specifies the flag to check.
  *                    This parameter can be one of the following values:
  *                       - LINUART_FLAG_LBD
 *                       - LINUART_FLAG_TXE
 *                       - LINUART_FLAG_TC
 *                       - LINUART_FLAG_RXNE
 *                       - LINUART_FLAG_IDLE
 *                       - LINUART_FLAG_ORE
 *                       - LINUART_FLAG_NE
 *                       - LINUART_FLAG_FE
 *                       - LINUART_FLAG_PE
 *		       - LINUART_FLAG_SBK
 *		       - LINUART_FLAG_LHDF //FOR CUT 1.0 only
 *		       - LINUART_FLAG_LSF  //FOR CUT 1.0 only
  * @retval FlagStatus (SET or RESET)
  * @par Required preconditions:
  * None
  * @par Called functions:
  * None
  * @par Example:
  * Check the status of TC flag.
  * @code
  * FlagStatus TC_flag;
  * TC_Flag = LINUART_GetFlagStatus(LINUART, LINUART_FLAG_TC);
  * @endcode
  */
FlagStatus LINUART_GetFlagStatus(LINUART_TypeDef* LINUARTx, LINUART_Flag_TypeDef LINUART_FLAG)
{
    assert(IS_LINUART_FLAG_VALUE_OK(LINUART_FLAG));

    switch (LINUART_FLAG)
    {
        /*< Returns the Transmit Data Register Empty flag     */
    case LINUART_FLAG_TXE:
        /*< Returns the Transmission Complete flag state   */
    case LINUART_FLAG_TC:
        /*< Returns the Read Data Not Empty flag state     */
    case LINUART_FLAG_RXNE:
        /*< Returns the IDLE Detection flag state          */
    case LINUART_FLAG_IDLE:
        /*< Returns the Overrun Error flag state           */
    case LINUART_FLAG_ORE:
        /*< Returns the Noise Error flag state             */
    case LINUART_FLAG_NE:
        /*< Returns the Framing Error flag state           */
    case LINUART_FLAG_FE:
        /*< Returns the Parity Error flag state            */
    case LINUART_FLAG_PE:
        if (LINUARTx->SR&(u8)LINUART_FLAG)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;
        /*< Returns the LIN Break Detection flag state */
    case LINUART_FLAG_LBD:
        if (LINUARTx->CR4&LINUART_CR4_LBDF)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;
        /*< Returns the Send Break flag state */
    case LINUART_FLAG_SBK:
        if (LINUARTx->CR2 & LINUART_CR2_SBK)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;
#ifdef  HW_PLATFORM_CUT10
    case LINUART_FLAG_LHDF:
        if (LINUARTx->CR5&LINUART_CR5_LHDF)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;
    case LINUART_FLAG_LSF:
        if (LINUARTx->CR5&LINUART_CR5_LSF)
        {
            return SET;
        }
        else
        {
            return RESET;
        }	  break;
#endif
    default:
        return SET;
        break;
    }
}

/**
  * @brief Checks whether the specified LINUART interrupt has occurred or not.
  * @par Full description:
  * Checks whether the specified LINUART interrupt has occurred or not.
  * @param[in] LINUARTx can be only LINUART.
  * @param[in] LINUART_IT specifies the LINUART interrupt source to check.
  *                    This parameter can be one of the following values:
  *                       - LINUART_IT_PIEN
  *                       - LINUART_IT_TCIEN
  *                       - LINUART_IT_RIEN
  *                       - LINUART_IT_ILIEN
  *                       - LINUART_IT_RIEN
  *                      - LINUART_IT_LBDIEN
  *		        - LINUART_IT_LHDIEN   //FOR CUT 1.0
  * @retval ITStatus - The new state of LINUART_IT (SET or RESET).
  * @par Required preconditions:
  * None
  * @par Called functions:
  * None
  * @par Example:
  * @code
  * IT_Status PIEN_ITStatus;
  * PIEN_ITStatus = LINUART_GetITStatus(LINUART, LINUART_IT_PIEN;
  * @endcode
  */
ITStatus LINUART_GetITStatus(LINUART_TypeDef* LINUARTx, LINUART_IT_TypeDef LINUART_IT)
{
    assert(IS_LINUART_IT_VALUE_OK(LINUART_IT));

    switch (LINUART_IT)
    {
        /*< Returns the Parity Interrupt Enable bit state               */
    case LINUART_IT_PIEN:
        if (LINUARTx->CR1 & LINUART_CR1_PIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;

        /*< Returns the Transmitter Interrupt Enable bit state           */
    case LINUART_IT_TIEN:
        if (LINUARTx->CR2 & LINUART_CR2_TIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;

        /*< Returns the Transmission Complete Interrupt Enable bit state */
    case LINUART_IT_TCIEN:
        if (LINUARTx->CR2 & LINUART_CR2_TCIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;

        /*< Returns the Receiver Interrupt Enable bit state              */
    case LINUART_IT_RIEN:
        if (LINUARTx->CR2 & LINUART_CR2_RIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;

        /*< Returns the Idle Line Interrupt Enable bit state             */
    case LINUART_IT_ILIEN:
        if (LINUARTx->CR2 & LINUART_CR2_ILIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;

        /*< Returns the LIN Break Detection Interrupt Enable bit state   */
    case LINUART_IT_LBDIEN:
        if (LINUARTx->CR4 & LINUART_CR4_LBDIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;
#ifdef  HW_PLATFORM_CUT10
    case LINUART_IT_LHDIEN:
        if (LINUARTx->CR5&LINUART_CR5_LHDIEN)
        {
            return SET;
        }
        else
        {
            return RESET;
        }
        break;
#endif
    default:
				return SET;
        break;
    }
}



/**
  * @brief Initializes the LINUART peripheral.
  * @par Full description:
  * Initializes the LINUART peripheral according to the specified
  * parameters .

⌨️ 快捷键说明

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