metti il .net framework nel micro !

22
Metti il .Net Framework nel micro ! Il mondo embedded secondo Microsoft Paolo Patierno Software Engineer

Upload: paolo-patierno

Post on 14-May-2015

349 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Metti il .Net Framework nel Micro !

Metti il .Net Framework nel micro ! Il mondo embedded secondo Microsoft

Paolo Patierno

Software Engineer

Page 2: Metti il .Net Framework nel Micro !

Ringraziamo gli sponsor!

Page 3: Metti il .Net Framework nel Micro !

Chi sono … contatti

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

• Blog (su Embedded101) • http://www.embedded101.com/Blogs/PaoloPatierno.aspx

• Twitter • @ppatierno

• Linkedin • http://it.linkedin.com/in/paolopatierno

• Skype • paolopat80

• Email • [email protected]

Page 4: Metti il .Net Framework nel Micro !

Agenda

• Perché e cos’è ? Ma soprattutto cosa non è !

• Internals : l’architettura

• IDE ed SDK

• Hardware Object Model

• Base Class Library e SPOT Library

• Hardware ed Emulatore

• DEMO : sviluppo e deploy

Page 5: Metti il .Net Framework nel Micro !

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 spesso non sono molto user friendly (Keil, Iar, AVR Studio, ...) rispetto Visual 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 6: Metti il .Net Framework nel Micro !

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, al reset il «TinyBooter» carica il «TinyCLR»;

Page 7: Metti il .Net Framework nel Micro !

OS HAL

PAL

CLR

Libraries

Architettura

.NET WPF COMM …

Execution

Engine

Type

System

Garbage

Collector Interop

Timers RAM I/O

Drivers or Facilities

User Applications & Libraries

managed

native

Runtime per il codice managed

Astrazione dell’hardware

Accesso diretto all’hardware

~20 – 30 KB

Hardware

Page 8: Metti il .Net Framework nel Micro !

Compilazione ed Esecuzione

Managed

Environment

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 9: Metti il .Net Framework nel Micro !

IDE, SDKs e Porting Kit

• Visual Studio 2010 e 2012;

• .Net Micro Framework SDK (fino alla 4.1 sul sito Microsoft, dalla 4.2 su CodePlex … è open source);

• OEMs SDK (SecretLabs, GHI, …) • 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 10: Metti il .Net Framework nel Micro !

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 11: Metti il .Net Framework nel Micro !

Hardware : Object Model

• Ogni Port è rappresentata attraverso l’istanza di una classe • OutputPort e InputPort rispettivamente per

rappresentare porte di output e di input; InterruptPort per la gestione delle interruzioni con un event handler;

• 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 12: Metti il .Net Framework nel Micro !

Hardware : Object Model

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

outPort

inPort

OutputPort

+Write(bool)

Native Code InputPort

+bool Read()

Native Code

Pin3 Pin2 Pin1 Pin0

Reference

sullo stack

Object sull’heap

Porta fisica

Page 13: Metti il .Net Framework nel Micro !

BCL e SPOT

• Supporto per le classi principali del «fratello maggiore» .Net Framework (es. collections, threading, networking, …);

• Namespace Microsoft.SPOT con le classi per la gestione managed dell’hardware e supporto per i principali protocolli di comunicazione (es. SPI, I2C, 1-Wire, UART, …);

• 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 14: Metti il .Net Framework nel Micro !

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

Page 15: Metti il .Net Framework nel Micro !

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 16: Metti il .Net Framework nel Micro !

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

1WIRE PWM

Microsoft.SPOT.Cryptoki

Microsoft.SPOT.Update

Microsoft.SPOT.Net.Security

Microsoft.VisualBasic

FTP

Microsoft.SPOT.Cryptography

RSA XTEA

Page 17: Metti il .Net Framework nel Micro !

Emulatore

• Configurabile via XML;

• Utilizzo e configurazione di componenti esistenti;

• Possibilità di creare nuovi componenti;

• Sviluppare la UI dell’emulatore;

Managed Application

Emulator

Emulator

Component

Emulator

Component

Custom Emulator

Component

Configuration

Engine

Page 18: Metti il .Net Framework nel Micro !

Hardware

Page 19: Metti il .Net Framework nel Micro !

Vantaggi/Svantaggi

• Costi hardware bassi (footprint RAM, CPU, …);

• Costi sviluppo bassi • Time to market rapido (prototipizzazione);

• Codice managed (indipendente dall’hardware);

• Visual Studio e C#/ VB.Net per lo sviluppo;

• Supporto debugging sul target via Visual Studio;

• Sviluppo iniziale su PC attraverso l’emulatore;

• No real time (latenza interrupt e GC);

• Più consumo di risorse (Flash e RAM);

• Meno performance (codice managed interpretato);

Page 20: Metti il .Net Framework nel Micro !

DEMO

Page 21: Metti il .Net Framework nel Micro !

Qualche libro ...

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

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

Page 22: Metti il .Net Framework nel Micro !

… e risorse dal Web

• .Net Micro Framework Official Site • http://www.netmf.com/

• .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/