📄 scc2modem.c
字号:
int bufLen=0;
if (!(pChan->uart.pSccReg->scce & SCCE_RX))
return (EAGAIN);
pChan->uart.pSccReg->scce|=SCCE_RX;
while(!(pChan->uart.rxBdBase[activeRxBd].statusMode & BD_RX_EMPTY_BIT))
{
tempLen=pChan->uart.rxBdBase[activeRxBd].dataLength;
for(j=0;j<bufLen;i++,j++)
{
buffer[i]=pChan->uart.rxBdBase[activeRxBd].dataPointer[j];
}
/*load this buffer*/
pChan->uart.rxBdBase[activeRxBd].statusMode |=BD_RX_EMPTY_BIT;
/*set this buffer empty*/
bufLen=bufLen+tempLen;
/*count the buffer length*/
pChan->uart.pSccReg->scce|=SCCE_RX;
activeRxBd=(activeRxBd+1)%(pChan->uart.rxBdNum);
/*point to next BD*/
}
return(bufLen);
}
/*
读取SCC2口数据
参数:PPC860SCC2MODEM_CHAN *pChan,这个设备的数据结构
char *buffer,读取数据的指针
int bufferLen,读取数据的长度
返回值:1、EAGIAN, 无数据或读取失败
2、OK,读取成功
*/
int scc2ModemRead
(
PPC860SCC2MODEM_CHAN *pChan,
char *buffer,
int maxBufLen
)
{
int bufLen;
bufLen=rngBufGet(pChan->scc2RingId,buffer,maxBufLen);
return(bufLen);
}
/*
SCC2中断服务程序,检查所有的接收缓冲区,取走所有的数据,然后将收到的数据发送到消息队列中
参数:PPC860SCC2MODEM_CHAN *pChan,这个设备的数据结构
返回值:无
*/
void scc2ModemInterrupt
(
PPC860SCC2MODEM_CHAN *pChan
)
{
char buffer[2*SCC2MODEM_RXBDNUM*SCC2MODEM_RXBUFFER];
int bufferLen;
if((bufferLen=scc2Read(pChan,buffer))!=0)
rngBufPut(pChan->scc2RingId,buffer,bufferLen);
pChan->uart.pSccReg->scce = (pChan->uart.pSccReg->scce&~(SCCE_RX|SCCE_TX));
*CISR(pChan->regBase)|=CISR_SCC2;
/*中断服务程序结束*/
}
/*
通道控制函数,用来改变通道的工作参数
参数:PPC860SCC2MODEM_CHAN *pChan,这个设备的数据结构
int request,包括:
1、SIO_BAUD_SET,设置波特率,arg代表波特率的数值,从50到115200
2、SIO_BAUD_GET,获取当前通道的波特率值,arg代表当前通道波特率的数值
3、SIO_MODE_SET,通道模式设置,arg参数有两种,SIO_MODE_POLL为轮询
方式,SIO_MODE_INT为中断方式
4、SIO_MODE_GET,获取当前通道的工作模式,arg代表当前的工作模式
5、SIO_AVAIL_MODES_GET,获取当前可供选择的通道工作模式,arg代表获取的
所有工作模式
int arg,根据不同的request的值,有不同的含义
返回值:错误代码
*/
STATUS scc2ModemIoctl
(
PPC860SCC2MODEM_CHAN *pChan,
int request,
int arg
)
{
int baudRate;
int oldlevel;
STATUS status = OK;
switch (request)
{
case SIO_BAUD_SET:
if (arg >= 50 && arg <= 115200)
{
/* calculate proper counter value, then enable BRG */
baudRate = (pChan->clockRate + (8 * arg)) / (16 * arg);
if (--baudRate > 0xfff)
*pChan->pBaud = (BRGC_CD_MSK &
(((baudRate + 8) / 16) << BRGC_CD_SHIFT)) | BRGC_EN |
BRGC_DIV16;
else
*pChan->pBaud = (BRGC_CD_MSK &
(baudRate << 1)) | BRGC_EN;
pChan->baudRate = arg;
}
else
status = EIO;
break;
case SIO_BAUD_GET:
* (int *) arg = pChan->baudRate;
break;
case SIO_MODE_SET:
if (!((int) arg == SIO_MODE_POLL || (int) arg == SIO_MODE_INT))
{
status = EIO;
break;
}
/* lock interrupt */
oldlevel = intLock();
/* initialize channel on first MODE_SET */
if (!pChan->channelMode)
scc2ModemResetChannel(pChan);
/*
* if switching from POLL to INT mode, wait for all characters to
* clear the output pins
*/
if ((pChan->channelMode == SIO_MODE_POLL) && (arg == SIO_MODE_INT))
{
int i;
for (i=0; i < pChan->uart.txBdNum; i++)
while (pChan->uart.txBdBase
[(pChan->uart.txBdNext + i) % pChan->uart.txBdNum].
statusMode & BD_TX_READY_BIT);
}
if (arg == SIO_MODE_INT)
{
* CISR(pChan->regBase) |= CISR_SCC2;
* CIMR(pChan->regBase) |= CISR_SCC2;
pChan->uart.pSccReg->scce = SCCE_RX;
/* reset the receiver status bit */
pChan->uart.pSccReg->sccm =0x0001;
/* enables receive interrupts */
}
else
{
pChan->uart.pSccReg->sccm = 0;
/* mask off the receive and transmit intrs */
* CIMR(pChan->regBase) &= (~ CISR_SCC2);
/* mask off this SMC's interrupt */
}
pChan->channelMode = arg;
intUnlock(oldlevel);
break;
case SIO_MODE_GET:
* (int *) arg = pChan->channelMode;
break;
case SIO_AVAIL_MODES_GET:
*(int *)arg = SIO_MODE_INT | SIO_MODE_POLL;
break;
default:
status = ENOSYS;
}
return (status);
}
/*
scc2 uart 设备安装,主要调用iosDrvInstall()完成
参数:无
返回值:无
*/
STATUS scc2ModemDrv( void )
{
/* check if driver already installed */
if (scc2ModemDrvNum > 0)
return (OK);
scc2ModemDrvNum=iosDrvInstall (scc2ModemOpen, (FUNCPTR) NULL,
scc2ModemOpen,(FUNCPTR) NULL,
scc2ModemRead, scc2ModemWrite, scc2ModemIoctl);
return (scc2ModemDrvNum == ERROR ? ERROR : OK);
}
/*
scc2 uart 设备安装
参数:PPC860SCC2MODEM_CHAN *pChan,这个设备的数据结构
char * name,设备的名称
FAST int channel,设备的物理通道号,只有一个,只能为1
返回值:错误,没安装成功
正确
*/
STATUS scc2ModemDevCreate
(
PPC860SCC2MODEM_CHAN *pChan,
char * name, /* name to use for this device */
FAST int channel /* physical channel for this device */
)
{
if (scc2ModemDrvNum <= 0)
{
return (ERROR);
}
/* if this doesn't represent a valid channel, don't do it */
if(channel < 0)
return (ERROR);
/* if this device already exists, don't create it */
if (pChan->creatFlag)
return (ERROR);
pChan->uart.pSccReg->gsmrl|=SCC_GSMRL_ENT|SCC_GSMRL_ENR;
/*enable transmitter
enable receiver
uart should be enabled after the driver is installed*/
/* mark the device as created, and add the device to the I/O system */
pChan->creatFlag = TRUE;
return (iosDevAdd (pChan->devHdr, name, scc2ModemDrvNum));
/*scc2 uart driver is finished installing*/
/*writen by d.c.peng,8.5,2001*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -