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

📄 scias.c

📁 用freescale公司的DSP56F8013芯片实现的PMSM的SVPWM 驱动
💻 C
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : SCIAS.C
**     Project   : PMSM
**     Processor : 56F8013VFAE
**     Beantype  : AsynchroSerial
**     Version   : Bean 02.377, Driver 01.24, CPU db: 2.87.089
**     Compiler  : Metrowerks DSP C Compiler
**     Date/Time : 2008-1-30, 下午 02:43
**     Abstract  :
**         This bean "AsynchroSerial" implements an asynchronous serial
**         communication. The bean supports different settings of
**         parity, word width, stop-bit and communication speed,
**         user can select interrupt or polling handler.
**         Communication speed can be changed also in runtime.
**         The bean requires one on-chip asynchronous serial channel.
**     Settings  :
**         Serial channel              : SCI
**
**         Protocol
**             Init baud rate          : 9600baud
**             Width                   : 8 bits
**             Stop bits               : 1
**             Parity                  : none
**             Breaks                  : Disabled
**
**         Registers
**             Input buffer            : SCI_SCIDR [61620]
**             Output buffer           : SCI_SCIDR [61620]
**             Control register        : SCI_SCICR [61617]
**             Mode register           : SCI_SCICR [61617]
**             Baud setting reg.       : SCI_SCIBR [61616]
**
**         Input interrupt
**             Vector name             : INT_SCI_RxFull
**             Priority                : 1
**
**         Output interrupt
**             Vector name             : INT_SCI_TxEmpty
**             Priority                : 1
**
**         Used pins:
**         ----------------------------------------------------------
**           Function | On package           |    Name
**         ----------------------------------------------------------
**         ----------------------------------------------------------
**
**
**
**     Contents  :
**         No public methods
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

/* MODULE SCIAS. */

#include "SCIAS.h"
#include "Events.h"


#define OVERRUN_ERR      1             /* Overrun error flag bit    */
#define FRAMING_ERR      2             /* Framing error flag bit    */
#define PARITY_ERR       4             /* Parity error flag bit     */
#define CHAR_IN_RX       8             /* Char is in RX buffer      */
#define FULL_TX          16            /* Full transmit buffer      */
#define RUNINT_FROM_TX   32            /* Interrupt is in progress  */
#define FULL_RX          64            /* Full receive buffer       */
#define NOISE_ERR        128           /* Noise erorr flag bit      */
#define IDLE_ERR         256           /* Idle character flag bit   */
#define BREAK_ERR        512           /* Break detect              */
#define COMMON_ERR       2048          /* Common error of RX       */

static word SerFlag;                   /* Flags for serial communication */
                                       /* Bits: 0 - OverRun error */
                                       /*       1 - Framing error */
                                       /*       2 - Parity error */
                                       /*       3 - Char in RX buffer */
                                       /*       4 - Full TX buffer */
                                       /*       5 - Running int from TX */
                                       /*       6 - Full RX buffer */
                                       /*       7 - Noise error */
                                       /*       8 - Idle character  */
                                       /*       9 - Break detected  */
                                       /*      10 - Unused */
                                       /*      11 - Unused */
static word InpLen;                    /* Length of input buffer's content */
static SCIAS_TComData *InpPtrR;        /* Pointer for reading from input buffer */
static SCIAS_TComData *InpPtrW;        /* Pointer for writing to input buffer */
static SCIAS_TComData InpBuffer[SCIAS_INP_BUF_SIZE]; /* Input buffer for SCI commmunication */
static word OutLen;                    /* Length of output bufer's content */
static SCIAS_TComData *OutPtrR;        /* Pointer for reading from output buffer */
static SCIAS_TComData *OutPtrW;        /* Pointer for writing to output buffer */
static SCIAS_TComData OutBuffer[SCIAS_OUT_BUF_SIZE]; /* Output buffer for SCI commmunication */

/*
** ===================================================================
**     Method      :  HWEnDi (bean AsynchroSerial)
**
**     Description :
**         Enables or disables the peripheral(s) associated with the bean.
**         The method is called automatically as a part of the Enable and 
**         Disable methods and several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void HWEnDi(void)
{
  getReg(SCI_SCISR);                   /* Reset interrupt request flags */
  setRegBits(SCI_SCICR, (SCI_SCICR_RFIE_MASK | SCI_SCICR_REIE_MASK)); /* Enable device */
}

