38
MS_uC / fue1 / V11 2- 1 ENET with MAC controller Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller 32K Byte 32K Byte Burst Flash Burst Flash 64K or 96K 64K or 96K Byte SRAM Byte SRAM 256K or 512K 256K or 512K Byte Burst Byte Burst Flash Flash OTP OTP Mem Mem UART UART I2C I2C SPI SPI TIM TIM RTC RTC EXT. EXT. Bus Bus GPIO GPIO USB USB 2.0FS 2.0FS CAN CAN 2.0B 2.0B Enet Enet MAC MAC PFQ PFQ BC BC DMA DMA INTR INTR Cntl Cntl ARM966E ARM966E CORE CORE w/DSP w/DSP 96 MHz 96 MHz CLK CLK Cntl Cntl ADC ADC LVD LVD BOD BOD PLL PLL JTAG JTAG ETM9 ETM9

Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

  • Upload
    bing

  • View
    51

  • Download
    1

Embed Size (px)

DESCRIPTION

Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller. 64K or 96K Byte SRAM. Enet MAC. ARM966E. CORE. w/DSP. USB 2.0FS. 96 MHz. 256K or 512K Byte Burst Flash. PFQ BC. CAN 2.0B. DMA. INTR Cntl. CLK Cntl. 32K Byte Burst Flash. - PowerPoint PPT Presentation

Citation preview

Page 1: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 2- 1

ENET with MAC controller

Programming MicrocontrollerENET (Ethernet) peripheral with

MAC (Media Access Control) controller

32K Byte 32K Byte Burst FlashBurst Flash

64K or 96K 64K or 96K Byte SRAM Byte SRAM

256K or 512K 256K or 512K Byte Burst Byte Burst

FlashFlash

OTP OTP MemMem

UARTUARTI2CI2CSPISPITIMTIMRTCRTC

EXT. EXT. Bus Bus

GPIOGPIO

USB USB 2.0FS 2.0FS

CAN CAN 2.0B 2.0B

Enet Enet MAC MAC

PFPFQ Q

BC BC

DMADMA

INTINTR R

CntlCntl

ARM96ARM966E 6E CORE CORE

w/DSPw/DSP96 MHz 96 MHz

CLK CLK CntlCntl

ADCADC

LVD LVD BODBOD

PLLPLL JTAJTAGG

ETMETM99

Page 2: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

2

The classical web applications

Standard way of web communication Browser as web client Web server with data base

The purpose of web application Represent the data of the server on the client Save the input of the client on the server

Example of web applications Query the SBB timetable Buy books Download information about a company

Page 3: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

3

Static web pages

Static web pages are displayed without further processing HTML, XHTML, XML CSS Plug-Ins (Multimedia)

Client Server

Web-

Browser

Web- Server

XHTML -File

1)

2)

HTTP

Page 4: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

4

Dynamic web pages

Client-side dynamic execution Script languages (JavaScript) Execution of Programs (Applet)

Server-side dynamic execution Script languages (Perl & PHP) Execution of Programs (Servlet)

Page 5: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

5

Client-side dynamic execution

Typical applications Context depending menus, input validation & calculation with

formula Client Server

Web-

Browser

Web

Server XHTML-File with

Client-Skript or Program

1)

2) HTTP

3)

4)

5)

Execution Script/

Program

Page 6: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

6

Server-side dynamic execution

Typical applications Creation of individual user web pages

Client Server

Web-

Browser

Web- Server

Server-Script or

Program

1)

6) HTTP

4)

5)

Data-base

3)

2)

XHTML-File Execution

Script or Program

Page 7: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

7

Programming languages for Internet

Script languages Client-side script languages

JavaScript, VBSkript & Jscript

Server-side script languages Perl & PHP

High-level languages C, C++, C#, Visual Basic or Java

Page 8: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

8

Comparison between Script & High-level Languages

Script programming language

High-level programming language

Taskclient Small help programs, plug-in

server dynamic generation of web pages

ExecutionScript are executed by an interpreter

Compiler generates a byte (intermediate) or an executable code

Learning time Small until medium Medium until high

Development environment

Text editor or script-tools Development environment: JDK or Visual Studio

Integration into XHTML pages

Integration directly into XHTML pages

XHTML page contains the reference for the plug-in

Security

client

Limited access to hard disk, memory & LAN for JavaScript.

Full access with VBScript

No direct access to hard disk, memory & LAN interface for Java applets.

serverFull access to databases, I / O system, etc

Full access to databases, I / O system, etc.

Page 9: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

9

Languages & technologies for web site development

sun Standard Microsoft

Client

Static

HTML, XHTML & CSS

XML

DynamicJavaScript

Java Applet

VBScript

Jscript JavaScript

.net

Server

JSP(Java Server Page)

Java Servlet

CGI / Perl PHP

(Pers. Homepage)

More complicateprogram

(C/C++ etc.)

ASP(Active Server

Page)

.net

Page 10: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

10

Embedded web server

Application examples for the embedded word Machines, automation etc. which should be accessible

through Internet

Purpose of the “Embedded web server” Remote maintenance (diagnostic, setting the

parameters) Alarming Configuration

Page 11: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

11

ISO/OSI Model for the Client-Server communication

Layer 1

Layer 2

IP

TCP

HTTP

Port 80

Client / Browser Embedded Webserver

Port >1024

Layer 1

Layer 2

IP

TCP

HTTP

Client- App. 2

Client- App. 1

CGI

Port 80 Port >1024

CGI

Server- App. 1

Server- App. 2

Transport

Network

Data link

Physical

Page 12: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

12

Principles of the Client-Server communication

Client Embedded Webserver

Web-

Browser

Micro-

Controller XHTML-

File with the Java-Applet

fort the client in memory

