Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Wireless Sensor Networks
Introduction to the Laboratory
Chiara Buratti
[email protected]+39 051 20 93147
Office Hours: Tuesday 3 – 5 pm @ Main Building, third floor
Credits: 6
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Outline
• MC1322x Devices
• IAR Embedded workbench / Beekit
• Basics of Network Software
• Freescale 802.15.4 Software
• Embedded C
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Outline
• MC1322x Devices
• IAR Embedded workbench / Beekit
• Basics of Network Software
• Freescale 802.15.4 Software
• Embedded C
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Freescale MC1322x Transceiver
• 16 Channels in the 2.4 GHz ISM band
• Transmit Power -30 dBm to +4 dBm typical
• Supports 250 kbps bit rate
• RX sensitivity of -96 dBm (Typical) at 1.0% Packet Error Rate (20 Bytes packets)
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Freescale MC1322x Transceiver
Current consumption:
• — 22 mA typical RX current draw (DCD mode) with radio and MCU active
• — 29 mA typical TX current draw with radio and MCU active (coin cell capable)
• — 3.3 mA typical current draw with MCU active (radio off)
• — 0.8 mA typical current with MCU idle (radio off)
• — 0.85 μA typical Hibernate current
(retain 8 Kbyte SRAM contents)
• — 0.4 μA maximum Off current
(device in reset)
Turnaround times:
• IEEE 802.15.4 requires a TX-to-RX or a
RX-to-TX TaT ≤ 12 Ts (192 μs).
• 11 Ts (176 μs) RX-to-TX
• 96 μs TX-to-RX.
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Freescale MC1322x MCU
• 32-bit ARM7 CPU
• 128 Kbytes FLASH Memory, 96 Kbyte SRAM, 80 Kbyte ROM
• Dedicated 802.15.4 modem/radio interface module (RIF)
• Up to 64 programmable I/O
• Two serial communications interface modules (UART)
• Serial peripheral interface module (SPI)
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MC1322x Block Diagram
Transceiver
CPU
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MAC Accelerator Block Diagram
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MACA core main features include:
• Acknowledgement transmission / reception
• Generate MAC data.request / reply to MAC data.request
• Dedicated DMA for transfer of TX/RX data from/to RAM
• Frame manager
— Handles preamble data
— Handles frame check sequence (FCS) using CRC
— Embedded header filter for received packets
MAC Accelerator Block Diagram
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Outline
• MC1322x Devices
• IAR Embedded workbench / Beekit
• Basics of Network Software
• Freescale 802.15.4 Software
• Embedded C
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
IAR / BeekitBeeKit:
A useful tool to create IAR
projects
IAR Embedded WorkbenchIntegrated Development
Environment (IDE) for MC1322x
Freescale Platform
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
IAR - Project
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Outline
• MC1322x Devices
• IAR Embedded workbench / Beekit
• Basics of Network Software
• Freescale 802.15.4 Software
• Embedded C
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Basics on Service Primitives
• Services of a layer are the capabilities it offers to the user in the next upper layer: Level n is a service provider for layer n+1, while layer n+1 is a service user for layer n.
• Services are described through the information flow between layers modeled through discrete events: each event consists of passing aservice primitive from one layer to another through Service Access Points (SAP).
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Basics on Service Primitives: Vertical view
Appl
MAC
PHY
request confirm
Service user for MAC Layer
Service user for PHY Layer
Service provider for APP Layer
Service provider for MAC Layer
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Basics on Service Primitives: Horizontal view
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Basics on Service Primitives
Primitive Meaning
requestan entity is requesting a service
(we are requesting a connection to a remote computer)
indicationan entity is informed of an event
(the receiver has just received a connection request)
responsean entity is responding to an event
(the receiver is sending the permission to connect)
confirm
an entity acknowledges the response to its request
(the sender acknoledge the permission to connect to the remote host)
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Service Primitives: an Example
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Service Primitives: an Example
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Outline
• MC1322x Devices
• IAR Embedded workbench / Beekit
• Basics of Network Software
• Freescale 802.15.4 Software
• Embedded C
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Freescale MAC/PHY Software
Vertical
Horizontal
• MLME interface: all MAC command
• MCPS interface: data primitive
• ASP interface: various application
support features
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Interfacing APP to MAC
• The interface between APP and MAC layers is based on service primitives passed as messages from one layer to another.
• Messages are sent to a SAP function which is responsible for handling the message.
• Five SAPs exist:
– NWN_MLME_SapHandler()
– NWK_MCPS_SapHandler()
– MLME_NWK_SapHandler()
– MCPS_NWK_SapHandler()
– APS_APP_SapHandler()
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
• Arrows Messages
Interfacing APP to MAC
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MAC API
• MAC Application Programming Interface (API) provides a simple way of interfacing to the Freescale MAC SW.
• The API functions available are used for:
– Initializing the MAC
– Running the MAC
– Allocating messages
– Deallocating messages
– Sending messages
– Queueing and dequeueing messages
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MAC API Functions
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MAC API - Messages
In order to request a service the Application must:
1. Allocate the message;2. Fill the message parameters
3. Send the message to the SAP Handler.
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MAC API – Queueing
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MAC API – Data Types
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Message Types: NWK-to-MLME directionmlmeMessage_t
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Message Types: MLME-to-NWK directionnwkMessage_t
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Message Types: NWK-to-MCPS directionmcpsMessage_t
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Message Types: MCPS-to-NWK directionmcpsToNwkMessage_t
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
AppTask
- Your code generally goes here
- It is called by task scheduler if an
event happens
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Coordinator Finite State Machine
InitScanED
Start
ScanEDWait
Confirm
Start CoordWait Confirm
Start Coord
Listen
gAppEvtRxFromUart_c
gAppEvtMessageFromMLME_c
gAppEvtMessageFromMCPS_c
gAppEvtDummyEvent_c gAppEvtStartCoordinator_c
gAppEvtMessageFromMLME_c
gAppEvtMessageFromMLME_c
gAppEvtDummyEvent_c
To generate a dummy event call:
TS_SendEvent(gAppTaskID_c, gAppEvtDummyEvent_c);
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
End Device Finite State Machine
InitScan
Active
ScanActiveWait
Confirm
Associate Wait Confirm
Associate
Listen
gAppEvtRxFromUart_c
gAppEvtMessageFromMLME_c
gAppEvtMessageFromMCPS_c
gAppEvtDummyEvent_c
gAppEvtMessageFromMLME_c
gAppEvtMessageFromMLME_c
gAppEvtDummyEvent_c
To generate a dummy event call:
TS_SendEvent(gAppTaskID_c, gAppEvtDummyEvent_c);
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MLME and MCPS Interfaces
• When requesting a service that is asynchronous, the MLME (or MCPS) must deallocate the message.
• SAP Handler only queue the message and returns asap.
• An event needs to be passed to the application task in order to notify that a new message from the MLME (or MCPS) has arrived from MLME_NWK (or MCPS_NKW).
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MLME_NWK SAP Handler
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
MCPS_NWK SAP Handler
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Outline
• MC1322x Devices
• IAR Embedded workbench / Beekit
• Basics of Network Software
• Freescale 802.15.4 Software
• Embedded C
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Standard Input / Output
• In the world of microcontrollers, there is no environment that provides standard IO. Unlike ANSI C, there is no printf() function that prints formatted strings to the default output and no scanf() function that reads formatted strings from standard input.
• In Freescale 802.15.4 MAC Stack:
• Sending strings to the serial port:
void UartUtil_Print(uint8_t* pString, uartUtilBlock_t allowToBlock)
allowToBlock: gNoBlock_d, gAllowToBlock_d
• Sending hex data to serial port:
void UartUtil_PrintHex(uint8_t* hex, uint8_t len, uint8_t flags)
flags: gPrtHexBigEndian_c, gPrtHexNewLine_c , gPrtHexCommas_c, PrtHexSpaces_c
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Standard Input / Output: Examples
• Example 1:
UartUtil_Print("\n\rStarting as PAN coordinator on channel 0x", gAllowToBlock_d);
UartUtil_PrintHex(&mLogicalChannel, 1, FALSE);
• Example 2:
UartUtil_Print("ED scan returned the following results:\n\r [", gAllowToBlock_d);
UartUtil_PrintHex(pEdList, 16, gPrtHexBigEndian_c | gPrtHexSpaces_c);
UartUtil_Print("]\n\r\n\r", gAllowToBlock_d);
• Example 3:
UartUtil_Tx(pMsgIn->msgData.dataInd.pMsdu, pMsgIn->msgData.dataInd.msduLength);
UartUtil_Print(" ",gAllowToBlock_d);
UartUtil_PrintHex(&pMsgIn->msgData.dataInd.mpduLinkQuality,1, gPrtHexBigEndian_c | gPrtHexNewLine_c);
UartUtil_Print("\n\r",gAllowToBlock_d);
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Data Types and Variables
Due to the restricted environment of embedded controllers, standard C variables and data
types are different.
In Freescale 802.15.4 MAC Library:
int8_t signed char
uint8_t unsigned char
int16_t signed short
uint16_t unsigned short
int32_t signed long
uint32_t unsigned long
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Types Definitions
Syntax:
typedef existing-type new-type ;
Example:
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Structures
Definition:
//PAN descriptor. Used, e.g., in Scan Confirm
typedef struct panDescriptor_tag {
uint8_t coordAddress[8];
uint8_t coordPanId[2];
uint8_t coordAddrMode;
uint8_t logicalChannel;
bool_t securityUse;
uint8_t aclEntry;
int8_t securityFailure;
uint8_t superFrameSpec[2];
bool_t gtsPermit;
uint8_t linkQuality;
uint8_t timeStamp[3];
} panDescriptor_t;
Usage:
panDescriptor_t.logicalChannel
(&panDescriptor_t)->logicalChannel
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
EnumeratorsDefinition:
/* The various states of the applications state
machines. */
enum {
stateInit,
stateScanEdStart,
stateScanEdWaitConfirm,
stateStartCoordinator,
stateStartCoordinatorWaitConfirm,
stateListen
};
/* Error codes */
enum {
errorNoError,
errorWrongConfirm,
errorNotSuccessful,
errorNoMessage,
errorAllocFailed,
errorInvalidParameter,
errorNoScanResults
};
Usage:
uint8_t gState;
switch(gState)
{
case stateInit:
//do something
break;
case stateScanActiveStart:
//do something
break;
}
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Bitwise Operators
Operator name Syntax
Bitwise left shift a << b
Bitwise right shift a >> b
Bitwise one's complement (NOT) ~a
Bitwise AND a & b
Bitwise OR a | b
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Bitwise Operators - Shift
Examples:
0000 0001 << 1 gives 0000 0010
0000 0010 << 1 gives 0000 0100
0000 0100 >> 1 gives 0000 0010
/* Events that are passed to the application task.
Are defined as byte masks to make possible
send multiple events to the task */
#define gAppEvtDummyEvent_c (1 << 0) //first bit
#define gAppEvtRxFromUart_c (1 << 1) //second bit
#define gAppEvtMessageFromMLME_c (1 << 2)
#define gAppEvtMessageFromMCPS_c (1 << 3)
#define gAppEvtStartCoordinator_c (1 << 4)
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Bitwise Operators – AND / OR
Bitwise AND operator
unsigned int a = 6; /* 6 = 0000 0110 */
unsigned int b = 3; /* 3 = 0000 0011 */
unsigned int c = 0;
c = a & b; /* 2= 0000 0010 */
Bitwise OR operator
unsigned int a = 6; /* 6 = 0000 0110 */
unsigned int b = 3; /* 3 = 0000 0011 */
unsigned int c = 0;
c = a I b; /* 7= 0000 0111 */
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Laboratory Material
• You can find on the website www.chiaraburatti.org the following meterial:
– Data Sheets of MC1322x Devices
– Freescale 802.15.4 Software Reference manual
– Laboratory Handbook
– This presentation
• Devices are available under request
• Virtual machine including all the needed SW is available under request
Chiara BurattiDEI, University of Bologna
Wireless Sensor Networks
Wireless Sensor Networks
Chiara Buratti
www.chiaraburatti.org