发布于 2004-07-27 20:09:42
0楼
原文注解非常详细:
// INT 120
//
// This interrupt routine will execute if the quiet line timer expires. When this happens, attach the main
// character receive interrupt to the port since the next character we receive should be the start of a
// message.
INT 120
LD SM0.0
DTCH 10 // disable quiet line timer
ATCH 122, 8 // attach receive routine to comm port
MOVW 0, VW3300 // set receive count to zero
MOVD &VB3302, VD3570 // set pointer to receive buffer
RETI
当间隔定时器到达时会产生本中断,也就是检测到一个帧间隔,初始化准备接收。
// INT 121
//
// This interrupt routine handles the serial port interrupts while looking for a quiet
// line. If there is a character received during the quiet line search the action is to
// restart the quiet line timer.
INT 121
LD SM0.0
ATCH 120,10 // re-enable the quiet line timer
RETI
在间隔定时器未到之前收到任一个字符,间隔定时器复位重启
// INT 122
//
// This routine will receive the first byte of the message after finding the
// quiet line time. The first byte of the message will be the address. Check
// to see if this is a request to this address. If it is, attach INT 123 to receive the entire message.
// If the message is not for this address then go back to looking for a quiet line time.
//
// NOTE: The broadcast address is not supported in this implementation as
// it would add extra code. If this feature is desired, this INT would
// have to be modified along with all of the function handlers, since
// the broadcast address is not supported by all functions.
INT 122
LD SM3.0 // if (parity error)
ATCH 120, 10 // start search for quiet line
ATCH 121, 8 // INT 1 if we get a character
CRETI
// else (parity is OK)
LDB= SMB2, VB4095 // if (address = my address)
MOVB SMB2, *VD3570 // store address in buffer
INCW VW3572 // increment buffer pointer
INCW VW3300 // increment receive byte counter
ATCH 123, 8 // receive rest of message
ATCH 124, 10 // end receive if timeout
CRETI // return
LD SM0.0 // else (address != my address)
ATCH 120,10 // re-enable the quiet line timer
ATCH 121,8 // INT 121 if we get a character
RETI
首字节接收,它是一个地址字节,如果接收OK,准备接收后续字符,并启动结束帧间隔侦测。
// INT 123
//
// This is the main character interrupt service routine. Characters are received, checked for
// parity errors and then placed in the comm buffer. The byte count is incremented for each character.
// If the number of bytes received is greater than 256 then the receive is aborted.
INT 123
LD SM0.0
ATCH 124, 10 // message complete on next timeout
MOVB SMB2, *VD3570 // store message byte in buffer
INCW VW3572 // increment buffer pointer
INCW VW3300 // increment receive byte counter
LD SM3.0 // if (parity error) or
O V3300.0 // (buffer overflow)
ATCH 120, 10 // start search for quiet line
ATCH 121, 8 // INT 1 if we get a character
RETI
后续字符的接收,如果出错,数据丢弃重来,否则存贮继续直至结束间隔出现。
// INT 124
//
// This interrupt routine will execute when a message has been received and we have found another
// quiet line meaning that the request is compete. The action here is to disable the quiet line timer,
// disable the port interrupt, and set a flag for the background scan to process the message.
INT 124
LD SM0.0
DTCH 10 // disable quiet line timer
DTCH 8 // disable port interrupt
S M31.7, 1 // flag background
RETI
检测到结束帧间隔后,置完成标志,等待主程序处理,同时不再接收新的字符。
// INT 125
//
// This interrupt routine will execute when the response has been completely transmitted back to
// the master. Reset the interrupt system to again search for a quiet line and the start of a new request.
INT 125
LD SM0.0
ATCH 120,10 // start search for quiet line
ATCH 121,8 // INT 1 if we get a character
RETI
发送完成中断,发送完回应的信息后,重新开始新一帧的搜索。
配合主程序,程序还是非常易懂的。