Google
 
Showing posts with label 接口与规范. Show all posts
Showing posts with label 接口与规范. Show all posts

Sunday, February 11, 2007

OpenWSN Frame/Packet Summary (draft 20070210)

OpenWSN Frame/Packet Summary (draft 20070210)

this document describes the format of frames/packets in the OpenWSN system.

attention: this design may be different from what we have done now. we will adjust our system to the following. however, some detail are still in discussion.

  • OpenWSN PHY Frame (in wireless communication)
This frame is identical with the frame format of IEEE 802.15.4 protocol. It can also be recognized by TI/Chipcon cc2420 ZigBee ready chip. OpenWSN wouldn't introduce new PHY format.

IEEE 802.15.4 PPDU format
[4B Preamble][1B SFD][7b Framelength, 1b Reserved][nB PSDU/Payload]

QQQ: whether the higher 7 bit or lower 7 bit represent framelength? can any one answer me?

Note that the preamble byte and SFD (start of eliminator) will be processed by hardware chips. so the software only need care about the data from frame length byte. so the real OpenWSN PHY frame defined in OpenWSN software is as the following:

OpenWSN PHY format (TOpenFrame type defined in hal_openframe.h):
[7b Framelength, 1b Reserved][nB PSDU/Payload]
here, PSDU(or namely the payload of PPDU)
is essentially the MAC frame.

  • OpenWSN MAC Frame (in wireless communication)
OpenWSN MAC frame is also identical with the format of IEEE 802.15.4 protocol. It can also be recognized by TI/Chipcon cc2420 ZigBee ready chip. OpenWSN wouldn't introduce new MAC format.

attention that OpenWSN MAC format may use the reserved values in IEEE 802.15.4 MAC in the future.

OpenWSN MAC/IEEE 802.15.4 MAC DATA (the payload of PHY frame)

Beacon Frame
[2B Frame Control] [1B Sequence Number][4 or 10 Address][2 Superframe Specification] [k GTS fields][m Padding address fields] [n Beacon payload][2 FCS]

Data Frame
[2B Frame Control] [1B Sequence Number][4 or 20 Address][n Data Payload][2 FCS]

ACK Frame
[2B Frame Control] [1B Sequence Number][2 FCS]

MAC Control Frame
[2B Frame Control] [1B Sequence Number][4 or 20 ADdress][1 Command Type][n Command Payload][2 FCS]

Frame Control
b2b1b0 frame type 000 beacon, 001 data 010 ACK 011 command 100-111 reserved
b12b13 reserved.


One problem puzzled the developer is the format of MAC address. the MAC address varies from 4 byte to even 20 bytes in 802.15.4. The type of address can be decided by the bit settings in Frame Control word in MAC frame.

In the current implementation of OpenWSN, it uses the short address of 802.15.4 MAC only. That is to say, the PAN id, source node id, and destination node id are all 16 bits.

In 802.15.4, the address(unique id) of a device/node, can be 16 bit/2 bytes (short address) or 64 bit/8 bytes (long address). The long 64 bits address is unique in the world. It should be allocated to the device before the device joins the network. While, the short 16 bit address is unique in a specific PAN. So the short address is only meaning full when combining with PAN id together.


However, there's some difference between OpenMAC and 802.15.4.
OpenMAC does more simplifications than 802.15.4 and also add some new features.


- OpenMAC doesn't provide Beacon Frame
- OpenMAC introduce RTS/CTS frame (not implemented till 20070130 in its simple MAC version, but the full version MAC will implement this mechanism)
- OpenMAC adopts the 802.15.4 MAC control frame and extend it to support RTS / CTS frame.
- OpenMAC adopts the 802.15.4 ACK frame. But the software implementation doesn't care this because the ACK frame is processed by cc2420 transceiver chip.


attention:
there's a macro defined in the OpenWSN software: MAC_HEADER_SIZE. this value is 7(???) = 2 frame control + 1 sequence + 4 address bytes (according to the DATA frame only).

  • OpenNET Packet (in wireless communication)
attention: the notation "frame" should be used in PHY/MAC layer (in chinese language, "zhen"). while, in NET and APP layer, you should use "packet". (in chinese language, "fen zu").

OpenNET packet is essentially the payload of the OpenMAC frame.

NET layer also has its address. The NET layer address and MAC layer address are not same. In OpenNET design, every node is assigned a 16 bit unique id (node id) and 16 bit network id (the same as PAN id). So the design can be simplified ---- OpenMAC and OpenNET share the same address fields.

The OpenNET packet:
[4-20B Address] [1B packet control] [1B Command Type] [nB Data]

attention here the "type" byte is the network layer command/packet type. Don't confuse it with MAC layer command. The MAC layer command is used in MAC layer only.

[4-20B Address]
the 4-20B address is shared by OpenMAC frame and OpenNET packet. Due to the complexity address assignment mechanism of MAC address in full version 802.15.4, OpenNET may introduce self-owned address field in the future. But i think it isn't necessary now. So i still let OpenMAC and OpenNET share the same address field.

[1B packet control] = [b7,...b0]
the packet control byte are reserved for future use.

b0 REQUEST flag, default 0
b0 = 0, means this is a RESPONSE packet. the destination node does nothing when it received the packet. this type is usually sent from the sink node to all the other sensor nodes.
b0 = 1 means this is a REQUEST packet. the destination node is required to reply a RESPONSE type packet. this type is often sent from the sensor nodes to the sink nodes.

b1 BROADCASR flag, default 0
b1 = 0, not broadcast
b1 = 1, the current node should broadcast this packet out.

the above attributes can help to implement NET layer protocols such as SPIN.

[1B Command Type] = [b7,...b0]

b7 is used to distinguish whether the command is a OpenWSN system command or user command (namely, application defined command). b7 is 0 for openwsn system command and 1 for application command.

/* system used data types */
#define ODA_TYPE_DEBUG 0x00
#define ODA_TYPE_CONFIGURE 0x01
#define ODA_TYPE_DATA 0x02
#define ODA_TYPE_LOCATION 0x06
#define ODA_TYPE_UPGRADE 0x07
#define ODA_TYPE_PROBE 0x08 // probing neighbor nodes

/* user defined data type
* the developer can add more TYPE defines if necessary. */
#define ODA_TYPE_USER 0x80
#define ODA_TYPE_TEMPSENSOR (ODA_TYPE_USER + 5)
#define ODA_TYPE_VIBSENSOR (ODA_TYPE_USER + 6)
#define ODA_TYPE_STRAINSENSOR (ODA_TYPE_USER + 7)
#define ODA_TYPE_LIGHTSENSOR (ODA_TYPE_USER + 8)
#define ODA_TYPE_OTHER_USER_DEFINED (ODA_TYPE_USER + 100)

attention the values may be adjusted in the near future. however, i'll try my best to make they are stable.



  • OpenWSN UART/SIO Frame (in serial communication)
The serial communication includes UART(such as RS232/485) and USB.
UART frame is quite similar to the wireless PHY frame.

[1B SFD] [1B Length] [nB Payload]

in UART frame, a special byte is used to indicate the start of the frame. attention here OpenWSN uses the technique of ESCAPE character idea to avoid data confilications. The SFD (start of eliminator) byte is used to represent the start of the frame. if there are SFD characters in Length and Payload, then the UART driver will insert another SFD as ESCAPE character.

(??? i have forgot the detail of UART/SIO driver, so this idea need confirmation)

attention that the Payload of the frame is essentially anything. But in our reference implementation of OpenWSN, we makes the "TOpenFrame" describe above as the payload. So the host application can got all the information of the hardware wireless communications. This feature facilitate the developing of host GUI applications.
.

Saturday, January 20, 2007

Monday, January 15, 2007

Q: 关于常用hal/service对象的简要功能说明?

这些对象是开发过程中最常用的,简要罗列于此(不全).更准确的说明请参考source code和有关文档.

名称

说明

代码分配原则

Timer

定时器,提供硬件Timer对象的封装

HAL

UART

串行通信口对象,提供硬件Uart对象的封装

HAL层,注意UART不同于串行通信对象SioSio中包含更上层的frame处理,后者属于DRIVER层。

目前UartDriver形式实现,但仍属于HAL层。

SPI

SPI接口对象,提供对SPI通信口的封装

HAL

仅仅包含SPI操作方法,提供一高度稳定可靠的SPI操作库。一切与被操作对象有关的代码都不应该放入SPI。目前以Driver形式实现,属于HAL层。

Transcever

接收发送器对象,如cc2420的软件封装

HAL

目前采用Driver方式实现,不要在该代码中引入任何RTOS调用。由于wireless通信的复杂性,该对象需要提供许多通用接口之外的函数接口如能耗和功率管理等。

SIO

串行IO通信对象,在UART基础上,进一步提供frame机制处理,包括frame帧头判断、帧尾判断、帧格式封装、帧格式解包、帧校验。

Driver

提供帧处理。

如果串行通信也组网的话,那还要包含地址处理

MAC

Medium Access Control

Driver方式实现,提供标准Driver读写接口,内部包含地址、信道访问冲突处理、帧处理、简单的时间配准、校验和重传、ACK机制等网络通信MAC层处理。

目前只提供一套MAC参考实现OpenMAC, 希望未来有兴趣的成员可以为其加入802.15.4两套各有特点,可针对不同场合选用。

DRIVER

MAC内部包含ACK机制。

NET

Networking Layer 拓扑和路由管理

service方式实现

SERVICE

Location

分布式Location构建在MAC基础之上

Service

TimeSync

时间同步,Time Synchronization

Service

Q: 我为OpenWSN开发了一个模块,如何决定这个模块归入的层次?

此问题即代码分配原则,这对于今后维护,不把整个architecture弄乱是很重要的.

为了回答这个问题,我们需要clarify每个层次的作用以及我们架构设计时的考虑.本answer可以看作是架构设计的进一步详细补充说明:

名称

说明

代码分配原则

依据该原则决定所写代码在何层

BOOT

启动/引导层

专用于初始化芯片和引导整个系统,例如初始化存储器映射、芯片内部连接、中断等。如果系统中引入了RTOS,则BOOT还要负责启动RTOS。一部分HAL代码的正常工作也需要依赖BOOT

BOOT应只包含MCU芯片的初始化代码,而与目标板(Target Evaluation Board)无关,因此,一切与板子设计有关的代码都不应该归入BOOT层。

RTOS

RTOS

提供一个实时调度内核。备选的RTOS有:eCos, FreeRTOS, uCOS-II, Linux 2.6 Embedded(准实时)MANTIS, TinyOS(非实时)

事实上,我们只是需要一个小的实时调度器,完全有能力自己开发一个或者移植一个。如果系统资源允许,我们可以引入更多的OS功能,如线程通信和同步、内存管理、调试和控制台等。

HAL

硬件抽象层

硬件抽象层(hardware abstraction layer)。为了最大限度保证上层代码的可移植性,提供HAL层。

可以认为,HAL层是各种硬件对象的软件代理。为了减小移植工作量,HAL中代码应尽可能精简。HAL中的代码是不允许使用RTOS功能的。

DRIVER

驱动程序层

在比HAL更高层次上提供对硬件功能的封装,比HAL更强调对上层的服务功能。DRIVER层次开发可以使用RTOS提供的调度、通信等功能。原则上,DRIVER中应该尽可能不出现强硬件依赖性代码,尽可能将此类代码放入HAL,但出于开发的便利性不对此做严格限制。

凡与硬件相关且不适合放在HAL中的代码都应该放在该层。如果该DRIVER的开发需要利用RTOS的功能,则只能归入DRIVER层。出于开发的方便,一部分没有必要利用RTOS功能的HAL层代码也直接做成了DRIVER,例如Uart, Transceiver, SPII2C等。

SERIVICE

服务层

从面向对象的角度看,一个系统,可以认为是由很多对象组成的,而系统的运行,就可以认为这些对象的动态交互行为。因此,我们需要重点设计和开发好各个对象。这也有助于提高软件代码的可重用性。可独立运行的进程/线程也可以认为是具有自治能力的对象。为了避免class/object名词的混淆,我们用service术语来表示对象,因为每个对象必然是要为其它对象服务的。每个service在设计的时候要牢记Hollywood原则:不要调用我,而要让我来调用你。

是系统的主要组成部分,包含了一个应用系统的绝大部分代码。

APPLICATION

应用层

设置各对象之间的连接方式,提供各对象之间的配置和粘合代码。

在一个完整的系统中,应尽可能将大部分代码对象化并归入SERVICE层,APPLICATION应尽可能保持精简。

主要的业务逻辑代码一定要放在SERVICEDRIVER中,不允许放在APPLICATION层。

.

Q: OpenWSN软件平台参考实现

整个软件系统大致分成四层:

- 应用层 Application
- 服务层 Service
- 驱动层 DRIVER + RTOS
- 硬件抽象层 HAL + BOOT



Fig. OpenWSN软件平台架构

HAL提供硬件的软件抽象,这是OpenWSN具有良好可移植性的主要原因。事实上,从诞生之日起,可移植性就是OpenWSN的重要目标。BOOT引导与HAL也处于同一层次。在代码中放在hal子目录下,并以"hal_"前缀标明。

DRIVER提供了更高层次的操作抽象。例如OpenWSN针对Uart提供一个Uart硬件抽象,提供基于byte的通信方式,在UART HAL基础上,系统提供SioComm串行通信对象,提供以行或者packet通信的方式。为简单实用起见,对很多硬件,系统只提供了Hal,因为没有必要再去提供额外的Driver. 在代码中放在service子目录下并以"svc_"前缀标明。

Service 更高层次的操作抽象。例如location服务。在代码中放在service子目录下并以"svc_"前缀标明。部分人所说的WSN Middleware也属于这个层次,但OpenWSN的Service目前只囊括了WSN Middleware中的基本必须部分,例如location, time sync等,还未包括诸如data aggregation等服务,原因是data aggregation非常接近于应用,应用相关性太强,难以抽象出来单独实现。

Application代表整个应用。在OOD/OOP体系下,由于service目录中已经提供了大多数可用对象,Application简化成为对象实例的初始化和对象之间的连接功能。代码中提供的rfmodem/analyzer等测试程序示例就展示了这点。当然,根据需要,用户也可以创建新的service对象并在Application中使用。OpenWSN鼓励用户开发新的service对象并反馈给OpenWSN项目。


由这个划分大家也可以看到,我们并未过多强调WSN系统本身的特性,这个设计是出于实用性考虑.目标是开发出的软件要足够的稳定可靠,可满足高可靠的工业实际应用要求.

Q: OpenWSN硬件平台参考实现---- OpenNode

OpenNODE是硬件规范的一个参考实现, 采用如下标准架构:


Fig. Architecture of OpenNODE

系统中的各个主要模块之间均通过标准的总线接口实现通信。最关键的是两个接口:wireless board的12 pin接口和sensor board的16 pin接口。母板可自行设计开发,板上可提供板载传感器电路,同时应提供一个16 pin扩展接口,使其可以利用第三方开放的sensor board。

目前的硬件平台方案有这样几条路线:
• low cost MCU based.  主要以Atmel和TI方案为主,实际中也可采用集成了wireless和MCU的Freescale和Chipcon方案。这些方案追求实用低成本。传感器数量有限且集成在母板上,不提供扩展插口。绝大部分目前的ZIGBEE方案都属于这一类。
• ARM 7 based + separate wireless board + separate sensor board。追求 灵活性和适度的处理能力,适合实验教学和原型化。由于处理能力较强,也适合在网络中担任sink、coordinator等责任。


我们现在走的路线是ARM7-based为主。

Sensor module和Processor module之间的连接通过一条简单的总线实现,并通过module selection pin实现模块选择。现在的设计中16根pin中有两根专用于片选功能,若每个sensor module支持译码功能,则可以最多支持四块module。考虑到要尽可能简单,我们并不推荐加译码,这样目前的设计最多支持两块sensor module,一块为母板集成,一块为扩展,足以满足绝大部分实际需要.
Google