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

📄 csp_usart.c

📁 IAR 平台ATMEL 的例程, 和说明
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
*   EUROPE TECHNOLOGIES Software Support
*------------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. This includes without
* limitation any warranty or condition with respect to merchantability or
* fitness for any particular purpose, or against the infringements of
* intellectual property rights of others.
*------------------------------------------------------------------------------
*
* File Name       : csp_usart.c
* Description     : Function declarations for Universal Synchronous/Asynchronous 
*                   Receiver/Transmitter management
* Library Version : 2.00
* Module Version  : 1.XX
*
*       +----- (NEW | MODify | ADD | DELete)                                 
*       |                                                                    
*  No   |   When       Who                What               
*-----+---+----------+------------------+--------------------------------------
* 000  NEW  01/05/99   Patrice VILCHEZ    Creation
* 001  MOD  01/04/01   Olivier MAZUYER    Clean up
* 002  ADD  07/06/01   Frederic SAMSON    Add fonctions :
*                                         CSP_USARTDisableInterrupt
* 003  MOD  08/06/01   Frederic SAMSON    Add CSP_USARTDisableInterrupt
* 004  MOD  16/07/01   Frederic SAMSON    Clean Up
* 005  MOD  05/11/01   Christophe GARDIN  Clean Up
* 006  MOD  11/04/02   Christophe GARDIN  Add CSP_USARTClose function
* 007  MOD  18/07/02   Christophe GARDIN  Add LIN functions
*----------------------------------------------------------------------------*/

/******************************************************************************
* Include Files
******************************************************************************/
#include "csp.h"


/******************************************************************************
****************************  F U N C T I O N S  ******************************
******************************************************************************/

/******************************************************************************
* Function          : CSP_USARTInit
* Description       : Switch on the clock, reset the registers and configure 
*                     the USART module mode and the PDC RX/TX lines
* Inputs            : <*usart>     = Pointer to USART structure
*                     <mode>       = Configure the USART mode
*                     <baudrate>   = Configure the Baud Rate Generator
*                     <time_out>   = Configure the receiver time-out : the time-out 
*                                    is loaded when the Start Time-out Command 
*                                    is given or when each new character is received
*                     <time_guard> = Configure the transmit time-guard : TXD is 
*                                    inactive (high level) after the transmission 
*                                    of each character for the time-guard duration
* Functions called  : CSP_PDCInitTx, CSP_PDCInitRx
* Returns           : None
******************************************************************************/
void CSP_USARTInit(CSP_USART_T *const usart, 
                   U32_T mode, 
                   U16_T baudrate, 
                   U8_T time_out, 
                   U8_T time_guard)
{
   /* Local Variables */
   U8_T transfert_size = 0;

   /* Enable USART Clock */
   CSP_USART_SET_ECR(usart, (USART | PIO));

   /* USART Software Reset */
   CSP_USART_SET_CR(usart, (SWRST | RSTRX | RSTTX | RSTSTA));

   /* Disable USART PIO */
   CSP_USART_SET_PDR(usart, (RXD | TXD | SCK));

   /* Configure USART Mode */
   CSP_USART_SET_MR(usart, mode);
    
   /* Set Receiver Time Out */
   CSP_USART_SET_RTOR(usart, time_out);
  
   /* Set Transmitter Timer Guard */
   CSP_USART_SET_TTGR(usart, time_guard);
  
   /* Set Baudrate */
   CSP_USART_SET_BRGR(usart, baudrate);
  
   /* Configure the transfer size in accordance with the Mode Register */
   if((mode & MODE9) == 0)
   {
      transfert_size = SIZE_BYTE;
   }
   else
   {
      transfert_size = SIZE_HALFWORD;
   }
   
   /* Configure PDC Tx Line */
   CSP_PDCInitTx((U32_T)usart, (U32_T) &(usart->THR), transfert_size);

   /* Configure PDC Rx Line */
   CSP_PDCInitRx((U32_T)usart, (U32_T) &(usart->RHR), transfert_size);
}
 

/******************************************************************************
* Function          : CSP_USARTInitLin
* Description       : Switch on the clock, reset the registers and configure 
*                     the USART module in LIN mode
* Inputs            : <*usart>     = Pointer to USART structure
*                     <time_guard> = Configure the transmit time-guard (interbyte 
*                                    space)
* Functions called  : None
* Returns           : None
******************************************************************************/
void CSP_USARTInitLin(CSP_USART_T *const usart, U8_T time_guard)
{
   /* Enable USART Clock */
   CSP_USART_SET_ECR(usart, (USART | PIO));

   /* USART Software Reset */
   CSP_USART_SET_CR(usart, (SWRST | RSTRX | RSTTX));

   /* Disable USART PIO */
   CSP_USART_SET_PDR(usart, (RXD | TXD | SCK));

   /* Configure LIN Mode */
   CSP_USART_SET_MR(usart, LIN);
    
   /* Set Transmitter Timer Guard */
   CSP_USART_SET_TTGR(usart, time_guard);
}


/******************************************************************************
* Function          : CSP_USARTClose
* Description       : Reset and switch off the clock
* Inputs            : <*usart> = Pointer to USART structure
* Functions called  : None
* Returns           : None
******************************************************************************/
void CSP_USARTClose(CSP_USART_T *const usart)
{
   /* USART Software Reset */
   CSP_USART_SET_CR(usart, (SWRST | RSTRX | RSTTX | RSTSTA));

   /* Disable USART Clock */
   CSP_USART_SET_DCR(usart, (USART | PIO));
}


/******************************************************************************
* Function          : CSP_USARTConfigInterrupt
* Description       : Configure USART Interrupts
* Inputs            : <*usart>   = Pointer to USART structure
*                     <int_mode> = Configure the priority level and source type
*                     <int_mask> = Configure which interrupt bits are activated
*                     <callback> = Function called through the assembler interrupt handler
* Functions called  : CSP_GET_INTERRUPT_NUMBER, CSP_GICConfigInterrupt
* Returns           : None
******************************************************************************/
void CSP_USARTConfigInterrupt(CSP_USART_T *const usart, 
                              U32_T int_mode, 
                              U32_T int_mask, 
                              U32_T callback)
{
   /* Local Variables */
   U8_T int_num = 0;

   /* Get Peripheral Interrupt Number */
   int_num = CSP_GET_INTERRUPT_NUMBER(usart);

   /* Disable all interrupt */
   CSP_USART_SET_IDR(usart, 0xFFFFFFFF);
   
   /* Interrupt Enable */
   CSP_USART_SET_IER(usart, int_mask);

   /* Configure USART controller interrupt mode in GIC module */
   CSP_GICConfigInterrupt(int_num, int_mode, callback);
}


/******************************************************************************
* Function          : CSP_USARTEnable
* Description       : Enable USART Rx and/or Tx
* Inputs            : <*usart>      = Pointer to USART structure
*                     <enable_mask> = Configure which functions (RX and/or TX) 
*                     are enabled
* Functions called  : None
* Returns           : None
******************************************************************************/
void CSP_USARTEnable(CSP_USART_T *const usart, U32_T enable_mask)
{
   /* USART Rx and/or Tx Enable */
   CSP_USART_SET_CR(usart, enable_mask);
}

⌨️ 快捷键说明

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