wireless sensor networks introduction to the laboratory

50
Chiara Buratti DEI, 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

Upload: others

Post on 03-Feb-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Wireless Sensor Networks Introduction to the Laboratory

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

Page 2: Wireless Sensor Networks Introduction to the Laboratory

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

Page 3: Wireless Sensor Networks Introduction to the Laboratory

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

Page 4: Wireless Sensor Networks Introduction to the Laboratory

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)

Page 5: Wireless Sensor Networks Introduction to the Laboratory

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.

Page 6: Wireless Sensor Networks Introduction to the Laboratory

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)

Page 7: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MC1322x Block Diagram

Transceiver

CPU

Page 8: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MAC Accelerator Block Diagram

Page 9: Wireless Sensor Networks Introduction to the Laboratory

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

Page 10: Wireless Sensor Networks Introduction to the Laboratory

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

Page 11: Wireless Sensor Networks Introduction to the Laboratory

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

Page 12: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

IAR - Project

Page 13: Wireless Sensor Networks Introduction to the Laboratory

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

Page 14: Wireless Sensor Networks Introduction to the Laboratory

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).

Page 15: Wireless Sensor Networks Introduction to the Laboratory

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

Page 16: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Basics on Service Primitives: Horizontal view

Page 17: Wireless Sensor Networks Introduction to the Laboratory

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)

Page 18: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Service Primitives: an Example

Page 19: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Service Primitives: an Example

Page 20: Wireless Sensor Networks Introduction to the Laboratory

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

Page 21: Wireless Sensor Networks Introduction to the Laboratory

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

Page 22: Wireless Sensor Networks Introduction to the Laboratory

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()

Page 23: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

• Arrows Messages

Interfacing APP to MAC

Page 24: Wireless Sensor Networks Introduction to the Laboratory

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

Page 25: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MAC API Functions

Page 26: Wireless Sensor Networks Introduction to the Laboratory

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.

Page 27: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MAC API – Queueing

Page 28: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MAC API – Data Types

Page 29: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Message Types: NWK-to-MLME directionmlmeMessage_t

Page 30: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Message Types: MLME-to-NWK directionnwkMessage_t

Page 31: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Message Types: NWK-to-MCPS directionmcpsMessage_t

Page 32: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Message Types: MCPS-to-NWK directionmcpsToNwkMessage_t

Page 33: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

AppTask

- Your code generally goes here

- It is called by task scheduler if an

event happens

Page 34: Wireless Sensor Networks Introduction to the Laboratory

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);

Page 35: Wireless Sensor Networks Introduction to the Laboratory

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);

Page 36: Wireless Sensor Networks Introduction to the Laboratory

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).

Page 37: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MLME_NWK SAP Handler

Page 38: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

MCPS_NWK SAP Handler

Page 39: Wireless Sensor Networks Introduction to the Laboratory

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

Page 40: Wireless Sensor Networks Introduction to the Laboratory

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

Page 41: Wireless Sensor Networks Introduction to the Laboratory

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);

Page 42: Wireless Sensor Networks Introduction to the Laboratory

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

Page 43: Wireless Sensor Networks Introduction to the Laboratory

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;

Page 44: Wireless Sensor Networks Introduction to the Laboratory

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

Page 45: Wireless Sensor Networks Introduction to the Laboratory

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;

}

Page 46: Wireless Sensor Networks Introduction to the Laboratory

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

Page 47: Wireless Sensor Networks Introduction to the Laboratory

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)

Page 48: Wireless Sensor Networks Introduction to the Laboratory

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 */

Page 49: Wireless Sensor Networks Introduction to the Laboratory

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

Page 50: Wireless Sensor Networks Introduction to the Laboratory

Chiara BurattiDEI, University of Bologna

Wireless Sensor Networks

Wireless Sensor Networks

Chiara Buratti

www.chiaraburatti.org

[email protected]