📄 inhr1.c
字号:
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_TXFULL - Transmitter is full
** ===================================================================
*/
byte Inhr1_SendChar(Inhr1_TComData Chr)
{
if (SerFlag & FULL_TX) /* Is any char is in TX buffer */
return ERR_TXFULL; /* If yes then error */
EnterCritical(); /* Disable global interrupts */
getReg(SCI0_SCISR); /* Reset interrupt request flags */
setReg(SCI0_SCIDR, Chr); /* Store char to transmitter register */
setRegBit(SCI0_SCICR, TEIE); /* Enable transmit interrupt */
SerFlag |= FULL_TX; /* Set the flag "full TX buffer" */
ExitCritical(); /* Enable global interrupts */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : Inhr1_GetError (bean AsynchroSerial)
**
** Description :
** Returns a set of errors on the channel (errors that
** cannot be returned by given methods). The errors
** accumulate in a set; after calling [GetError] this set is
** returned and cleared.
** Parameters :
** NAME - DESCRIPTION
** * Err - Pointer to the returned set of errors
** Returns :
** --- - Error code (if GetError did not succeed),
** possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ===================================================================
*/
byte Inhr1_GetError(Inhr1_TError *Err)
{
EnterCritical(); /* Disable global interrupts */
Err->err = 0;
Err->errName.OverRun = ((ErrFlag & OVERRUN_ERR) != 0); /* Overrun error */
Err->errName.Framing = ((ErrFlag & FRAMING_ERR ) != 0); /* Framing error */
Err->errName.Parity = ((ErrFlag & PARITY_ERR) != 0); /* Parity error */
Err->errName.Noise = ((ErrFlag & NOISE_ERR) != 0); /* Noise error */
ErrFlag = 0; /* Clear error flags */
ExitCritical(); /* Enable global interrupts */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : Inhr1_InterruptRx (bean AsynchroSerial)
**
** Description :
** The method services the interrupt of the selected peripheral(s)
** and eventually invokes the beans 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 saveall
void Inhr1_InterruptRx(void)
{
register Inhr1_TComData Data; /* Temporary variable for data */
register byte OnFlags = 0; /* Temporary variable for flags */
getReg(SCI0_SCISR); /* Reset interrupt request flags */
Data = (Inhr1_TComData)getReg(SCI0_SCIDR); /* 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 */
SerFlag |= CHAR_IN_RX; /* Set flag "char in RX buffer" */
if (!(SerFlag & OVERRUN_ERR )) { /* Is an overrun detected? */
BufferRead = Data;
OnFlags |= ON_RX_CHAR; /* Set flag "OnRxChar" */
}
else
OnFlags |= ON_ERROR; /* Set flag "OnError" */
ErrFlag |= SerFlag; /* Add new error flags into the ErrorFlag status variable */
if (OnFlags & ON_ERROR) { /* Was error flag detect? */
__EI(3); /* Enable interrupts of the selected priority level */
Inhr1_OnError(); /* If yes then invoke user event */
}
else {
if (OnFlags & ON_RX_CHAR) { /* Is OnRxChar flag set? */
__EI(3); /* Enable interrupts of the selected priority level */
Inhr1_OnRxChar(); /* If yes then invoke user event */
}
}
}
/*
** ===================================================================
** Method : Inhr1_InterruptTx (bean AsynchroSerial)
**
** Description :
** The method services the interrupt of the selected peripheral(s)
** and eventually invokes the beans 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 saveall
void Inhr1_InterruptTx(void)
{
register byte OnFlags = 0; /* Temporary variable for flags */
if (SerFlag & FULL_TX) /* Is any char already present in the transmit buffer? */
OnFlags |= ON_TX_CHAR; /* Set flag "OnTxChar" */
SerFlag &= ~FULL_TX; /* Reset flag "full TX buffer" */
clrRegBit(SCI0_SCICR, TEIE); /* Disable transmit interrupt */
ErrFlag |= SerFlag; /* Add new error flags into the ErrorFlag status variable */
if (OnFlags & ON_TX_CHAR) { /* Is flag "OnTxChar" set? */
__EI(3); /* Enable interrupts of the selected priority level */
Inhr1_OnTxChar(); /* If yes then invoke user event */
}
}
/*
** ===================================================================
** Method : Inhr1_InterruptError (bean AsynchroSerial)
**
** Description :
** The method services the interrupt of the selected peripheral(s)
** and eventually invokes the beans event(s).
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp saveall
void Inhr1_InterruptError(void)
{
register word StatReg = getReg(SCI0_SCISR); /* Read status register */
register word OnFlags = 0; /* Temporary variable for flags */
setReg(SCI0_SCISR, 0); /* Reset error request flags */
if (StatReg & SCI0_SCISR_OR_MASK) /* Is overrun error flag set? */
OnFlags |= OVERRUN_ERR; /* If yes then set the flag */
if (StatReg & SCI0_SCISR_NF_MASK) /* Is noise error flag set? */
OnFlags |= NOISE_ERR; /* If yes then set the flag */
if (StatReg & SCI0_SCISR_FE_MASK) /* Is framing error flag set? */
OnFlags |= FRAMING_ERR; /* If yes then set the flag */
if (StatReg & SCI0_SCISR_PF_MASK) /* Is parity error flag set? */
OnFlags |= PARITY_ERR; /* If yes then set the flag */
SerFlag |= OnFlags; /* Copy flags status to SerFlag status variable */
ErrFlag |= OnFlags; /* Copy flags status to ErrFlag status variable */
if (SerFlag & (OVERRUN_ERR|FRAMING_ERR|PARITY_ERR|NOISE_ERR)) { /* Was any error set? */
__EI(3); /* Enable interrupts of the selected priority level */
Inhr1_OnError(); /* If yes then invoke user event */
}
}
/*
** ===================================================================
** Method : Inhr1_Init (bean AsynchroSerial)
**
** Description :
** Initializes the associated peripheral(s) and the beans
** 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 Inhr1_Init(void)
{
SerFlag = 0; /* Reset flags */
/* SCI0_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(SCI0_SCICR, 0); /* Set the SCI configuration */
setReg(SCI0_SCIBR, 391); /* Set prescaler bits */
HWEnDi(); /* Enable/disable device according to status flags */
}
/* END Inhr1. */
/*
** ###################################################################
**
** This file was created by UNIS Processor Expert 2.97 [03.74]
** for the Freescale 56800 series of microcontrollers.
**
** ###################################################################
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -