📄 cominfsci3_2.cpp
字号:
/***********************************************************************/
/* */
/* FILE :ComInfSCI3_2.cpp */
/* DATE :Thu, Nov 18, 2004 */
/* DESCRIPTION :Implementation of the Communication Interface Class */
/* for SCI32 */
/* CPU TYPE :H8/38076 */
/* */
/***********************************************************************/
#include "common.h"
#include "ComInfSCI3_2.h"
#include "iodefine.h"
#include "extern_variable.h"
#include <machine.h>
CComInfSCI3_2::CComInfSCI3_2()
{
}
CComInfSCI3_2::~CComInfSCI3_2()
{
}
void CComInfSCI3_2::initChild (unsigned char bitRate, unsigned char byteSize, unsigned char parity, unsigned char stopBits, unsigned char clock, unsigned char isInvert)
{ SCI3_2.SCR3.BYTE = 0x00; //Serial Control Register is set to 0.
unsigned char smrValue = 0;
if (byteSize != 8)
smrValue |= 0x40;
parity <<= 4;
smrValue |= parity;
if (stopBits)
smrValue |= 0x08;
smrValue |= clock;
SCI3_2.SMR3.BYTE = smrValue; //Serial Mode Register.
SCI3_2.BRR3 = bitRate; //Bit Rate Register.
nop();
SCI3_2.SPCR.BIT.SPC32 = TRUE; //Serial Port Control Register.
if (Neutral_Fail)
//if (0)
{
// SCI3_2.SPCR.BIT.SCINV3 = TRUE;
// SCI3_2.SPCR.BIT.SCINV2 = FALSE;
}
else
{
// SCI3_2.SPCR.BIT.SCINV3 = FALSE;
// SCI3_2.SPCR.BIT.SCINV2 = FALSE;
}
// IO.PDR9.BIT.B0=~Neutral_Fail; // no use of this pin bhaskar
/*if (isInvert)
{
SCI3_2.SPCR.BIT.SCINV3 = TRUE;
SCI3_2.SPCR.BIT.SCINV2 = TRUE;
}
else
{
SCI3_2.SPCR.BIT.SCINV3 = FALSE;
SCI3_2.SPCR.BIT.SCINV2 = FALSE;
}*/
INTC.IPRD.BIT._SCI3_2 = TRUE;
SCI3_2.SCR3.BIT.TE = TRUE;
SCI3_2.SSR3.BIT.RDRF = FALSE;
SCI3_2.SSR3.BIT.OER = FALSE;
SCI3_2.SSR3.BIT.FER = FALSE;
SCI3_2.SSR3.BIT.PER = FALSE;
}
void CComInfSCI3_2::receiveEnable()
{ OPTICAL_RIE = TRUE;
OPTICAL_RE = TRUE;
}
void CComInfSCI3_2::receiveDisable()
{ OPTICAL_RIE = FALSE;
OPTICAL_RE = FALSE;
}
void CComInfSCI3_2::init(unsigned char bitRate, unsigned char byteSize, unsigned char parity, unsigned char stopBits, unsigned char clock, unsigned char isInvert, unsigned char *txBufferPtr, unsigned char *rxBufferPtr)
{
rxEnable = FALSE;
txRequest = FALSE;
dataReceived = FALSE;
txDataCount = NULL;
rxDataCount = NULL;
txDataPointer = txBufferPtr;
rxDataPointer = rxBufferPtr;
initChild(bitRate, byteSize, parity, stopBits, clock, isInvert);
}
void CComInfSCI3_2::requestProc(unsigned char command)
{ switch (command)
{ case RX_ENABLE:
rxEnable = TRUE;
receiveEnable();
break;
case RX_DISABLE:
rxEnable = FALSE;
receiveDisable();
break;
}
dataReceived = FALSE;
rxDataCount = NULL;
rxDataPointer = txRxBuffer;
}
void CComInfSCI3_2::transmitData()
{
// if(Transmit_Flag)
// {
// SCI3_2.SPCR.BIT.SCINV3 = FALSE;
// SCI3_2.SPCR.BIT.SCINV2 = FALSE;
// for (temp_int=0;temp_int<0xff;temp_int++) nop(); // delay
// }
if (OPTICAL_TDRE)
{ OPTICAL_TDR = *txDataPointer;
txDataPointer++;
txDataCount--;
if (txDataCount == NULL)
txRequest = FALSE;
}
}
void CComInfSCI3_2::receiveData()
{ if ((OPTICAL_RDRF || OPTICAL_FER) && (!OPTICAL_OER) && (!OPTICAL_PER))
{ *rxDataPointer = OPTICAL_RDR;
rxDataPointer++;
rxDataCount++;
dataReceived = TRUE;
if ((rxDataPointer < txRxBuffer) || (rxDataPointer > (txRxBuffer + 128)) || (rxDataCount > 128))
{ rxDataPointer = txRxBuffer;
rxDataCount = NULL;
dataReceived = FALSE;
}
}
OPTICAL_RDRF = FALSE;
OPTICAL_OER = FALSE;
OPTICAL_FER = FALSE;
OPTICAL_PER = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -