SlideShare a Scribd company logo
1 of 66
Download to read offline
1 
Speech Transmission over ZigBee Network 
THESIS 
Submitted for the partial fulfilment of the 
degree of 
Bachelor of Technology 
(Electronics and Communication Engineering) 
By 
Chandana Kandru (BT09ECE004) 
Pragya Agrawal (BT09ECE011) 
Under the guidance of 
Dr. A.S. Gandhi 
Professor 
Department of Electronics and 
Communication Engineering 
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING 
VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY, NAGPUR 
2012-13
2 
DECLARATION 
We the students of the Department of Electronics and Communication Engineering, VNIT Nagpur state that the thesis entitled “Speech transmission over ZigBee Network” is our original work and has not been submitted to any other institute or university for any other degree. This work is being submitted for the partial fulfilment of the B.Tech degree for the session 2012-13. 
Chandana Kandru 
Pragya Agrawal
3 
CERTIFICATE 
This is to certify that the project work embodied in the thesis entitled “Speech transmission over ZigBee Network” is genuine and has not been submitted to any other institute or university for any other degree. This bonafide work has been carried out by: 
CHANDANA KANDRU BT09ECE004 
PRAGYA AGRAWAL BT09ECE011 
in partial fulfilment of the requirements for the award of the Degree of Bachelor of Technology (Electronics and Communication Engineering) from Visvesvaraya National Institute of Technology, Nagpur, during 2012-2013. 
Dr. A.S. Gandhi 
Professor, 
Department of Electronics and 
Communication Engineering, 
VNIT, Nagpur. 
Dr. K.D. Kulat 
Head of Department, 
Department of Electronics and 
Communication Engineering, 
VNIT, Nagpur.
4 
ACKNOWLEDGEMENTS 
We would like to express our heartfelt gratitude to our guides Dr. A. S. Gandhi for their valuable advice and constant support. His insightful suggestions have aided us in the successful completion of our project work. 
We also thank Prof. K.D.Kulat, Head of the Department, Electronics and Communication Engineering, VNIT Nagpur for extending the departmental facilities for our research. 
We are extremely grateful to all the faculty and staff of the Department of Electronics and Communication Engineering for providing us unwavering guidance and support for the entire four years of our bachelors’ degree course. Finally we would like to express our deepest gratitude to all our friends in VNIT Nagpur for the help and cooperation they have extended over the past four years.
5 
ABSTRACT 
The ZigBee standard is designed to enable the deployment of low-cost, low-power wireless sensor and control networks based on the IEEE 802.15.4 physical radio standard. Transmission of voice with acceptable QoS requires high bandwidth channel. ZigBee operates in 2.4 GHz ISM band with a maximum possible data rate of 250 kbps. Despite the low data rates of ZigBee, its use for transmission of voice has been proven to be feasible. 
However, the system should guarantee the QoS throughput on the channel with minimal occupancy of the allowable channel bandwidth. So, voice must be compressed before being transmitted. The compression algorithm should be implemented on a low power processor for extending the lifetime of the system. The challenges include selection and implementation of the most suitable voice codec for high-quality voice transmission over constrained networks, using constrained devices. 
In this project we transmit human speech over ZigBee by implementing Speex compression algorithm on DSP hardware TMS320C5505. The RF module used for transmission is CC2520.
6 
TABLE OF CONTENTS 
DECLARATION.........................................................................................................2 
CERTIFICATE...........................................................................................................3 
ACKNOWLEDGEMENTS.......................................................................................4 
ABSTRACT…………………………………………………………….....................5 
LIST OF FIGURES……………………….……………………………...................8 
LIST OF TABLES......................................................................................................9 
CHAPTERS 
1. INTRODUCTION.........................................................................................10 
1.1 NETWORK SELECTION.....................................................................10 
1.2 CODEC SELECTION............................................................................12 
1.3 PLATFORM SELECTION...................................................................12 
2. BACKGROUND...........................................................................................13 
2.1 SPEECH CODEC...................................................................................13 
2.1.1 Speex Codec.................................................................................14 
2.1.2 Analysis of node data rate..........................................................15 
2.2 ZIGBEE NETWORK.............................................................................15 
2.2.1 Nodes in ZigBee Network...........................................................15 
2.2.2 ZigBee PANs................................................................................16 
2.2.3 ZigBee Channels..........................................................................16 
2.2.4 ZigBee PAN Ids...........................................................................17 
2.2.5 Network Address.........................................................................17 
2.2.6 MAC Address..............................................................................17 
2.2.7 Sending and Receiving data in ZigBee network.......................18 
2.2.8 Addressing within the node........................................................18 
2.2.8.1 Endpoints...............................................................................19 
2.2.8.2 Clusters..................................................................................19 
2.2.9 ZigBee Application Support Sublayer (APS)...........................20 
2.2.9.1 APS Acknowledgements.......................................................21 
2.2.9.2 Application Profiles..............................................................21 
2.2.9.3 Device Ids...............................................................................21
7 
2.2.9.4 Simple Descriptor..................................................................22 
2.2.10 ZigBee Network Services............................................................22 
2.2.10.1 ZigBee device profile.................................................22 
3. HARDWARE................................................................................................24 
3.1 ezDSP STICK..........................................................................................25 
3.2 ProFLEX01-R2 MODULE....................................................................27 
4. SOFTWARE IMPLEMENTATION..........................................................28 
4.1 TOOLS USED.........................................................................................28 
4.2 SPEECH COMPRESSION....................................................................29 
4.2.1 Speex Codec.................................................................................29 
4.2.2 DMA.............................................................................................30 
4.2.3 UART...........................................................................................31 
4.3 TRANSMISSION OVER ZIGBEE......................................................35 
4.3.1 LSRApp_Init( )............................................................................37 
4.3.2 LSRApp_ProcessEvent()............................................................38 
4.3.3 Sending Message.........................................................................39 
4.3.4 Receiving Message......................................................................41 
4.4 CONCLUSION.......................................................................................43 
APPENDIX................................................................................................................44 
Program code for Speex Compression on TMS320C5505.........................44 
Program code for ZigBee transmission........................................................57 
REFERENCES.........................................................................................................66
8 
LIST OF FIGURES 
Figure 1: ZigBee Stack Architecture.......................................................................................10 
Figure 2: APS end-to-end acknowledgements........................................................................11 
Figure 3: Block diagram of the overall system.......................................................................14 
Figure 4: TMS320C5505 ezDSP STICK................................................................................15 
Figure 5: Expansion connector for ezDSP STICK..................................................................16 
Figure 6: Board with expansion connector indicating connections........................................16 
Figure 7: PROFLEX01-R2 development board……………………………………………17 
Figure 8: ProFLEX01-R2 Module Block Diagram…………………………………………18 
Figure 9: Programming the ProFLEX Module using MSP FET430UIF JTAG Debugger.....18 
Figure 10: Flowchart representing speech compression using Speex.....................................23 
Figure 11: Screenshots indicating project build in Code Composer Studio...........................24 
Figure 12: Flowchart representing sending of message over the air using ZigBee................30 
Figure 13: Flowchart representing receiving of message over the air using ZigBee..............31 
Figure 14: Screenshots indicating Coordinator and End device project build in IAR............32
9 
LIST OF TABLES 
Table 1: Comparison of ZigBee with contemporary technologies...........................................1 
Table 2: Nodes in ZigBee Network..........................................................................................6 
Table 3: List of source and header files of Speex that need to be included in the project.....20
10 
1. INTRODUCTION 
IEEE 802.15.4 ZigBee standard is a wireless technology operating over 2.4 GHz frequency. 
The maximum data rate supported by this technology is 250 kbps. 
ZigBee has following features: 
 Low power consumption 
 Network can have large number of devices (65535 per network) when it uses short addressing 
 Leaving and joining network is rapid of the order of milliseconds (less than 30ms) 
 Protocol stack is simpler 
 Supports periodic, intermittent and repetitive data 
1.1 NETWORK SELECTION: 
1.1.1 Why ZigBee? 
The main advantages of ZigBee over rival technologies like Bluetooth, Wi-Fi is low power consumption and higher network range. 
This is because of the mesh and tree networking being allowed in addition to the star networking supported by Bluetooth and Wi-fi, which means when we are not in the range of the node that we wish to communicate with, other nodes in between, can be asked to pass the message along. 
Thus by halving the range of radio reduces power consumption by 75%, leading to dramatic power consumptions without compromising range. 
ZigBee Wi-Fi Bluetooth Range 10-100 m 50-100 m 10-100 m 
Networking Topology 
Ad-hoc, peer to peer, star, mesh 
Point to hub 
Ad-hoc, very small networks Operating Frequency 868 MHz (Europe) 915 MHz (USA) 2.4 GHz (worldwide) 2.4 GHz, 5 GHz. 2.4 GHz 
Complexity 
Low 
High 
High Power Consumption Very low High Medium 
Table 1: Comparison of ZigBee with contemporary technologies
11 
1.2 CODEC SELECTION: 
Due to the limited available bandwidth for ZigBee, voice must be compressed before being transmitted. 
 The maximum bit rate supported by ZigBee is 250kbps but due to packet overheads while transmission the data rate is reduced to 38kbps. Hence for high quality speech transmission over ZigBee only narrowband voice codecs can be used. 
 Also the DSP processor used to implement codec eliminates the use of wideband codecs due to performance limitations pertaining to the low power application. 
The popular voice codecs are: G723.1, iLBC, Speex. 
1.3 PLATFORM SELECTION: 
To implement the voice codec the DSP hardware must support the following features: 
 High processing power (up to 30MIPS). 
 To be able to implement compression/decompression algorithms like Speex, G723.1etc. 
 Support of serial interfaces like UART, SPI. 
 Low power consumption. 
Popular DSP platforms: TMS320C5505, dsPIC 33Fxx, BelaSigna 300
12 
2. BACKGROUND 
2.1 SPEECH CODEC 
The human voice acoustic sensor initially generates an analog signal. This signal is converted into a bit stream by an Analog-to-Digital converter (ADC) and applied to a multiple compression algorithms. There are various compression techniques available in the literature. The most popular ones are standardized in the ITU-T G-series. The most commonly used codecs are: G.711 PCM, G.726 ADPCM, G.728 LD-CELP and G. 729/G.729a CS-ACELP. 
PCM and ADPCM belong to the family of so called waveform codecs. These codecs simply analyze the input signal without any knowledge of the human source. Most of these codecs work in time domain, like PCM. These codecs offer high quality speech at a low computational complexity. But if we try to get the bit rate below 8 kbps the quality decreases tremendously. To get the low bit rate with better voice quality another approach is necessary. 
Human source codecs need to know the characteristics of the human voice. When a human voice is encoded, the source codec tries to extract the voice parameters from the voice signal. Then these parameters along with two states of excitation are transmitted. These types of codecs can simply transport the pure informational content of the speech samples and not the voice signal samples itself. The big advantage is that they operate with bit rates as low as 2.4 kbps of course with poor voice quality. 
Hybrid codecs try to combine the advantages of both waveform codecs and source codecs to obtain good voice quality. To get the best voice parameters all possible waveforms are tested and then one with the least error is chosen. This involves a very high computational complexity to analyze every voice frame. The low bit rate codecs usually involve a high computational complexity and a delay while the waveform codecs have the advantage of low delay and excellent voice quality. One example of this is Speex codec.
13 
2.1.1 Speex: 
Unlike many other speech codecs, Speex has the advantage of being capable to be used for packet networks and voice over IP (VoIP) applications also. It uses CELP (code excited linear prediction) coding techniques. Speex is mainly designed for three different sampling rates: 8 kHz, 16 kHz and 32 kHz referred as narrowband, wideband and ultra-wideband respectively. 
It can be configured either for variable bit rate or fixed bit rate. The variable bit-rate (VBR) allows a codec to change its bit-rate dynamically to adapt to the "difficulty" of the audio being encoded. Sounds like vowels and high energy transients require a large number of bits to achieve good quality, while fricatives (s, f sounds) can be coded adequately with less number of bits. With this VBR we can achieve lower bit-rate for the same quality, or a better quality for a certain bit-rate. 
Despite its advantages VBR has two main drawbacks: first, by only specifying quality, there's no guaranty about the final average bit-rate, second, for some real-time applications like voice over IP (VoIP), the maximum bit-rate must be low enough for the communication channel. 
Speex has VAD (Voice activity detection) feature. When enabled the VAD detects whether the audio being encoded is speech or silence/background noise. VAD is always implicitly activated when encoded in VBR, so the option is only useful in non-VBR operation. In this case, Speex detects non-speech periods and encode them with just enough bits to reproduce the background noise. This is called "Comfort noise generation" (CNG). 
Thus, Speex compression algorithm is used for the proposed model which compresses 20ms voice data at a time, sampled at 8khz and results in compressed data size of 20 byte in case of 5.3kbps rate and 24 byte in case of 6.3kbps rate. 
Now the compressed voice data is integrated into a voice packet. This voice packet is basically a ZigBee network packet which contain voice packet as data payload to send to the receiver. The packet is sent to the ZigBee module over UART. The ZigBee network layer utilizes the coordinators, routers and end devices. When the receiver receives the packet, the packet goes through the reverse process for playback of voice.
14 
2.1.2 Analysis of node data rate: 
When UART as interface between Sensor Board (DSP) and RF board(ZigBee) 
Baud Rate: 115200 bps 
Data Rate of Transceiver: 250kbps 
UART transmit (Sensor to RF Board) time (160 bytes): 32ms (approx.) 
Over the air Transmit time/bit: 4us (approx.) 
For a single packet: 6.4 ms approx. 
So, ideal time for transmission of a single packet is ~40ms. 
Considering the total packet size including overhead to be 200 bytes 
Data Transmission Rate = Total packets size (in bits) / Total Time taken 
Thus achieving a data transmission rate of ~40kbps, which is the actual available data rate excluding headers in ZigBee network. 
2.2 ZIGBEE NETWORK 
ZigBee is a WPAN (Wireless Personal Area Network) protocol which defines the higher layers of the protocol stack. It is built over the IEEE 802.15.4 WPAN standard. IEEE 802.15.4 defines only lower layers (PHY and MAC) of the protocol stack. 
2.2.1 Nodes in ZigBee Network: 
Two types of devices can participate in an IEEE 802.15.4 network: 
 Full-function device (FFD) 
 Reduced-function device (RFD). 
The FFD can operate in three modes serving as a PAN coordinator, a coordinator, or an end device. An FFD can talk to RFDs or other FFDs, while an RFD can talk only to an FFD. 
An RFD is intended for applications that are extremely simple, such as a light switch or a passive infrared sensor as an end device; they do not have the need to send large amounts of data and may only associate with a single FFD at a time. Consequently, the RFD can be implemented using minimal resources and memory capacity. 
Every node in a ZigBee network is one of three types: a ZigBee Coordinator (ZC), a ZigBee Router (ZR), or a ZigBee End-Device (ZED). In IEEE 802.15.4-speak, both ZCs and ZRs are full-function devices, and a ZED is a reduced-function device:
15 
Device Name Description Coordinator  Create the Network  Accept new element into the network  Participate the message routing  Participate self-healing when link broke  Mains powered 
Router 
 Accept new element into the network 
 Participate the message routing 
 Participate self-healing when kink broke 
 Mains Powered End device  Only communicate with direct parent  Does not participate with message routing  Cannot adopt new element into the network  Can be battery powered and go to sleep mode periodically 
Table 2: Nodes in ZigBee Network 
2.2.2 ZigBee PANs: 
ZigBee nodes can only send data requests to other nodes on the same network. A single ZigBee network is called a Personal Area Network (PAN). 
ZigBee PANs are formed by ZigBee Coordinators. Only ZigBee Coordinators (ZCs) may form a PAN. The other ZigBee node types, ZigBee Routers (ZRs) and ZigBee End-Devices (ZEDs) may join a network, but cannot form a PAN alone. 
2.2.3 ZigBee Channels: 
The 2.4 GHz band is a worldwide unlicensed portion of the RF spectrum for use by many radio products like Bluetooth, WiFi™, Microwaves and others. This band is also known as the ISM (Industrial, Scientific, and Medical) band. ZigBee uses the same channel set as specified in 802.15.4. 
In the 2.4 GHz band, these channels are numbered 11 through 26. Channel numbers 0 through 10 are defined by the sub-1 GHz 802.15.4 radios, but ZigBee does not run on the sub-1 GHz radios. Channels are just a portion of the RF spectrum. In the case of 802.15.4, each of these channels is separated by 5 MHz in the 2.4 GHz band.
16 
802.15.4 uses Direct Sequence Spread Spectrum (DSSS) to spread the packets into symbols and reassemble them on the other end, verifying that the data was decoded correctly through use of a 16-bit CRC. Due to the robust nature of O-QPSK and DSSS, 802.15.4 radios are very robust, even in a noisy RF environment. 
2.2.4 ZigBee PAN IDs: 
ZigBee Personal Area Network identifiers (or PAN IDs) are used to logically separate a collection of ZigBee nodes from other ZigBee nodes in the same vicinity or on the same physical channel. This allows network A and network B to exist in close proximity without interfering with each other, other than consuming over-the-air bandwidth that they both share. 
ZigBee PAN IDs are 16-bit numbers that range from 0x0000 to 0x3fff. Note this is different than the 802.15.4 specification, which allows PAN IDs from 0x0000 to 0xfffe. 
A device is only allowed to join one PAN at a time. When PAN is configured as 0xffff, the device will join/create random PAN. 
2.2.5 The Network Address: 
The network address, also called NwkAddr, short address, or node address, is a 16-bit number used to uniquely identify a particular node on a ZigBee network. 
The ZigBee Coordinator is always NwkAddr 0x0000. Two ZigBee coordinators can exist on the same channel with NwkAddr 0x0000 because of their different PAN IDs. 
2.2.6 MAC Addresses: 
The MAC address, also called IEEE address, long address, or extended address, is a 64bit number that uniquely identifies a board from all other ZigBee boards in the world. 
The 64-bit MAC addresses have no direct relationship to the 16-bit NwkAddr. If a node leaves one ZigBee network and joins another, its MAC address will remain the same, but the NwkAddr will likely change.
17 
2.2.7 Sending and Receiving Data in a Zigbee network: 
Different message sending methods in ZigBee are: 
 Unicast with end-to-end acknowledgment 
 Unicast without end-to-end acknowledgment 
 Broadcast 
 Groupcast/Multicast 
Unicasts are transmitted from one node to exactly one other node. Unless the nodes are neighbours (within radio range of each other), route discovery takes place the first time these nodes speak together. If end-to-end is acknowledged, the unicast will be retried up to three times, perhaps even initiating a new route discovery if the old route is broken. 
A broadcast is used to send a data request from one node to the entire ZigBee network, at least within a given radius. 
Broadcasts are used by some underlying ZigBee management functions, such as route discovery or NWK_addr_req, and may be also used by applications. 
 Unlike unicasts, broadcasts have no acknowledgment mechanism. 
 Broadcasts don't need specific commissioning. There is no "binding" to a broadcast destination address. A node simply broadcasts to a specified radius. The default radius for a broadcast spans the entire network. 
2.2.8 Addressing Within the Node: 
ZigBee goes beyond a networking protocol and also offers application-level compatibility. To achieve this, ZigBee contains a variety of concepts: endpoints, clusters, command, attributes, and profiles. 
Addressing within ZigBee includes all of the following components: 
 PAN ID (MAC) 
 NwkAddr (NWK) 
 Endpoint (APS) 
 Profile ID (APS) 
 Cluster (APS) 
 Command and/or attribute (ZCL)
18 
2.2.8.1 Endpoints: 
Endpoints are defined within each node. Endpoints serve three purposes in ZigBee: 
 Endpoints allow for different application profiles to exist within each node 
 Endpoints allow for separate control points to exist within each node 
 Endpoints allow for separate devices to exist within each node 
Endpoints, identified by a number between 1 and 240, define each application running in a ZigBee node (where, a single ZigBee node can run multiple applications). 
A node may contain any number of endpoints (up to 240), with any set of endpoint identifiers. For example, a single node might contain just one endpoint, numbered 55. Or a node might contain 20 endpoints, numbered 1 through 10 and 201 through 210. 
Hence endpoints can be viewed as virtual wires connecting applications. Endpoints allow for separate profiles, devices, and control points to exist within a single node. 
2.2.8.2 Clusters: 
Clusters, defined by a 16-bit identifier, are application objects. While the NwkAddr and endpoint are addressing concepts, the cluster defines application meaning. 
 Clusters encapsulate both commands and data. 
 Clusters have direction. In the Simple Descriptor which describes an endpoint, a cluster is listed as either input or output. This is used only for the purposes of service discovery. 
Clusters contain both code (commands) and data (attributes). Commands cause action on a cluster while attributes keep track of the current state of that cluster. 
 Commands: Commands are identified by an 8-bit number, and are either cluster- specific, or cross-cluster. Cluster-specific commands depend on the cluster number, and generally start at 0x00. 
 Attributes: Attributes store the current "state" of a given cluster. Collectively, a set of attributes on all clusters supported by a device define the state of that device. There are generic ZCL commands to read and write attributes on any given cluster.
19 
ZIGBEE STACK ARCHITECTURE 
Figure 1: ZigBee Stack Architecture 
2.2.9 ZigBee Application Support Sublayer (APS): 
The Application Support Sublayer, or APS, sits above the NWK layer, and is the layer in ZigBee which understands applications. The APS frame over-the-air includes endpoints, clusters, profile IDs, and even groups. 
APS is responsible for the following activities: 
 Filtering out packets for non-registered endpoints, or profiles that don't match 
 Generating end-to-end acknowledgment with retries to maximise the chance of successful transmission and to inform the sender whether or not the packet was delivered. 
 Maintaining the local binding table 
 Maintaining the local groups table 
 Maintaining the local address map of a 64-bit MAC address with a ZigBee 16-bit NwkAddr.
20 
2.2.9.1 APS Acknowledgements:: 
While the MAC layer provides per-hop acknowledgments, the APS layer is what provides end-to-end acknowledgments, also called ACKs 
Figure 2: APS end-to-end acknowledgements 
2.2.9.2 Application Profiles: 
Every data request in ZigBee is sent (and received) on an Application Profile. Application Profile IDs are 16-bit numbers and range from 0x0000 to 0x7fff for public profiles and 0xbf00 to 0xffff for manufacturer-specific profiles. 
A profile is a domain space of related applications and devices. Public profiles are those specified by the ZigBee Alliance (as opposed to private profiles specified by individual OEMs). 
Any number of Application Profiles, both public and manufacturer-specific, may exist in a single ZigBee network. In fact, any number of profiles may exist in a single node on the network, separated on different endpoints. 
2.2.9.3 Device Ids: Every endpoint includes a profile identifier and a device identifier. A device is a physical thing like a light, temperature sensor, thermostat etc. ZigBee Device IDs range from 0x0000 to 0xffff. 
Device IDs serve two purposes: 
 To allow human-readable displays (your PC, the TV, etc.) to show a proper icon for the device in question. 
 To allow ZigBee commissioning tools to be more intelligent.
21 
2.2.9.3 The Simple Descriptor: 
The simple descriptor ties all the endpoint information, which defines an application, together in one place. The simple descriptor defines the fields: an endpoint ID, a profile ID, cluster IDs, and a device ID. 
The simple descriptor of any endpoint can be retrieved over-the-air when performing service discovery. 
The simple descriptor does not list the commands and/or attributes available on any given cluster. By asking for the simple descriptor, any device in the network can determine which clusters are supported by any other device, and can then make an informed decision about optional functionality. 
There are both input and output cluster lists in the simple descriptor. This is how ZigBee determines which devices match. If one side has an output cluster (say a dimmer switch) and the other side has the same cluster as an input cluster (say, a dimming light), then they match. Any overlap indicates a match, so if an application is looking for a particular cluster, it can send a "simplified" simple descriptor to match just that one cluster. 
2.2.10 Zigbee network services: 
ZigBee contains two sets of services for network commissioning and maintenance: 
 The ZigBee Device Object (together with the ZigBee Device Profile) 
 The ZigBee Cluster Library 
ZigBee Device Object is a specialized form of application object (with profile ID 0x0000) which each node must have. 
2.2.10.1 ZigBee Device Profile services include the following categories: 
 Device discovery services 
 Service discovery services 
 Binding services 
 Management services
22 
Device Discovery involves interrogating a remote node for address information. The retrieved information can be either:  the MAC (IEEE) address of the node with a given network address  the network address of the node with a given MAC address. Service discovery involves interrogating a remote node for information about its capabilities. This information is stored in a number of descriptors on the remote node, and includes:  The device type and capabilities of the node (Node Descriptor)  The power characteristics of the node (Node Power Descriptor)  Information about each application running on the node (Simple Descriptor) Requests for these descriptors are made by a device during its configuration and integration into a ZigBee network. ZigBee performs service discovery based on profile IDs and cluster IDs, not device IDs. 
Binding provides a mechanism for attaching an endpoint on one node to one or more endpoints on another node. Binding can even be destined for groups of nodes. Each binding table entry stores the following information: 
 Source endpoint 
 the short (16-bit NwkAddr) and long (IEEE) address of a node 
 Cluster ID Binding, coupled with the over-the-air ZDP binding commands, allows any endpoint on any node to be connected easily with any endpoint on any other node. Management services provide the ability to retrieve management information from the devices, including network discovery results, routing table contents, link quality to neighbour nodes, and binding table contents.
23 
3. HARDWARE 
Figure 3: Block diagram of the overall system 
The stereo codec, AIC3204 is used for capturing, sampling the speech signal and converting the samples back into analog signal. The sampled speech signal is compressed using Speex compressing algorithm which is ported to DSP platform TMS320C5505. This compressed data is further packetized using the ZigBee stack implemented on micro-controller MSP430F5437. The ZigBee packets are transmitted using RF transceiver CC2520. While reception the received signal is depacketized, decompressed and fed into speaker.
24 
3.1 ezDSP STICK: 
Figure 4: TMS320C5505 ezDSP STICK 
The end device consists of sensor board using TI DSP (TMS320C5505) processor of C55x series and AIC3204 stereo codec. TMS320C5505 16-bit DSP is a low power, Fixed point DSP working at 100 MHz processing speed and is capable of executing some DSP algorithms as well as some of the voice compression or decompression algorithms. The DSP is also rich in peripherals like DMA controller and serial interfaces like SPI, UART, I2S, I2C. It is therefore, possible to implement several interfaces in order to connect various ZigBee devices. This makes it possible to evaluate different components. 
The stereo codec (AIC3204), a low power Codec from TI is used for capturing, sampling the audio signal and converting the samples back into analog audio. It connects to the TI C5505 DSP using I2C for configuration & I2S for data communication. 
The UART connections required for interaction with ZigBee board is obtained using an expansion connector connected to the end of the board.
25 
Figure 5: Expansion connector for eZDSP Stick 
Figure 6: Board with expansion connector indicating connections
26 
3.2 ProFLEX01-R2 MODULE: 
The ZigBee modules used for RF transmission and reception are PROFLEX01- R2 module 
by LS Research. 
Figure 7: PROFLEX01-R2 development board 
The ProFLEX01-R2 module is a high performance 2.4GHz IEEE 802.15.4 radio (CC2520 & 
CC2591) and microcontroller (MSP430F5437A) in a cost effective, pre-certified footprint. 
The microcontroller is connected to CC2520 via serial interface. The board comes preloaded 
with TI MAC stack and we have implemented TI Z-Stack 2.5.1 to develop our application. 
The board can be connected to an external PC/Microcontroller for communication via the 
UART interface of MSP430F5437A. The programming software used is IAR Embedded 
Workbench compatible with TI Z-Stack 2.5.1.
27 
Figure 8: ProFLEX01-R2 Module Block Diagram 
The important features of the board are: 
 100mW output power 
 Long range: 4000 feet 
 Integrated PCB F antenna or U.FL connector for external antenna 
 Worldwide acceptance: FCC, IC and CE 
 Powerful Texas Instruments 256k MSP430 with 802.15.4 MAC or ZigBee Stack 
 LSR serial interface based on 802.15.4 MAC 
 Low power operation  RoHS compliant 
Figure 9: Programming the ProFLEX Module using MSP FET430UIF JTAG Debugger
28 
SOFTWARE IMPLEMENTATION 
4.1 TOOLS USED: 
IAR Embedded Work bench - This tool is a complete IDE for compiling, debugging and programming a RF board which has MSP430 controller. We customize & build z-stack as per our RF board and develop a user application. 
Code Composer Studio (CCS) - This tool is a complete IDE for compiling, debugging and programming Sensor board which has TI C5505 DSP controller. We develop a user application to capture voice, compress it and transfer to RF board. 
Z-Stack - Z-Stack is a ZigBee compliant protocol stack for IEEE 802.15.4 products. The Stack is developed for TI ultra low power microcontrollers and RF transceivers. The ZigBee- stack architecture shown in Fig.6 includes a number of layered components including the IEEE 802.15.4 Physical (PHY) layer, Medium Access Control (MAC) layer, and the ZigBee Network (NWK) layer and Application layer. Each component provides an application with its own set of services and capabilities. 
ZigBee Sniffer tool (WiSens) is used for observing the packet being transmitted and received by the devices. 
MSP FET430 UIF JTAG Debugger is used for programming and debugging ProFLEX01- R2 Modules through 14pin JTAG interface. 
The implementation of the project broadly comprises of 2 parts: 
 Capturing voice and compressing it on DSP. 
 Transmitting the compressed data over ZigBee, 
This is followed by reception and decompression on the receiver side.
29 
4.2 SPEECH COMPRESSION: 
4.2.1 SPEEX: 
Speex is open-source software and is available for download on www.xiph.org.The list of files to be included in the CCS project is 
Source files 
Header files bits.c arch.h 
cb_search.c 
cb_search.h exc_10_16.c config.h 
exc_10_32.c 
filters.h exc_20_32.c fixed_generic.h 
exc_5_256.c 
lpc.h exc_5_64.c lsp.h 
exc_8_128.c 
ltp.h filters.c modes.h 
gain_table.c 
nb_celp.h gain_table_lbr.c os_support.h 
lpc.c 
os_support_custom.h lsp.c quant_lsp.h 
lsp_tables_nb.c 
sb_celp.h ltp.c speex/speex_bits.h 
modes.c 
speex/speex_buffer.h nb_celp.c speex/speex_callbacks.h 
quant_lsp.c 
speex/speex_echo.h sb_celp.c speex/speex_header.h 
speex.c 
speex/speex_jitter.h speex_callbacks.c speex/speex_preprocess.h 
vbr.c 
speex/speex_resampler.h vq.c speex/speex_stereo.h 
window.c 
speex/speex_types.h testenc_TI_c5x.c speex/speex.h 
Table 3: List of source and header files of Speex that need to be included in the project
30 
The example project “testencTIc55x.c” available for TI-C5xx for encoding speech in the wav format is modified to work in real-time conditions. 
For this, speech from the mic is recorded every 20 ms and is provided for processing.20 ms of speech sampled at 8 kHz accounts to 160 bytes of data, described as 1 frame. Each frame is encoded using encoder state “st”. The compressed data accounts to 20 bytes per frame. 
Before recording speech from mic, initialisation of the codec (AIC3204) is to be done. It is done using aic3204.c. The corresponding header file aic3204.h is also to be included. 
Parameters set during Speex compression include Speex_quality set to 4, complexity set to 1. 
In loopback mode, the compressed data is decompressed using the decoder state “dec” on the same device. The decoded data is sent to HP_OUT and is heard through the headphones connected to this port. 
4.2.2 DMA 
The quality of the decoded speech was found to be below par from expected.This is due to the delay in the processing during compression. This is countered by using DMA to transfer the data to and from the peripherals while the processor is entirely dedicated for processing the data. 
The TMS320C55x™ DSP Chip Support Library (CSL) which provides C-program functions to configure and control on-chip peripherals, is used to configure DMA.DMA is used in Interrupt mode i.e. DMA module generates an interrupt at the completion of specified transfer. 
The test code of csl_dma_IntcExample.c, which tests the basic working of the DMA module in interrupt mode, is modified to suit the present application. The transfer type is modified to CSL_DMA_TRANSFER_IO_MEMORY since I/O peripherals are being read from or written to. Auto reload mode is enabled which continuously reads the peripherals so that DMA need not be configured each time. The source address for the dma_receive function is set to 2828h, which is the address of the I2S register, I2SRXLT0.This register stores the data received from AIC3204 codec i.e. digital version of speech from mic. The destination address would be a buffer in memory which would be further processed using speex.
31 
Similarly, dma_transmit function has its source address as a buffer in memory with the destination address being 2808h, I2STXLT0. These two functions are included in the “testencTIc55x.c” where encoding and decoding of the data is done. 
In loopback mode, both dma_transmit and dma_receive are implemented on the same device. 
4.2.3 UART 
In the transmission mode, the compressed data is transmitted further through UART.UART is again configured in DMA mode using CSL. csl_uartDmaExample.c is modified and is included in “testencTIc55x.c”, where DMA transfer and encoding has been done so far. 
The baud rate of UART is set at 115200 bps and word length of 8 is used with no start and stop bits. The source address of UART_transmit function is cbits, which temporarily stores the encoded data and the destination address is (hUart->uartregs->THR), which is transmit buffer of UART. Similarly,the source address of UART_Receive is (hUart->uartregs->RBR), which is receive buffer of UART and the destination address is a buffer in memory of the received device. The encoded data is present in this buffer which is further decoded and sent to HP_OUT and played through headphones. 
The program “testencTIc55x.c” with all the above mentioned modifications is included in Appendix A. 
NOTE : 
 While using aic3204.c(present in usbstk5505_v2 files) and codes of CSL(present in c55xx_csl/ccs_v4.0_examples), usbstk5505bsl.lib and cslVC5505.lib are to be built in the workspace and then included in the File Search Path of the main project properties (Properties / C/C++ Build / File Search Path), since all the macros and functions are defined there. 
 Since in this program several codes from Speex, usbstk5505, csl are combined, care is to be taken that all are built using the same memory model. 
 During the implementation of Speex, certain symbols need to be predefined. They are _DEBUG, CONFIG_TI_C55X, HAVE_CONFIG_H.
32 
Initialize AIC3204 codec to 
capture speech from mic 
Transfer this data over 
UART in DMA mode 
Invoke DMA to transfer the 
decoded data to speaker 
Store the data in a buffer 
Receive the data at the other 
end through UART 
Store the encoded data in a 
buffer (memory) 
Encoding one frame of data 
using Speex 
Invoke DMA of DSP to read 
data from I2S peripheral 
Read the data from memory 
Decode the compressed data 
Loopback 
Transmission 
Figure 9: Flowchart representing speech compression using Speex
33 
Figure 10: Screenshots indicating project build in Code Composer Studio
34 
4.3 TRANSMISSION OVER ZIGBEE: 
The application is developed using TI Z-Stack version 2.5.1 and implemented over PROFLEX01-R2 module. A network is formed using two Proflex01 R2 modules, one configured as the Coordinator and the other configured as End Device. Our application allows transfer of messages from the Coordinator to the End device and vice versa. 
The data of 20ms frame size, sent over the UART interface by TMS320C5505 is received in the UART receive buffer of MSP430F5437A of Coordinator. In our application we have used USCI_A0 module for UART communication. The data in receive buffer (UCA0RXBUF) is transferred to an array RxString which is further transmitted over the air using CC2520. These message packets are received at the receiver CC2520 (End Device) and transferred to the UART transmit buffer of MSP430F5437A. The data in UART transmit buffer (UCA0TXBUF) is finally sent over UART interface to TMS320C5505 for decoding. 
The various parameters set for setting up of Zigbee Network are: 
PAN ID: 0xFF00 Channel of operation: Channel 11 
The parameters required for setup of network are defined in the file f8wConfig.cfg in the project. 
We have built an application specific project “LSRApp.ewp” in IAR Embedded Workbench using the TI Z- Stack which consists of following source files: 
1. LSRApp.c (LSRApp.h) 
2. OSAL_LSRApp.c
35 
The application instantiates a single Application Object for each ZDO with a unique endpoint defined using the following Simple Descriptor: 
const SimpleDescriptionFormat_t LSRApp_SimpleDesc = 
{ 
LSRAPP_ENDPOINT, // int Endpoint; 
LSRAPP_PROFID, // uint16 AppProfId[2]; 
LSRAPP_DEVICEID, // uint16 AppDeviceId[2]; 
LSRAPP_DEVICE_VERSION, // int AppDevVer:4; 
LSRAPP_FLAGS, // int AppFlags:4; 
LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; 
(cId_t *) NULL, // byte *pAppInClusterList; 
LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; 
(cId_t *)LSRApp_ClusterList // byte *pAppInClusterList; 
}; 
const cId_t LSRApp_ClusterList[LSRAPP_MAX_CLUSTERS] = 
{ 
LSRAPP_CLUSTERID 
}; 
We have used a single cluster id: LSRAPP_CLUSTERID for both sending and receiving the messages from a ZDO. 
The two major functions to be implemented for a task defined for an application object are: 
 Task initialization function: LSRApp_Init() 
 Function to handle task events: LSRApp_ProcessEvent()
36 
4.3.1 LSRApp_Init(): 
The initialization function deals with initialization of variables local to or specific for the corresponding Application Object. 
Here we define the following: 
 task id: LSRApp_TaskId which is set to the task id value assigned by OSAL. 
 Network state: LSRApp_NwkState = DEV_INIT , this indicates that the network state at power-up is “not connected”. 
 Message transaction counter: LSRApp_TransID = 0, keeps track of the no of times message is sent. 
 Here we also define the endpoint description of the application object and register it with the application framework using afRegister( &LSRApp_epDesc ). This allows the AF layer to know how to route incoming packets destined for the profile/endpoint. 
 The application is also registered for the exclusive system service of key press notification. 
 RegisterForKeys( LSRApp_TaskID ) 
 A default destination address is initialized so that messages will be sent as bound messages 
 GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; 
 GenericApp_DstAddr.endPoint = 0; 
 GenericApp_DstAddr.addr.shortAddr = 0; 
 The UART module is configured and the state machine is released. Interrupts to be used in the application are enabled. 
 SFRIE1 |= WDTIE; // Enable WDT interrupt 
 P3SEL |= 0x3C; // P3.4,5 = USCI_A0 TXD/RXD 
 P3DIR |= 0x01; 
 UCA0CTL1 |= UCSWRST; // 8-bit characters 
 UCA0CTL1 = UCSSEL_1; // CLK = ACLK 
 UCA0BR0 = 0x03; // 32k/9600=3.41
37 
 UCA0BR1 = 0x00; 
 UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation 
 UCA0CTL1 &= ~UCSWRST; // Release USCI state machine 
4.3.2 LSRApp_ProcessEvent(): 
This is a callback function to handle task events. 
SYS_EVENT_MSG (0x8000): This is a mandatory event and all the global system messages are sent via the SYS_EVENT_MSG. The task event handler processes the following minimal subset of these global system messages. 
 AF_DATA_CONFIRM_CMD: This is an indication of the over-the-air result for each data request that is successfully initiated by invoking AF_DataRequest(). Since the data request is made with the AF_ACK_REQUEST flag set hence the ZSuccess confirms that the message was successfully received at the final destination. 
 AF_INCOMING_MSG_CMD: This is an indication of an incoming AF message. 
 KEY_CHANGE: This is an indication of a key press action. 
 ZDO_STATE_CHANGE: With the device power up, initially its network state is not connected. The device immediately tries to either join or form the network. The change in network state generates ZDO_STATE_CHANGE sytem event and the device receives notification of the status of the network formation or join. 
 ZDO_CB_MSG: This message is sent to the application for every registered ZDO response message [ZDO_RegisterForZDOMsg()].
38 
4.3.3 Sending Message: 
The program flow for sending a Message over the air is as follows: 
 Address Initialization 
 Register “Service discovery” call back 
 Issue the service discovery operation i.e Match description request 
 Handle the message call back 
 Send the device bind request 
 Send the message via the Af_DataRequest 
 If the return value of AF_DataRequest() = ZSuccess, this signifies that the message has been accepted by the Network Layer which will attempt to send it to the MAC layer which will attempt to send it over-the-air . This results in a “callback” by way of the AF_DATA_CONFIRM_CMD system event message. 
 The AF_DATA_CONFIRM_CMD ultimately generates the "sentStatus = Zsuccess" to indicate message is delivered to the destination address.
39 
With power up, device network state is not 
connected 
Match description request is made 
Call AF_DataRequest() to send the 
message received over UART 
ZDO_STATE_CHANGE 
E 
System Events generated 
KEY_CHANGE User 1 Key is pressed 
ZDO_CB_MSG 
Match description request response 
indicates status of request 
KEY_CHANGE User 2 Key is pressed 
End device Binding request is made 
ZDO_CB_MSG 
Device binding request response 
indicates status of request 
LSRAPP_SEND_MSG_EVT 
If AF_ACK_REQUEST= Zsuccess 
AF_DATA_CONFIRM_CMD 
If SentStatus = Zsuccess 
Message successfully sent over the air 
TRUE 
FALSE 
Figure 11: Flowchart representing sending of message over the air using ZigBee
40 
4.3.4 Receiving Message: 
The program flow for receiving the message is as follows: 
 Address Initialization 
 Register “Service discovery” call back 
 Issue the service discovery operation 
 Handle the message call back 
 Send the bind request 
 Process the incoming message 
The above flow is similar to the program flow for sending message except for the last stage to 
process the incoming message. 
The receiving Application Object is notified about the incoming message by the SYS_EVENT_MSG 
message AF_INCOMING_MSG_CMD. This event generates a call to the function 
LSRApp_MessageMSGCB(MSGpkt). 
Message successfully received over the air 
AF_INCOMING_MSG_CMD 
System Events generated 
Put the data in UART transmit buffer 
Data is sent to the DSP processor for 
decoding and further processing 
Figure 12: Flowchart representing receiving of message over the air using ZigBee
41 
Figure 13: Screenshots indicating Coordinator and End device project build in IAR
42 
4.4 CONCLUSION: 
We have successfully implemented the speech compression and decompression using Speex Codec in the loop back mode with high voice quality.
43 
APPENDIX 
Program code for Speex Compression on TMS320C5505: 
/* Modified from speexlib/testenc.c for Code Composer simulator */ 
#ifdef HAVE_CONFIG_H 
#include "config.h" 
#endif 
#include <stdio.h> 
#include <string.h> 
#include <stdlib.h> 
#include <speex/speex.h> 
#include <speex/speex_callbacks.h> 
#include "arch.h" 
#include "usbstk5505.h" 
#include "usbstk5505_i2s.h" 
#include "csl_i2s.h" 
#include "csl_intc.h" 
#include "csl_dma.h" 
#include "csl_uart.h" 
#include "csl_uartAux.h" 
#undef DECODE_ONLY 
#define CHECK_RESULT /* Compares original file with encoded/decoder file */ 
#define TESTENC_BYTES_PER_FRAME 20 /* 8kbps */ 
#define TESTENC_QUALITY 4 /* 8kbps */ 
//#define TESTENC_BYTES_PER_FRAME 28 /* 11kbps */ 
//#define TESTENC_QUALITY 5 /* 11 kbps */ 
/* For narrowband, QUALITY maps to these bit rates (see modes.c, manual.pdf) 
* {1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7} 
* 0 -> 2150 
* 1 -> 3950 
* 2 -> 5950 
* 3 -> 8000 
* 4 -> 8000 
* 5 -> 11000 
* 6 -> 11000 
* 7 -> 15000
44 
* 8 -> 15000 
* 9 -> 18200 
*10 -> 26400 */ 
#define FRAME_SIZE 160 
#define CSL_DMA_BUFFER_SIZE 160 
extern void AIC3204_init( ); 
short out_short[FRAME_SIZE]; 
char cbits[TESTENC_BYTES_PER_FRAME/2 + 2]; // temp store for encoded data 
//int busyEncoding; 
int i_loop,j_loop; 
static int count ; 
#ifdef FIXED_DEBUG 
extern long long spx_mips; 
#endif 
//#include <math.h> 
#ifdef MANUAL_ALLOC 
/* Take all Speex space from this private heap */ 
/* This is useful for multichannel applications */ 
#pragma DATA_SECTION(spxHeap, ".myheap"); 
static char spxHeap[SPEEX_PERSIST_STACK_SIZE]; 
#pragma DATA_SECTION(spxScratch, ".myheap"); 
static char spxScratch[SPEEX_SCRATCH_STACK_SIZE]; 
char *spxGlobalHeapPtr, *spxGlobalHeapEnd; 
char *spxGlobalScratchPtr, *spxGlobalScratchEnd; 
#endif 
//from try_i2sdma_regs.c 
#define CSL_TEST_FAILED (1) 
#define CSL_TEST_PASSED (0) 
#define CSL_DMA0_CH0 (0) 
//Int16 count=0; 
volatile Int16 PaSs_StAtE = 0x0001; // Init to 1. Reset to 0 at any monitored execution error. 
volatile Int16 PaSs = 0x0000; 
Int16 ReadyToEncode=0; 
Int16 tx_done=0; 
short RcvL1[FRAME_SIZE]; 
//from uart.c 
#define CSL_TEST_FAILED (-1) 
#define NO_OF_CHAR_TO_READ TESTENC_BYTES_PER_FRAME 
#define NO_OF_CHAR_TO_WRITE TESTENC_BYTES_PER_FRAME 
#define CSL_UART_WRBUF_SIZE (NO_OF_CHAR_TO_WRITE*4) 
#define CSL_UART_RDBUF_SIZE (NO_OF_CHAR_TO_READ*4)
45 
#define CSL_PLL_DIV_000 (0) 
#define CSL_PLL_DIV_001 (1u) 
#define CSL_PLL_DIV_002 (2u) 
#define CSL_PLL_DIV_003 (3u) 
#define CSL_PLL_DIV_004 (4u) 
#define CSL_PLL_DIV_005 (5u) 
#define CSL_PLL_DIV_006 (6u) 
#define CSL_PLL_DIV_007 (7u) 
#define CSL_PLL_CLOCKIN (32768u) 
/* Global data definition */ 
/* UART setup structure */ 
CSL_UartSetup mySetup = 
{ 
100000000, /* Input clock freq in MHz */ 
115200, /* baud rate */ 
/* word length of 8 */ 
CSL_UART_WORD8, 
/* To generate 1 stop bit */ 
0, 
/* Disable the parity */ 
CSL_UART_DISABLE_PARITY, 
/* enable trigger 14 fifo */ 
CSL_UART_FIFO_DMA1_ENABLE_TRIG14, 
/* Loop Back enable */ 
CSL_UART_NO_LOOPBACK, 
/* No auto flow control*/ 
CSL_UART_NO_AFE , 
/* No RTS */ 
CSL_UART_NO_RTS , 
}; 
/** 
* brief Function to calculate the system clock 
* param none 
* return System clock value in Hz 
*/ 
Uint32 getSysClk(void); 
/* CSL UART object */ 
CSL_UartObj uartObj; 
/* CSL DMA data structures used for UART data transfers */ 
CSL_DMA_Handle dmaWrHandle; 
CSL_DMA_Handle dmaRdHandle; 
CSL_DMA_Config dmaConfig_uart; 
CSL_DMA_Config dmaConfig_uart2;
46 
CSL_DMAChanNum chanNum3; 
CSL_DMAChanNum chanNum4; 
CSL_DMA_ChannelObj dmaWrChanObj; 
CSL_DMA_ChannelObj dmaRdChanObj; 
char guartDmaReadBuf[CSL_UART_RDBUF_SIZE]; 
/* Reference the start of the interrupt vector table */ 
extern void VECSTART(void); 
/* Protype declaration for ISR function */ 
interrupt void dma_isr(void); 
CSL_DMA_Handle dmaHandle; 
CSL_DMA_Config dmaConfig; 
CSL_DMA_Config getdmaConfig; 
CSL_DMA_ChannelObj dmaObj; 
CSL_DMA_Handle dmaHandle2; 
CSL_DMA_Config dmaConfig2; 
CSL_DMA_Config getdmaConfig2; 
CSL_DMA_ChannelObj dmaObj2; 
CSL_DMA_Handle dmaLeftRxHandle; 
CSL_DMA_Handle dmaLeftTxHandle; 
Uint16 dmaSRCBuff[CSL_DMA_BUFFER_SIZE]; 
Uint16 dmaDESTBuff[CSL_DMA_BUFFER_SIZE]; 
void dma_func() 
{ 
CSL_Status status; 
Uint16 i; 
Uint16 chanNumber; 
Uint16 chanNumber2; 
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) 
dmaConfig.pingPongMode = CSL_DMA_PING_PONG_DISABLE; 
#endif 
dmaConfig.autoMode = CSL_DMA_AUTORELOAD_ENABLE; 
dmaConfig.burstLen = CSL_DMA_TXBURST_1WORD; 
dmaConfig.trigger = CSL_DMA_SOFTWARE_TRIGGER; 
dmaConfig.dmaEvt = CSL_DMA_EVT_NONE; 
dmaConfig.dmaInt = CSL_DMA_INTERRUPT_ENABLE; 
dmaConfig.chanDir = CSL_DMA_READ; 
dmaConfig.trfType = CSL_DMA_TRANSFER_IO_MEMORY; 
dmaConfig.dataLen = CSL_DMA_BUFFER_SIZE * 2; 
dmaConfig.srcAddr = (Uint32)(0x00002828); 
dmaConfig.destAddr = (Uint32)RcvL1;
47 
IRQ_globalDisable(); 
IRQ_clearAll(); 
IRQ_disableAll(); 
IRQ_setVecs((Uint32)&VECSTART); 
IRQ_clear(DMA_EVENT); 
IRQ_plug (DMA_EVENT, &dma_isr); 
IRQ_enable(DMA_EVENT); 
IRQ_globalEnable(); 
status = DMA_init(); 
if (status != CSL_SOK) 
{ 
printf("DMA_init() Failed n"); 
/////INSTRUMENTATION FOR BATCH TESTING -- Part 2 -- 
///// Reseting PaSs_StAtE to 0 if error detected here. 
PaSs_StAtE = 0x0000; // Was intialized to 1 at declaration. 
///// 
} 
chanNumber=0; 
count = 0; 
// printf("n Test for DMA Channel No : %d t", chanNumber); 
dmaHandle = DMA_open((CSL_DMAChanNum)chanNumber,&dmaObj, &status); 
if (dmaHandle == NULL) 
{ 
printf("DMA_open() Failed n"); 
//break; 
} 
status = DMA_config(dmaHandle, &dmaConfig); 
if (status != CSL_SOK) 
{ 
printf("DMA_config() Failed n"); 
//break; 
} 
status = DMA_start(dmaHandle); 
if (status != CSL_SOK) 
{ 
printf("DMA_start() Failed n"); 
//break; 
} 
while(count != 1);
48 
while(count == 0); 
} 
void dma_func2() 
{ 
CSL_Status status; 
Uint16 i; 
Uint16 chanNumber2; 
tx_done=0; 
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) 
dmaConfig2.pingPongMode = CSL_DMA_PING_PONG_DISABLE; 
#endif 
dmaConfig2.autoMode = CSL_DMA_AUTORELOAD_ENABLE; 
dmaConfig2.burstLen = CSL_DMA_TXBURST_1WORD; 
dmaConfig2.trigger = CSL_DMA_SOFTWARE_TRIGGER; 
dmaConfig2.dmaEvt = CSL_DMA_EVT_NONE; 
dmaConfig2.dmaInt = CSL_DMA_INTERRUPT_ENABLE; 
dmaConfig2.chanDir = CSL_DMA_WRITE; 
dmaConfig2.trfType = CSL_DMA_TRANSFER_IO_MEMORY; 
dmaConfig2.dataLen = CSL_DMA_BUFFER_SIZE * 2; 
dmaConfig2.srcAddr = (Uint32) out_short; 
dmaConfig2.destAddr = (Uint32)(0x00002808); 
IRQ_globalDisable(); 
IRQ_clearAll(); 
IRQ_disableAll(); 
IRQ_setVecs((Uint32)&VECSTART); 
IRQ_clear(DMA_EVENT); 
IRQ_plug (DMA_EVENT, &dma_isr); 
IRQ_enable(DMA_EVENT); 
IRQ_globalEnable(); 
chanNumber2=1; 
count = 0; 
// printf("n Test for DMA Channel No : %d t", chanNumber); 
dmaHandle2 = DMA_open((CSL_DMAChanNum)chanNumber2,&dmaObj2, &status); 
if (dmaHandle2 == NULL) 
{ 
printf("DMA_open() Failed n"); 
//break; 
}
49 
status = DMA_config(dmaHandle2, &dmaConfig2); 
if (status != CSL_SOK) 
{ 
printf("DMA_config() Failed n"); 
//break; 
} 
status = DMA_start(dmaHandle2); 
if (status != CSL_SOK) 
{ 
printf("DMA_start() Failed n"); 
//break; 
} 
while(count == 0); 
} //end of dma_func2 
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) 
Uint32 getSysClk(void) 
{ 
Bool pllRDBypass; 
Bool pllOutDiv; 
Uint32 sysClk; 
Uint16 pllVP; 
Uint16 pllVS; 
Uint16 pllRD; 
Uint16 pllVO; 
pllVP = CSL_FEXT(CSL_SYSCTRL_REGS->CGCR1, SYS_CGCR1_VP); 
pllVS = CSL_FEXT(CSL_SYSCTRL_REGS->CGCR1, SYS_CGCR1_VS); 
pllRD = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDRATIO); 
pllVO = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OD); 
pllRDBypass = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDBYPASS); 
pllOutDiv = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OUTDIVEN); 
sysClk = CSL_PLL_CLOCKIN; 
if (0 == pllRDBypass) 
{ 
sysClk = sysClk/(pllRD + 4); 
}
50 
sysClk = (sysClk * ((pllVP << 2) + pllVS + 4)); 
if (1 == pllOutDiv) 
{ 
sysClk = sysClk/(pllVO + 1); 
} 
/* Return the value of system clock in KHz */ 
return(sysClk); 
} 
#else 
Uint32 getSysClk(void) 
{ 
Bool pllRDBypass; 
Bool pllOutDiv; 
Bool pllOutDiv2; 
Uint32 sysClk; 
Uint16 pllVP; 
Uint16 pllVS; 
Uint16 pllRD; 
Uint16 pllVO; 
Uint16 pllDivider; 
Uint32 pllMultiplier; 
pllVP = CSL_FEXT(CSL_SYSCTRL_REGS->CGCR1, SYS_CGCR1_MH); 
pllVS = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_ML); 
pllRD = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDRATIO); 
pllVO = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_ODRATIO); 
pllRDBypass = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDBYPASS); 
pllOutDiv = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OUTDIVEN); 
pllOutDiv2 = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OUTDIV2BYPASS); 
pllDivider = ((pllOutDiv2) | (pllOutDiv << 1) | (pllRDBypass << 2)); 
pllMultiplier = ((Uint32)CSL_PLL_CLOCKIN * ((pllVP << 2) + pllVS + 4)); 
switch(pllDivider) 
{ 
case CSL_PLL_DIV_000: 
case CSL_PLL_DIV_001: 
sysClk = pllMultiplier / (pllRD + 4); 
break;
51 
case CSL_PLL_DIV_002: 
sysClk = pllMultiplier / ((pllRD + 4) * (pllVO + 4) * 2); 
break; 
case CSL_PLL_DIV_003: 
sysClk = pllMultiplier / ((pllRD + 4) * 2); 
break; 
case CSL_PLL_DIV_004: 
case CSL_PLL_DIV_005: 
sysClk = pllMultiplier; 
break; 
case CSL_PLL_DIV_006: 
sysClk = pllMultiplier / ((pllVO + 4) * 2); 
break; 
case CSL_PLL_DIV_007: 
sysClk = pllMultiplier / 2; 
break; 
} 
/* Return the value of system clock in KHz */ 
return(sysClk); 
} 
#endif 
CSL_DMA_Handle CSL_configDmaForUart(CSL_DMA_ChannelObj *dmaChanObj, 
CSL_DMAChanNum chanNum) 
{ 
CSL_DMA_Handle dmaHandle; 
CSL_Status status; 
dmaHandle = NULL; 
/* Open A Dma channel */ 
dmaHandle = DMA_open(chanNum, dmaChanObj, &status); 
if(dmaHandle == NULL) 
{ 
printf("DMA_open Failed!n"); 
} 
/* Configure a Dma channel */ 
status = DMA_config(dmaHandle, &dmaConfig_uart); 
if(status != CSL_SOK) 
{ 
printf("DMA_config Failed!n");
52 
dmaHandle = NULL; 
} 
return(dmaHandle); 
} 
CSL_Status uart_tx_rx(void) 
{ 
CSL_UartHandle hUart; 
CSL_Status status; 
int looper; 
Uint32 sysClk; 
sysClk = getSysClk(); 
mySetup.clkInput = sysClk; 
/* Initialize CSL UART module */ 
status = UART_init(&uartObj,CSL_UART_INST_0,UART_POLLED); 
if(CSL_SOK != status) 
{ 
printf("UART_init failed error code %dn",status); 
return(status); 
} 
else 
{ 
printf("UART_init Successfuln"); 
} 
/* Handle created*/ 
hUart = (CSL_UartHandle)(&uartObj); 
/* Configure the DMA channel for UART transmit */ 
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) 
dmaConfig_uart.pingPongMode = CSL_DMA_PING_PONG_DISABLE; 
#endif 
dmaConfig_uart.autoMode = CSL_DMA_AUTORELOAD_DISABLE; 
dmaConfig_uart.burstLen = CSL_DMA_TXBURST_1WORD; 
dmaConfig_uart.trigger = CSL_DMA_EVENT_TRIGGER; 
dmaConfig_uart.dmaEvt = CSL_DMA_EVT_UART_TX; 
dmaConfig_uart.dmaInt = CSL_DMA_INTERRUPT_DISABLE; 
dmaConfig_uart.chanDir = CSL_DMA_WRITE; 
dmaConfig_uart.trfType = CSL_DMA_TRANSFER_IO_MEMORY; 
dmaConfig_uart.dataLen = CSL_UART_WRBUF_SIZE; 
dmaConfig_uart.srcAddr = (Uint32) cbits; 
dmaConfig_uart.destAddr = (Uint32)&(hUart->uartRegs->THR); 
dmaWrHandle = CSL_configDmaForUart(&dmaWrChanObj, CSL_DMA_CHAN4);
53 
/* Start Dma transfer */ 
status = DMA_start(dmaWrHandle); 
if(status != CSL_SOK) 
{ 
printf("Uart Dma Write Failed!!n"); 
return(status); 
} 
/* Configure UART registers using setup structure */ 
status = UART_setup(hUart,&mySetup); 
if(CSL_SOK != status) 
{ 
printf("UART_setup failed error code %dn",status); 
return status; 
} 
else 
{ 
printf("UART_setup Successfuln"); 
} 
/* Check transfer complete status */ 
while(DMA_getStatus(dmaWrHandle)); 
/* Configure the DMA channel for UART receive */ 
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) 
dmaConfig_uart.pingPongMode = CSL_DMA_PING_PONG_DISABLE; 
#endif 
dmaConfig_uart.autoMode = CSL_DMA_AUTORELOAD_DISABLE; 
dmaConfig_uart.burstLen = CSL_DMA_TXBURST_1WORD; 
dmaConfig_uart.trigger = CSL_DMA_SOFTWARE_TRIGGER; 
dmaConfig_uart.dmaEvt = CSL_DMA_EVT_NONE; 
dmaConfig_uart.dmaInt = CSL_DMA_INTERRUPT_DISABLE; 
dmaConfig_uart.chanDir = CSL_DMA_READ; 
dmaConfig_uart.trfType = CSL_DMA_TRANSFER_IO_MEMORY; 
dmaConfig_uart.dataLen = CSL_UART_RDBUF_SIZE; 
dmaConfig_uart.srcAddr = (Uint32)&(hUart->uartRegs->THR); 
dmaConfig_uart.destAddr = (Uint32)guartDmaReadBuf; 
dmaRdHandle = CSL_configDmaForUart(&dmaRdChanObj,CSL_DMA_CHAN4); 
/* Open A Dma channel */ 
chanNum4=CSL_DMA_CHAN5; 
dmaRdHandle = DMA_open(chanNum4, &dmaRdChanObj, &status); 
if(dmaRdHandle == NULL) 
{ 
printf("DMA_open Failed!n"); 
} 
/* Configure a Dma channel */ 
status = DMA_config(dmaRdHandle, &dmaConfig_uart2);
54 
if(status != CSL_SOK) 
{ 
printf("DMA_config Failed!n"); 
dmaRdHandle = NULL; 
} 
if(dmaRdHandle == NULL) 
{ 
printf("DMA Config for DMA Read Failed!n!"); 
//return(CSL_TEST_FAILED); 
} 
/* Start Dma transfer */ 
status = DMA_start(dmaRdHandle); 
if(status != CSL_SOK) 
{ 
printf("Uart Dma Write Failed!!n"); 
return(status); 
} 
/* Check transfer complete status */ 
while(DMA_getStatus(dmaRdHandle)); 
} 
void main() 
{ 
Uint16 i; 
//Uint16 i_loop; 
int nbChars; 
char cbits[TESTENC_BYTES_PER_FRAME/2 + 2]; // temp store for encoded data 
void *st; 
void *dec; 
SpeexBits bits; 
spx_int32_t tmp; 
unsigned long bitCount=0; 
spx_int32_t skip_group_delay; 
SpeexCallback callback; 
// C54xx defaults to max wait states, even for parts like C5416 with 
// larger internal memory. Need to force the wait state register to zero 
#ifdef CONFIG_TI_C54X 
asm(" STM #0,SWWSR"); 
#endif 
/* 
#ifdef CHECK_RESULT 
sigpow = 0; 
errpow = 0; 
#endif 
*/
55 
#ifdef MANUAL_ALLOC 
spxGlobalHeapPtr = spxHeap; 
spxGlobalHeapEnd = spxHeap + sizeof(spxHeap); 
spxGlobalScratchPtr = spxScratch; 
spxGlobalScratchEnd = spxScratch + sizeof(spxScratch); 
#endif 
st = speex_encoder_init(&speex_nb_mode); 
#ifdef MANUAL_ALLOC 
spxGlobalScratchPtr = spxScratch; // Reuse scratch for decoder 
#endif 
dec = speex_decoder_init(&speex_nb_mode); 
callback.callback_id = SPEEX_INBAND_CHAR; 
callback.func = speex_std_char_handler; 
callback.data = stderr; 
speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); 
callback.callback_id = SPEEX_INBAND_MODE_REQUEST; 
callback.func = speex_std_mode_request_handler; 
callback.data = st; 
speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); 
tmp=0; 
speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp); 
tmp=0; 
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp); 
tmp=TESTENC_QUALITY; 
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp); 
tmp=1; // Lowest 
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp); 
#ifdef DISABLE_HIGHPASS 
// Turn this off if you want to measure SNR (on by default) 
tmp=0; 
speex_encoder_ctl(st, SPEEX_SET_HIGHPASS, &tmp); 
speex_decoder_ctl(dec, SPEEX_SET_HIGHPASS, &tmp); 
#endif 
speex_encoder_ctl(st, SPEEX_GET_LOOKAHEAD, &skip_group_delay); 
speex_decoder_ctl(dec, SPEEX_GET_LOOKAHEAD, &tmp); 
skip_group_delay += tmp; 
fprintf (stderr, "decoder lookahead = %ldn", skip_group_delay); 
AIC3204_init( ); 
speex_bits_init(&bits); 
for(i = 0; i < CSL_DMA_BUFFER_SIZE; i++) 
{
56 
out_short[i]=0; 
} 
while(1) 
{ 
dma_func(); 
//refer speex.h for these functions 
speex_bits_reset(&bits); 
speex_encode_int(st, RcvL1, &bits); 
nbChars = speex_bits_write(&bits, cbits,sizeof(cbits)*BYTES_PER_CHAR) /BYTES_PER_CHAR; 
speex_bits_reset(&bits); 
uart_tx_rx(); 
speex_bits_rewind(&bits); 
//speex_bits_read_from(&bits, cbits,TESTENC_BYTES_PER_FRAME); 
speex_bits_read_from(&bits, guartDmaReadBuf,TESTENC_BYTES_PER_FRAME); 
//printf("%dn",counterDecode++); 
// counterDecode++; 
speex_decode_int(dec, &bits, out_short); 
skip_group_delay = 0; 
count=0; 
dma_func2(); 
}//end of while 
}//end of main 
interrupt void dma_isr(void) 
{ 
int ifrValue; 
ifrValue = CSL_SYSCTRL_REGS->DMAIFR; 
CSL_SYSCTRL_REGS->DMAIFR |= ifrValue; 
//printf("entered dma_isrn"); 
++count; 
}
57 
Program code for transmission and receiving message over ZigBee: 
#include "OSAL.h" 
#include "AF.h" 
#include "ZDApp.h" 
#include "ZDObject.h" 
#include "ZDProfile.h" 
#include "LSRApp.h" 
#include "DebugTrace.h" 
#if !defined( WIN32 ) 
#include "OnBoard.h" 
#endif 
/* HAL */ 
#include "hal_lcd.h" 
#include "hal_led.h" 
#include "hal_key.h" 
#include "hal_uart.h" 
/* RTOS */ 
#if defined( IAR_ARMCM3_LM ) 
#include "RTOS_App.h" 
#endif 
/********************************************************************* 
* GLOBAL VARIABLES 
*/ 
// This list should be filled with Application specific Cluster IDs. 
const cId_t LSRApp_ClusterList[LSRAPP_MAX_CLUSTERS] = 
{ 
LSRAPP_CLUSTERID 
}; 
const SimpleDescriptionFormat_t LSRApp_SimpleDesc = 
{ 
LSRAPP_ENDPOINT, // int Endpoint; 
LSRAPP_PROFID, // uint16 AppProfId[2]; 
LSRAPP_DEVICEID, // uint16 AppDeviceId[2]; 
LSRAPP_DEVICE_VERSION, // int AppDevVer:4; 
LSRAPP_FLAGS, // int AppFlags:4; 
LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; 
(cId_t *)LSRApp_ClusterList, // byte *pAppInClusterList; 
LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; 
(cId_t *)LSRApp_ClusterList // byte *pAppInClusterList; 
}; 
// This is the Endpoint/Interface description. It is defined here, but 
// filled-in in LSRApp_Init(). Another way to go would be to fill
58 
// in the structure here and make it a "const" (in code space). The 
// way it's defined in this sample app it is define in RAM. 
endPointDesc_t LSRApp_epDesc; 
/********************************************************************* 
* LOCAL VARIABLES 
*/ 
byte LSRApp_TaskID; // Task ID for internal task/event processing 
// This variable will be received when 
// LSRApp_Init() is called. 
devStates_t LSRApp_NwkState; 
byte LSRApp_TransID; // This is the unique message ID (counter) 
afAddrType_t LSRApp_DstAddr; 
/********************************************************************* 
* LOCAL FUNCTIONS 
*/ 
static void LSRApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ); 
static void LSRApp_HandleKeys( /*byte shift,*/ byte keys ); 
static void LSRApp_MessageMSGCB( afIncomingMSGPacket_t *pckt ); 
static void LSRApp_SendTheMessage( void ); 
#if defined( IAR_ARMCM3_LM ) 
static void LSRApp_ProcessRtosMessage( void ); 
#endif 
/********************************************************************* 
* PUBLIC FUNCTIONS 
/********************************************************************* 
* @fn LSRApp_Init 
* @brief Initialization function for the Generic App Task. 
* This is called during initialization and should contain 
* any application specific initialization (ie. hardware 
* initialization/setup, table initialization, power up 
* notificaiton ... ). 
* @param task_id - the ID assigned by OSAL. This ID should be 
* used to send messages and set timers. 
* @return none */ 
void LSRApp_Init( uint8 task_id ) 
{ 
LSRApp_TaskID = task_id; 
LSRApp_NwkState = DEV_INIT; 
LSRApp_TransID = 0; 
// Device hardware initialization can be added here or in main() (Zmain.c). 
// If the hardware is application specific - add it here. 
// If the hardware is other parts of the device add it in main(). 
LSRApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; 
LSRApp_DstAddr.endPoint = 0;
59 
LSRApp_DstAddr.addr.shortAddr = 0; 
SFRIE1 |= WDTIE; // Enable WDT interrupt 
P3SEL |= 0x3C; // P3.4,5 = USCI_A0 TXD/RXD 
P3DIR |= 0x01; // P3.0 = CSn OUTPUT DIRECTION 
UCA0CTL1 |= UCSWRST; // 8-bit characters 
UCA0CTL1 = UCSSEL_1; // CLK = ACLK 
UCA0BR0 = 0x03; // 32k/9600=3.41 
UCA0BR1 = 0x00; 
UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation 
UCA0CTL1 &= ~UCSWRST; // Release USCI state machine 
HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); 
HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); 
HalLedSet( HAL_LED_3, HAL_LED_MODE_ON ); 
// Fill out the endpoint description. 
LSRApp_epDesc.endPoint = LSRAPP_ENDPOINT; 
LSRApp_epDesc.task_id = &LSRApp_TaskID; 
LSRApp_epDesc.simpleDesc 
= (SimpleDescriptionFormat_t *)&LSRApp_SimpleDesc; 
LSRApp_epDesc.latencyReq = noLatencyReqs; 
// Register the endpoint description with the AF 
afRegister( &LSRApp_epDesc ); 
// Register for all key events - This app will handle all key events 
RegisterForKeys( LSRApp_TaskID ); 
// Update the display 
#if defined ( LCD_SUPPORTED ) 
HalLcdWriteString( "LSRApp", HAL_LCD_LINE_1 ); 
#endif 
ZDO_RegisterForZDOMsg( LSRApp_TaskID, End_Device_Bind_rsp ); 
ZDO_RegisterForZDOMsg( LSRApp_TaskID, Match_Desc_rsp ); 
#if defined( IAR_ARMCM3_LM ) 
// Register this task with RTOS task initiator 
RTOS_RegisterApp( task_id, LSRAPP_RTOS_MSG_EVT ); 
#endif 
} 
/********************************************************************* 
* @fn LSRApp_ProcessEvent 
* @brief Generic Application Task event processor. This function 
* is called to process all events for the task. Events 
* include timers, messages and any other user defined events. 
* @param task_id - The OSAL assigned task ID. 
* @param events - events to process. This is a bit map and can 
* contain more than one event. 
* @return none */
60 
uint16 LSRApp_ProcessEvent( uint8 task_id, uint16 events ) 
{ 
afIncomingMSGPacket_t *MSGpkt; 
afDataConfirm_t *afDataConfirm; 
// Data Confirmation message fields 
byte sentEP; 
ZStatus_t sentStatus; 
byte sentTransID; // This should match the value sent 
(void)task_id; // Intentionally unreferenced parameter 
if ( events & SYS_EVENT_MSG ) 
{ 
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( LSRApp_TaskID ); 
while ( MSGpkt ) 
{ 
switch ( MSGpkt->hdr.event ) 
{ 
case ZDO_CB_MSG: 
LSRApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt ); 
break; 
case KEY_CHANGE: 
LSRApp_HandleKeys( ((keyChange_t *)MSGpkt)->keys ); 
break; 
case AF_DATA_CONFIRM_CMD: 
// This message is received as a confirmation of a data packet sent. 
// The status is of ZStatus_t type [defined in ZComDef.h] 
// The message fields are defined in AF.h 
afDataConfirm = (afDataConfirm_t *)MSGpkt; 
sentEP = afDataConfirm->endpoint; 
sentStatus = afDataConfirm->hdr.status; 
sentTransID = afDataConfirm->transID; 
(void)sentEP; 
(void)sentTransID; 
// Action taken when confirmation is received. 
if ( sentStatus != ZSuccess ) 
{ 
// The data wasn't delivered -- Do something 
HalLedSet(HAL_LED_2, HAL_LED_MODE_FLASH); //BLINK red led 
} 
break; 
case AF_INCOMING_MSG_CMD: 
//extern byte zclYour_TaskID; 
//osal_msg_send( zclYour_TaskID, msgPtr ); 
//osal_msg_send( LSRAPP_CLUSTERID, msgPtr ); 
LSRApp_MessageMSGCB( MSGpkt );
61 
break; 
case ZDO_STATE_CHANGE: 
LSRApp_NwkState = (devStates_t)(MSGpkt->hdr.status); 
if ( (LSRApp_NwkState == DEV_ZB_COORD) 
|| (LSRApp_NwkState == DEV_ROUTER) 
|| (LSRApp_NwkState == DEV_END_DEVICE) ) 
{ 
// Start sending "the" message in a regular interval. 
osal_start_timerEx( LSRApp_TaskID, 
LSRAPP_SEND_MSG_EVT, 
LSRAPP_SEND_MSG_TIMEOUT ); 
//osal_set_event(LSRApp_TransID, LSRAPP_SEND_MSG_EVT); 
} 
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON); //flash red led 
HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH); //flash green led*/ 
break; 
} 
osal_msg_deallocate( (uint8 *)MSGpkt ); // Release the memory 
// Next 
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( LSRApp_TaskID ); 
} 
return (events ^ SYS_EVENT_MSG); // return unprocessed events 
} 
// Send a message out - This event is generated by a timer 
// (setup in LSRApp_Init()). 
if ( events & LSRAPP_SEND_MSG_EVT ) 
{ 
// Send "the" message 
LSRApp_SendTheMessage(); 
// Setup to send message again 
osal_start_timerEx( LSRApp_TaskID, LSRAPP_SEND_MSG_EVT, LSRAPP_SEND_MSG_TIMEOUT ); 
// return unprocessed events 
return (events ^ LSRAPP_SEND_MSG_EVT); 
} 
#if defined( IAR_ARMCM3_LM ) 
// Receive a message from the RTOS queue 
if ( events & LSRAPP_RTOS_MSG_EVT ) 
{ 
// Process message from RTOS queue 
LSRApp_ProcessRtosMessage();
62 
// return unprocessed events 
return (events ^ LSRAPP_RTOS_MSG_EVT); 
} 
#endif 
// Discard unknown events 
return 0; 
} 
/********************************************************************* 
* Event Generation Functions 
/********************************************************************* 
* @fn LSRApp_ProcessZDOMsgs() * 
* @brief Process response messages 
* @param none 
* @return none */ 
static void LSRApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) 
{ 
zAddrType_t dstAddr; 
switch ( inMsg->clusterID ) 
{ 
case End_Device_Bind_rsp: 
if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess ) 
{ 
// Light LED 
HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );// green led on 
} 
//#if defined( BLINK_LEDS ) 
else 
{ 
dstAddr.addrMode = Addr16Bit; 
dstAddr.addr.shortAddr = 0x0000; // Coordinator 
ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), 
LSRApp_epDesc.endPoint, 
LSRAPP_PROFID, 
LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, 
LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, 
FALSE ); 
// Flash LED to show failure 
//HalLedSet ( HAL_LED_1, HAL_LED_MODE_FLASH );// green led blinking 
} 
//#endif 
break; 
case Match_Desc_rsp: 
{ 
ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); 
if ( pRsp )
63 
{ 
if ( pRsp->status == ZSuccess && pRsp->cnt ) 
{ 
LSRApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; 
LSRApp_DstAddr.addr.shortAddr = pRsp->nwkAddr; 
// Take the first endpoint, Can be changed to search through endpoints 
LSRApp_DstAddr.endPoint = pRsp->epList[0]; 
// Light LED 
HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH); //blink green yellow led 
//HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );// green led on 
} 
osal_mem_free( pRsp ); 
} 
} 
break; 
} 
} 
/********************************************************************* 
* @fn LSRApp_HandleKeys 
* @brief Handles all key events for this device. 
* @param shift - true if in shift/alt. 
* @param keys - bit field for key events. Valid entries: 
* HAL_KEY_SW_4 
* HAL_KEY_SW_3 
* HAL_KEY_SW_2 
* HAL_KEY_SW_1 
* @return none */ 
static void LSRApp_HandleKeys( /*uint8 shift,*/ uint8 keys ) 
{ 
zAddrType_t dstAddr; 
if ( keys & HAL_KEY_SW_1 ) 
{ 
// Initiate a Match Description Request (Service Discovery) 
//HalLedSet ( HAL_LED_1, HAL_LED_MODE_ON ); // green led off initially 
dstAddr.addrMode = AddrBroadcast; 
dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR; 
ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, 
LSRAPP_PROFID, 
LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, 
LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, 
FALSE ); 
} 
if ( keys & HAL_KEY_SW_2 ) 
{ 
// Initiate an End Device Bind Request for the mandatory endpoint
64 
dstAddr.addrMode = Addr16Bit; 
dstAddr.addr.shortAddr = 0x0000; // Coordinator 
ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), 
LSRApp_epDesc.endPoint, 
LSRAPP_PROFID, 
LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, 
LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, 
FALSE ); 
} 
} 
/********************************************************************* 
* LOCAL FUNCTIONS 
/********************************************************************* 
* @fn LSRApp_MessageMSGCB 
* @brief Data message processor callback. This function processes 
* any incoming data - probably from other devices. So, based 
* on cluster ID, perform the intended action. 
* @param none 
* @return none */ 
static void LSRApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) 
{ 
char *l1; 
uint8 l2; 
HalLedSet(HAL_LED_3, HAL_LED_MODE_FLASH); 
l1 = (char*)pkt->cmd.Data; 
l2 = *l1; 
while (!(UCA0IFG&UCTXIFG)); 
UCA0TXBUF = l2; 
} 
/********************************************************************* 
* @fn LSRApp_SendTheMessage 
* @brief Send "the" message. 
* @param none 
* @return none */ 
static void LSRApp_SendTheMessage( void ) 
{ 
for(int i=0;i<160;i++) 
{ 
theMessageData[i] = UCA0RXBUF; 
} 
if ( AF_DataRequest( &LSRApp_DstAddr, &LSRApp_epDesc, 
LSRAPP_CLUSTERID, 
(byte) sizeof(theMessageData)*4, 
(byte *)&theMessageData,
65 
&LSRApp_TransID, 
AF_ACK_REQUEST, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) 
{ 
// Successfully requested to be sent. 
HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF); //ON yellow led 
} 
else 
{ 
// Error occurred in request to send. 
HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF );// Red Led on 
} 
} 
#if defined( IAR_ARMCM3_LM ) 
/********************************************************************* 
* @fn LSRApp_ProcessRtosMessage 
* @brief Receive message from RTOS queue, send response back. 
* @param none 
* @return none */ 
static void LSRApp_ProcessRtosMessage( void ) 
{ 
osalQueue_t inMsg; 
if ( osal_queue_receive( OsalQueue, &inMsg, 0 ) == pdPASS ) 
{ 
uint8 cmndId = inMsg.cmnd; 
uint32 counter = osal_build_uint32( inMsg.cbuf, 4 ); 
switch ( cmndId ) 
{ 
case CMD_INCR: 
counter += 1; /* Increment the incoming counter */ 
/* Intentionally fall through next case */ 
case CMD_ECHO: 
{ 
userQueue_t outMsg; 
outMsg.resp = RSP_CODE | cmndId; /* Response ID */ 
osal_buffer_uint32( outMsg.rbuf, counter ); /* Increment counter */ 
osal_queue_send( UserQueue1, &outMsg, 0 ); /* Send back to UserTask */ 
break; 
} 
default: 
break; /* Ignore unknown command */ 
} 
} 
} 
#endif 
/**********************************************************************/
66 
REFERENCES 
1. E. Touloupis et al., “Speech Codecs for High-Quality Voiceover ZigBee Applications: Evaluation and Implementation Challenges,” IEEE Commun. Mag., vol. 50, no. 4, April 2012. 2. J.-M. Valin, “The Speex Codec Manual Version 1.2 Beta3,” Dec. 2007. 3. Human Voice streaming over ZigBee - Low Bandwidth Communication by Manish Kumar Verma, Adarsh Pillai. 4. L. Y. Hua and F. F. Teng, “Delivering High Quality, Secure Speech Communication through Low Data Rate 802.15.4 WPAN,” IEEE Int’l. Conf. Telecommunications and Malaysia Int’l. Conf. Commun., 2007. ICT-MICC 2007. 
5. TI TMS320C5505 Family Reference Manual. 
6. eZDSP Stick User Guide. 
7. LS Research ProFLEX01 R2 Module User Guide and datasheet. 
8. http://www.iar.com/en/Service-Center/Downloads/ 9. http://support.spectrumdigital.com/boards/usbstk5505/revc/ 10. http://www.lsr.com/wireless-products/proflex01-r2 11. http://www.ti.com/tool/z-stack

More Related Content

What's hot

Implementation of intelligent wide area network(wan)- report
Implementation of intelligent wide area network(wan)- reportImplementation of intelligent wide area network(wan)- report
Implementation of intelligent wide area network(wan)- reportJatin Singh
 
Shah M Saklaen 072809056
Shah M Saklaen 072809056Shah M Saklaen 072809056
Shah M Saklaen 072809056mashiur
 
IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES | IEEE 2012 ...
IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES  | IEEE 2012 ...IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES  | IEEE 2012 ...
IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES | IEEE 2012 ...John Britto
 
Time Table Management System using Raspberry PI and RFID
Time Table Management System using Raspberry PI and RFIDTime Table Management System using Raspberry PI and RFID
Time Table Management System using Raspberry PI and RFIDIRJET Journal
 
Final Year Project Report Device Control using sms
Final Year Project Report Device Control using smsFinal Year Project Report Device Control using sms
Final Year Project Report Device Control using smsMuhammad Shakeel
 
GSM Mobile Phone Based LCD Message Display System
GSM Mobile Phone Based LCD Message Display SystemGSM Mobile Phone Based LCD Message Display System
GSM Mobile Phone Based LCD Message Display SystemManish Kumar
 
Making Sense Of Bandwidth The NetSense Way by Face To Face Live
Making Sense Of Bandwidth The NetSense Way by Face To Face LiveMaking Sense Of Bandwidth The NetSense Way by Face To Face Live
Making Sense Of Bandwidth The NetSense Way by Face To Face LiveFace to Face Live
 
Nortel cs-1000-voip-phone-system-technical
Nortel cs-1000-voip-phone-system-technicalNortel cs-1000-voip-phone-system-technical
Nortel cs-1000-voip-phone-system-technicalSlayer King
 

What's hot (14)

Implementation of intelligent wide area network(wan)- report
Implementation of intelligent wide area network(wan)- reportImplementation of intelligent wide area network(wan)- report
Implementation of intelligent wide area network(wan)- report
 
Shah M Saklaen 072809056
Shah M Saklaen 072809056Shah M Saklaen 072809056
Shah M Saklaen 072809056
 
Nat report1
Nat report1Nat report1
Nat report1
 
Resume_Mayalagu updated
Resume_Mayalagu updatedResume_Mayalagu updated
Resume_Mayalagu updated
 
50120140504012
5012014050401250120140504012
50120140504012
 
IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES | IEEE 2012 ...
IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES  | IEEE 2012 ...IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES  | IEEE 2012 ...
IEEE 2012 PROJECT TITLES FOR CSC & IT, IEEE 2012 PROJECT TITLES | IEEE 2012 ...
 
Vaibhav Pandya-best-2
Vaibhav Pandya-best-2Vaibhav Pandya-best-2
Vaibhav Pandya-best-2
 
Time Table Management System using Raspberry PI and RFID
Time Table Management System using Raspberry PI and RFIDTime Table Management System using Raspberry PI and RFID
Time Table Management System using Raspberry PI and RFID
 
Final Year Project Report Device Control using sms
Final Year Project Report Device Control using smsFinal Year Project Report Device Control using sms
Final Year Project Report Device Control using sms
 
GSM Mobile Phone Based LCD Message Display System
GSM Mobile Phone Based LCD Message Display SystemGSM Mobile Phone Based LCD Message Display System
GSM Mobile Phone Based LCD Message Display System
 
Nidhi Shankar Yadav
Nidhi Shankar YadavNidhi Shankar Yadav
Nidhi Shankar Yadav
 
Making Sense Of Bandwidth The NetSense Way by Face To Face Live
Making Sense Of Bandwidth The NetSense Way by Face To Face LiveMaking Sense Of Bandwidth The NetSense Way by Face To Face Live
Making Sense Of Bandwidth The NetSense Way by Face To Face Live
 
Nortel cs-1000-voip-phone-system-technical
Nortel cs-1000-voip-phone-system-technicalNortel cs-1000-voip-phone-system-technical
Nortel cs-1000-voip-phone-system-technical
 
Tufail javed -cv
Tufail javed -cvTufail javed -cv
Tufail javed -cv
 

Similar to Speech Transmission over ZigBee Using Speex Codec

Project Dissertation - ZigBee Based Wireless Sensor Network
Project Dissertation - ZigBee Based Wireless Sensor NetworkProject Dissertation - ZigBee Based Wireless Sensor Network
Project Dissertation - ZigBee Based Wireless Sensor NetworkAnand Agrawal
 
Optical Fiber link Design Complete guide by Aamir Saleem
Optical Fiber link Design Complete guide by Aamir SaleemOptical Fiber link Design Complete guide by Aamir Saleem
Optical Fiber link Design Complete guide by Aamir SaleemAamir Saleem
 
Performance Analysis of Routing Protocols of Wireless Sensor Networks
Performance Analysis of Routing Protocols of Wireless Sensor NetworksPerformance Analysis of Routing Protocols of Wireless Sensor Networks
Performance Analysis of Routing Protocols of Wireless Sensor NetworksDarpan Dekivadiya
 
GSM BASED e-NOTICE BOARD final year project report
GSM BASED e-NOTICE BOARD final year project reportGSM BASED e-NOTICE BOARD final year project report
GSM BASED e-NOTICE BOARD final year project reportVenkatesh Agnihotri
 
final year project
final year projectfinal year project
final year projectshiola kofi
 
FINAL PROJECT REPORT
FINAL PROJECT REPORTFINAL PROJECT REPORT
FINAL PROJECT REPORTSoham Wadekar
 
Full report on WIMAX Network Planning by Yubraj gupta
Full report on WIMAX Network Planning by Yubraj guptaFull report on WIMAX Network Planning by Yubraj gupta
Full report on WIMAX Network Planning by Yubraj guptaYubraj Gupta
 
Report File On Virtual Private Network(VPN)
Report File On Virtual Private Network(VPN)Report File On Virtual Private Network(VPN)
Report File On Virtual Private Network(VPN)Rajendra Dangwal
 
IOT Personal Weather Station
IOT Personal Weather StationIOT Personal Weather Station
IOT Personal Weather StationIRJET Journal
 
Audinate avb white paper v1.2
Audinate avb white paper v1.2Audinate avb white paper v1.2
Audinate avb white paper v1.2Bob Vanden Burgt
 
GSM BASED DEVICES CONTROL SYSTEM PROJECT REPORT
GSM BASED DEVICES CONTROL SYSTEM PROJECT REPORTGSM BASED DEVICES CONTROL SYSTEM PROJECT REPORT
GSM BASED DEVICES CONTROL SYSTEM PROJECT REPORTAvinash Kannojia
 
E Assistance for Elderly and Disabled Part 1
E Assistance for Elderly and Disabled Part 1E Assistance for Elderly and Disabled Part 1
E Assistance for Elderly and Disabled Part 1NISHANT SHRISTIRAJ
 
Final thesis paper Digital Optical fiber link design
Final thesis paper Digital Optical fiber link designFinal thesis paper Digital Optical fiber link design
Final thesis paper Digital Optical fiber link designMd. Nadimul Islam
 
Seminar report of ewt
Seminar report of ewtSeminar report of ewt
Seminar report of ewtRanol R C
 
Gifi technology full seminar report
Gifi technology full seminar reportGifi technology full seminar report
Gifi technology full seminar reportSusheel Marati
 
ISI_Report_(Repaired) (4) (1)
ISI_Report_(Repaired) (4) (1)ISI_Report_(Repaired) (4) (1)
ISI_Report_(Repaired) (4) (1)Indranil Roy
 
Maneuvering Robotic Vehicle based on Motion Sensor Feedback
Maneuvering Robotic Vehicle based on Motion Sensor FeedbackManeuvering Robotic Vehicle based on Motion Sensor Feedback
Maneuvering Robotic Vehicle based on Motion Sensor FeedbackIshanMalpotra
 
Project final filewith front
Project final filewith frontProject final filewith front
Project final filewith frontPankaj Patidar
 

Similar to Speech Transmission over ZigBee Using Speex Codec (20)

Project Dissertation - ZigBee Based Wireless Sensor Network
Project Dissertation - ZigBee Based Wireless Sensor NetworkProject Dissertation - ZigBee Based Wireless Sensor Network
Project Dissertation - ZigBee Based Wireless Sensor Network
 
Optical Fiber link Design Complete guide by Aamir Saleem
Optical Fiber link Design Complete guide by Aamir SaleemOptical Fiber link Design Complete guide by Aamir Saleem
Optical Fiber link Design Complete guide by Aamir Saleem
 
Performance Analysis of Routing Protocols of Wireless Sensor Networks
Performance Analysis of Routing Protocols of Wireless Sensor NetworksPerformance Analysis of Routing Protocols of Wireless Sensor Networks
Performance Analysis of Routing Protocols of Wireless Sensor Networks
 
GSM BASED e-NOTICE BOARD final year project report
GSM BASED e-NOTICE BOARD final year project reportGSM BASED e-NOTICE BOARD final year project report
GSM BASED e-NOTICE BOARD final year project report
 
IP PBX
IP PBXIP PBX
IP PBX
 
final year project
final year projectfinal year project
final year project
 
FINAL PROJECT REPORT
FINAL PROJECT REPORTFINAL PROJECT REPORT
FINAL PROJECT REPORT
 
Full report on WIMAX Network Planning by Yubraj gupta
Full report on WIMAX Network Planning by Yubraj guptaFull report on WIMAX Network Planning by Yubraj gupta
Full report on WIMAX Network Planning by Yubraj gupta
 
Report File On Virtual Private Network(VPN)
Report File On Virtual Private Network(VPN)Report File On Virtual Private Network(VPN)
Report File On Virtual Private Network(VPN)
 
IOT Personal Weather Station
IOT Personal Weather StationIOT Personal Weather Station
IOT Personal Weather Station
 
Audinate avb white paper v1.2
Audinate avb white paper v1.2Audinate avb white paper v1.2
Audinate avb white paper v1.2
 
GSM BASED DEVICES CONTROL SYSTEM PROJECT REPORT
GSM BASED DEVICES CONTROL SYSTEM PROJECT REPORTGSM BASED DEVICES CONTROL SYSTEM PROJECT REPORT
GSM BASED DEVICES CONTROL SYSTEM PROJECT REPORT
 
E Assistance for Elderly and Disabled Part 1
E Assistance for Elderly and Disabled Part 1E Assistance for Elderly and Disabled Part 1
E Assistance for Elderly and Disabled Part 1
 
Final thesis paper Digital Optical fiber link design
Final thesis paper Digital Optical fiber link designFinal thesis paper Digital Optical fiber link design
Final thesis paper Digital Optical fiber link design
 
Seminar report of ewt
Seminar report of ewtSeminar report of ewt
Seminar report of ewt
 
Gifi technology full seminar report
Gifi technology full seminar reportGifi technology full seminar report
Gifi technology full seminar report
 
ISI_Report_(Repaired) (4) (1)
ISI_Report_(Repaired) (4) (1)ISI_Report_(Repaired) (4) (1)
ISI_Report_(Repaired) (4) (1)
 
Maneuvering Robotic Vehicle based on Motion Sensor Feedback
Maneuvering Robotic Vehicle based on Motion Sensor FeedbackManeuvering Robotic Vehicle based on Motion Sensor Feedback
Maneuvering Robotic Vehicle based on Motion Sensor Feedback
 
Project final filewith front
Project final filewith frontProject final filewith front
Project final filewith front
 
Thesis Main
Thesis MainThesis Main
Thesis Main
 

