📄 tms320vc5416与tlc16c554的接口函数.c
字号:
TMS320VC5416与TLC16C554的接口函数
#include "N1S16DSP.H"
//////////////////////
// 串口访问参数设置 //
//////////////////////
//////////////////////////////
// 串口信息的流向设计思想 //
//////////////////////////////
// 1、临时发送和接收缓冲、实际发送和接收缓冲均为缓冲缓冲;
//
// 2、串口接收的信息,首先存放到临时接收缓冲*uiLowComRxd中,当接收的实际字节数uiComTempRecvBytePtr大于等于
// 2*cnComTmpRecvBufWordSize时,将*uiLowComRxd的数据转存到扩展RAM中的uiExtComRxd;然后根据转发到网络
// 的需要转移到低端RAM中的uTxdNet,即组织网络报文;当扩展RAM中没有数据时,也可以从uiLowComRxd中直接
// 组织网络报文,具体如下:
//
// 中断 当接收的字节数大于等于临时缓冲的大小时, 发送时
// COM ------> 临时接收缓冲*uiLowComRxd -----------------------------------------> 扩展RAM中的uiExtComRxd --------> 低端RAM的uTxdNet
// 查询 | 每次转移cnComTmpRecvBufWordSize个字 |
// | |
// ------------------------------------扩展RAM中没有数据或数据不足时--------------------->>-
//
// 3、网络接收的信息,即串口将要发送的信息,首先存放到临时发送缓冲*uiLowComTxd中,多余的数据存放到扩展RAM
// 中的uiExtComTxd,然后根据发送情况转移到临时发送缓冲*uiLowComTxd中,以便发送到串口;具体如下:
//
// 中断 发送时
// 网络 ------> 低端RAM的uRxdNet --> 扩展RAM中的uiExtComTxd --------> 临时发送缓冲*uiLowComTxd
// 查询 | |
// | |
// -----------临时发送缓冲为空时----------->>-
//
UINT uiComTempRecvBytePtr[cnMaxComThisType]; // 串口临时接收字节指针(以字节为单位),单向缓冲,满时转入扩展RAM
UINT uiComTempRecvByteUse[cnMaxComThisType]; // 串口临时接收使用字节指针(以字节为单位),单向缓冲,满时转入扩展RAM
UINT uiComTempSendBytePtr[cnMaxComThisType]; // 串口临时发送字节指针(以字节为单位),单向缓冲,空时由扩展RAM转入
UINT uiComTempSendByteUse[cnMaxComThisType]; // 串口临时发送使用字节指针(以字节为单位),单向缓冲,空时由扩展RAM转入
UINT uiComRealRecvWordPtr[cnMaxComThisType]; // 串口实际接收字节指针(以字为单位),环形缓冲
UINT uiComRealRecvWordUse[cnMaxComThisType]; // 串口实际接收使用字节指针(以字为单位),环形缓冲
UINT uiComRealSendWordPtr[cnMaxComThisType]; // 串口实际发送字节指针(以字为单位),环形缓冲
UINT uiComRealSendWordUse[cnMaxComThisType]; // 串口实际发送使用字节指针(以字为单位),环形缓冲
// 网络数据的按帧接收,或帧数据流的识别:
// =====================================
// 串口发向网络的条件具体为:
// ⑴ 待发送的字节数满足一个以太网帧最大字节数时;
// ⑵ 未满足以太网帧最大字节数,串口接收空闲时间超过10倍单字节发送时间(由波特率折算);
UINT uiM10Sec10CharsTime[cnMaxComThisType]; // 按波特率计算,接收(发送)一个字节所需要的时间(以10ms为单位)
UINT uiM10SecCountCharDelay[cnMaxComThisType]; // 该串口自接收完上一个字节到现在的时间间隔
UINT *uiLowComRxd[cnMaxComThisType]; // 串口临时接收缓冲区指针
UINT *uiLowComTxd[cnMaxComThisType]; // 串口临时发送缓冲区指针
//////////////////////////////////////////////////////////////////////////////////////
// Three types of information are stored in the internal registers used in the ACE:
// control, status, and data. Mnemonic abbreviations for the registers are shown in
// Table 1. Table 2 defines the address location of each register and whether it is
// read only, write only, or read writable.
//
// Table 1. Internal Register Mnemonic Abbreviations
// ================================================================================================================
// CONTROL MNEMONIC | STATUS MNEMONIC | DATA MNEMONIC
// ------------------------- -------- | --------------------- -------- | ---------------------------- --------
// Line control register LCR | Line status register LSR | Receiver buffer register RBR
// FIFO control register FCR | Modem status register MSR | Transmitter holding register THR
// Modem control register MCR | |
// Divisor latch LSB DLL | |
// Divisor latch MSB DLM | |
// Interrupt enable register IER | |
// -----------------------------------------------------------------------------------------------------------------
//
// Table 2. Register Selection
// ===========================
// DLAB A2 A1 A0 READ MODE WRITE MODE
// ---- -- -- -- ------------------------ ----------------------------
// 0 0 0 0 Receiver buffer register Transmitter holding register
// 0 0 0 1 Interrupt enable register
// X 0 1 0 Interrupt identification register FIFO control register
// X 0 1 1 Line control register
// X 1 0 0 Modem control register
// X 1 0 1 Line status register
// X 1 1 0 Modem status register
// X 1 1 1 Scratchpad register Scratchpad register
// 1 0 0 0 LSB divisor latch
// 1 0 0 1 MSB divisor latch
// ------------------------------------------------------------------------
// X = irrelevant, 0 = low level, 1 = high level
// The serial channel is accessed when either /CSA or /CSD is low.
// DLAB is the divisor latch access bit and bit 7 in the LCR.
// A2-A0 are device terminals.
//
// Individual bits within the registers are referred to by the register mnemonic
// and the bit number in parentheses. For example, LCR7 refers to line control
// register bit 7. The transmitter buffer register and receiver buffer register
// are data registers that hold from five to eight bits of data. If less than eight
// data bits are transmitted, data is right justified to the LSB. Bit 0 of a data
// word is always the first serial data bit received and transmitted. The ACE data
// registers are double buffered (TL16450 mode) or FIFO buffered (FIFO mode) so
// that read and write operations can be performed when the ACE is performing the
// parallel-to-serial or serial-to-parallel conversion.
//
// The scratch register is an 8-bit read/write register that has no affect on either
// channel in the ACE. It is intended to be used by the programmer to hold data
// temporarily.
//
// /RXRDY operation 选择 mode 1
// ================
// In mode 0, /RXRDY is asserted (low) when the receive FIFO is not empty; it is
// released (high) when the FIFO is empty. In this way, the receiver FIFO is read
// when /RXRDY is asserted (low).
// In mode 1, /RXRDY is asserted (low) when the receive FIFO has filled to the
// trigger level or a character time-out has occurred (four character times with
// no transmission of characters); it is released (high) when the FIFO is empty. In
// this mode, multiple received characters are read by the DMA device, reducing the
// number of times it is interrupted.
// /RXRDY and /TXRDY outputs from each of the four internal ACEs of the TL16C554 are
// ANDed together internally. This combined signal is brought out externally to
// /RXRDY and /TXRDY. Following the removal of the reset condition (RESET low), the
// ACE remains in the idle mode until programmed.
// A hardware reset of the ACE sets the THRE and TEMT status bits in the LSR. When
// interrupts are subsequently enabled, an interrupt occurs due to THRE. A summary
// of the effect of a reset on the ACE is given in Table 12.
//
// /TXRDY operation 选择 mode 1
// ================
// In mode 0, /TXRDY is asserted (low) when the transmit FIFO is empty; it is released
// (high) when the FIFO contains at least one byte. In this way, the FIFO is written
// with 16 bytes when /TXRDY is asserted (low).
// In mode 1, /TXRDY is asserted (low) when the transmit FIFO is not full; in this mode,
// the transmit FIFO is written with another UINT when /TXRDY is asserted (low).
//
// scratchpad register
// ===================
// The scratch register is an 8-bit read/write register that has no affect on either
// channel in the ACE. It is intended to be used by the programmer to hold data
// temporarily.
////////////////////////////////////////////////////////////////////////////////////////
#define cnMaxBaudRate 691200 // 对应主振频率为11.0592MHz = 691200 * 16
////////////////////////////////////////////////////////////////////////////////////////
//
// =============================
// TL16C554访问基地址:读/写100H
// =============================
//
// ==================================
// 分选片选控制地址如下表:低电平有效
// ==================================
// 端口地址 D0 D1 D2 D3 D4 D5 D6 D7
// -------- ---- ---- ---- ---- ---- ---- ---- ----
// INT0: 200H CSA1 CSB1 CSC1 CSD1 CSA3 CSB3 CSC3 CSD3
// INT1: 300H CSA5 CSB5 CSC5 CSD5 CSA7 CSB7 CSC7 CSD7
// INT2: 700H CSA2 CSB2 CSC2 CSD2 CSA4 CSB4 CSC4 CSD4
// Nmi: 900H CSA6 CSB6 CSC6 CSD6 CSA8 CSB8 CSC8 CSD8
//
// 用通道号表示
// ------------
// INT0: 200H 1 2 3 4 9 10 11 12
// INT1: 300H 17 18 19 20 25 26 27 28
// INT2: 700H 5 6 7 8 13 14 15 16
// Nmi: 900H 21 22 23 24 29 39 31 32
//
// 如要选择第 1路port900 = 0xff, port700 = 0xff, port300 = 0xff, port200 = 0xfe;
// 如要选择第 5路port900 = 0xff, port700 = 0xfe, port300 = 0xff, port200 = 0xff;
// 如要选择第 9路port900 = 0xff, port700 = 0xff, port300 = 0xff, port200 = 0xef;
// 如要选择第13路port900 = 0xff, port700 = 0xef, port300 = 0xff, port200 = 0xff;
// 如要选择第17路port900 = 0xff, port700 = 0xff, port300 = 0xfe, port200 = 0xff;
// 如要选择第21路port900 = 0xfe, port700 = 0xff, port300 = 0xff, port200 = 0xff;
// 如要选择第25路port900 = 0xff, port700 = 0xff, port300 = 0xef, port200 = 0xff;
// 如要选择第29路port900 = 0xef, port700 = 0xff, port300 = 0xff, port200 = 0xff;
//
// ================
// 串口芯片复位地址
// ================
// 写400H;D0 = 1,复位第一片串口芯片,D0 = 0,使第一片串口芯片工作;
// 写400H;D1 = 1,复位第二片串口芯片,D1 = 0,使第二片串口芯片工作;
// 写400H;D2 = 1,复位第三片串口芯片,D2 = 0,使第三片串口芯片工作;
// 写400H;D3 = 1,复位第四片串口芯片,D3 = 0,使第四片串口芯片工作;
// 写400H;D4 = 1,复位第五片串口芯片,D4 = 0,使第五片串口芯片工作;
// 写400H;D5 = 1,复位第六片串口芯片,D5 = 0,使第六片串口芯片工作;
// 写400H;D6 = 1,复位第七片串口芯片,D6 = 0,使第七片串口芯片工作;
// 写400H;D7 = 1,复位第八片串口芯片,D7 = 0,使第八片串口芯片工作;
//
// ==========================
// 串口芯片中断标识位读取地址
// ==========================
// INT0: 写500H,D1D0 = 00,同时读取600H,D0-D8分别对应INTA1、INTB1、INTC1、INTD1、INTA3、INTB3、INTC3、INTD3;
// INT2: 写500H,D1D0 = 01,同时读取A00H,D0-D8分别对应INTA2、INTB2、INTC2、INTD2、INTA4、INTB4、INTC4、INTD4;
// INT1: 写500H,D1D0 = 10,同时读取600H,D0-D8分别对应INTA5、INTB5、INTC5、INTD5、INTA7、INTB7、INTC7、INTD7;
// Nmi: 写500H,D1D0 = 11,同时读取A00H,D0-D8分别对应INTA6、INTB6、INTC6、INTD6、INTA8、INTB8、INTC8、INTD8;
//
// 用通道号表示
// ------------
// INT0:写500H,D1D0 = 00,同时读取600H,D0-D8分别对应 1、 2、 3、 4、 9、10、11、12;
// INT2:写500H,D1D0 = 01,同时读取A00H,D0-D8分别对应 5、 6、 7、 8、13、14、15、16;
// INT1:写500H,D1D0 = 10,同时读取600H,D0-D8分别对应17、18、19、20、25、26、27、28;
// Nmi: 写500H,D1D0 = 11,同时读取A00H,D0-D8分别对应21、22、23、24、29、30、31、32;
//
// ========
// 中断处理
// ========
// INT0:第一、三片串口芯片中断使用DSP的INT0, 1、 2、 3、 4、 9、10、11、12;
// INT1:第五、七片串口芯片中断使用DSP的INT1,17、18、19、20、25、26、27、28;
// INT2:第二、四片串口芯片中断使用DSP的INT2, 5、 6、 7、 8、13、14、15、16;
// Nmi: 第六、八片串口芯片中断使用DSP的NMI, 21、22、23、24、29、30、31、32;
//
/////////////////////////////////////////////////////////////////////////////////////////
// TL16c554访问I/O地址
// ===================
// 0,cnRBR_16c554,Receiver buffer register(READ)
// 0,cnTHR_16c554,Transmitter holding register(WRITE)
// 0,cnDLL_16c554,Divisor latch LSB(When LCR.7=1)(WRITE)
// 1,cnDLM_16c554,Divisor latch MSB(When LCR.7=1)(WRITE)
// 1,cnIER_16c554,Interrupt enable register(WRITE)
// 2,cnIIR_16c554,Interrupt identification(READ)
// 2,cnFCR_16c554,FIFO control register(WRITE)
// 3,cnLCR_16c554,Line control register(WRITE)
// 4,cnMCR_16c554,Modem control register(WRITE)
// 5,cnLSR_16c554,Line status register(READ)
// 6,cnMSR_16c554,Modem status register(READ)
// 7,cnSCR_16c554,Scratchpad register(READ & WRITE)
ioport UINT port100; // 0,cnRBR_16c554,Receiver buffer register(READ)
// 0,cnTHR_16c554,Transmitter holding register(WRITE)
// 0,cnDLL_16c554,Divisor latch LSB(When LCR.7=1)(WRITE)
ioport UINT port101; // 1,cnDLM_16c554,Divisor latch MSB(When LCR.7=1)(WRITE)
// 1,cnIER_16c554,Interrupt enable register(WRITE)
ioport UINT port102; // 2,cnIIR_16c554,Interrupt identification(READ)
// 2,cnFCR_16c554,FIFO control register(WRITE)
ioport UINT port103; // 3,cnLCR_16c554,Line control register(WRITE)
ioport UINT port104; // 4,cnMCR_16c554,Modem control register(WRITE)
ioport UINT port105; // 5,cnLSR_16c554,Line status register(READ)
ioport UINT port106; // 6,cnMSR_16c554,Modem status register(READ)
ioport UINT port107; // 7,cnSCR_16c554,Scratchpad register(READ & WRITE)
// TL16c554路选方法
// ================
// 端口地址 D0 D1 D2 D3 D4 D5 D6 D7
// -------- ---- ---- ---- ---- ---- ---- ---- ----
// INT0: 200H CSA1 CSB1 CSC1 CSD1 CSA3 CSB3 CSC3 CSD3
// INT1: 300H CSA5 CSB5 CSC5 CSD5 CSA7 CSB7 CSC7 CSD7
// INT2: 700H CSA2 CSB2 CSC2 CSD2 CSA4 CSB4 CSC4 CSD4
// Nmi: 900H CSA6 CSB6 CSC6 CSD6 CSA8 CSB8 CSC8 CSD8
//
// 用通道号表示
// ------------
// INT0: 200H 1 2 3 4 9 10 11 12
// INT1: 300H 17 18 19 20 25 26 27 28
// INT2: 700H 5 6 7 8 13 14 15 16
// Nmi: 900H 21 22 23 24 29 39 31 32
//
// 如要选择第 1路port900 = 0xff, port700 = 0xff, port300 = 0xff, port200 = 0xfe;
// 如要选择第 5路port900 = 0xff, port700 = 0xfe, port300 = 0xff, port200 = 0xff;
// 如要选择第 9路port900 = 0xff, port700 = 0xff, port300 = 0xff, port200 = 0xef;
// 如要选择第13路port900 = 0xff, port700 = 0xef, port300 = 0xff, port200 = 0xff;
// 如要选择第17路port900 = 0xff, port700 = 0xff, port300 = 0xfe, port200 = 0xff;
// 如要选择第21路port900 = 0xfe, port700 = 0xff, port300 = 0xff, port200 = 0xff;
// 如要选择第25路port900 = 0xff, port700 = 0xff, port300 = 0xef, port200 = 0xff;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -