.Net Micro Framework : il mondo embedded secondo Microsoft

79
.Net Micro Framework Il mondo embedded secondo Microsoft Paolo Patierno

Transcript of .Net Micro Framework : il mondo embedded secondo Microsoft

Page 1: .Net Micro Framework : il mondo embedded secondo Microsoft

.Net Micro Framework Il mondo embedded secondo Microsoft

Paolo Patierno

Page 2: .Net Micro Framework : il mondo embedded secondo Microsoft

Chi sono ... contatti

• Blog (su DotNetCampania) – http://dotnetcampania.org/blogs/paolopat/default.

aspx

• Twitter – @ppatierno

• LinkedIn – http://it.linkedin.com/in/paolopatierno

• Email – [email protected]

• Skype – paolopat80

Page 3: .Net Micro Framework : il mondo embedded secondo Microsoft

Agenda

• .Net MF e le altre piattaforme embedded • .Net MF Internals : l’architettura • Uno sguardo alla Base Class Library e SPOT Library • Hardware ed emulazione • Integrazione in Visual Studio • Interfacciamento con i dispositivi

– GPIO, Serial RS232, I2C, SPI, 1-Wire

• Networking – Socket, DPWS

• User Interface – Drawing, WPF

• Customizzazione dell’emulatore • Web of Things

– RESTful, Pachube

Page 4: .Net Micro Framework : il mondo embedded secondo Microsoft

Perchè ?

• Nel mondo, i sistemi embedded sono ormai diffusi ovunque ma : – Gli skill necessari per lo sviluppo sono elevati; – Il firmware è tipicamente sviluppato in C/C++; – I tool di sviluppo sono pochi e spesso non molto user

friendly (Keil, Iar, AVR Studio, ...);

• Il .Net Micro Framework si propone come strumento per lo sviluppo sui sistemi embedded, sfruttando un ambiente come Visual Studio ed un linguaggio come il C# (anche VB dalla 4.2). Il tutto ovviamente con codice managed;

Page 5: .Net Micro Framework : il mondo embedded secondo Microsoft

Piattaforme Embedded di Microsoft

.NET Micro

Framework (bootable)

Sensors

Actuators

.NET Framework

.NET Compact Framework

Windows XP Embedded

Windows Embedded CE

Windows for Automotive

Windows POS Ready

Windows Mobile / Windows Phone

Wearable Devices

Embedded Controllers

Automotive PDA Cell Phones

Home Appliances

Game Devices

Point of Sale Devices

Network Managers

Industrial Automation

smaller size

bigger size

Emb

ed

de

d

Ap

plic

atio

ns

Pla

tfo

rm

Page 6: .Net Micro Framework : il mondo embedded secondo Microsoft

Piattaforme Embedded di Microsoft

Set-top boxes

Windows CE Windows XP Embedded

Windows Mobile Smartphone

Pocket PC Phone

Windows Automotive

Portable Media Center

VoIP phones

Mobile handhelds Gateways

Retail Point-of-Sale

Windows-based Terminals

Medical devices

Entertainment devices

.NET Micro Framework

Health Monitoring

Wearable Devices Auxiliary Displays

Remote Controls

Sensor Networks

Funzionalità

Page 7: .Net Micro Framework : il mondo embedded secondo Microsoft

Piattaforme Embedded di Microsoft : Confronto

.NET Micro Framework Windows CE Windows XPe

Example Devices

Sensor Nodes, Aux displays,

Health Monitoring, Remote

Controls, Robotics

GPS Handhelds, PDAs,

Automotive, Set Top Boxes Thin Clients, ATMs, Kiosks

Features Connected, Small, Wearable,

Graphical UI

Connected, Graphical UI,

Server, Browser, RAS, DirectX

PCclass performance,

PC networking

Footprint (RAM) 250-500KB managed code

Full featured (bootable)

300KB+ without managed code

12MB with managed code 40MB + Depending on features

Power Very low power Low power Mains power

CPU ARM7, ARM9, No MMU X86, MIPS, SH4, ARM,

with MMU X86

Real-time Not Real-time Hard Real-time Real-time capable through 3rd

party extensions

Managed vs. Native Code

Managed via .NET Micro

Framework,

native code through interop

only.

Supports both,

managed code requires .NET

Compact Framework

Supports both, managed code

requires .NET Framework

Page 8: .Net Micro Framework : il mondo embedded secondo Microsoft

Piattaforme Embedded di Microsoft : Confronto

• Windows XPe – Footprint dai 40 MB in su – Codice nativo – Codice managed

• Windows CE – Footprint da 300 KB fino a 64 MB – Codice nativo – Codice managed (almeno 12 MB)

• .Net Micro Framework – Footprint circa 300 KB (512 KB Flash) – Bootable runtime (con o senza S.O.) – Codice managed – Codice nativo (tramite interop)

Page 9: .Net Micro Framework : il mondo embedded secondo Microsoft

Vantaggi/Svantaggi

• Costi hardware bassi (vs Windows CE/XPe) – Footprint memoria RAM ridotto – Processori meno costosi (MMU non necessaria)

• Costi sviluppo bassi (vs Sistemi Embedded C/C++) – Time to market rapido (prototipizzazione) – Codice managed, APIs indipendenti dall’hardware ed OOP – Visual Studio e C# per lo sviluppo (VB.Net dalla versione 4.2) – Supporto debugging sul target via Visual Studio – Sviluppo iniziale su PC attraverso l’emulatore (estendibile)

• Consumi ridotti – Per device con batterie

• No real time (vs Windows CE) – Latenza interrupt non real time – Il GC blocca l’esecuzione di tutti i thread quando necessario

• Più consumo di risorse (vs Sistemi Embedded C/C++) – Flash e RAM

• Meno performance (vs Sistemi Embedded C/C++) – Codice managed interpretato

Page 10: .Net Micro Framework : il mondo embedded secondo Microsoft

Cosa non è ... Cosa è ...

• Non è ...

– Un sistema operativo tradizionale con un runtime (virtual machine) di codice managed on top

• E’...

– Un mix tra le funzionalità tradizionali di un sistema operativo (gestione risorse, controllo esecuzione, Input/Output, ...) e le funzionalità tradizionali di un runtime (GC, execution engine, interop, ...)

– Bootable runtime

Page 11: .Net Micro Framework : il mondo embedded secondo Microsoft

Architettura

~20-30 KB

Accesso diretto all’ hardware

Astrazione dell’ hardware

Runtime per il codice managed

Page 12: .Net Micro Framework : il mondo embedded secondo Microsoft

Architettura

• HAL (Hardware Abstraction Layer) – Interfacciamento diretto verso l’hardware – Scritto in Assembler dal produttore del chip – Contiene il codice di bootstrap che inizializza il

microprocessore e le periferiche principali – Lancia l’esecuzione del CLR – Non ha la gestione dei thread e dell’heap come un

tradizionale sistema opertivo – Demanda queste gestioni al CLR – Ha due execution modes :

• Single-threaded application • ISR (Interrupt Service Routine)

– Vede un unico thread ... Quello del CLR

Page 13: .Net Micro Framework : il mondo embedded secondo Microsoft

Architettura

• PAL (Platform Abstraction Layer) – Fornisce un livello di astrazione dell’hardware verso il

CLR – Rende il CLR indipendente dall’hardware – Ogni driver è sempre composto da una coppia di

moduli PAL e HAL

• TinyCLR – Sottoinsieme del runtime del .Net Framework

• Execution engine, gestione thread, heap, garbage collector

– Aggiunge lo strato di multithreading – Multitasking è cooperativo (ogni thread ha una time

slice di 20 ms) – GC solo “mark and sweep” e non generazionale

Page 14: .Net Micro Framework : il mondo embedded secondo Microsoft

Librerie

• Libraries

– Sottoinsieme della BCL del .Net Framework

• Grafica implementata con il medesimo object model di WPF (no XAML ma programmaticamente). Supporto alle immagine BMP e JPG e alle principali primitive di drawing

– Eventuali librerie managed sviluppate da altri

Page 15: .Net Micro Framework : il mondo embedded secondo Microsoft

CLR : execution loop

Page 16: .Net Micro Framework : il mondo embedded secondo Microsoft

Managed Environment

Compilazione ed Esecuzione : Confronto

Assembler Source

Source code Source code Source code

Assembler Compiler

Compiler Compiler

Microsoft Intermediate

Language Assembly

Microsoft Intermediate

Language Assembly

Just in Time Compiler

Machine Code Machine Code Machine Code

Intermediate Language

Interpreter

Computer Processor

1 : 1 1 : n

.Net Framework .Net Micro Framework C/C++ Assembler

Page 17: .Net Micro Framework : il mondo embedded secondo Microsoft

Compilazione ed Esecuzione : Confronto

• Assembler – Rapporto 1:1 con il codice macchina

• Embedded C/C++ – Linguaggi di alto livello – Rapporto 1:n con il codice macchina

• .Net Framework – Compilatore genera MSIL (non codice macchina) – JIT (Just In Time) Compiler genera codice macchina “a runtime” – NGEN (Native Image Generation) esegue precompilazione in

codice macchina

• .Net Micro Framework – Compilatore genera MSIL (non codice macchina) – No JIT Compiler – MSIL interpretato a runtime (non appropriato per il real-time)

Page 18: .Net Micro Framework : il mondo embedded secondo Microsoft

Base Class Library

System Array Enum Delegate Exception Attribute

Math

DateTime

TimeSpan Type TimeZone WeakReference

System.Collections ArrayList

System.Diagnostics Debugger

System.Globalization CultureInfo DaylightTime

System.IO Stream

System.Text UTF8Encoding

DateTime/Number FormatInfo

System.Resources ResourceManager Hashtable

Queue Stack

System.Xml XmlReader

StringBuilder System.Text.RegularExpressions Regex Match

Hashtable

• No Generics • No Linq (esiste implementazione terze parti ... MicroLinq)

Page 19: .Net Micro Framework : il mondo embedded secondo Microsoft

Base Class Library

System.Reflection Assembly FieldInfo MethodInfo PropertyInfo

System.Threading Thread Timer Interlocked

AutoResetEvent ManualResetEvent

System.Net WebRequest WebResponse HttpWebRequest HttpWebResponse

Dns EndPoint IPEndPoint Socket

Page 20: .Net Micro Framework : il mondo embedded secondo Microsoft

SPOT Library e DPWS

Microsoft.SPOT

Microsoft.SPOT.Input

Microsoft.SPOT.Messaging

Microsoft.SPOT.Net

Microsoft.SPOT.Cryptography

RSA XTEA

Microsoft.SPOT.Hardware

GPIO UART SPI I2C

Microsoft.SPOT.Presentation

Controls Media Shapes Microsoft.SPOT.Touch

Microsoft.SPOT.Net.Security

SSL Protocol X509 Certicate

Microsoft.SPOT.IO

Removable Media VolumeInfo

Microsoft.SPOT.Net.NetworkInformation

NetworkInterface NetworkChange

Microsoft.SPOT.Wireless

Dpws

Client Device

Ws.Services

Soap Binding

Discovery Transport

Microsoft.SPOT.Time

Page 21: .Net Micro Framework : il mondo embedded secondo Microsoft

SPOT Library e DPWS

Microsoft.SPOT

Microsoft.SPOT.Input

Microsoft.SPOT.Messaging

Microsoft.SPOT.Net

Microsoft.SPOT.Hardware

GPIO UART SPI I2C

Microsoft.SPOT.Presentation

Controls Media Shapes Microsoft.SPOT.Touch

Microsoft.SPOT.IO

Removable Media VolumeInfo

Microsoft.SPOT.Net.NetworkInformation

NetworkInterface NetworkChange

Microsoft.SPOT.Wireless

Dpws

Client Device

Ws.Services

Soap Binding

Discovery Transport

Microsoft.SPOT.Time

1-WIRE PWM

Microsoft.SPOT.Cryptoki Microsoft.SPOT.Update

Microsoft.SPOT.Net.Security

Microsoft.VisualBasic

FTP

Microsoft.SPOT.Cryptography

RSA XTEA

Page 22: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware disponibili

Managed Application

Emulator

Emulator Component

Emulator Component

Custom Emulator Components

Configuration Engine

• Configurabile via XML • Utilizzo e configurazione di componenti esistenti • Possibilità di creare nuovi componenti • Sviluppare la UI dell’emulatore

Emulatore

Page 23: .Net Micro Framework : il mondo embedded secondo Microsoft

Netduino (by Secret Labs)

CPU Atmel 48 Mhz ARM7

Flash 512 KB (128 KB utente)

SDRAM 128 KB (60 KB utente)

2 × UART, SPI, I2C, PWM, 20 GPIO

Ethernet, micro SD card, RAM utente 28 KB , FLASH utente 64 KB (con networking)

1 UART, 16 GPIO, RAM utente 64 KB, Flash utente 152 KB

Netduino (30 €)

Netduino Mini (27 €) Netduino Plus (54 €)

Page 24: .Net Micro Framework : il mondo embedded secondo Microsoft

USBizi series (by GHI Electronics)

FEZ Panda II (37 €) FEZ Domino (50 €)

CPU NXP LPC2378 72 Mhz ARM7

Flash 512 KB (148 KB utente)

SDRAM 96 KB (62 KB utente)

4 UART, 2 SPI, I2C, PWM, 71 GPIO

USBizi144 Chipset (14 €)

54 Digital GPIO, 6 Analog GPIO, micro SD, USB port, RTC

14 Digital GPIO, 6 Analog GPIO, micro SD, USB port

Page 25: .Net Micro Framework : il mondo embedded secondo Microsoft

EMX series (by GHI Electronics)

EMX Development System (250 €) FEZ Cobra (120 €)

CPU NXP LPC2478 72 Mhz ARM7

Flash 4.5 MB

SDRAM 16 MB

4 UART, 2 SPI, I2C, PWM, 76 GPIO

EMX Module (70 €)

Basato su EMX module 320 x 240 3.5" TFT Display con touch screen 6 bottoni, USB port, RS232 DB-9, Ethernet, SD/MMC

Basato su EMX module 1 bottone, 1 LED, USB port, Ethernet, SD/MMC

Page 26: .Net Micro Framework : il mondo embedded secondo Microsoft

ChipworkX series (by GHI Electronics)

ChipworkX Development System (350 €)

CPU Atmel 200 Mhz ARM9

Flash 256 MB (NAND), 8 MB (NOR)

SDRAM 64 MB

3 UART, 2 SPI, I2C, PWM, 80 GPIO, RTC, LCD controller

ChipworkX Module (120 €)

Basato su ChipworkX module 480x272 4.3" TFT Display con touch screen 6 bottoni, USB port, RS232 DB-9, Ethernet, SD/MMC

Page 27: .Net Micro Framework : il mondo embedded secondo Microsoft

.Net Gadgeteer

Basato su EMX module 320x240 3.5" Color Display Module con touch screen Una serie di moduli da collegare alla mainboard : • USB Client • Camera • 2 LED • 2 Button • Ethernet • USB Host • SD card • Joystick

FEZ Spider Starter Kit (220 €)

Specifiche .Net Gadgeteer su ... http://gadgeteer.codeplex.com/

Page 28: .Net Micro Framework : il mondo embedded secondo Microsoft

Device Solutions

Tahoe Development Board (250 €) Tahoe-II Development Board (350 €)

Meridian CPU

CPU i.MXS Freescale 100 MHz (ARM920T)

Flash 4 MB

SDRAM 8 MB

2 × UART, SPI, I2C, PWM, 16 -32 GPIO

Basato su Meridian CPU 2.7" TFT display 240 × 320 9 bottoni, RS232 DB-9, USB port

Basato su Meridian CPU 3.5“ TFT display 320 × 240 9 bottoni, RS232 DB-9, USB port Ethernet, accelerometro, SD card, Sensore temperatura, 2x ADC

Meridian/P (90 €)

i.MXS Freescale 100 MHz (ARM920T) 4 MB Flash 8 MB SDRAM 2 × UART, SPI, I2C, PWM, 16 -32 GPIO 1 LED, 1 bottone

Page 29: .Net Micro Framework : il mondo embedded secondo Microsoft

Licensing

• Licensing – “In November 2009, the .NET Micro Framework team

at Microsoft released the 4.0 version of the .NET Micro Framework (.NET MF) as an open source product under the Apache 2.0 license. The 4.0 version included the .NET Micro Framework SDK and the Porting Kit.”

– “Together with 4.0 we launched our community development Web Site and gathered important contributions. In order to boost the number of contribution, facilitate tracking any issues and create a stronger and more cohesive community development experience we are now publishing the 4.1 source code in this CodePlex project as well and allow a complete Community Development experience through Visual Studio and TFS”

Page 30: .Net Micro Framework : il mondo embedded secondo Microsoft

SDKs e Porting Kit

• .Net Micro Framework SDK (fino a 4.1 dal sito Microsoft, la 4.2 da Codeplex)

• OEMs SDK (SecretLabs, GHI, DeviceSolutions) – Ciascun OEM può customizzare alcune funzionalità ed

esportarne delle altre

• Porting Kit : permette di sviluppare la parte di basso livello (in C/C++ e Assembler) che si interfaccia con l’hardware : – Non c’è un IDE specifico (c’è un tentativo nella 4.2) e si

può compilare con GCC (CodeSourcery), Keil MDK, ARM RVDS

– Include lwIP come stack TCP/IP ed OpenSSL per le funzionalità di SSL/TLS;

Page 31: .Net Micro Framework : il mondo embedded secondo Microsoft

Integrazione Visual Studio 2010

Page 32: .Net Micro Framework : il mondo embedded secondo Microsoft

Integrazione Visual Studio 2010

• Project Propertiers – Transport (sul target) : Emulator, USB, Serial, Ethernet – Device : Emulator oppure target reale

Page 33: .Net Micro Framework : il mondo embedded secondo Microsoft

Integrazione Visual Studio 2010

Page 34: .Net Micro Framework : il mondo embedded secondo Microsoft

Tools

• MFDeploy : per configurare una board e riscrivere il firmware (bootloader TinyBoot ed applicativo)

• TFConvert : convert un font da .TTF a .TinyFNT

• MFSvcUtil : per la generazione del client proxy e dell’hosted service a partire da un WSDL

• SampleEmulator : emulatore di default

Page 35: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware : Object Model

• Memory Mapped I/O

– Dispositivi di I/O mappati attraverso indirizzi di memoria

• I/O Address Space

– Spazio di indirizzamento dedicato ai dispositivi di I/O

– Ports : locazioni dello spazio di indirizzamento suddetto;

Page 36: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware : Object Model

• Bit-Based Control

– Scrittura/Lettura di una porta e quindi della sequenza di bit che ne costituiscono il contenuto avviene attraverso delle operazioni logiche AND e OR e con l’ausilio di opportune maschere

#define PORTA 0x0000A000 // indirizzo PORTA

...

...

DWORD* pPort = PORTA;

*pPort |= 0x00000020; // setto ad 1 il bit 5

...

if (*pPort & 0x00000001) // verifico se il bit 0 vale 1

{

...

Page 37: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware : Object Model

• Ogni Port è rappresentata attraverso l’istanza di una classe

– OutputPort e InputPort rispettivamente per rappresentare porte di output e di input

– Scrittura/Lettura attraverso i due metodi Write() e Read()

OutputPort outPort = new OutputPort(Cpu.Pin.GPIO_Pin0, false);

outPort.Write(true);

...

InputPort inPort = new InputPort(Cpu.Pin.GPIO_Pin1, true,

Port.ResistorMode.Disabled);

bool value = inPort.Read();

Page 38: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware : Object Model

outPort

inPort

OutputPort

+Write(bool)

Native Code InputPort

+bool Read()

Native Code

Pin3 Pin2 Pin1 Pin0

Reference sullo stack

Object sull’heap

Porta fisica

• Più che alla port, permettono di accedere al singolo pin all’interno di essa

Page 39: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO

• GPIO (General Purpose Input Output)

– Pin customizzabili che possono essere utilizzati come input oppure come output tra il micro ed il mondo esterno

GPIO Output

GPIO Input

public enum ResistorMode {

Disabled, PullDown, PullUp

}

Page 40: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO : Output

• OutputPort

– Ctor : permette di definire il pin relativo all’output e lo stato iniziale del pin medesimo

– Write(bool) : permette di settare lo stato del pin di uscita

OutputPort outPort = new OutputPort(Cpu.Pin.GPIO_Pin0, false);

outPort.Write(true);

Page 41: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO : Input

• InputPort

– Ctor : permette di definire il pin relativo all’output, l’eventuale uso di un glitch filter e la configurazione o meno di una resistenza di pull-up oppure pull-down e lo stato iniziale del pin medesimo

– bool Read() : permette di leggere lo stato del pin di input

InputPort inPort = new InputPort(Cpu.Pin.GPIO_Pin1, true,

Port.ResistorMode.Disabled);

bool value = inPort.Read();

Page 42: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO : Interrupt ed eventi

• InterruptPort – Ctor : stesse informazioni di una InputPort con in più la

possibilità di specificare il fronte o il livello dell’interrupt sul quale segnalare l’evento

– OnInterrupt : evento sollevato allo scatenarsi dell’interrupt

public enum InterruptMode {

InterruptNone, // The port is deactivated InterruptEdgeLow, // falling edge (Change from high to low) InterruptEdgeHigh, // rising edge (Change from low to high) InterruptEdgeBoth, // both edges (Any state change) InterruptEdgeLevelHigh, // high InterruptEdgeLevelLow // low

}

Page 43: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO : Interrupt ed eventi

InterruptPort intPort = new InterruptPort(Cpu.Pin.GPIO_Pin0,

true, Port.ResistorMode.PullDown,

Port.InterruptMode.InterruptEdgeHigh); // fronte di salita

• Creazione e specifica fronte/livello interrupt

• Associazione event handler all’evento OnInterrupt intPort.OnInterrupt += new

NativeEventHandler(intPort_OnInterrupt);

• Event handler relativo all’interrupt

void intPort_OnInterrupt(uint data1, uint data2, DateTime time)

{

// data1 : numero pin che causa l'interrupt

// data2 : stato del pin

// time : timestamp dell'interrupt

}

Page 44: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO : Tristate

• TristatePort

– Permette di utilizzare il medesimo pin come input e come output, senza dover dichiarare due variabili distinte

– Ctor : ibrido tra una InputPort ed OutputPort

– Active : proprietà che permette di settare il comportamento come output (true) o come input (false)

– OnInterrupt : evento del tutto analogo ad una InterruptPort

Page 45: .Net Micro Framework : il mondo embedded secondo Microsoft

GPIO

Demo Ultrasonic / Pir (uPLibrary)

Page 46: .Net Micro Framework : il mondo embedded secondo Microsoft

RS232 Serial Port

• Classe SerialPort ad hoc per il .Net Micro Framework

• Supporta controllo di flusso software XON/XOFF ed hardware con RTS

• I metodi Read() e Write() per la lettura/scrittura sono sincroni e bloccanti per un timeout prefissato

• Espone evento DataReceived per evitare il polling sulla porta in ricezione

Page 47: .Net Micro Framework : il mondo embedded secondo Microsoft

I²C Bus

• I²C Bus (Inter-Integrated Circuit)

– Permette la comunicazione tra il micro e gli altri moduli hardware in modalità sincrona. Sviluppato da Philips (anni 80) ora è uno standard

– E’ un bus seriale che utilizza solo 2 fili (two wires)

• SCL (Serial Clock) : segnale di clock sul bus

• SDA (Serial Data) : linea su cui viaggiano i dati

– Comunicazione Master/Slave, indirizzo 7 bit ed in più 1 bit per specificare operazione Read/Write, segnale di ACK per ogni pacchetto

Page 48: .Net Micro Framework : il mondo embedded secondo Microsoft

I²C Bus

Master

Slave Slave Slave

SDA

SCL

• Indirizzo 7 bit – 4 bit (MSB) : classe dei moduli hardware – 3 bit (LSB) : indirizzo di ciascun modulo

• 121 moduli indirizzabili (128 totali meno 7 indirizzi riservati); 8 moduli per ciascuna classe

• 1 bit Read/Write • Half duplex

........

Page 49: .Net Micro Framework : il mondo embedded secondo Microsoft

I²C Bus

• Master invia la start condition

• Master invia 1 byte (7 bit indirizzo + 1 bit R/W)

• Lo Slave che riconosce il suo indirizzo risponde con un pacchetto di ACK

• Inizia la comunicazione R/W e per ogni byte scambiato c’è sempre un pacchetto di ACK

• Master invia la stop condition

Page 50: .Net Micro Framework : il mondo embedded secondo Microsoft

I²C Bus

• Classe I2CDevice.Configuration – Address : indirizzo device

– ClockRateKhz : clock rate in Khz

• Classe I2CDevice istanziata utilizzando la configurazione suddetta – CreateReadTransaction() : crea una

I2CDevice.I2CReadTransaction per una transazione in lettura da un device

– CreateWriteTransaction() : crea una I2CDevice.I2CWriteTransaction per una transazione in scrittura verso un device

– Execute() : esegue una o più transazioni sul bus

Page 51: .Net Micro Framework : il mondo embedded secondo Microsoft

I²C Bus

Demo TMP102 / DS1307 (uPLibrary)

Page 52: .Net Micro Framework : il mondo embedded secondo Microsoft

SPI Bus

• SPI Bus (Serial Peripheral Interface) – Permette la comunicazione tra il micro e gli altri

moduli hardware in modalità sincrona. Sviluppato da Motorola ora è uno standard

– E’ un bus seriale che utilizza 3 fili (three wires) • SCKL (Serial Clock Line) : segnale di clock sul bus • SDO (Serial Data Out) - MOSI (Master Out / Slave In) : linea

su cui viaggiano i dati dal Master allo Slave • SDI (Serial Data In) - MISO (Master In / Slave Out) : linea su

cui viaggiano i dati dallo Slave al Master

– Non usa indirizzamento ma ciascuno Slave è collegato al Master attraverso un pin di GPIO noto anche come SS/CS (Slave Select/Chip Select), attraverso il quale il Master abilita lo Slave con cui vuole comunicare

Page 53: .Net Micro Framework : il mondo embedded secondo Microsoft

SPI Bus

Master

Slave Slave Slave

SDO/MOSI

SDI/MISO

........

SCKL

CSn CS1 CS0

• Indirizzamento attraverso le linee CS

• Full duplex

Page 54: .Net Micro Framework : il mondo embedded secondo Microsoft

SPI Bus

• Classe SPI.Configuration

– Informazioni sul chip select (pin GPIO, active state, ...)

– Informazioni sul clock (idle state, rate, edge, ...)

• Classe SPI istanziata utilizzando la configurazione suddetta

– Write() per le operazioni di scrittura verso un device

– WriteRead() per le operazioni di scrittura e successiva lettura verso/da un device

Page 55: .Net Micro Framework : il mondo embedded secondo Microsoft

I²C Bus e SPI Bus Class Diagram

Page 56: .Net Micro Framework : il mondo embedded secondo Microsoft

1-Wire Bus

• Permette la comunicazione tra il micro e gli altri moduli hardware

• E’ un bus seriale che utilizza 1 filo (one wire)

– Data, clock ed alimentazione

• Un Master collegato ad uno o più Slave, ciascuno dei quali ha un proprio ID programmato in fase di produzione

Page 57: .Net Micro Framework : il mondo embedded secondo Microsoft

1-Wire Bus

Master

Slave Slave Slave ........

• Indirizzamento attraverso un comando (ROM Command) con il quale il Master invia l’ID dello Slave con cui comunicare

• Half duplex

Page 58: .Net Micro Framework : il mondo embedded secondo Microsoft

1-Wire Bus

Page 59: .Net Micro Framework : il mondo embedded secondo Microsoft

Socket

• Supporto per le socket TCP/UDP

• Modalità di utilizzo analoga al .Net Framework

• Operazioni di invio (Send/SentTo) e di ricezione (Receive/ReceiveFrom) sincrone

• Possibilità di impostare un timeout in ricezione

Page 60: .Net Micro Framework : il mondo embedded secondo Microsoft

Socket

Demo DdnsClient (uPLibrary)

Page 61: .Net Micro Framework : il mondo embedded secondo Microsoft

DPWS

• DPWS (Device Profile for Web Services) implementa un sottoinsieme delle specifiche dei Web Services (WS-*) ed aggiunge un meccanismo di ricerca dei devices che esponsono determinati servizi (discovery/probing)

Page 62: .Net Micro Framework : il mondo embedded secondo Microsoft

DPWS

• L’implementazione DPWS nel .Net Micro Framework supporta la specifica DPWS 1.0 ed 1.1 (compatibile con WCF 4) – Discovery dei device e dei servizi offerti (via UDP)

– Invio/Ricezione messaggi tra device

– Descrizione di un web service con WSDL

– Sottoscrizione/ricezione eventi da un web service

• MFSvcUtil.exe per la generazione del client proxy e del servizio a partire da un WSDL

• E’ come UPnP ma Ethernet oriented

Page 63: .Net Micro Framework : il mondo embedded secondo Microsoft

DPWS Assembly

• MFWsStack.dll : funzionalità di base dello stack DPWS;

• MFDpwsDevice.dll : classi specifiche per l’hosting dei servizi con DPWS;

• MFDpwsClient.dll : classi specifiche per il discovery e l’invocazione dei servizi DPWS;

• MFDpwsExtensions.dll : classi di utilità per l’eventuale manipolazione di messaggi SOAP;

Page 64: .Net Micro Framework : il mondo embedded secondo Microsoft

DPWS

Hosted Service 1

Hosted Service N

Host Service

Discovery Service

Metadata Exchange

Eventing Service

• Host Service (0..1) : servizio principale (discovery)

• Hosted Services (0..n) : servizi funzionali

• Built-In Services : discovery, eventing, metadata exchange

• Endpoint Address (logical address) – Urn:uuid:c5201073-fa27-c8c9-9634-

0000001dd159

• Transport Address (physical address) – http://192.168.1.3:8084/c5201073-

fa27-c8c9-9634-0000001dd159

Page 65: .Net Micro Framework : il mondo embedded secondo Microsoft

Socket

Demo DpwsClient/Server – WcfServer/Client

Page 66: .Net Micro Framework : il mondo embedded secondo Microsoft

User Interface : Drawing e WPF

• Drawing

– Possibilità di disegnare direttamente sullo schermo attraverso l’utilizzo di una bitmap (linee, rettangoli, testo, ...)

• WPF

– Sottoinsieme di WPF desktop anche se manca il supporto XAML ed un designer nell’IDE. Tutto va fatto via codice

Page 67: .Net Micro Framework : il mondo embedded secondo Microsoft

User Interface : WPF

Page 68: .Net Micro Framework : il mondo embedded secondo Microsoft

Socket

Demo WPF

Page 69: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware Emulation

• Iniziare lo sviluppo di un prototipo software ancor prima che il prototipo hardware sia pronto

• Emulazione della comunicazione con dispositivi con i vari protocolli (GPIO, I²C, SPI, Serial, ..) oltre che di LCD, RAM e Flash

• Emulator è un’applicazione Console oppure WinForms che gira sul PC (UI thread separato) quindi con .Net Framework

• Gli emulator components sono class library su .Net Framework

• Costituito da componenti configurabili via XML (Emulator.config) o programmaticamente

Page 70: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware Emulation

• Ereditare dalla classe Emulator

• Utilizzare i builtin emulator components

• Ereditare dalla classe EmulatorComponent per implementare un nuovo componente (la stessa Emulator deriva da essa) oppure estendere il comportamento di quelli esistenti

• Override metodi : – SetupComponent()

– InitializeComponent()

– UninitializeComponent()

Page 71: .Net Micro Framework : il mondo embedded secondo Microsoft

Hardware Emulation

Page 72: .Net Micro Framework : il mondo embedded secondo Microsoft

Web of Things ... L’Internet delle cose

• Device embedded sempre più potenti

• Connessione ad Internet

• Dotazione di un web server embedded

• Modellazione dei servizi come risorse mediante architettura ROA (RESTful API)

• Interconnessione e comunicazione tra dispositivi anche eterogenei sfruttando le potenzialità del Web e dell’HTTP

Page 73: .Net Micro Framework : il mondo embedded secondo Microsoft

Pachube

• Gerarchia : feed > datastream >datapoint

• Feed : collezione di dati misurati

• Datastream : misurazione individuale di un device all’interno di un Feed (ha un ID univoco all’interno di esso)

• Datapoint : singolo valore di un Datastream in un certo istante di tempo

Page 74: .Net Micro Framework : il mondo embedded secondo Microsoft

Pachube

• Esempio : Rilevamento della temperatura, umidità e luminosità nella propria stanza

– Feed : un solo feed per la collezione dei dati (es. titolo “MyRoom”);

– Datastream : definizione di 3 datastream

• Temperatura (id = “temperature”)

• Umidità (id = “humidity”)

• Luminosità (id = “brightness”)

– Datapoint : le misure delle tre grandezze nel tempo

Page 75: .Net Micro Framework : il mondo embedded secondo Microsoft

Pachube

• Fornisce una rappresentazione grafica dei dati

• Possibilità di lettura dei dati archiviati online

Page 76: .Net Micro Framework : il mondo embedded secondo Microsoft

Web of Things

Demo PachubeDemo

Page 77: .Net Micro Framework : il mondo embedded secondo Microsoft

Qualche libro ...

• Expert .Net Micro Framework 2° Edition - Jens Kuhner, Apress (2009)

• Embedded Programming with the Microsoft .Net Mifro Framework – D.Thompson, R.S.Miles, Microsoft Press (2007)

Page 78: .Net Micro Framework : il mondo embedded secondo Microsoft

… e risorse dal Web

• .Net Micro Framework Official Site – http://www.microsoft.com/en-us/netmf/default.aspx

• .Net Micro Framework Codeplex – http://netmf.codeplex.com/

• .Net Gadgeteer – http://www.netmf.com/gadgeteer/

• TinyCLR.it – http://www.tinyclr.it/

• TinyCLR.com – http://tinyclr.com/

• Netduino – http://netduino.com/

• uPLibrary – http://uplibrary.codeplex.com/

Page 79: .Net Micro Framework : il mondo embedded secondo Microsoft

Q & A

Q & A … non sparate sul pianista …