📄 usb.c
字号:
return ERR_TXFULL; /* If yes then error */
EnterCritical(); /* Save the PS register */
SCI2S1; /* Reset interrupt request flag */
SCI2D = (byte)Chr; /* Store char to transmitter register */
SCI2C2_TIE = 1; /* Enable transmit interrupt */
SerFlag |= FULL_TX; /* Set the flag "full TX buffer" */
ExitCritical(); /* Restore the PS register */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : USB_GetCharsInRxBuf (bean AsynchroSerial)
**
** Description :
** Returns the number of characters in the input buffer.
** This method is available only if the receiver property is
** enabled.
** 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 :
** --- - The number of characters in the input
** buffer.
** ===================================================================
*/
word USB_GetCharsInRxBuf(void)
{
return (SerFlag & CHAR_IN_RX) != 0; /* Return number of chars in receive buffer */
}
/*
** ===================================================================
** Method : USB_GetCharsInTxBuf (bean AsynchroSerial)
**
** Description :
** Returns the number of characters in the output buffer.
** This method is available only if the transmitter property
** is enabled.
** DMA mode:
** If DMA controller is available on the selected CPU and
** the transmitter is configured to use DMA controller then
** this method returns the number of characters in the
** transmit buffer.
** Parameters : None
** Returns :
** --- - The number of characters in the output
** buffer.
** ===================================================================
*/
word USB_GetCharsInTxBuf(void)
{
return (SerFlag & FULL_TX) != 0; /* Return number of chars in the transmitter buffer */
}
/*
** ===================================================================
** Method : USB_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
#define ON_IDLE_CHAR 8
ISR(USB_InterruptRx)
{
USB_TComData Data; /* Temporary variable for data */
byte StatReg = getReg(SCI2S1);
byte OnFlags = 0; /* Temporary variable for flags */
PTAD |= 0x80;
Data = SCI2D; /* Read data from the receiver */
if(SerFlag & CHAR_IN_RX) { /* Is any char already present in the receive buffer? */
SerFlag |= OVERRUN_ERR; /* If yes then set flag OVERRUN_ERR */
}
if(!(SerFlag & OVERRUN_ERR )) { /* Is an overrun detected? */
BufferRead = Data;
SerFlag |= CHAR_IN_RX; /* Set flag "char in RX buffer" */
OnFlags |= ON_RX_CHAR; /* Set flag "OnRxChar" */
}
else
OnFlags |= ON_ERROR; /* Set flag "OnError" */
if(OnFlags & ON_ERROR) { /* Was error flag detect? */
USB_OnError(); /* If yes then invoke user event */
}
else {
if(OnFlags & ON_RX_CHAR) { /* Is OnRxChar flag set? */
USB_OnRxChar(); /* If yes then invoke user event */
}
}
}
/*
** ===================================================================
** Method : USB_InterruptTx (bean AsynchroSerial)
**
** Description :
** The method services the transmit 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
ISR(USB_InterruptTx)
{
byte OnFlags = 0; /* Temporary variable for flags */
if(SerFlag & FULL_TX) /* Is a char already present in the transmit buffer? */
OnFlags |= ON_TX_CHAR; /* Set flag "OnTxChar" */
SerFlag &= ~FULL_TX; /* Reset flag "full TX buffer" */
SCI2C2_TIE = 0; /* Disable transmit interrupt */
if(OnFlags & ON_TX_CHAR) { /* Is flag "OnTxChar" set? */
USB_OnTxChar(); /* If yes then invoke user event */
}
}
/*
** ===================================================================
** Method : USB_InterruptError (bean AsynchroSerial)
**
** Description :
** The method services the error 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.
** ===================================================================
*/
ISR(USB_InterruptError)
{
byte StatReg = getReg(SCI2S1);
if(StatReg & (SCI2S1_OR_MASK|SCI2S1_NF_MASK|SCI2S1_FE_MASK|SCI2S1_PF_MASK)) { /* Is an error detected? */
SerFlag |= COMMON_ERR; /* If yes then set an internal flag */
}
SCI2D; /* Dummy read of data register - clear error bits */
if(SerFlag & (COMMON_ERR)) { /* Was any error set? */
USB_OnError(); /* If yes then invoke user event */
}
}
/*
** ===================================================================
** Method : USB_Init (bean AsynchroSerial)
**
** 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 USB_Init(void)
{
SerFlag = 0; /* Reset flags */
/* SCI2C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
setReg8(SCI2C1, 0x00); /* Configure the SCI */
/* SCI2C3: R8=0,T8=0,TXDIR=0,??=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
setReg8(SCI2C3, 0x00); /* Disable error interrupts */
/* SCI2C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
setReg8(SCI2C2, 0x00); /* Disable all interrupts */
USB_SetHigh(); /* Initial speed CPU mode is high */
}
/*
** ===================================================================
** Method : USB_SetHigh (bean AsynchroSerial)
**
** 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 USB_SetHigh(void)
{
EnMode = TRUE; /* Set the flag "device enabled" in the actual speed CPU mode */
HWEnDi(); /* Enable/disable device according to status flags */
}
/*
** ===================================================================
** Method : USB_SetLow (bean AsynchroSerial)
**
** 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 USB_SetLow(void)
{
EnMode = FALSE; /* Set the flag "device disabled" in the actual speed CPU mode */
HWEnDi(); /* Enable/disable device according to status flags */
}
/* END USB. */
/*
** ###################################################################
**
** 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 + -