Speech Transmission over ZigBee Using Speex Codec

  • 1. 1 Speech Transmission over ZigBee Network THESIS Submitted for the partial fulfilment of the degree of Bachelor of Technology (Electronics and Communication Engineering) By Chandana Kandru (BT09ECE004) Pragya Agrawal (BT09ECE011) Under the guidance of Dr. A.S. Gandhi Professor Department of Electronics and Communication Engineering DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY, NAGPUR 2012-13
  • 2. 2 DECLARATION We the students of the Department of Electronics and Communication Engineering, VNIT Nagpur state that the thesis entitled “Speech transmission over ZigBee Network” is our original work and has not been submitted to any other institute or university for any other degree. This work is being submitted for the partial fulfilment of the B.Tech degree for the session 2012-13. Chandana Kandru Pragya Agrawal
  • 3. 3 CERTIFICATE This is to certify that the project work embodied in the thesis entitled “Speech transmission over ZigBee Network” is genuine and has not been submitted to any other institute or university for any other degree. This bonafide work has been carried out by: CHANDANA KANDRU BT09ECE004 PRAGYA AGRAWAL BT09ECE011 in partial fulfilment of the requirements for the award of the Degree of Bachelor of Technology (Electronics and Communication Engineering) from Visvesvaraya National Institute of Technology, Nagpur, during 2012-2013. Dr. A.S. Gandhi Professor, Department of Electronics and Communication Engineering, VNIT, Nagpur. Dr. K.D. Kulat Head of Department, Department of Electronics and Communication Engineering, VNIT, Nagpur.
  • 4. 4 ACKNOWLEDGEMENTS We would like to express our heartfelt gratitude to our guides Dr. A. S. Gandhi for their valuable advice and constant support. His insightful suggestions have aided us in the successful completion of our project work. We also thank Prof. K.D.Kulat, Head of the Department, Electronics and Communication Engineering, VNIT Nagpur for extending the departmental facilities for our research. We are extremely grateful to all the faculty and staff of the Department of Electronics and Communication Engineering for providing us unwavering guidance and support for the entire four years of our bachelors’ degree course. Finally we would like to express our deepest gratitude to all our friends in VNIT Nagpur for the help and cooperation they have extended over the past four years.
  • 5. 5 ABSTRACT The ZigBee standard is designed to enable the deployment of low-cost, low-power wireless sensor and control networks based on the IEEE 802.15.4 physical radio standard. Transmission of voice with acceptable QoS requires high bandwidth channel. ZigBee operates in 2.4 GHz ISM band with a maximum possible data rate of 250 kbps. Despite the low data rates of ZigBee, its use for transmission of voice has been proven to be feasible. However, the system should guarantee the QoS throughput on the channel with minimal occupancy of the allowable channel bandwidth. So, voice must be compressed before being transmitted. The compression algorithm should be implemented on a low power processor for extending the lifetime of the system. The challenges include selection and implementation of the most suitable voice codec for high-quality voice transmission over constrained networks, using constrained devices. In this project we transmit human speech over ZigBee by implementing Speex compression algorithm on DSP hardware TMS320C5505. The RF module used for transmission is CC2520.
  • 6. 6 TABLE OF CONTENTS DECLARATION.........................................................................................................2 CERTIFICATE...........................................................................................................3 ACKNOWLEDGEMENTS.......................................................................................4 ABSTRACT…………………………………………………………….....................5 LIST OF FIGURES……………………….……………………………...................8 LIST OF TABLES......................................................................................................9 CHAPTERS 1. INTRODUCTION.........................................................................................10 1.1 NETWORK SELECTION.....................................................................10 1.2 CODEC SELECTION............................................................................12 1.3 PLATFORM SELECTION...................................................................12 2. BACKGROUND...........................................................................................13 2.1 SPEECH CODEC...................................................................................13 2.1.1 Speex Codec.................................................................................14 2.1.2 Analysis of node data rate..........................................................15 2.2 ZIGBEE NETWORK.............................................................................15 2.2.1 Nodes in ZigBee Network...........................................................15 2.2.2 ZigBee PANs................................................................................16 2.2.3 ZigBee Channels..........................................................................16 2.2.4 ZigBee PAN Ids...........................................................................17 2.2.5 Network Address.........................................................................17 2.2.6 MAC Address..............................................................................17 2.2.7 Sending and Receiving data in ZigBee network.......................18 2.2.8 Addressing within the node........................................................18 2.2.8.1 Endpoints...............................................................................19 2.2.8.2 Clusters..................................................................................19 2.2.9 ZigBee Application Support Sublayer (APS)...........................20 2.2.9.1 APS Acknowledgements.......................................................21 2.2.9.2 Application Profiles..............................................................21 2.2.9.3 Device Ids...............................................................................21
  • 7. 7 2.2.9.4 Simple Descriptor..................................................................22 2.2.10 ZigBee Network Services............................................................22 2.2.10.1 ZigBee device profile.................................................22 3. HARDWARE................................................................................................24 3.1 ezDSP STICK..........................................................................................25 3.2 ProFLEX01-R2 MODULE....................................................................27 4. SOFTWARE IMPLEMENTATION..........................................................28 4.1 TOOLS USED.........................................................................................28 4.2 SPEECH COMPRESSION....................................................................29 4.2.1 Speex Codec.................................................................................29 4.2.2 DMA.............................................................................................30 4.2.3 UART...........................................................................................31 4.3 TRANSMISSION OVER ZIGBEE......................................................35 4.3.1 LSRApp_Init( )............................................................................37 4.3.2 LSRApp_ProcessEvent()............................................................38 4.3.3 Sending Message.........................................................................39 4.3.4 Receiving Message......................................................................41 4.4 CONCLUSION.......................................................................................43 APPENDIX................................................................................................................44 Program code for Speex Compression on TMS320C5505.........................44 Program code for ZigBee transmission........................................................57 REFERENCES.........................................................................................................66
  • 8. 8 LIST OF FIGURES Figure 1: ZigBee Stack Architecture.......................................................................................10 Figure 2: APS end-to-end acknowledgements........................................................................11 Figure 3: Block diagram of the overall system.......................................................................14 Figure 4: TMS320C5505 ezDSP STICK................................................................................15 Figure 5: Expansion connector for ezDSP STICK..................................................................16 Figure 6: Board with expansion connector indicating connections........................................16 Figure 7: PROFLEX01-R2 development board……………………………………………17 Figure 8: ProFLEX01-R2 Module Block Diagram…………………………………………18 Figure 9: Programming the ProFLEX Module using MSP FET430UIF JTAG Debugger.....18 Figure 10: Flowchart representing speech compression using Speex.....................................23 Figure 11: Screenshots indicating project build in Code Composer Studio...........................24 Figure 12: Flowchart representing sending of message over the air using ZigBee................30 Figure 13: Flowchart representing receiving of message over the air using ZigBee..............31 Figure 14: Screenshots indicating Coordinator and End device project build in IAR............32
  • 9. 9 LIST OF TABLES Table 1: Comparison of ZigBee with contemporary technologies...........................................1 Table 2: Nodes in ZigBee Network..........................................................................................6 Table 3: List of source and header files of Speex that need to be included in the project.....20
  • 10. 10 1. INTRODUCTION IEEE 802.15.4 ZigBee standard is a wireless technology operating over 2.4 GHz frequency. The maximum data rate supported by this technology is 250 kbps. ZigBee has following features:  Low power consumption  Network can have large number of devices (65535 per network) when it uses short addressing  Leaving and joining network is rapid of the order of milliseconds (less than 30ms)  Protocol stack is simpler  Supports periodic, intermittent and repetitive data 1.1 NETWORK SELECTION: 1.1.1 Why ZigBee? The main advantages of ZigBee over rival technologies like Bluetooth, Wi-Fi is low power consumption and higher network range. This is because of the mesh and tree networking being allowed in addition to the star networking supported by Bluetooth and Wi-fi, which means when we are not in the range of the node that we wish to communicate with, other nodes in between, can be asked to pass the message along. Thus by halving the range of radio reduces power consumption by 75%, leading to dramatic power consumptions without compromising range. ZigBee Wi-Fi Bluetooth Range 10-100 m 50-100 m 10-100 m Networking Topology Ad-hoc, peer to peer, star, mesh Point to hub Ad-hoc, very small networks Operating Frequency 868 MHz (Europe) 915 MHz (USA) 2.4 GHz (worldwide) 2.4 GHz, 5 GHz. 2.4 GHz Complexity Low High High Power Consumption Very low High Medium Table 1: Comparison of ZigBee with contemporary technologies
  • 11. 11 1.2 CODEC SELECTION: Due to the limited available bandwidth for ZigBee, voice must be compressed before being transmitted.  The maximum bit rate supported by ZigBee is 250kbps but due to packet overheads while transmission the data rate is reduced to 38kbps. Hence for high quality speech transmission over ZigBee only narrowband voice codecs can be used.  Also the DSP processor used to implement codec eliminates the use of wideband codecs due to performance limitations pertaining to the low power application. The popular voice codecs are: G723.1, iLBC, Speex. 1.3 PLATFORM SELECTION: To implement the voice codec the DSP hardware must support the following features:  High processing power (up to 30MIPS).  To be able to implement compression/decompression algorithms like Speex, G723.1etc.  Support of serial interfaces like UART, SPI.  Low power consumption. Popular DSP platforms: TMS320C5505, dsPIC 33Fxx, BelaSigna 300
  • 12. 12 2. BACKGROUND 2.1 SPEECH CODEC The human voice acoustic sensor initially generates an analog signal. This signal is converted into a bit stream by an Analog-to-Digital converter (ADC) and applied to a multiple compression algorithms. There are various compression techniques available in the literature. The most popular ones are standardized in the ITU-T G-series. The most commonly used codecs are: G.711 PCM, G.726 ADPCM, G.728 LD-CELP and G. 729/G.729a CS-ACELP. PCM and ADPCM belong to the family of so called waveform codecs. These codecs simply analyze the input signal without any knowledge of the human source. Most of these codecs work in time domain, like PCM. These codecs offer high quality speech at a low computational complexity. But if we try to get the bit rate below 8 kbps the quality decreases tremendously. To get the low bit rate with better voice quality another approach is necessary. Human source codecs need to know the characteristics of the human voice. When a human voice is encoded, the source codec tries to extract the voice parameters from the voice signal. Then these parameters along with two states of excitation are transmitted. These types of codecs can simply transport the pure informational content of the speech samples and not the voice signal samples itself. The big advantage is that they operate with bit rates as low as 2.4 kbps of course with poor voice quality. Hybrid codecs try to combine the advantages of both waveform codecs and source codecs to obtain good voice quality. To get the best voice parameters all possible waveforms are tested and then one with the least error is chosen. This involves a very high computational complexity to analyze every voice frame. The low bit rate codecs usually involve a high computational complexity and a delay while the waveform codecs have the advantage of low delay and excellent voice quality. One example of this is Speex codec.
  • 13. 13 2.1.1 Speex: Unlike many other speech codecs, Speex has the advantage of being capable to be used for packet networks and voice over IP (VoIP) applications also. It uses CELP (code excited linear prediction) coding techniques. Speex is mainly designed for three different sampling rates: 8 kHz, 16 kHz and 32 kHz referred as narrowband, wideband and ultra-wideband respectively. It can be configured either for variable bit rate or fixed bit rate. The variable bit-rate (VBR) allows a codec to change its bit-rate dynamically to adapt to the "difficulty" of the audio being encoded. Sounds like vowels and high energy transients require a large number of bits to achieve good quality, while fricatives (s, f sounds) can be coded adequately with less number of bits. With this VBR we can achieve lower bit-rate for the same quality, or a better quality for a certain bit-rate. Despite its advantages VBR has two main drawbacks: first, by only specifying quality, there's no guaranty about the final average bit-rate, second, for some real-time applications like voice over IP (VoIP), the maximum bit-rate must be low enough for the communication channel. Speex has VAD (Voice activity detection) feature. When enabled the VAD detects whether the audio being encoded is speech or silence/background noise. VAD is always implicitly activated when encoded in VBR, so the option is only useful in non-VBR operation. In this case, Speex detects non-speech periods and encode them with just enough bits to reproduce the background noise. This is called "Comfort noise generation" (CNG). Thus, Speex compression algorithm is used for the proposed model which compresses 20ms voice data at a time, sampled at 8khz and results in compressed data size of 20 byte in case of 5.3kbps rate and 24 byte in case of 6.3kbps rate. Now the compressed voice data is integrated into a voice packet. This voice packet is basically a ZigBee network packet which contain voice packet as data payload to send to the receiver. The packet is sent to the ZigBee module over UART. The ZigBee network layer utilizes the coordinators, routers and end devices. When the receiver receives the packet, the packet goes through the reverse process for playback of voice.
  • 14. 14 2.1.2 Analysis of node data rate: When UART as interface between Sensor Board (DSP) and RF board(ZigBee) Baud Rate: 115200 bps Data Rate of Transceiver: 250kbps UART transmit (Sensor to RF Board) time (160 bytes): 32ms (approx.) Over the air Transmit time/bit: 4us (approx.) For a single packet: 6.4 ms approx. So, ideal time for transmission of a single packet is ~40ms. Considering the total packet size including overhead to be 200 bytes Data Transmission Rate = Total packets size (in bits) / Total Time taken Thus achieving a data transmission rate of ~40kbps, which is the actual available data rate excluding headers in ZigBee network. 2.2 ZIGBEE NETWORK ZigBee is a WPAN (Wireless Personal Area Network) protocol which defines the higher layers of the protocol stack. It is built over the IEEE 802.15.4 WPAN standard. IEEE 802.15.4 defines only lower layers (PHY and MAC) of the protocol stack. 2.2.1 Nodes in ZigBee Network: Two types of devices can participate in an IEEE 802.15.4 network:  Full-function device (FFD)  Reduced-function device (RFD). The FFD can operate in three modes serving as a PAN coordinator, a coordinator, or an end device. An FFD can talk to RFDs or other FFDs, while an RFD can talk only to an FFD. An RFD is intended for applications that are extremely simple, such as a light switch or a passive infrared sensor as an end device; they do not have the need to send large amounts of data and may only associate with a single FFD at a time. Consequently, the RFD can be implemented using minimal resources and memory capacity. Every node in a ZigBee network is one of three types: a ZigBee Coordinator (ZC), a ZigBee Router (ZR), or a ZigBee End-Device (ZED). In IEEE 802.15.4-speak, both ZCs and ZRs are full-function devices, and a ZED is a reduced-function device:
  • 15. 15 Device Name Description Coordinator  Create the Network  Accept new element into the network  Participate the message routing  Participate self-healing when link broke  Mains powered Router  Accept new element into the network  Participate the message routing  Participate self-healing when kink broke  Mains Powered End device  Only communicate with direct parent  Does not participate with message routing  Cannot adopt new element into the network  Can be battery powered and go to sleep mode periodically Table 2: Nodes in ZigBee Network 2.2.2 ZigBee PANs: ZigBee nodes can only send data requests to other nodes on the same network. A single ZigBee network is called a Personal Area Network (PAN). ZigBee PANs are formed by ZigBee Coordinators. Only ZigBee Coordinators (ZCs) may form a PAN. The other ZigBee node types, ZigBee Routers (ZRs) and ZigBee End-Devices (ZEDs) may join a network, but cannot form a PAN alone. 2.2.3 ZigBee Channels: The 2.4 GHz band is a worldwide unlicensed portion of the RF spectrum for use by many radio products like Bluetooth, WiFi™, Microwaves and others. This band is also known as the ISM (Industrial, Scientific, and Medical) band. ZigBee uses the same channel set as specified in 802.15.4. In the 2.4 GHz band, these channels are numbered 11 through 26. Channel numbers 0 through 10 are defined by the sub-1 GHz 802.15.4 radios, but ZigBee does not run on the sub-1 GHz radios. Channels are just a portion of the RF spectrum. In the case of 802.15.4, each of these channels is separated by 5 MHz in the 2.4 GHz band.
  • 16. 16 802.15.4 uses Direct Sequence Spread Spectrum (DSSS) to spread the packets into symbols and reassemble them on the other end, verifying that the data was decoded correctly through use of a 16-bit CRC. Due to the robust nature of O-QPSK and DSSS, 802.15.4 radios are very robust, even in a noisy RF environment. 2.2.4 ZigBee PAN IDs: ZigBee Personal Area Network identifiers (or PAN IDs) are used to logically separate a collection of ZigBee nodes from other ZigBee nodes in the same vicinity or on the same physical channel. This allows network A and network B to exist in close proximity without interfering with each other, other than consuming over-the-air bandwidth that they both share. ZigBee PAN IDs are 16-bit numbers that range from 0x0000 to 0x3fff. Note this is different than the 802.15.4 specification, which allows PAN IDs from 0x0000 to 0xfffe. A device is only allowed to join one PAN at a time. When PAN is configured as 0xffff, the device will join/create random PAN. 2.2.5 The Network Address: The network address, also called NwkAddr, short address, or node address, is a 16-bit number used to uniquely identify a particular node on a ZigBee network. The ZigBee Coordinator is always NwkAddr 0x0000. Two ZigBee coordinators can exist on the same channel with NwkAddr 0x0000 because of their different PAN IDs. 2.2.6 MAC Addresses: The MAC address, also called IEEE address, long address, or extended address, is a 64bit number that uniquely identifies a board from all other ZigBee boards in the world. The 64-bit MAC addresses have no direct relationship to the 16-bit NwkAddr. If a node leaves one ZigBee network and joins another, its MAC address will remain the same, but the NwkAddr will likely change.
  • 17. 17 2.2.7 Sending and Receiving Data in a Zigbee network: Different message sending methods in ZigBee are:  Unicast with end-to-end acknowledgment  Unicast without end-to-end acknowledgment  Broadcast  Groupcast/Multicast Unicasts are transmitted from one node to exactly one other node. Unless the nodes are neighbours (within radio range of each other), route discovery takes place the first time these nodes speak together. If end-to-end is acknowledged, the unicast will be retried up to three times, perhaps even initiating a new route discovery if the old route is broken. A broadcast is used to send a data request from one node to the entire ZigBee network, at least within a given radius. Broadcasts are used by some underlying ZigBee management functions, such as route discovery or NWK_addr_req, and may be also used by applications.  Unlike unicasts, broadcasts have no acknowledgment mechanism.  Broadcasts don't need specific commissioning. There is no "binding" to a broadcast destination address. A node simply broadcasts to a specified radius. The default radius for a broadcast spans the entire network. 2.2.8 Addressing Within the Node: ZigBee goes beyond a networking protocol and also offers application-level compatibility. To achieve this, ZigBee contains a variety of concepts: endpoints, clusters, command, attributes, and profiles. Addressing within ZigBee includes all of the following components:  PAN ID (MAC)  NwkAddr (NWK)  Endpoint (APS)  Profile ID (APS)  Cluster (APS)  Command and/or attribute (ZCL)
  • 18. 18 2.2.8.1 Endpoints: Endpoints are defined within each node. Endpoints serve three purposes in ZigBee:  Endpoints allow for different application profiles to exist within each node  Endpoints allow for separate control points to exist within each node  Endpoints allow for separate devices to exist within each node Endpoints, identified by a number between 1 and 240, define each application running in a ZigBee node (where, a single ZigBee node can run multiple applications). A node may contain any number of endpoints (up to 240), with any set of endpoint identifiers. For example, a single node might contain just one endpoint, numbered 55. Or a node might contain 20 endpoints, numbered 1 through 10 and 201 through 210. Hence endpoints can be viewed as virtual wires connecting applications. Endpoints allow for separate profiles, devices, and control points to exist within a single node. 2.2.8.2 Clusters: Clusters, defined by a 16-bit identifier, are application objects. While the NwkAddr and endpoint are addressing concepts, the cluster defines application meaning.  Clusters encapsulate both commands and data.  Clusters have direction. In the Simple Descriptor which describes an endpoint, a cluster is listed as either input or output. This is used only for the purposes of service discovery. Clusters contain both code (commands) and data (attributes). Commands cause action on a cluster while attributes keep track of the current state of that cluster.  Commands: Commands are identified by an 8-bit number, and are either cluster- specific, or cross-cluster. Cluster-specific commands depend on the cluster number, and generally start at 0x00.  Attributes: Attributes store the current "state" of a given cluster. Collectively, a set of attributes on all clusters supported by a device define the state of that device. There are generic ZCL commands to read and write attributes on any given cluster.
  • 19. 19 ZIGBEE STACK ARCHITECTURE Figure 1: ZigBee Stack Architecture 2.2.9 ZigBee Application Support Sublayer (APS): The Application Support Sublayer, or APS, sits above the NWK layer, and is the layer in ZigBee which understands applications. The APS frame over-the-air includes endpoints, clusters, profile IDs, and even groups. APS is responsible for the following activities:  Filtering out packets for non-registered endpoints, or profiles that don't match  Generating end-to-end acknowledgment with retries to maximise the chance of successful transmission and to inform the sender whether or not the packet was delivered.  Maintaining the local binding table  Maintaining the local groups table  Maintaining the local address map of a 64-bit MAC address with a ZigBee 16-bit NwkAddr.
  • 20. 20 2.2.9.1 APS Acknowledgements:: While the MAC layer provides per-hop acknowledgments, the APS layer is what provides end-to-end acknowledgments, also called ACKs Figure 2: APS end-to-end acknowledgements 2.2.9.2 Application Profiles: Every data request in ZigBee is sent (and received) on an Application Profile. Application Profile IDs are 16-bit numbers and range from 0x0000 to 0x7fff for public profiles and 0xbf00 to 0xffff for manufacturer-specific profiles. A profile is a domain space of related applications and devices. Public profiles are those specified by the ZigBee Alliance (as opposed to private profiles specified by individual OEMs). Any number of Application Profiles, both public and manufacturer-specific, may exist in a single ZigBee network. In fact, any number of profiles may exist in a single node on the network, separated on different endpoints. 2.2.9.3 Device Ids: Every endpoint includes a profile identifier and a device identifier. A device is a physical thing like a light, temperature sensor, thermostat etc. ZigBee Device IDs range from 0x0000 to 0xffff. Device IDs serve two purposes:  To allow human-readable displays (your PC, the TV, etc.) to show a proper icon for the device in question.  To allow ZigBee commissioning tools to be more intelligent.
  • 21. 21 2.2.9.3 The Simple Descriptor: The simple descriptor ties all the endpoint information, which defines an application, together in one place. The simple descriptor defines the fields: an endpoint ID, a profile ID, cluster IDs, and a device ID. The simple descriptor of any endpoint can be retrieved over-the-air when performing service discovery. The simple descriptor does not list the commands and/or attributes available on any given cluster. By asking for the simple descriptor, any device in the network can determine which clusters are supported by any other device, and can then make an informed decision about optional functionality. There are both input and output cluster lists in the simple descriptor. This is how ZigBee determines which devices match. If one side has an output cluster (say a dimmer switch) and the other side has the same cluster as an input cluster (say, a dimming light), then they match. Any overlap indicates a match, so if an application is looking for a particular cluster, it can send a "simplified" simple descriptor to match just that one cluster. 2.2.10 Zigbee network services: ZigBee contains two sets of services for network commissioning and maintenance:  The ZigBee Device Object (together with the ZigBee Device Profile)  The ZigBee Cluster Library ZigBee Device Object is a specialized form of application object (with profile ID 0x0000) which each node must have. 2.2.10.1 ZigBee Device Profile services include the following categories:  Device discovery services  Service discovery services  Binding services  Management services
  • 22. 22 Device Discovery involves interrogating a remote node for address information. The retrieved information can be either:  the MAC (IEEE) address of the node with a given network address  the network address of the node with a given MAC address. Service discovery involves interrogating a remote node for information about its capabilities. This information is stored in a number of descriptors on the remote node, and includes:  The device type and capabilities of the node (Node Descriptor)  The power characteristics of the node (Node Power Descriptor)  Information about each application running on the node (Simple Descriptor) Requests for these descriptors are made by a device during its configuration and integration into a ZigBee network. ZigBee performs service discovery based on profile IDs and cluster IDs, not device IDs. Binding provides a mechanism for attaching an endpoint on one node to one or more endpoints on another node. Binding can even be destined for groups of nodes. Each binding table entry stores the following information:  Source endpoint  the short (16-bit NwkAddr) and long (IEEE) address of a node  Cluster ID Binding, coupled with the over-the-air ZDP binding commands, allows any endpoint on any node to be connected easily with any endpoint on any other node. Management services provide the ability to retrieve management information from the devices, including network discovery results, routing table contents, link quality to neighbour nodes, and binding table contents.
  • 23. 23 3. HARDWARE Figure 3: Block diagram of the overall system The stereo codec, AIC3204 is used for capturing, sampling the speech signal and converting the samples back into analog signal. The sampled speech signal is compressed using Speex compressing algorithm which is ported to DSP platform TMS320C5505. This compressed data is further packetized using the ZigBee stack implemented on micro-controller MSP430F5437. The ZigBee packets are transmitted using RF transceiver CC2520. While reception the received signal is depacketized, decompressed and fed into speaker.
  • 24. 24 3.1 ezDSP STICK: Figure 4: TMS320C5505 ezDSP STICK The end device consists of sensor board using TI DSP (TMS320C5505) processor of C55x series and AIC3204 stereo codec. TMS320C5505 16-bit DSP is a low power, Fixed point DSP working at 100 MHz processing speed and is capable of executing some DSP algorithms as well as some of the voice compression or decompression algorithms. The DSP is also rich in peripherals like DMA controller and serial interfaces like SPI, UART, I2S, I2C. It is therefore, possible to implement several interfaces in order to connect various ZigBee devices. This makes it possible to evaluate different components. The stereo codec (AIC3204), a low power Codec from TI is used for capturing, sampling the audio signal and converting the samples back into analog audio. It connects to the TI C5505 DSP using I2C for configuration & I2S for data communication. The UART connections required for interaction with ZigBee board is obtained using an expansion connector connected to the end of the board.
  • 25. 25 Figure 5: Expansion connector for eZDSP Stick Figure 6: Board with expansion connector indicating connections
  • 26. 26 3.2 ProFLEX01-R2 MODULE: The ZigBee modules used for RF transmission and reception are PROFLEX01- R2 module by LS Research. Figure 7: PROFLEX01-R2 development board The ProFLEX01-R2 module is a high performance 2.4GHz IEEE 802.15.4 radio (CC2520 & CC2591) and microcontroller (MSP430F5437A) in a cost effective, pre-certified footprint. The microcontroller is connected to CC2520 via serial interface. The board comes preloaded with TI MAC stack and we have implemented TI Z-Stack 2.5.1 to develop our application. The board can be connected to an external PC/Microcontroller for communication via the UART interface of MSP430F5437A. The programming software used is IAR Embedded Workbench compatible with TI Z-Stack 2.5.1.
  • 27. 27 Figure 8: ProFLEX01-R2 Module Block Diagram The important features of the board are:  100mW output power  Long range: 4000 feet  Integrated PCB F antenna or U.FL connector for external antenna  Worldwide acceptance: FCC, IC and CE  Powerful Texas Instruments 256k MSP430 with 802.15.4 MAC or ZigBee Stack  LSR serial interface based on 802.15.4 MAC  Low power operation  RoHS compliant Figure 9: Programming the ProFLEX Module using MSP FET430UIF JTAG Debugger
  • 28. 28 SOFTWARE IMPLEMENTATION 4.1 TOOLS USED: IAR Embedded Work bench - This tool is a complete IDE for compiling, debugging and programming a RF board which has MSP430 controller. We customize & build z-stack as per our RF board and develop a user application. Code Composer Studio (CCS) - This tool is a complete IDE for compiling, debugging and programming Sensor board which has TI C5505 DSP controller. We develop a user application to capture voice, compress it and transfer to RF board. Z-Stack - Z-Stack is a ZigBee compliant protocol stack for IEEE 802.15.4 products. The Stack is developed for TI ultra low power microcontrollers and RF transceivers. The ZigBee- stack architecture shown in Fig.6 includes a number of layered components including the IEEE 802.15.4 Physical (PHY) layer, Medium Access Control (MAC) layer, and the ZigBee Network (NWK) layer and Application layer. Each component provides an application with its own set of services and capabilities. ZigBee Sniffer tool (WiSens) is used for observing the packet being transmitted and received by the devices. MSP FET430 UIF JTAG Debugger is used for programming and debugging ProFLEX01- R2 Modules through 14pin JTAG interface. The implementation of the project broadly comprises of 2 parts:  Capturing voice and compressing it on DSP.  Transmitting the compressed data over ZigBee, This is followed by reception and decompression on the receiver side.
  • 29. 29 4.2 SPEECH COMPRESSION: 4.2.1 SPEEX: Speex is open-source software and is available for download on www.xiph.org.The list of files to be included in the CCS project is Source files Header files bits.c arch.h cb_search.c cb_search.h exc_10_16.c config.h exc_10_32.c filters.h exc_20_32.c fixed_generic.h exc_5_256.c lpc.h exc_5_64.c lsp.h exc_8_128.c ltp.h filters.c modes.h gain_table.c nb_celp.h gain_table_lbr.c os_support.h lpc.c os_support_custom.h lsp.c quant_lsp.h lsp_tables_nb.c sb_celp.h ltp.c speex/speex_bits.h modes.c speex/speex_buffer.h nb_celp.c speex/speex_callbacks.h quant_lsp.c speex/speex_echo.h sb_celp.c speex/speex_header.h speex.c speex/speex_jitter.h speex_callbacks.c speex/speex_preprocess.h vbr.c speex/speex_resampler.h vq.c speex/speex_stereo.h window.c speex/speex_types.h testenc_TI_c5x.c speex/speex.h Table 3: List of source and header files of Speex that need to be included in the project
  • 30. 30 The example project “testencTIc55x.c” available for TI-C5xx for encoding speech in the wav format is modified to work in real-time conditions. For this, speech from the mic is recorded every 20 ms and is provided for processing.20 ms of speech sampled at 8 kHz accounts to 160 bytes of data, described as 1 frame. Each frame is encoded using encoder state “st”. The compressed data accounts to 20 bytes per frame. Before recording speech from mic, initialisation of the codec (AIC3204) is to be done. It is done using aic3204.c. The corresponding header file aic3204.h is also to be included. Parameters set during Speex compression include Speex_quality set to 4, complexity set to 1. In loopback mode, the compressed data is decompressed using the decoder state “dec” on the same device. The decoded data is sent to HP_OUT and is heard through the headphones connected to this port. 4.2.2 DMA The quality of the decoded speech was found to be below par from expected.This is due to the delay in the processing during compression. This is countered by using DMA to transfer the data to and from the peripherals while the processor is entirely dedicated for processing the data. The TMS320C55x™ DSP Chip Support Library (CSL) which provides C-program functions to configure and control on-chip peripherals, is used to configure DMA.DMA is used in Interrupt mode i.e. DMA module generates an interrupt at the completion of specified transfer. The test code of csl_dma_IntcExample.c, which tests the basic working of the DMA module in interrupt mode, is modified to suit the present application. The transfer type is modified to CSL_DMA_TRANSFER_IO_MEMORY since I/O peripherals are being read from or written to. Auto reload mode is enabled which continuously reads the peripherals so that DMA need not be configured each time. The source address for the dma_receive function is set to 2828h, which is the address of the I2S register, I2SRXLT0.This register stores the data received from AIC3204 codec i.e. digital version of speech from mic. The destination address would be a buffer in memory which would be further processed using speex.
  • 31. 31 Similarly, dma_transmit function has its source address as a buffer in memory with the destination address being 2808h, I2STXLT0. These two functions are included in the “testencTIc55x.c” where encoding and decoding of the data is done. In loopback mode, both dma_transmit and dma_receive are implemented on the same device. 4.2.3 UART In the transmission mode, the compressed data is transmitted further through UART.UART is again configured in DMA mode using CSL. csl_uartDmaExample.c is modified and is included in “testencTIc55x.c”, where DMA transfer and encoding has been done so far. The baud rate of UART is set at 115200 bps and word length of 8 is used with no start and stop bits. The source address of UART_transmit function is cbits, which temporarily stores the encoded data and the destination address is (hUart->uartregs->THR), which is transmit buffer of UART. Similarly,the source address of UART_Receive is (hUart->uartregs->RBR), which is receive buffer of UART and the destination address is a buffer in memory of the received device. The encoded data is present in this buffer which is further decoded and sent to HP_OUT and played through headphones. The program “testencTIc55x.c” with all the above mentioned modifications is included in Appendix A. NOTE :  While using aic3204.c(present in usbstk5505_v2 files) and codes of CSL(present in c55xx_csl/ccs_v4.0_examples), usbstk5505bsl.lib and cslVC5505.lib are to be built in the workspace and then included in the File Search Path of the main project properties (Properties / C/C++ Build / File Search Path), since all the macros and functions are defined there.  Since in this program several codes from Speex, usbstk5505, csl are combined, care is to be taken that all are built using the same memory model.  During the implementation of Speex, certain symbols need to be predefined. They are _DEBUG, CONFIG_TI_C55X, HAVE_CONFIG_H.
  • 32. 32 Initialize AIC3204 codec to capture speech from mic Transfer this data over UART in DMA mode Invoke DMA to transfer the decoded data to speaker Store the data in a buffer Receive the data at the other end through UART Store the encoded data in a buffer (memory) Encoding one frame of data using Speex Invoke DMA of DSP to read data from I2S peripheral Read the data from memory Decode the compressed data Loopback Transmission Figure 9: Flowchart representing speech compression using Speex
  • 33. 33 Figure 10: Screenshots indicating project build in Code Composer Studio
  • 34. 34 4.3 TRANSMISSION OVER ZIGBEE: The application is developed using TI Z-Stack version 2.5.1 and implemented over PROFLEX01-R2 module. A network is formed using two Proflex01 R2 modules, one configured as the Coordinator and the other configured as End Device. Our application allows transfer of messages from the Coordinator to the End device and vice versa. The data of 20ms frame size, sent over the UART interface by TMS320C5505 is received in the UART receive buffer of MSP430F5437A of Coordinator. In our application we have used USCI_A0 module for UART communication. The data in receive buffer (UCA0RXBUF) is transferred to an array RxString which is further transmitted over the air using CC2520. These message packets are received at the receiver CC2520 (End Device) and transferred to the UART transmit buffer of MSP430F5437A. The data in UART transmit buffer (UCA0TXBUF) is finally sent over UART interface to TMS320C5505 for decoding. The various parameters set for setting up of Zigbee Network are: PAN ID: 0xFF00 Channel of operation: Channel 11 The parameters required for setup of network are defined in the file f8wConfig.cfg in the project. We have built an application specific project “LSRApp.ewp” in IAR Embedded Workbench using the TI Z- Stack which consists of following source files: 1. LSRApp.c (LSRApp.h) 2. OSAL_LSRApp.c
  • 35. 35 The application instantiates a single Application Object for each ZDO with a unique endpoint defined using the following Simple Descriptor: const SimpleDescriptionFormat_t LSRApp_SimpleDesc = { LSRAPP_ENDPOINT, // int Endpoint; LSRAPP_PROFID, // uint16 AppProfId[2]; LSRAPP_DEVICEID, // uint16 AppDeviceId[2]; LSRAPP_DEVICE_VERSION, // int AppDevVer:4; LSRAPP_FLAGS, // int AppFlags:4; LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *) NULL, // byte *pAppInClusterList; LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)LSRApp_ClusterList // byte *pAppInClusterList; }; const cId_t LSRApp_ClusterList[LSRAPP_MAX_CLUSTERS] = { LSRAPP_CLUSTERID }; We have used a single cluster id: LSRAPP_CLUSTERID for both sending and receiving the messages from a ZDO. The two major functions to be implemented for a task defined for an application object are:  Task initialization function: LSRApp_Init()  Function to handle task events: LSRApp_ProcessEvent()
  • 36. 36 4.3.1 LSRApp_Init(): The initialization function deals with initialization of variables local to or specific for the corresponding Application Object. Here we define the following:  task id: LSRApp_TaskId which is set to the task id value assigned by OSAL.  Network state: LSRApp_NwkState = DEV_INIT , this indicates that the network state at power-up is “not connected”.  Message transaction counter: LSRApp_TransID = 0, keeps track of the no of times message is sent.  Here we also define the endpoint description of the application object and register it with the application framework using afRegister( &LSRApp_epDesc ). This allows the AF layer to know how to route incoming packets destined for the profile/endpoint.  The application is also registered for the exclusive system service of key press notification.  RegisterForKeys( LSRApp_TaskID )  A default destination address is initialized so that messages will be sent as bound messages  GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;  GenericApp_DstAddr.endPoint = 0;  GenericApp_DstAddr.addr.shortAddr = 0;  The UART module is configured and the state machine is released. Interrupts to be used in the application are enabled.  SFRIE1 |= WDTIE; // Enable WDT interrupt  P3SEL |= 0x3C; // P3.4,5 = USCI_A0 TXD/RXD  P3DIR |= 0x01;  UCA0CTL1 |= UCSWRST; // 8-bit characters  UCA0CTL1 = UCSSEL_1; // CLK = ACLK  UCA0BR0 = 0x03; // 32k/9600=3.41
  • 37. 37  UCA0BR1 = 0x00;  UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation  UCA0CTL1 &= ~UCSWRST; // Release USCI state machine 4.3.2 LSRApp_ProcessEvent(): This is a callback function to handle task events. SYS_EVENT_MSG (0x8000): This is a mandatory event and all the global system messages are sent via the SYS_EVENT_MSG. The task event handler processes the following minimal subset of these global system messages.  AF_DATA_CONFIRM_CMD: This is an indication of the over-the-air result for each data request that is successfully initiated by invoking AF_DataRequest(). Since the data request is made with the AF_ACK_REQUEST flag set hence the ZSuccess confirms that the message was successfully received at the final destination.  AF_INCOMING_MSG_CMD: This is an indication of an incoming AF message.  KEY_CHANGE: This is an indication of a key press action.  ZDO_STATE_CHANGE: With the device power up, initially its network state is not connected. The device immediately tries to either join or form the network. The change in network state generates ZDO_STATE_CHANGE sytem event and the device receives notification of the status of the network formation or join.  ZDO_CB_MSG: This message is sent to the application for every registered ZDO response message [ZDO_RegisterForZDOMsg()].
  • 38. 38 4.3.3 Sending Message: The program flow for sending a Message over the air is as follows:  Address Initialization  Register “Service discovery” call back  Issue the service discovery operation i.e Match description request  Handle the message call back  Send the device bind request  Send the message via the Af_DataRequest  If the return value of AF_DataRequest() = ZSuccess, this signifies that the message has been accepted by the Network Layer which will attempt to send it to the MAC layer which will attempt to send it over-the-air . This results in a “callback” by way of the AF_DATA_CONFIRM_CMD system event message.  The AF_DATA_CONFIRM_CMD ultimately generates the "sentStatus = Zsuccess" to indicate message is delivered to the destination address.
  • 39. 39 With power up, device network state is not connected Match description request is made Call AF_DataRequest() to send the message received over UART ZDO_STATE_CHANGE E System Events generated KEY_CHANGE User 1 Key is pressed ZDO_CB_MSG Match description request response indicates status of request KEY_CHANGE User 2 Key is pressed End device Binding request is made ZDO_CB_MSG Device binding request response indicates status of request LSRAPP_SEND_MSG_EVT If AF_ACK_REQUEST= Zsuccess AF_DATA_CONFIRM_CMD If SentStatus = Zsuccess Message successfully sent over the air TRUE FALSE Figure 11: Flowchart representing sending of message over the air using ZigBee
  • 40. 40 4.3.4 Receiving Message: The program flow for receiving the message is as follows:  Address Initialization  Register “Service discovery” call back  Issue the service discovery operation  Handle the message call back  Send the bind request  Process the incoming message The above flow is similar to the program flow for sending message except for the last stage to process the incoming message. The receiving Application Object is notified about the incoming message by the SYS_EVENT_MSG message AF_INCOMING_MSG_CMD. This event generates a call to the function LSRApp_MessageMSGCB(MSGpkt). Message successfully received over the air AF_INCOMING_MSG_CMD System Events generated Put the data in UART transmit buffer Data is sent to the DSP processor for decoding and further processing Figure 12: Flowchart representing receiving of message over the air using ZigBee
  • 41. 41 Figure 13: Screenshots indicating Coordinator and End device project build in IAR
  • 42. 42 4.4 CONCLUSION: We have successfully implemented the speech compression and decompression using Speex Codec in the loop back mode with high voice quality.
  • 43. 43 APPENDIX Program code for Speex Compression on TMS320C5505: /* Modified from speexlib/testenc.c for Code Composer simulator */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include <speex/speex.h> #include <speex/speex_callbacks.h> #include "arch.h" #include "usbstk5505.h" #include "usbstk5505_i2s.h" #include "csl_i2s.h" #include "csl_intc.h" #include "csl_dma.h" #include "csl_uart.h" #include "csl_uartAux.h" #undef DECODE_ONLY #define CHECK_RESULT /* Compares original file with encoded/decoder file */ #define TESTENC_BYTES_PER_FRAME 20 /* 8kbps */ #define TESTENC_QUALITY 4 /* 8kbps */ //#define TESTENC_BYTES_PER_FRAME 28 /* 11kbps */ //#define TESTENC_QUALITY 5 /* 11 kbps */ /* For narrowband, QUALITY maps to these bit rates (see modes.c, manual.pdf) * {1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7} * 0 -> 2150 * 1 -> 3950 * 2 -> 5950 * 3 -> 8000 * 4 -> 8000 * 5 -> 11000 * 6 -> 11000 * 7 -> 15000
  • 44. 44 * 8 -> 15000 * 9 -> 18200 *10 -> 26400 */ #define FRAME_SIZE 160 #define CSL_DMA_BUFFER_SIZE 160 extern void AIC3204_init( ); short out_short[FRAME_SIZE]; char cbits[TESTENC_BYTES_PER_FRAME/2 + 2]; // temp store for encoded data //int busyEncoding; int i_loop,j_loop; static int count ; #ifdef FIXED_DEBUG extern long long spx_mips; #endif //#include <math.h> #ifdef MANUAL_ALLOC /* Take all Speex space from this private heap */ /* This is useful for multichannel applications */ #pragma DATA_SECTION(spxHeap, ".myheap"); static char spxHeap[SPEEX_PERSIST_STACK_SIZE]; #pragma DATA_SECTION(spxScratch, ".myheap"); static char spxScratch[SPEEX_SCRATCH_STACK_SIZE]; char *spxGlobalHeapPtr, *spxGlobalHeapEnd; char *spxGlobalScratchPtr, *spxGlobalScratchEnd; #endif //from try_i2sdma_regs.c #define CSL_TEST_FAILED (1) #define CSL_TEST_PASSED (0) #define CSL_DMA0_CH0 (0) //Int16 count=0; volatile Int16 PaSs_StAtE = 0x0001; // Init to 1. Reset to 0 at any monitored execution error. volatile Int16 PaSs = 0x0000; Int16 ReadyToEncode=0; Int16 tx_done=0; short RcvL1[FRAME_SIZE]; //from uart.c #define CSL_TEST_FAILED (-1) #define NO_OF_CHAR_TO_READ TESTENC_BYTES_PER_FRAME #define NO_OF_CHAR_TO_WRITE TESTENC_BYTES_PER_FRAME #define CSL_UART_WRBUF_SIZE (NO_OF_CHAR_TO_WRITE*4) #define CSL_UART_RDBUF_SIZE (NO_OF_CHAR_TO_READ*4)
  • 45. 45 #define CSL_PLL_DIV_000 (0) #define CSL_PLL_DIV_001 (1u) #define CSL_PLL_DIV_002 (2u) #define CSL_PLL_DIV_003 (3u) #define CSL_PLL_DIV_004 (4u) #define CSL_PLL_DIV_005 (5u) #define CSL_PLL_DIV_006 (6u) #define CSL_PLL_DIV_007 (7u) #define CSL_PLL_CLOCKIN (32768u) /* Global data definition */ /* UART setup structure */ CSL_UartSetup mySetup = { 100000000, /* Input clock freq in MHz */ 115200, /* baud rate */ /* word length of 8 */ CSL_UART_WORD8, /* To generate 1 stop bit */ 0, /* Disable the parity */ CSL_UART_DISABLE_PARITY, /* enable trigger 14 fifo */ CSL_UART_FIFO_DMA1_ENABLE_TRIG14, /* Loop Back enable */ CSL_UART_NO_LOOPBACK, /* No auto flow control*/ CSL_UART_NO_AFE , /* No RTS */ CSL_UART_NO_RTS , }; /** * brief Function to calculate the system clock * param none * return System clock value in Hz */ Uint32 getSysClk(void); /* CSL UART object */ CSL_UartObj uartObj; /* CSL DMA data structures used for UART data transfers */ CSL_DMA_Handle dmaWrHandle; CSL_DMA_Handle dmaRdHandle; CSL_DMA_Config dmaConfig_uart; CSL_DMA_Config dmaConfig_uart2;
  • 46. 46 CSL_DMAChanNum chanNum3; CSL_DMAChanNum chanNum4; CSL_DMA_ChannelObj dmaWrChanObj; CSL_DMA_ChannelObj dmaRdChanObj; char guartDmaReadBuf[CSL_UART_RDBUF_SIZE]; /* Reference the start of the interrupt vector table */ extern void VECSTART(void); /* Protype declaration for ISR function */ interrupt void dma_isr(void); CSL_DMA_Handle dmaHandle; CSL_DMA_Config dmaConfig; CSL_DMA_Config getdmaConfig; CSL_DMA_ChannelObj dmaObj; CSL_DMA_Handle dmaHandle2; CSL_DMA_Config dmaConfig2; CSL_DMA_Config getdmaConfig2; CSL_DMA_ChannelObj dmaObj2; CSL_DMA_Handle dmaLeftRxHandle; CSL_DMA_Handle dmaLeftTxHandle; Uint16 dmaSRCBuff[CSL_DMA_BUFFER_SIZE]; Uint16 dmaDESTBuff[CSL_DMA_BUFFER_SIZE]; void dma_func() { CSL_Status status; Uint16 i; Uint16 chanNumber; Uint16 chanNumber2; #if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) dmaConfig.pingPongMode = CSL_DMA_PING_PONG_DISABLE; #endif dmaConfig.autoMode = CSL_DMA_AUTORELOAD_ENABLE; dmaConfig.burstLen = CSL_DMA_TXBURST_1WORD; dmaConfig.trigger = CSL_DMA_SOFTWARE_TRIGGER; dmaConfig.dmaEvt = CSL_DMA_EVT_NONE; dmaConfig.dmaInt = CSL_DMA_INTERRUPT_ENABLE; dmaConfig.chanDir = CSL_DMA_READ; dmaConfig.trfType = CSL_DMA_TRANSFER_IO_MEMORY; dmaConfig.dataLen = CSL_DMA_BUFFER_SIZE * 2; dmaConfig.srcAddr = (Uint32)(0x00002828); dmaConfig.destAddr = (Uint32)RcvL1;
  • 47. 47 IRQ_globalDisable(); IRQ_clearAll(); IRQ_disableAll(); IRQ_setVecs((Uint32)&VECSTART); IRQ_clear(DMA_EVENT); IRQ_plug (DMA_EVENT, &dma_isr); IRQ_enable(DMA_EVENT); IRQ_globalEnable(); status = DMA_init(); if (status != CSL_SOK) { printf("DMA_init() Failed n"); /////INSTRUMENTATION FOR BATCH TESTING -- Part 2 -- ///// Reseting PaSs_StAtE to 0 if error detected here. PaSs_StAtE = 0x0000; // Was intialized to 1 at declaration. ///// } chanNumber=0; count = 0; // printf("n Test for DMA Channel No : %d t", chanNumber); dmaHandle = DMA_open((CSL_DMAChanNum)chanNumber,&dmaObj, &status); if (dmaHandle == NULL) { printf("DMA_open() Failed n"); //break; } status = DMA_config(dmaHandle, &dmaConfig); if (status != CSL_SOK) { printf("DMA_config() Failed n"); //break; } status = DMA_start(dmaHandle); if (status != CSL_SOK) { printf("DMA_start() Failed n"); //break; } while(count != 1);
  • 48. 48 while(count == 0); } void dma_func2() { CSL_Status status; Uint16 i; Uint16 chanNumber2; tx_done=0; #if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) dmaConfig2.pingPongMode = CSL_DMA_PING_PONG_DISABLE; #endif dmaConfig2.autoMode = CSL_DMA_AUTORELOAD_ENABLE; dmaConfig2.burstLen = CSL_DMA_TXBURST_1WORD; dmaConfig2.trigger = CSL_DMA_SOFTWARE_TRIGGER; dmaConfig2.dmaEvt = CSL_DMA_EVT_NONE; dmaConfig2.dmaInt = CSL_DMA_INTERRUPT_ENABLE; dmaConfig2.chanDir = CSL_DMA_WRITE; dmaConfig2.trfType = CSL_DMA_TRANSFER_IO_MEMORY; dmaConfig2.dataLen = CSL_DMA_BUFFER_SIZE * 2; dmaConfig2.srcAddr = (Uint32) out_short; dmaConfig2.destAddr = (Uint32)(0x00002808); IRQ_globalDisable(); IRQ_clearAll(); IRQ_disableAll(); IRQ_setVecs((Uint32)&VECSTART); IRQ_clear(DMA_EVENT); IRQ_plug (DMA_EVENT, &dma_isr); IRQ_enable(DMA_EVENT); IRQ_globalEnable(); chanNumber2=1; count = 0; // printf("n Test for DMA Channel No : %d t", chanNumber); dmaHandle2 = DMA_open((CSL_DMAChanNum)chanNumber2,&dmaObj2, &status); if (dmaHandle2 == NULL) { printf("DMA_open() Failed n"); //break; }
  • 49. 49 status = DMA_config(dmaHandle2, &dmaConfig2); if (status != CSL_SOK) { printf("DMA_config() Failed n"); //break; } status = DMA_start(dmaHandle2); if (status != CSL_SOK) { printf("DMA_start() Failed n"); //break; } while(count == 0); } //end of dma_func2 #if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) Uint32 getSysClk(void) { Bool pllRDBypass; Bool pllOutDiv; Uint32 sysClk; Uint16 pllVP; Uint16 pllVS; Uint16 pllRD; Uint16 pllVO; pllVP = CSL_FEXT(CSL_SYSCTRL_REGS->CGCR1, SYS_CGCR1_VP); pllVS = CSL_FEXT(CSL_SYSCTRL_REGS->CGCR1, SYS_CGCR1_VS); pllRD = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDRATIO); pllVO = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OD); pllRDBypass = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDBYPASS); pllOutDiv = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OUTDIVEN); sysClk = CSL_PLL_CLOCKIN; if (0 == pllRDBypass) { sysClk = sysClk/(pllRD + 4); }
  • 50. 50 sysClk = (sysClk * ((pllVP << 2) + pllVS + 4)); if (1 == pllOutDiv) { sysClk = sysClk/(pllVO + 1); } /* Return the value of system clock in KHz */ return(sysClk); } #else Uint32 getSysClk(void) { Bool pllRDBypass; Bool pllOutDiv; Bool pllOutDiv2; Uint32 sysClk; Uint16 pllVP; Uint16 pllVS; Uint16 pllRD; Uint16 pllVO; Uint16 pllDivider; Uint32 pllMultiplier; pllVP = CSL_FEXT(CSL_SYSCTRL_REGS->CGCR1, SYS_CGCR1_MH); pllVS = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_ML); pllRD = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDRATIO); pllVO = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_ODRATIO); pllRDBypass = CSL_FEXT(CSL_SYSCTRL_REGS->CGICR, SYS_CGICR_RDBYPASS); pllOutDiv = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OUTDIVEN); pllOutDiv2 = CSL_FEXT(CSL_SYSCTRL_REGS->CGOCR, SYS_CGOCR_OUTDIV2BYPASS); pllDivider = ((pllOutDiv2) | (pllOutDiv << 1) | (pllRDBypass << 2)); pllMultiplier = ((Uint32)CSL_PLL_CLOCKIN * ((pllVP << 2) + pllVS + 4)); switch(pllDivider) { case CSL_PLL_DIV_000: case CSL_PLL_DIV_001: sysClk = pllMultiplier / (pllRD + 4); break;
  • 51. 51 case CSL_PLL_DIV_002: sysClk = pllMultiplier / ((pllRD + 4) * (pllVO + 4) * 2); break; case CSL_PLL_DIV_003: sysClk = pllMultiplier / ((pllRD + 4) * 2); break; case CSL_PLL_DIV_004: case CSL_PLL_DIV_005: sysClk = pllMultiplier; break; case CSL_PLL_DIV_006: sysClk = pllMultiplier / ((pllVO + 4) * 2); break; case CSL_PLL_DIV_007: sysClk = pllMultiplier / 2; break; } /* Return the value of system clock in KHz */ return(sysClk); } #endif CSL_DMA_Handle CSL_configDmaForUart(CSL_DMA_ChannelObj *dmaChanObj, CSL_DMAChanNum chanNum) { CSL_DMA_Handle dmaHandle; CSL_Status status; dmaHandle = NULL; /* Open A Dma channel */ dmaHandle = DMA_open(chanNum, dmaChanObj, &status); if(dmaHandle == NULL) { printf("DMA_open Failed!n"); } /* Configure a Dma channel */ status = DMA_config(dmaHandle, &dmaConfig_uart); if(status != CSL_SOK) { printf("DMA_config Failed!n");
  • 52. 52 dmaHandle = NULL; } return(dmaHandle); } CSL_Status uart_tx_rx(void) { CSL_UartHandle hUart; CSL_Status status; int looper; Uint32 sysClk; sysClk = getSysClk(); mySetup.clkInput = sysClk; /* Initialize CSL UART module */ status = UART_init(&uartObj,CSL_UART_INST_0,UART_POLLED); if(CSL_SOK != status) { printf("UART_init failed error code %dn",status); return(status); } else { printf("UART_init Successfuln"); } /* Handle created*/ hUart = (CSL_UartHandle)(&uartObj); /* Configure the DMA channel for UART transmit */ #if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) dmaConfig_uart.pingPongMode = CSL_DMA_PING_PONG_DISABLE; #endif dmaConfig_uart.autoMode = CSL_DMA_AUTORELOAD_DISABLE; dmaConfig_uart.burstLen = CSL_DMA_TXBURST_1WORD; dmaConfig_uart.trigger = CSL_DMA_EVENT_TRIGGER; dmaConfig_uart.dmaEvt = CSL_DMA_EVT_UART_TX; dmaConfig_uart.dmaInt = CSL_DMA_INTERRUPT_DISABLE; dmaConfig_uart.chanDir = CSL_DMA_WRITE; dmaConfig_uart.trfType = CSL_DMA_TRANSFER_IO_MEMORY; dmaConfig_uart.dataLen = CSL_UART_WRBUF_SIZE; dmaConfig_uart.srcAddr = (Uint32) cbits; dmaConfig_uart.destAddr = (Uint32)&(hUart->uartRegs->THR); dmaWrHandle = CSL_configDmaForUart(&dmaWrChanObj, CSL_DMA_CHAN4);
  • 53. 53 /* Start Dma transfer */ status = DMA_start(dmaWrHandle); if(status != CSL_SOK) { printf("Uart Dma Write Failed!!n"); return(status); } /* Configure UART registers using setup structure */ status = UART_setup(hUart,&mySetup); if(CSL_SOK != status) { printf("UART_setup failed error code %dn",status); return status; } else { printf("UART_setup Successfuln"); } /* Check transfer complete status */ while(DMA_getStatus(dmaWrHandle)); /* Configure the DMA channel for UART receive */ #if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) dmaConfig_uart.pingPongMode = CSL_DMA_PING_PONG_DISABLE; #endif dmaConfig_uart.autoMode = CSL_DMA_AUTORELOAD_DISABLE; dmaConfig_uart.burstLen = CSL_DMA_TXBURST_1WORD; dmaConfig_uart.trigger = CSL_DMA_SOFTWARE_TRIGGER; dmaConfig_uart.dmaEvt = CSL_DMA_EVT_NONE; dmaConfig_uart.dmaInt = CSL_DMA_INTERRUPT_DISABLE; dmaConfig_uart.chanDir = CSL_DMA_READ; dmaConfig_uart.trfType = CSL_DMA_TRANSFER_IO_MEMORY; dmaConfig_uart.dataLen = CSL_UART_RDBUF_SIZE; dmaConfig_uart.srcAddr = (Uint32)&(hUart->uartRegs->THR); dmaConfig_uart.destAddr = (Uint32)guartDmaReadBuf; dmaRdHandle = CSL_configDmaForUart(&dmaRdChanObj,CSL_DMA_CHAN4); /* Open A Dma channel */ chanNum4=CSL_DMA_CHAN5; dmaRdHandle = DMA_open(chanNum4, &dmaRdChanObj, &status); if(dmaRdHandle == NULL) { printf("DMA_open Failed!n"); } /* Configure a Dma channel */ status = DMA_config(dmaRdHandle, &dmaConfig_uart2);
  • 54. 54 if(status != CSL_SOK) { printf("DMA_config Failed!n"); dmaRdHandle = NULL; } if(dmaRdHandle == NULL) { printf("DMA Config for DMA Read Failed!n!"); //return(CSL_TEST_FAILED); } /* Start Dma transfer */ status = DMA_start(dmaRdHandle); if(status != CSL_SOK) { printf("Uart Dma Write Failed!!n"); return(status); } /* Check transfer complete status */ while(DMA_getStatus(dmaRdHandle)); } void main() { Uint16 i; //Uint16 i_loop; int nbChars; char cbits[TESTENC_BYTES_PER_FRAME/2 + 2]; // temp store for encoded data void *st; void *dec; SpeexBits bits; spx_int32_t tmp; unsigned long bitCount=0; spx_int32_t skip_group_delay; SpeexCallback callback; // C54xx defaults to max wait states, even for parts like C5416 with // larger internal memory. Need to force the wait state register to zero #ifdef CONFIG_TI_C54X asm(" STM #0,SWWSR"); #endif /* #ifdef CHECK_RESULT sigpow = 0; errpow = 0; #endif */
  • 55. 55 #ifdef MANUAL_ALLOC spxGlobalHeapPtr = spxHeap; spxGlobalHeapEnd = spxHeap + sizeof(spxHeap); spxGlobalScratchPtr = spxScratch; spxGlobalScratchEnd = spxScratch + sizeof(spxScratch); #endif st = speex_encoder_init(&speex_nb_mode); #ifdef MANUAL_ALLOC spxGlobalScratchPtr = spxScratch; // Reuse scratch for decoder #endif dec = speex_decoder_init(&speex_nb_mode); callback.callback_id = SPEEX_INBAND_CHAR; callback.func = speex_std_char_handler; callback.data = stderr; speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); callback.callback_id = SPEEX_INBAND_MODE_REQUEST; callback.func = speex_std_mode_request_handler; callback.data = st; speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback); tmp=0; speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp); tmp=0; speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp); tmp=TESTENC_QUALITY; speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp); tmp=1; // Lowest speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp); #ifdef DISABLE_HIGHPASS // Turn this off if you want to measure SNR (on by default) tmp=0; speex_encoder_ctl(st, SPEEX_SET_HIGHPASS, &tmp); speex_decoder_ctl(dec, SPEEX_SET_HIGHPASS, &tmp); #endif speex_encoder_ctl(st, SPEEX_GET_LOOKAHEAD, &skip_group_delay); speex_decoder_ctl(dec, SPEEX_GET_LOOKAHEAD, &tmp); skip_group_delay += tmp; fprintf (stderr, "decoder lookahead = %ldn", skip_group_delay); AIC3204_init( ); speex_bits_init(&bits); for(i = 0; i < CSL_DMA_BUFFER_SIZE; i++) {
  • 56. 56 out_short[i]=0; } while(1) { dma_func(); //refer speex.h for these functions speex_bits_reset(&bits); speex_encode_int(st, RcvL1, &bits); nbChars = speex_bits_write(&bits, cbits,sizeof(cbits)*BYTES_PER_CHAR) /BYTES_PER_CHAR; speex_bits_reset(&bits); uart_tx_rx(); speex_bits_rewind(&bits); //speex_bits_read_from(&bits, cbits,TESTENC_BYTES_PER_FRAME); speex_bits_read_from(&bits, guartDmaReadBuf,TESTENC_BYTES_PER_FRAME); //printf("%dn",counterDecode++); // counterDecode++; speex_decode_int(dec, &bits, out_short); skip_group_delay = 0; count=0; dma_func2(); }//end of while }//end of main interrupt void dma_isr(void) { int ifrValue; ifrValue = CSL_SYSCTRL_REGS->DMAIFR; CSL_SYSCTRL_REGS->DMAIFR |= ifrValue; //printf("entered dma_isrn"); ++count; }
  • 57. 57 Program code for transmission and receiving message over ZigBee: #include "OSAL.h" #include "AF.h" #include "ZDApp.h" #include "ZDObject.h" #include "ZDProfile.h" #include "LSRApp.h" #include "DebugTrace.h" #if !defined( WIN32 ) #include "OnBoard.h" #endif /* HAL */ #include "hal_lcd.h" #include "hal_led.h" #include "hal_key.h" #include "hal_uart.h" /* RTOS */ #if defined( IAR_ARMCM3_LM ) #include "RTOS_App.h" #endif /********************************************************************* * GLOBAL VARIABLES */ // This list should be filled with Application specific Cluster IDs. const cId_t LSRApp_ClusterList[LSRAPP_MAX_CLUSTERS] = { LSRAPP_CLUSTERID }; const SimpleDescriptionFormat_t LSRApp_SimpleDesc = { LSRAPP_ENDPOINT, // int Endpoint; LSRAPP_PROFID, // uint16 AppProfId[2]; LSRAPP_DEVICEID, // uint16 AppDeviceId[2]; LSRAPP_DEVICE_VERSION, // int AppDevVer:4; LSRAPP_FLAGS, // int AppFlags:4; LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)LSRApp_ClusterList, // byte *pAppInClusterList; LSRAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)LSRApp_ClusterList // byte *pAppInClusterList; }; // This is the Endpoint/Interface description. It is defined here, but // filled-in in LSRApp_Init(). Another way to go would be to fill
  • 58. 58 // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t LSRApp_epDesc; /********************************************************************* * LOCAL VARIABLES */ byte LSRApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // LSRApp_Init() is called. devStates_t LSRApp_NwkState; byte LSRApp_TransID; // This is the unique message ID (counter) afAddrType_t LSRApp_DstAddr; /********************************************************************* * LOCAL FUNCTIONS */ static void LSRApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ); static void LSRApp_HandleKeys( /*byte shift,*/ byte keys ); static void LSRApp_MessageMSGCB( afIncomingMSGPacket_t *pckt ); static void LSRApp_SendTheMessage( void ); #if defined( IAR_ARMCM3_LM ) static void LSRApp_ProcessRtosMessage( void ); #endif /********************************************************************* * PUBLIC FUNCTIONS /********************************************************************* * @fn LSRApp_Init * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * @return none */ void LSRApp_Init( uint8 task_id ) { LSRApp_TaskID = task_id; LSRApp_NwkState = DEV_INIT; LSRApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). LSRApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; LSRApp_DstAddr.endPoint = 0;
  • 59. 59 LSRApp_DstAddr.addr.shortAddr = 0; SFRIE1 |= WDTIE; // Enable WDT interrupt P3SEL |= 0x3C; // P3.4,5 = USCI_A0 TXD/RXD P3DIR |= 0x01; // P3.0 = CSn OUTPUT DIRECTION UCA0CTL1 |= UCSWRST; // 8-bit characters UCA0CTL1 = UCSSEL_1; // CLK = ACLK UCA0BR0 = 0x03; // 32k/9600=3.41 UCA0BR1 = 0x00; UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation UCA0CTL1 &= ~UCSWRST; // Release USCI state machine HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); HalLedSet( HAL_LED_3, HAL_LED_MODE_ON ); // Fill out the endpoint description. LSRApp_epDesc.endPoint = LSRAPP_ENDPOINT; LSRApp_epDesc.task_id = &LSRApp_TaskID; LSRApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&LSRApp_SimpleDesc; LSRApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &LSRApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( LSRApp_TaskID ); // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "LSRApp", HAL_LCD_LINE_1 ); #endif ZDO_RegisterForZDOMsg( LSRApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( LSRApp_TaskID, Match_Desc_rsp ); #if defined( IAR_ARMCM3_LM ) // Register this task with RTOS task initiator RTOS_RegisterApp( task_id, LSRAPP_RTOS_MSG_EVT ); #endif } /********************************************************************* * @fn LSRApp_ProcessEvent * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * @return none */
  • 60. 60 uint16 LSRApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; afDataConfirm_t *afDataConfirm; // Data Confirmation message fields byte sentEP; ZStatus_t sentStatus; byte sentTransID; // This should match the value sent (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( LSRApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case ZDO_CB_MSG: LSRApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt ); break; case KEY_CHANGE: LSRApp_HandleKeys( ((keyChange_t *)MSGpkt)->keys ); break; case AF_DATA_CONFIRM_CMD: // This message is received as a confirmation of a data packet sent. // The status is of ZStatus_t type [defined in ZComDef.h] // The message fields are defined in AF.h afDataConfirm = (afDataConfirm_t *)MSGpkt; sentEP = afDataConfirm->endpoint; sentStatus = afDataConfirm->hdr.status; sentTransID = afDataConfirm->transID; (void)sentEP; (void)sentTransID; // Action taken when confirmation is received. if ( sentStatus != ZSuccess ) { // The data wasn't delivered -- Do something HalLedSet(HAL_LED_2, HAL_LED_MODE_FLASH); //BLINK red led } break; case AF_INCOMING_MSG_CMD: //extern byte zclYour_TaskID; //osal_msg_send( zclYour_TaskID, msgPtr ); //osal_msg_send( LSRAPP_CLUSTERID, msgPtr ); LSRApp_MessageMSGCB( MSGpkt );
  • 61. 61 break; case ZDO_STATE_CHANGE: LSRApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( (LSRApp_NwkState == DEV_ZB_COORD) || (LSRApp_NwkState == DEV_ROUTER) || (LSRApp_NwkState == DEV_END_DEVICE) ) { // Start sending "the" message in a regular interval. osal_start_timerEx( LSRApp_TaskID, LSRAPP_SEND_MSG_EVT, LSRAPP_SEND_MSG_TIMEOUT ); //osal_set_event(LSRApp_TransID, LSRAPP_SEND_MSG_EVT); } HalLedSet(HAL_LED_1, HAL_LED_MODE_ON); //flash red led HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH); //flash green led*/ break; } osal_msg_deallocate( (uint8 *)MSGpkt ); // Release the memory // Next MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( LSRApp_TaskID ); } return (events ^ SYS_EVENT_MSG); // return unprocessed events } // Send a message out - This event is generated by a timer // (setup in LSRApp_Init()). if ( events & LSRAPP_SEND_MSG_EVT ) { // Send "the" message LSRApp_SendTheMessage(); // Setup to send message again osal_start_timerEx( LSRApp_TaskID, LSRAPP_SEND_MSG_EVT, LSRAPP_SEND_MSG_TIMEOUT ); // return unprocessed events return (events ^ LSRAPP_SEND_MSG_EVT); } #if defined( IAR_ARMCM3_LM ) // Receive a message from the RTOS queue if ( events & LSRAPP_RTOS_MSG_EVT ) { // Process message from RTOS queue LSRApp_ProcessRtosMessage();
  • 62. 62 // return unprocessed events return (events ^ LSRAPP_RTOS_MSG_EVT); } #endif // Discard unknown events return 0; } /********************************************************************* * Event Generation Functions /********************************************************************* * @fn LSRApp_ProcessZDOMsgs() * * @brief Process response messages * @param none * @return none */ static void LSRApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) { zAddrType_t dstAddr; switch ( inMsg->clusterID ) { case End_Device_Bind_rsp: if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess ) { // Light LED HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );// green led on } //#if defined( BLINK_LEDS ) else { dstAddr.addrMode = Addr16Bit; dstAddr.addr.shortAddr = 0x0000; // Coordinator ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), LSRApp_epDesc.endPoint, LSRAPP_PROFID, LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, FALSE ); // Flash LED to show failure //HalLedSet ( HAL_LED_1, HAL_LED_MODE_FLASH );// green led blinking } //#endif break; case Match_Desc_rsp: { ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); if ( pRsp )
  • 63. 63 { if ( pRsp->status == ZSuccess && pRsp->cnt ) { LSRApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; LSRApp_DstAddr.addr.shortAddr = pRsp->nwkAddr; // Take the first endpoint, Can be changed to search through endpoints LSRApp_DstAddr.endPoint = pRsp->epList[0]; // Light LED HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH); //blink green yellow led //HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );// green led on } osal_mem_free( pRsp ); } } break; } } /********************************************************************* * @fn LSRApp_HandleKeys * @brief Handles all key events for this device. * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_4 * HAL_KEY_SW_3 * HAL_KEY_SW_2 * HAL_KEY_SW_1 * @return none */ static void LSRApp_HandleKeys( /*uint8 shift,*/ uint8 keys ) { zAddrType_t dstAddr; if ( keys & HAL_KEY_SW_1 ) { // Initiate a Match Description Request (Service Discovery) //HalLedSet ( HAL_LED_1, HAL_LED_MODE_ON ); // green led off initially dstAddr.addrMode = AddrBroadcast; dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR; ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, LSRAPP_PROFID, LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, FALSE ); } if ( keys & HAL_KEY_SW_2 ) { // Initiate an End Device Bind Request for the mandatory endpoint
  • 64. 64 dstAddr.addrMode = Addr16Bit; dstAddr.addr.shortAddr = 0x0000; // Coordinator ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), LSRApp_epDesc.endPoint, LSRAPP_PROFID, LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, LSRAPP_MAX_CLUSTERS, (cId_t *)LSRApp_ClusterList, FALSE ); } } /********************************************************************* * LOCAL FUNCTIONS /********************************************************************* * @fn LSRApp_MessageMSGCB * @brief Data message processor callback. This function processes * any incoming data - probably from other devices. So, based * on cluster ID, perform the intended action. * @param none * @return none */ static void LSRApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { char *l1; uint8 l2; HalLedSet(HAL_LED_3, HAL_LED_MODE_FLASH); l1 = (char*)pkt->cmd.Data; l2 = *l1; while (!(UCA0IFG&UCTXIFG)); UCA0TXBUF = l2; } /********************************************************************* * @fn LSRApp_SendTheMessage * @brief Send "the" message. * @param none * @return none */ static void LSRApp_SendTheMessage( void ) { for(int i=0;i<160;i++) { theMessageData[i] = UCA0RXBUF; } if ( AF_DataRequest( &LSRApp_DstAddr, &LSRApp_epDesc, LSRAPP_CLUSTERID, (byte) sizeof(theMessageData)*4, (byte *)&theMessageData,
  • 65. 65 &LSRApp_TransID, AF_ACK_REQUEST, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { // Successfully requested to be sent. HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF); //ON yellow led } else { // Error occurred in request to send. HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF );// Red Led on } } #if defined( IAR_ARMCM3_LM ) /********************************************************************* * @fn LSRApp_ProcessRtosMessage * @brief Receive message from RTOS queue, send response back. * @param none * @return none */ static void LSRApp_ProcessRtosMessage( void ) { osalQueue_t inMsg; if ( osal_queue_receive( OsalQueue, &inMsg, 0 ) == pdPASS ) { uint8 cmndId = inMsg.cmnd; uint32 counter = osal_build_uint32( inMsg.cbuf, 4 ); switch ( cmndId ) { case CMD_INCR: counter += 1; /* Increment the incoming counter */ /* Intentionally fall through next case */ case CMD_ECHO: { userQueue_t outMsg; outMsg.resp = RSP_CODE | cmndId; /* Response ID */ osal_buffer_uint32( outMsg.rbuf, counter ); /* Increment counter */ osal_queue_send( UserQueue1, &outMsg, 0 ); /* Send back to UserTask */ break; } default: break; /* Ignore unknown command */ } } } #endif /**********************************************************************/
  • 66. 66 REFERENCES 1. E. Touloupis et al., “Speech Codecs for High-Quality Voiceover ZigBee Applications: Evaluation and Implementation Challenges,” IEEE Commun. Mag., vol. 50, no. 4, April 2012. 2. J.-M. Valin, “The Speex Codec Manual Version 1.2 Beta3,” Dec. 2007. 3. Human Voice streaming over ZigBee - Low Bandwidth Communication by Manish Kumar Verma, Adarsh Pillai. 4. L. Y. Hua and F. F. Teng, “Delivering High Quality, Secure Speech Communication through Low Data Rate 802.15.4 WPAN,” IEEE Int’l. Conf. Telecommunications and Malaysia Int’l. Conf. Commun., 2007. ICT-MICC 2007. 5. TI TMS320C5505 Family Reference Manual. 6. eZDSP Stick User Guide. 7. LS Research ProFLEX01 R2 Module User Guide and datasheet. 8. http://www.iar.com/en/Service-Center/Downloads/ 9. http://support.spectrumdigital.com/boards/usbstk5505/revc/ 10. http://www.lsr.com/wireless-products/proflex01-r2 11. http://www.ti.com/tool/z-stack