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

📄 mc13191.c

📁 FreeRTOS-3.2.4-HCS08 Files
💻 C
📖 第 1 页 / 共 2 页
字号:
** ===================================================================
**     Method      :  MC13191_CharsInRxBuf (bean SynchroMaster)
**
**     Description :
**         Returns the number of characters in the input buffer.
**         Note: If the Interrupt service is disabled, and the
**         Ignore empty character is set to yes, and a character has
**         been received, then this method returns 1 although it was
**         an empty character.
**         (deprecated method)
**         DMA mode:
**         If DMA controller is available on the selected CPU and
**         the receiver is configured to use DMA controller then
**         this method returns the number of characters in the
**         receive buffer.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Chr             - A pointer to number of characters in
**                           the input buffer
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte MC13191_CharsInRxBuf(word *Chr)
{
  if (!EnMode)                         /* Is the device disabled in the actual speed CPU mode? */
    return ERR_SPEED;                  /* If yes then error */
  *Chr = SPI1S_SPRF;                   /* Return number of chars in receive buffer */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  MC13191_GetCharsInRxBuf (bean SynchroMaster)
**
**     Description :
**         Returns the number of characters in the input buffer.
**         Note: If the Interrupt service is disabled, and the
**         Ignore empty character is set to yes, and a character has
**         been received, then this method returns 1 although it was
**         an empty character.
**         DMA mode:
**         If DMA controller is available on the selected CPU and
**         the receiver is configured to use DMA controller then
**         this method returns the number of characters in the
**         receive buffer.
**     Parameters  : None
**     Returns     :
**         ---             - Number of characters in the input
**                           buffer.
** ===================================================================
*/
/*
word MC13191_GetCharsInRxBuf(void)

**      This method is implemented as a macro. See header module. **
*/

/*
** ===================================================================
**     Method      :  MC13191_SetShiftClockPolarity (bean SynchroMaster)
**
**     Description :
**         Sets the shift clock polarity at runtime. Output data
**         will be shifted on the selected edge polarity.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Edge            - Edge polarity.
**                           0-falling edge
**                           1-rising edge
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
**                           ERR_RANGE - Parameter out of range
** ===================================================================
*/
byte MC13191_SetShiftClockPolarity(byte Edge)
{
  if(!EnMode)
    return ERR_SPEED;
  if(Edge > 1)
    return ERR_RANGE;
  EnUser=FALSE;
  HWEnDi();                            /* Disable device */
  SPI1C1_CPHA = SPI1C1_CPOL ^ Edge;    /* Set phase bit */
  EnUser=TRUE;
  HWEnDi();                            /* Enable device */
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  MC13191_SetIdleClockPolarity (bean SynchroMaster)
**
**     Description :
**         Sets the idle clock polarity at runtime. If the
**         communication does not run, the clock signal will have
**         required level.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Level           - Idle clock polarity:
**                           0-low
**                           1-high
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
**                           ERR_RANGE - Parameter out of range
** ===================================================================
*/
byte MC13191_SetIdleClockPolarity(byte Level)
{
  if(!EnMode)
    return ERR_SPEED;
  if(Level > 1)
    return ERR_RANGE;
  if(SPI1C1_CPOL != Level) {
    PTED_PTED5 = Level;                /* Define level on clk pin when device is disabled */
    EnUser=FALSE;
    HWEnDi();                          /* Disable device */
    SPI1C1 ^= 0x0C;                    /* Invert polarity and phase bit */
    EnUser=TRUE;
    HWEnDi();                          /* Enable device */
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  MC13191_Init (bean SynchroMaster)
**
**     Description :
**         Initializes the associated peripheral(s) and the bean's 
**         internal variables. 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 MC13191_Init(void)
{
  SerFlag = 0;                         /* Reset all flags */
  EnUser = TRUE;                       /* Enable device */
  #pragma MESSAGE DISABLE C4002        /* Disable warning C4002 "Result not used" */
  SPI1S;                               /* Read the status register */
  SPI1D;                               /* Read the device register */
  /* SPI1BR: ??=0,SPPR2=0,SPPR1=0,SPPR0=0,??=0,SPR2=0,SPR1=0,SPR0=0 */
  setReg8(SPI1BR, 0x00);               /* Set the baud rate register */ 
  /* SPI1C2: ??=0,??=0,??=0,MODFEN=0,BIDIROE=0,??=0,SPISWAI=0,SPC0=0 */
  setReg8(SPI1C2, 0x00);               /* Configure the SPI port - control register 2 */ 
  /* SPI1C1: SPIE=0,SPE=0,SPTIE=0,MSTR=1,CPOL=0,CPHA=1,SSOE=0,LSBFE=0 */
  setReg8(SPI1C1, 0x14);               /* Configure the SPI port - control register 1 */ 
  MC13191_SetHigh();                   /* Initial speed CPU mode is high */
}

/*
** ===================================================================
**     Method      :  MC13191_SetHigh (bean SynchroMaster)
**
**     Description :
**         The method reconfigures the bean and its selected peripheral(s)
**         when the CPU is switched to the High speed mode. The method is 
**         called automatically as s part of the CPU SetHighSpeed method.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void MC13191_SetHigh(void)
{
  EnMode = TRUE;                       /* Set the flag "device enabled" in the actual speed CPU mode */
  HWEnDi();                            /* Enable/disable device according to the status flags */
}

/*
** ===================================================================
**     Method      :  MC13191_SetLow (bean SynchroMaster)
**
**     Description :
**         The method reconfigures the bean and its selected peripheral(s)
**         when the CPU is switched to the Low speed mode. The method is 
**         called automatically as a part of the CPU SetLowSpeed method.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void MC13191_SetLow(void)
{
  EnMode = FALSE;                      /* Set the flag "device disabled" in the actual speed CPU mode */
  HWEnDi();                            /* Enable/disable device according to the status flags */
}


/* END MC13191. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.97 [03.74]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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