2) 3) HTTP

4)

5)

1) 6)

Java

Applet

C-Program

Technical process Inputs / Outputs

Socket-Connection

Page 13: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

13

Socket (Buchse / prise)

Socket is an endpoint for communication between two machines IP Address Protocol (TCP or UDP) Port number

General procedure for exchanging data Build a connection using two sockets Exchange of data Close the connection

Page 14: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

14

TCP based application

TCP is a connection-oriented transport protocol Transmission Control Protocol

Creating the TCP connection First, start the server Next the client must connect himself to the server Finally the data can be exchanged in both directions

Page 15: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

15

Page 16: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

16

socket()

socket() creates a TCP or UDP socket Server Socket SS on the server Client Socket CS on the client

Specification of the used protocol (TCP or UDP)

Page 17: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

17

bind()

bind() binds the socket with a local protocol address IP address & port number

bind() is only uses by the server

Page 18: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

18

listen()

listen() sets the server in a listening mode

Maximum number of connections that will be processed simultaneously

Page 19: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

19

accept()

accept() enables the Server to accept a connection from a client Full queue (backlog)

Next connection request from the queue

Empty queue New connection request from a client

Page 20: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

20

connect()

connect() enables the client to build a connection with the server

Server socket creates a new socket (newSS) Dedicated line to the requested client

Page 21: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

21

recv() and send()

The data are exchanged in both direction with recv() & send()

Page 22: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

22

close()

After successful communication The sockets newSS & CS must be closed

Page 23: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

23

UDP-based applications UDP is minimal and non connection-oriented transport

protocol User Datagram Protocol

Page 24: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

24

Socket programming in C

Programming of client and server applications in C Application Programming Interface (API) functions of the TCP/IP-

Stacks

Page 25: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

25

Data structure for the protocol addresses (1)

Common data structure struct sockaddr {

unsigned short sa_family // Address family (AF_INET)

unsigned sa_data[14]; /* Protocol-specific

address information */

}

Data structure for AF_INET (Address Family Interactive Network System) struct sockaddr_in {

unsigend short sin_family // Protocol family (PF_INET)

unsigned short sin_port; // Address port (16 bits)

struct in_addr sin_addr; // IP address (32 bits)

}

struct in_addr {

NET_IP_ADDR s_addr; // IP address (32 bits)

}

Page 26: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

26

Data structure for the protocol addresses (2)

Page 27: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

27

Help function

Transmission of sockaddr & sockaddr_in in big endian Network byte order

Conversion from the “host byte order” into “network byte order” uint32_t htonl (uint32_t hostlong); uint16_t htons (uint32_t hostshort);

Page 28: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

28

socket()

Prototype int socket (int domain, int type, int protocol);

Argument domain

Application domain of the socket (PF_INET) type

Behavior of the socket (SOCK_STREAM or SOCK_DGRAM) protocol

IPPROTO_TCP or IPPROTO_UDP

Result Success: Socket-ID Error: -1

Page 29: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

29

bind()

Prototype int bind (int sock_id, struct sockaddr *addr, int addrlen);

Argument sock_id

Result of socket() addr

Information about Port number & IP address addrlen

Size of addr

Result Success: 0 Error: -1

Page 30: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

30

listen()

Prototype int listen (int sock_id, int backlog);

Argument sock_id

Result of socket() backlog

Maximum waiting clients

Result Success: 0 Error: -1

Page 31: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

31

connect()

Prototype int connect (int sock_id, struct sockaddr *addr, int addrlen);

Argument sock_id

Result of socket() addr

Information about Port number & IP address of the server to connect

addrlen Size of addr

Result Success: 0 Error: -1

Page 32: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

32

accept()

Prototype int accept (int sock_id, struct sockaddr *addr_remote, int *addrlen_remote);

Argument sock_id

Result of socket() addr_remote

Information about Port number & IP address of the client addrlen_remote

Size of addr_remote

Result Success: new socket ID Error: -1

Page 33: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

33

recv()

Prototype int recv (int newSock_id, void *buf, int *buf_len, int flags);

Argument newSock_id or sock_id

Result of accept() on server side or socket() on client side buf

Buffer for the received data buf_len

Length of buf flags

Receive option: can be set to zero

Result Success: Number of received bytes Error: -1

Page 34: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

34

send()

Prototype int send (int newSock_id, void *data, int datalen, int flags);

Argument newSock_id or sock_id

Result of accept() on server side or socket() on client side data

The data to transmit datalen

The length of the data to transmit flags

Transmit option: can be set to zero

Result Success: Number of transmitted bytes Error: -1

Page 35: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

35

Programming in Java

Class Socket Socket (String host, int port);

Stream Classes for sending or receiving the data BufferedReader InputStreamReader (ASCII unicode) InputStream (ASCII)

PrintStream (unicode ASCII) OutputStream (ASCII)

Page 36: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

36

Generating a client socket in Java

public void openSocket(){ try{ // replace parameters with real values sock = new Socket(Server_Address, Port); // Send without delay sock.setTcpNoDelay(true); inputStream = sock.getInputStream(); bufferedReader = new BufferedReader new InputStreamReader(inStream)); outputStream = sock.getOutputStream(); printStream = new PrintStream(outStream, true); } catch (SocketException e){ // error handling } catch (IOException e){ // error handling }}

Page 37: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

37

Closing the socket and the data stream

public void closeSocket(){

try {

inputStream.close();

outputStream.close();

sock.close();

}

catch (IOException e){

// error handling

}

}

Page 38: Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller

MS_uC / fue1 / V11 21.04.23

38

Transmitting & Receiving the data

public void sendData(String data){ printStream.print(data);}

public void getData(){ String data; try { data = bufferedReader.readLine(); // process data } catch (IOException e){ // error handling }}