需要修改oalintr.h cfw.c armint.c 在里面添加相应的中断,复制uart0的就可以了。然后在ser2410_ser.c参考uart0建立其他两个串口的函数表。在 ser2410_hw.c里面修改S2410_SetSerialIOP以及SL_Init两个函数就可以了,具体就是根据iobase不同对串口寄存器 进行操作,完全可以参考uart0的就ok了,最后还得改注册表,也是参考uart0的,改一下中断号以及iobase就ok了。
const
HW_VTBL IoVTbl = {
SerInitSerial1,
SL_PostInit,
SerDeinit,
SerOpen,
SerClose,
SL_GetInterruptType,
SL_RxIntr,
SL_TxIntr,
SL_ModemIntr,
SL_LineIntr,
SL_GetRxBufferSize,
SerPowerOff,
SerPowerOn,
SL_ClearDTR,
SL_SetDTR,
SL_ClearRTS,
SL_SetRTS,
SerEnableSerial,
SerDisableSerial,
SL_ClearBreak,
SL_SetBreak,
SL_XmitComChar,
SL_GetStatus,
SL_Reset,
SL_GetModemStatus,
SerGetCommProperties,
SL_PurgeComm,
SL_SetDCB,
SL_SetCommTimeouts,
};
// COM2 函数表
const
HW_VTBL IoVTbl2 = {
SerInitSerial2,
SL_PostInit,
SerDeinit,
SerOpen,
SerClose,
SL_GetInterruptType,
SL_RxIntr,
SL_TxIntr,
SL_ModemIntr,
SL_LineIntr,
SL_GetRxBufferSize,
SerPowerOff,
SerPowerOn,
SL_ClearDTR,
SL_SetDTR,
SL_ClearRTS,
SL_SetRTS,
SerEnableSerial,
SerDisableSerial,
SL_ClearBreak,
SL_SetBreak,
SL_XmitComChar,
SL_GetStatus,
SL_Reset,
SL_GetModemStatus,
SerGetCommProperties,
SL_PurgeComm,
SL_SetDCB,
SL_SetCommTimeouts,
};
// COM3 函数表
const
HW_VTBL IoVTbl3 = {
SerInitSerial3,
SL_PostInit,
SerDeinit,
SerOpen,
SerClose,
SL_GetInterruptType,
SL_RxIntr,
SL_TxIntr,
SL_ModemIntr,
SL_LineIntr,
SL_GetRxBufferSize,
SerPowerOff,
SerPowerOn,
SL_ClearDTR,
SL_SetDTR,
SL_ClearRTS,
SL_SetRTS,
SerEnableSerial,
SerDisableSerial,
SL_ClearBreak,
SL_SetBreak,
SL_XmitComChar,
SL_GetStatus,
SL_Reset,
SL_GetModemStatus,
SerGetCommProperties,
SL_PurgeComm,
SL_SetDCB,
SL_SetCommTimeouts,
};
onst HWOBJ IoObj1 = {
THREAD_AT_INIT,
SYSINTR_SERIAL,
(PHW_VTBL) &IoVTbl
};
const HWOBJ IoObj2 = {
THREAD_AT_INIT,
SYSINTR_SERIAL2,
(PHW_VTBL) &IoVTbl2
};
const HWOBJ IoObj3 = {
THREAD_AT_INIT,
SYSINTR_SERIAL3,
(PHW_VTBL) &IoVTbl3
};
const PCHWOBJ HWObjects[] = {
&IoObj1,
/* &IrObj */
&IoObj2,
&IoObj3
};
PHWOBJ
GetSerialObject(
DWORD DeviceArrayIndex
)
{
PHWOBJ pSerObj;
RETAILMSG(DEBUGMODE,(TEXT("\n------------>GetSerialObject : DeviceArrayIndex = %d\r\n"), DeviceArrayIndex));
// Now return this structure to the MDD.
if ( DeviceArrayIndex == 0 )
/* pSerObj = (PHWOBJ)(&IrObj);
else
*/ pSerObj = (PHWOBJ)(&IoObj1);
else if ( DeviceArrayIndex == 1 )
pSerObj = (PHWOBJ)(&IoObj2);
else if ( DeviceArrayIndex == 2 )
pSerObj = (PHWOBJ)(&IoObj3);
else
RETAILMSG(DEBUGMODE,(TEXT("\nGetSerialObject : ERROR! no this serial port ---> DeviceArrayIndex = %d\r\n"), DeviceArrayIndex));
return (pSerObj);
}
ser2410_hw.c修改
else if ( pHWHead1->dwIOBase == 0x50008000)
{
#if USEVIRTUAL
EnterCriticalSection(&(pHWHead->RegCritSec));
v_pIOPregs->rGPHCON &= ~(0x3<<0 | 0x3<<2 | 0x3<<12 | 0x3<<14); // clear uart 2 - rx, tx
v_pIOPregs->rGPHCON |= (0x2<<0 | 0x2<<2 | 0x2<<12 | 0x2<<14);
v_pIOPregs->rGPHUP |= 0xc0;
// 设置控制RS485的IO口为输出模式
/* v_pIOPregs->rGPDCON &= ~(0x3<<6 | 0x3<<14);
v_pIOPregs->rGPDCON |= (0x1<<6 | 0x1<<14);
v_pIOPregs->rGPDUP |= 0x88;*/
// MAX485控制信号初始化为接收模式:PDD3---RE = 0, PDD7---DE = 0
// v_pIOPregs->rGPDDAT &= ~(0x1<<3 | 0x1<<7);
#else
volatile IOPreg *s2410IOP;
s2410IOP = (volatile IOPreg *)IOP_BASE;
EnterCriticalSection(&(pHWHead->RegCritSec));
s2410IOP->rGPHCON &= ~(0x3<<0 | 0x3<<2 | 0x3<<12 | 0x3<<14); // clear uart 2 - rx, tx
s2410IOP->rGPHCON |= (0x2<<0 | 0x2<<2 | 0x2<<12 | 0x2<<14);
s2410IOP->rGPHUP |= 0xc0;
// 设置控制RS485的IO口为输出模式
/* c->rGPDCON &= ~(0x3<<6 | 0x3<<14);
s2410IOP->rGPDCON |= (0x1<<6 | 0x1<<14);
s2410IOP->rGPDUP |= 0x88;
*/
// MAX485控制信号初始化为接收模式:PDD3---RE = 0, PDD7---DE = 0
// s2410IOP->rGPDDAT &= ~(0x1<<3 | 0x1<<7);
#endif
LeaveCriticalSection(&(pHWHead->RegCritSec));
}