A FLASH Bootloader for PIC16 and PIC18 Devices--硬译(三)
Author: ?Ross M. Fosler and Communication Protocol 通信协议 The bootloader employs a basic communication protocol that is robust,simple to use,and easy toimplement. Bootloader使用了一个基本的通信协议,是健壮的,使用简单,并且容易实现。 (译者注:其他串行通信的文件传输协议主要有:Xmodem、Ymodem、Zmodem和KERMIT等,请自行 参考资料) PACKET FORMAT (数据包格式)All data that is transmitted to or from the device follows the basic packet format 所有发送的数据或从器件发出的数据遵循如下基本的数据包格式: <STX><STX>[<DATA><DATA>...]<CHKSUM><ETX> where each <...> represents a byte and [...] represents the data field. 其中每个<…>表示一个字节和[…]表示数据字段。 The start of a packet is indicated by two 'Start of TeXt' control characters (<STX>),? and is terminated by a single 'End of TeXt' control character (<ETX>).? 一个数据包的开始用两个'正文开始'的控制字符(用<STX>表示),和终止用单一的'文本结束'的控制字符(用<ETX>表示)。 The last byte before the <ETX> is always a checksum,which is the two’s complement of? the Least Significant Byte of the sum of all data bytes. 在<ETX>之前的一个字节是一个校验和<CHKSUM>,这是所有数据字节的和的最低有效字节的二进制补码。 (译者:关于校验和计算参看这两篇文章:http://wenku.baidu.com/view/16ed1f6ea45177232f60a2c8.html | ?? ? ?http://blog.chinaunix.net/uid-26758209-id-3146230.html, ?? ? ?不过这边指定的是补码,而且是最低有效字节,不是反码(其实解码出来一样) ?? ? ,不是字(因为这里<CHKSUM>用8位表示),有点出入) The data field is limited to 255 data bytes. If more bytes are received,then the packet is ignored until the next <STX> pair is received. 数据字段限制为255字节的数据。如果收到更多的字节,则这个包将会被忽略,直到下一次收到一对<STX>。 Note: Although the protocol supports 255 bytes of data,the specific device that contains the bootloader firmware may have a sufficiently large data memory to support the largest packet size. Refer to the data sheet for the particular device for more information. 注意: 尽管协议支持255字节的数据,有些特殊的器件,包含bootloader固件可能足够有大的数据内存支持最大的 数据包的?大小。参考具体器件数据表的更多信息。 CONTROL CHARACTERS(控制字符)There are three control characters that have special meaning. Two of them,<STX> and <ETX>,? are introduced above. The last character not shown is the 'Data Link Escape',<DLE>.? Table 1 provides a summary of the three control characters. 有三个控制具有特殊意义的字符。其中两个,<STX>和<ETX>,已经上面介绍了。最后一个字符没有显示是 "Data Link Escape",<DLE>(<数据通信换码>)。表1总结了三个控制字符。 The <DLE> is used to identify a value that could be interpreted in the data field as a? control character. Within the data field,the bootloader will always accept the byte? following a <DLE> as data,and will always send a <DLE> before any of the three control? characters. For example,if a byte of value 0Fh is transmitted as part of the data field,? rather than as the <STX> control character,the <DLE> character is inserted before the <STX>. This is called "byte stuffing". <DLE>是用来确定一个值,可以解释的数据字段作为一个控制字符。在数据字段,bootloader将总是接收跟随一个 <DLE>作为数据字节,并且总是在任意三个控制字符之前发送一个<DLE>。例如,如果一个值为0FH的字节传输作 为数据字段的一部分,而不是<STX>控制字符,那么<DLE>字符前会插入<STX>之前.(译者注:这个<DLE>相当 于C语言中转义字符'',不过应该表示的是实际的值,反转义)。这就是所谓的"byte stuffing"。 Note: Control characters are not considered data and are not included in the checksum. 注意: 控制字符是不会被考虑进数据,并且不包括进校验和(译者注:<STX><ETX><DLE>不包括进数据长度, <CHKSUM>考虑进数据长度)。 COMMANDS(命令)The data field for each packet contains one command and its associated data.? The commands are detailed in Appendix A. 每个包的数据字段包含一个命令及其相关的数据。详细的命令见附录一。 COMMAND RESPONSE LATENCY(命令响应延迟) Flow control is built into the protocol. Thus,for every received command (except RESET),there is a response. If there is no response,then one (or more) of the following has happened: 流量控制在协议建立。因此,每收到命令(除了复位),有一个响应。如果没有响应,那么一个(或更多)发生了下面的事?1 ? the data was corrupted (bad checksum)? ? the packet was never received ? the data field was too long ? RESET was executed ? 数据发生错误 (校验和发生错误,如果发送端checksum字段设为0,那么接收端checksum字段应该为1)? ? 没有接收到包 ? 数据字段过长 ? 执行了复位操作 So how long do you wait before deciding a problem has occurred? The response latency? (shown in Figure 6) is dependent on the amount of data sent,the command being executed,and ?the clock frequency. 所以你等待多久才能决定一个上述问题发生了?响应延迟(如图6)依赖于发送的数据量,命令是否被执行,还有时钟频率。 the packet. For a small packet at high frequency,the response is almost immediate,typically? on the order of a few microseconds. For large packets,the latency could be on the order of (大约)hundreds of microseconds. 读命令,延迟是高度依赖于时钟频率,包的大小。对于一个小包在高频率,响应几乎立即,通常大约几微秒。对于一 个大的数据包,延迟可能要在大约数百微秒。 In general,read commands require very little time compared to write commands. Write commands?are mostly dependent on internally timed write cycles. For example,the typical write time required for a single EEPROM location is 4 ms. If the maximum packet size (250 bytes of writable data) was sent,the receive to transmit latency would be about 1 second. 通常,读命令相对于写命令要求更小的时间。写命令大多数依赖于内部固定的写周期。例如,典型的写操 作所需的时间对于单个EEPROM位置是4ms,如果最大数据包大小(250字节的可写数据)被发送,传输到 接收延迟约1秒。 SYNCHRONIZING 同步 新的数据包时,该器件与发送源是同步的。 SELECTING FOSC AND BAUD RATE 选择FOSC和波特率 FOSC = (1 ± E)(X + 1)(16)(B) rate. A table of calculated?clock oscillator ranges for most of the common?baud rates is provided in Appendix ?B for quick?reference. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |