A FLASH Bootloader for PIC16 and PIC18 Devices--硬译(三)

Author:  Ross M. Fosler and
             Rodger Richey
             Microchip Technology Inc.
译者: 逐影Linux

Communication Protocol 通信协议

The bootloader employs a basic communication protocol that is robust, simple to use, and easy to
implement.

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"。

表1 控制字符(译者注:这些跟ASC||表有出入)
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:
流量控制在协议建立。因此,每收到命令(除了复位),有一个响应。如果没有响应,那么一个(或更多)发生了下面的事:
• 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)依赖于发送的数据量,命令是否被执行,还有时钟频率。

图6 发送到接收延时

For read commands, the latency is highly dependent on the clock frequency, and the size of 
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 同步
The first <STX> in the protocol is the synchronization byte. It is used to match the 
device’s baud rate to the source’s baud rate. Thus, the device is synchronized to the 
source on every new packet.
第一个<STX>在协议中是同步的字节。它是用来匹配器件的波特率和发送源的波特率。因此,在发送每个

新的数据包时,该器件与发送源是同步的。
Note: If a 'Start of Text' condition is received during the reception of a packet, then no
synchronization occurs.
注:  如果一个'Start of Text'的条件是在接收一个包期间被收到,那么不是同步发生。
    (译者注:同步指双方的时钟要调整到同一个频率)

SELECTING FOSC AND BAUD RATE 选择FOSC和波特率
The recommended baud rate for this application is 9600 bps. This is the ideal rate for a 
device operating from 4 MHz, to the device’s maximum operating frequency (40 MHz in most cases).
Higher baud rates are possible, but degenerate conditions can occur.
推荐波特率对于这个应用程序为9600 bps。这是对于一个器件操作的理想的速率从4 MHz,到器件的最高工作频率
(40 MHz在大多数情况下)。更高的波特率是有可能,但退化条件下可以发生。

There are a few clock frequency/standard baud rate combinations that lead to a degenerate 
baud rate selection during synchronization; under such conditions, the device will never 
synchronize to the source. Clock frequencies that avoid such degenerate
conditions are given by the equation:
有几个时钟频率/标准波特率组合,导致退化的波特率选择在同步;在这种情况下,该器件将永远不会同步与发送源。
为了时钟频率避免这样的退化条件是给出了下面的方程:

FOSC = (1 ± E)(X + 1)(16)(B)
where(其中) E is the error (误差)(typically 2%), X is the value for the SPBRG register, and B is the baud 

rate. A table of calculated clock oscillator ranges for most of the common baud rates is provided in Appendix

 B for quick reference.
其中E是误差值(通常是2%), X是SPBRG寄存器的值,B是波特率。一个用来计算时钟振荡器范围的最常见的波特率表
在附录B中提供了快速参考。

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值