/*
** ===================================================================
**     Method      :  SCIAS_InterruptRx (bean AsynchroSerial)
**
**     Description :
**         The method services the receive interrupt of the selected 
**         peripheral(s) and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#define ON_ERROR    1
#define ON_FULL_RX  2
#define ON_RX_CHAR  4
#pragma interrupt alignsp 
void SCIAS_InterruptRx(void)
{
  register SCIAS_TComData Data;        /* Temporary variable for data */
  register byte OnFlags = 0;           /* Temporary variable for flags */

  getReg(SCI_SCISR);                   /* Reset interrupt request flags */
  Data = (SCIAS_TComData)getReg(SCI_SCIDR); /* Read data from the receiver */
  if (InpLen < SCIAS_INP_BUF_SIZE) {   /* Is number of bytes in the receive buffer lower than size of buffer? */
    InpLen++;                          /* Increse number of chars in the receive buffer */
    *(InpPtrW++) = Data;               /* Save received char to the receive buffer */
    if (InpPtrW >= InpBuffer + SCIAS_INP_BUF_SIZE) { /* Is the pointer out of the receive buffer? */
      InpPtrW = InpBuffer;             /* Set pointer on the first item into the receive buffer */
    }
  }
  else {
    SerFlag |= FULL_RX;                /* If yes then set flag buffer overflow */
    OnFlags |= ON_ERROR;               /* Set flag "OnError" */
  }
  if (OnFlags & ON_ERROR) {            /* Was error flag detect? */
    SCIAS_OnError();                   /* If yes then invoke user event */
  }
}

/*
** ===================================================================
**     Method      :  SCIAS_InterruptTx (bean AsynchroSerial)
**
**     Description :
**         The method services the receive interrupt of the selected 
**         peripheral(s) and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#define ON_FREE_TX  1
#define ON_TX_CHAR  2
#pragma interrupt alignsp 
void SCIAS_InterruptTx(void)
{
  register byte OnFlags = 0;           /* Temporary variable for flags */

  SerFlag &= ~RUNINT_FROM_TX;          /* Reset flag "running int from TX" */
  if (OutLen) {                        /* Is number of bytes in the transmit buffer greater then 0? */
    OutLen--;                          /* Decrease number of chars in the transmit buffer */
    SerFlag |= RUNINT_FROM_TX;         /* Set flag "running int from TX"? */
    getReg(SCI_SCISR);                 /* Reset interrupt request flags */
    SCI_SCIDR = (SCIAS_TComData)*(OutPtrR++); /* Store char to transmitter register */
    if (OutPtrR >= (OutBuffer + SCIAS_OUT_BUF_SIZE)) { /* Is the pointer out of the transmit buffer? */
      OutPtrR = OutBuffer;             /* Set pointer on the first item into the transmit buffer */
    }
  }
  else {
    clrRegBit(SCI_SCICR, TEIE);        /* Disable transmit interrupt */
  }
}

/*
** ===================================================================
**     Method      :  SCIAS_InterruptError (bean AsynchroSerial)
**
**     Description :
**         The method services the receive interrupt of the selected 
**         peripheral(s) and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp 
void SCIAS_InterruptError(void)
{
  register word StatReg = getReg(SCI_SCISR); /* Read status register */

  setReg(SCI_SCISR, 0);                /* Reset error request flags */
  if(StatReg & (SCI_SCISR_OR_MASK|SCI_SCISR_NF_MASK|SCI_SCISR_FE_MASK|SCI_SCISR_PF_MASK)) { /* Is an error detected? */
    SerFlag |= COMMON_ERR;             /* If yes then set an internal flag */
  }
  if (SerFlag & COMMON_ERR) {          /* Was any error set? */
    SCIAS_OnError();                   /* If yes then invoke user event */
  }
}

/*
** ===================================================================
**     Method      :  SCIAS_Init (bean AsynchroSerial)
**
**     Description :
**         Initializes the associated peripheral(s) and internal 
**         variables of the bean. The method is called automatically as a 
**         part of the application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void SCIAS_Init(void)
{
  SerFlag = 0;                         /* Reset flags */
  /* SCI_SCICR: LOOP=0,SWAI=0,RSRC=0,M=0,WAKE=0,POL=0,PE=0,PT=0,TEIE=0,TIIE=0,RFIE=0,REIE=0,TE=0,RE=0,RWU=0,SBK=0 */
  setReg(SCI_SCICR, 0);                /* Set the SCI configuration */
  InpLen = 0;                          /* No char in the receive buffer */
  InpPtrW = InpPtrR = InpBuffer;       /* Set pointer on the first item in the receive buffer */
  OutLen = 0;                          /* No char in the transmit buffer */
  OutPtrW = OutPtrR = OutBuffer;       /* Set pointer on the first item in the transmit buffer */
  /* SCI_SCIBR: ??=0,??=0,??=0,SBR=208 */
  setReg(SCI_SCIBR, 208);              /* Set prescaler bits */
  HWEnDi();                            /* Enable/disable device according to status flags */
}


/* END SCIAS. */


/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.98 [03.79]
**     for the Freescale 56800 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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