已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
天津工程师范学院2009届本科生毕业设计外文资料1-wire search algorithmabstractdallas semiconductors 1-wire devices each have a 64-bit unique registration number in read-only-memory (rom).that is used to address them individually by a 1-wire master in a 1-wire network. if the rom numbers of the slave devices on the 1-wire network are not known, then using a search algorithm can discover them. this document explains the search algorithm in detail and provides an example implementation for rapid integration. this algorithm is valid for all current and future devices that feature a 1-wire interface.table 1 bit unique rom registration number.msb 64-bit registration rom number lsb8-bit crcmsb lsb48-bit serial numbermsb lsb8-bit family codemsb lsbsearch algorithmthe search algorithm is a binary tree search where branches are followed until a device rom number, or leaf, is found. subsequent searches then take the other branch paths until all of the leaves present are discovered.the search algorithm begins with the devices on the 1-wire being reset using the reset and presence pulse sequence. if this is successful then the 1-byte search command is sent. the search command readies the 1-wire devices to begin the search.there are two types of search commands. the normal search command (0f0 hex) will perform a search with all devices participating. the alarm or conditional search command (0ec hex) will perform a search with only the devices that are in some sort of alarm state. this reduces the search pool to quickly respond to devices that need attention.following the search command, the actual search begins with all of the participating devices simultaneously sending the first bit (least significant) in their rom number (also called registration number). (see figure 1.) as with all 1-wire communication, the 1-wire master starts every bit whether it is data to be read or written to the slave devices. due to the characteristics of the 1-wire, when all devices respond at the same time, the result will be a logical and of the bits sent. after the devices send the first bit of their rom number, the master initiates the next bit and the devices then send the complement of the first bit. from these two bits, information can be derived about the first bit in the rom numbers of the participating devices. (see table 1.)table 2 bit search informationbit(true)bit(complement)information known00there are both 0s and 1s in the current bit position of the participating rom numbers. this is a discrepancy.01there are only 0s in the bit of the participating rom numbers.10there are only 1s in the bit of the participating rom numbers.11no devices participating in search.according to the search algorithm, the 1-wire master must then send a bit back to the participating devices. if the participating device has that bit value, it continues participating. if it does not have the bit value, it goes into a wait state until the next 1-wire reset is detected. this read two bits and write one bit pattern is then repeated for the remaining 63 bits of the rom number (see table 2). in this way the search algorithm forces all but one device to go into this wait state. at the end of one pass, the rom number of this last device is known. on subsequent passes of the search, a different path (or branch) is taken to find the other device rom numbers. note that this document refers to the bit position in the rom number as bit 1 (least significant) to bit 64 (most significant). this convention was used instead of bit 0 to bit 63 for convenience to allow initialization of discrepancy counters to 0 for later comparisons.on examination of table 1, it is obvious that if all of the participating devices have the same value in a bit position then there is only one choice for the branch path to be taken. the condition where no devices are participating is an atypical situation that may arise if the device being discovered is removed from the 1- wire during the search. if this situation arises then the search should be terminated and a new search could be done starting with a 1-wire reset. table 3 wire master and slave search sequencemasterslave1-wire reset stimulusproduce presence pulse.write search command (normal or alarm)each slave readies for search.read and of bit 1each slave sends bit 1 of its rom number.read and of complement bit 1each slave sends complement bit 1 of its rom number.write bit 1 direction (according to algorithm)each slave receives the bit written by master, if bit read is not the same as bit 1 of its rom number then go into a wait state.read and of bit 64each slave sends bit 64 of its rom number.read and of complement bit 64each slave sends complement bit 64 of its rom number.write bit 64 direction (according to algorithm)each slave receives the bit written by master, if bit read is not the same as bit 64 of its rom number then go into a wait state.the condition where there are both 0s and 1s in the bit position is called a discrepancy and is the key to finding devices in the subsequent searches. the search algorithm specifies that on the first pass, when there is a discrepancy (bit/complement = 0/0), the 0 path is taken. note that this is arbitrary for this particular algorithm. another algorithm could be devised to use the 1 path first. the bit position for the last discrepancy is recorded for use in the next search. table 3 describes the paths that are taken on subsequent searches when a discrepancy occurs.table 4 search path directionsearch bit position vslast discrepancypath taken=take the 1 pathtake the 0 paththe search algorithm also keeps track of the last discrepancy that occurs within the first eight bits of the algorithm. the first eight bits of the 64-bit registration number is a family code. as a result, the devices discovered during the search are grouped into family types. the last discrepancy within that family code can be used to selectively skip whole groups of 1-wire devices. see the description of advanced search variations for doing selective searches. the 64-bit rom number also contains an 8-bit cyclic-redundancy-check (crc). this crc value is verified to ensure that only correct rom numbers are discovered. see figure 1 for the layout of the rom number.figure 2 shows a flow chart of the search sequence. note the reference that explains the terms used in the flow chart. these terms are also used in the source code appendix to this document.referenceid_bitthe first bit read in a bit search sequence. this bit is the and of all of the id_bit_number bits of the devices that are still participating in the search.cmp_id_bitthe complement of the id_bit .this bit is the and of the complement of all of the id_bit_number bits of the devices that are still participating in the search.id_bit_numberthe rom bit number 1 to 64 currently being searched.lastdeviceflagflag to indicate previous search was the last device.lastdiscrepancybit index that identifies from which bit the (next) search discrepancy check should start.lastfamilydiscrepancybit index that identifies the lastdiscrepancy within the first 8-bit family code of rom number.last_zerobit position of the last zero written where there was a discrepancy.rom_no8-byte buffer that contains the current rom registration number discovered.search_directionbit value indicating the direction of the search. all devices with this bit stay in the search and the rest go into a wait state for a 1-wire reset.there are two basic types of operations that can be performed by using the search algorithm by manipulating the lastdiscrepancy, lastfamilydiscrepancy, lastdeviceflag, and rom_no register values (see table 4). these operations concern basic discovery of the rom numbers of 1-wire devices.firstthe first operation is to search on the 1-wire for the first device. this is performed by setting lastdiscrepancy, lastfamilydiscrepancy, and lastdeviceflag to zero and then doing the search. the resulting rom number can then be read from the rom_no register. if no devices are present on the 1- wire the reset sequence will not detect a presence and the search is aborted.nextthe next operation is to search on the 1-wire for the next device. this search is usually performed after a first operation or another next operation. it is performed by leaving the state unchanged from the previous search and performing another search. the resulting rom number can then be read from the rom_no register. if the previous search was the last device on the 1-wire then the result will be false and the condition will be set to execute a first with the next call of the search algorithm.the following goes through a simple search example with three devices. for illustration, this example assumes devices with a 2-bit rom number only.search example(for simplicity the family discrepancy register and tracking has been left out of this example)firstlastdiscrepancy = lastdeviceflag = 0do 1-wire reset and wait for presence pulse ,if no presence pulse then done id_bit_number = 1, last_zero = 0send search command ,0f0 hexread first bit id_bit : 1 (device a) and 0 (device b) and 1 (device c) = 0read complement of first bit cmp_id_bit : 0 (device a) and 1 (device b) and 0 (device c) = 0since id_bit_number lastdiscrepancy,then search_direction = 0, last_zero = 1send search_direction bit of 0 , both device a and c go into wait stateincrement id_bit_number to 2read second bit id_bit : 0(device b) = 0read complement of second bit cmp_id_bit : 1 (device b) = 1since bit and complement are different then search_direction = id_bitsend search_direction bit of 0 ,device b is discovered with rom_no of 00 and is now selectedlastdiscrepancy = last_zeronextdo 1-wire reset and wait for presence pulse ,if no presence pulse then doneid_bit_number = 1, last_zero = 0send search command ,0f0 hexread first bit id_bit : 1 (device a) and 0 (device b) and 1 (device c) = 0read complement of first bit cmp_id_bit : 0 (device a) and 1 (device b) and 0 (device c) = 0since id_bit_number = lastdiscrepancy then search_direction = 1send search_direction bit of 1 , device b goes into wait stateincrement id_bit_number to 2read second bit id_bit : 0(device a) and 1(device c) = 0read complement of second bit cmp_id_bit : 1(device a) and 0(device c) = 0since id_bit_number lastdiscrepancy,then search_direction = 0, last_zero = 2send search_direction bit of 0 , device c goes into wait statedevice a is discovered with rom_no of 01 and is now selectedlastdiscrepancy = last_zeronextdo 1-wire reset and wait for presence pulse ,if no presence pulse then doneid_bit_number = 1, last_zero = 0send search command ,0f0 hexread first bit id_bit : 1 (device a) and 0 (device b) and 1 (device c) = 0read complement of first bit cmp_id_bit : 0 (device a) and 1 (device b) and 0 (device c) = 0since id_bit_number lastdiscrepancy then search_direction = rom_no (first bit) = 1send search_direction bit of 1 , device b goes into wait stateincrement id_bit_number to 2read second bit id_bit : 0(device a) and 1(device c) = 0read complement of second bit cmp_id_bit : 1(device a) and 0(device c) = 0since id_bit_number = lastdiscrepancy,then search_direction = 1send search_direction bit of 1 , device a goes into wait statedevice c is discovered with rom_no of 11 and is now selectedlastdiscrepancy = last_zero which is 0 so lastdeviceflag = truenextlastdeviceflag is true so return false lastdiscrepancy = lastdeviceflag = 0advanced search variationsthere are three advanced search variations using the same state information, namely lastdiscrepancy, lastfamilydiscrepancy, lastdeviceflag, and rom_no. these variations allow specific family types to be targeted or skipped and device present verification (see table 4).verifythe verify operation verifies if a device with a known rom number is currently connected to the 1- wire. it is accomplished by supplying the rom number and doing a targeted search on that number to verify it is present. first, set the rom_no register to the known rom number. then set the lastdiscrepancy to 64 (40 hex) and the lastdeviceflag to 0. perform the search operation and then read the rom_no result. if the search was successful and the rom_no remains the rom number that was being searched for, then the device is currently on the 1-wire.target setupthe target setup operation is a way to preset the search state to first find a particular family type. each 1-wire device has a one byte family code embedded within the rom number (see figure 1). this family code allows the 1-wire master to know what operations this device is capable of. if there are multiple devices on the 1-wire it is common practice to target a search to only the family of devices that are of interest. to target a particular family, set the desired family code byte into the first byte of the rom_no register and fill the rest of the rom_no register with zeros. then set the lastdiscrepancy to 64 (40 hex) and both lastdeviceflag and lastfamilydiscrepancy to 0. when the search algorithm is next performed the first device of the desired family type will be discovered and placed in the rom_no register. note that if no devices of the desired family are currently on the 1-wire, then another type will be found, so the family code in the resulting rom_no must be verified after the search.family skip setupthe family skip setup operation sets the search state to skip all of the devices that have the family code that was found in the previous search. this operation can only be performed after a search. it is accomplished by copying the lastfamilydiscrepancy into the lastdiscrepancy and clearing out the lastdeviceflag. the next search will then find devices that come after the current family code. if the current family code group was the last group in the search then the search will return with the lastdeviceflag set.table5 search variations state setuplastdiscrepancylastfamily-discrepancylastdeviceflagrom_nofirst000resultnextleave unchangedleave unchangedleave unchangedresultverify64random0set with rom to verify, check if same after searchtargetsetup6400set first byte to family code, set rest to zerosfamily skip setupcopy from lastfamilydiscrepancyleave unchanged0leave unchangedconclusionthe supplied search algorithm allows the discovery of the individually unique rom numbers from any given group of 1-wire devices. this is essential to any multidrop 1-wire application. with the rom numbers in hand, each 1-wire device can be selected individually for operations. this document also discussed search variations to find or skip particular 1-wire device types. see appendix for a c code example implementation of the search and all of the search variations.中文译文1-wire 搜索算法绪论dallas semiconductor的每片1-wire器件都有唯一的64位注册码它存储在只读存储器(rom)中。在1-wire网络中注册码用于1-wire主机对从机器件进行逐一寻址。如果1-wire网络中从机器件的rom 码是未知的,可以通过搜索算法来找到此码。本文不仅详细地解释了搜索算法,而且还提供了实现快速整合的例程该算法适用于任何具有1-wire接口特性的现有产品及未来产品。表1 64 位唯一的rom 注册码msb 64位rom注册码 lsb8位crc校验码msb lsb48位序列号msb lsb8位家族码msb lsb搜索算法搜索算法采用的是二叉树型结构,搜索过程沿各分节点进行,直到找到器件的rom码即叶子为止;后续的搜索操作沿着节点上的其它路径进行,按照同样的方式直到找到总线上的所有器件代码。搜索算法首先通过复位(reset)和在线应答脉冲(presence pulse)时隙将1-wire总线上的所有器件复位;成功地执行该操作后,发送1个字节的搜索命令;搜索命令使1-wire器件准备、就绪开始进行搜索操作。搜索命令分为两类标准搜索命令(0f0h)用来搜索连接到网络中所有器件;报警或有条件搜索命令(0ech)只用来搜索那些处于报警状态下的器件,这种方式缩小了搜索范围,可以快速查找到所需要注意的器件。搜索命令发出之后,开始实际的搜索过程。首先总线上的所有从机器件同时发送rom 码(也叫注册码)中的第一位(最低有效位)(参见图1)。与所有的1-wire通信一样无论是读取数据还是向从机器件写数据,都由1-wire主机启动每一位操作。按照1-wire的特性,当所有从机器件同时应答主机时,结果相当于全部发送数据位的逻辑and;从机发送其rom码的第一位后,主机启动下一位操作、接着从机发送第一位数据的补码;从两次读到的数据位可以对rom码的第一位做出几种判断(参见表2)。按照搜索算法的要求,1-wire主机必须向总线上的从机发回一个指定位;如果从机器件中rom码的当前位的值与该数据位匹配,则继续参与搜索过程;若从机器件的当前位与之不匹配,则该器件转换到等待状态,并保持等待状态直到下一个1-wire复位信号到来。其余63位rom 码的搜索依然按照这种读两位、写一位的模式进行重复操作(参见表3)。表2 检索信息位位(实际值)位(补码)结论00从机rom码中的当前位既有0,也有1;即存在差异01从机rom码中的当前位均为0。10从机rom码中的当前位均为1。11总线上没有从机器件响应。按照这种搜索算法进行下去,最终除了一个从机器件外所有从机将进入等待状态,经过最后一轮检测,就可得到最后保留(未进入等待状态)器件的rom码。在后续搜索过程中,选用不同的路径(或分支)来查找其它器件的rom码。需要注意的是本文rom码的数据位用第1位(最低有效位)到第64位(最高有效位)表示,而不是我们常用的那种第0位到第63位的模式;这样设置允许将差异位置记数器初始值置为0,为以后的比较提供了方便。表3 1-wire 主机和从机的搜索过程主机从机1-wire 发出复位信号产生在线应答脉冲。写搜索命令 (标准或报警)从机准备搜索。读第1 位的and从机发送rom 码的第1 位。读第1 位补码的and从机发送rom 码的第1 位的补码。写第1 位指定位(依照算法)从机接收主机的指定位若所读的位与rom码的第1 位不匹配,则进入等待状态。 读第64 位的and从机发送rom 码的第64 位。读第64 位补码的and从机发送rom 码的第64 位的补码。写第64 位指定位(依照算法)从机接收主机的指定位若所读的位与rom码的第64 位不匹配,则进入等待状态。从表4 可以看出:如果所有总线上的器件在当前位具有相同值,那么只有一条分支路径可选;总线上没有器件响应的情况是一种异常状态,可能是要查找的器件在搜寻过程中与1-wire 总线脱离。如果当前位既有0也有1,这种情况称为位值差异,它对在后续搜索过程中查找器件起关键作用。搜索算法指定在第一轮查询中若出现差异(数据位/补码 = 0/0), 则选用0路径。注意:这一点是由本文档中介绍的特定算法决定的,其它算法中或许首先选用1路径。记录最后一次值差异的位置以供下一次搜索使用,表3列出了出现值差异时路径的选取情况。表4 搜索路径方向搜索位所在位置和最后一次值差异所在位置的比较路径选取=采用路径1采用路径 0搜索算法计算还对最初8位过程中出现的最后一次位差异保持跟踪;64位注册码的前8位是家族码,在器件的搜索过程中可以按照其家族码进行分类。记录家族码的最后一次差异可以用于有选择性地跳过1-wire器件的整个分组。如需进行选择性地搜索,可参考关于高级变量搜索的详细解释。64位rom码中包含8位循环冗余校验码(crc);crc值用于验证是否搜索到正确的rom码注释对实例中出现的符号进行了说明;在本文档的源代码附录中也将用到这些专用符号。注释:id_bit在位搜索中第一次读取的值,该位是搜索过程中所有应答器件的id_bit_number 位的逻辑andcmp_id_bitid_bit 位的补码,该位是搜索过程中所有应答器件的id_bit_number位的补码的逻辑andid_bit_number记录当前搜索是1到64位rom码中哪一位的量lastdeviceflag指明前一次搜索到的已是最后一个器件的标志位lastdiscrepancy 位指针指明下次搜索从哪个值差异位开始lastfamilydiscrepancy位指针。用来指明lastdiscrepancy是否是在rom码中前8位家族码内和其位置last_zero上次被写入0的值差异位的位置rom_no记录当前正在查找的rom,注册码的8字节缓冲器search_di
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年及未来5年中国PPS聚苯硫醚行业发展趋势预测及投资战略咨询报告
- 2025年下学期高二化学定量分析实验试题
- 2025年超星尔雅学习通《环境生态学与资源管理案例分析》考试备考题库及答案解析
- 2025年煤矿安全管理人员考试题库及解析及答案
- 2025年超星尔雅学习通《科技创新成功案例管理实践探索企业全面创新升级效果评估与企业核心竞争力提升》考试备考题库及答案解析
- 2025年超星尔雅学习通《软件项目管理与团队协作》考试备考题库及答案解析
- 2025年超星尔雅学习通《多元文化管理》考试备考题库及答案解析
- 2025年超星尔雅学习通《世界文化遗产保护》考试备考题库及答案解析
- 2025年超星尔雅学习通《计算机图像处理与模式识别》考试备考题库及答案解析
- 2025年超星尔雅学习通《工程制图基础(上海交通大学版)》考试备考题库及答案解析
- 树木买卖砍伐协议书
- 2025研发投入绩效评估体系构建及企业创新激励机制规划
- 高空曲臂车安全操作规程
- 2025年粉尘涉爆培训题库及答案
- 厨房消防安全培训课件
- 2025江苏吉安吉水县城控人力资源服务有限公司招聘水电工2人笔试考试参考试题附答案解析
- 新员工CNC操机技能培训计划含理论实操
- 丙型肝炎防治指南
- 2025中国农业科学院第三批统一招聘2人笔试考试备考题库及答案解析
- GB/T 30340-2025机动车驾驶员培训机构业务条件
- 传统文化经典教案范例分享
评论
0/150
提交评论