cse 466 – fall 2000 - introduction - 1 commands responses master/slave software architecture...

23
CSE 466 – Fall 2000 - Introduction - 1 COMMANDS RESPONSES Master/Slave Software Architecture Master void master() _task_ MAST{ Button(mode); // enq(cmd) checkDB(mode); // enq(cmd) } void comTop() _task_ COM{ wait(K_TMO, 1); if (!deq(cmd)) { cmd = pollCmd(next++); slave = next; } else slave = toWho(cmd); write(slave, cmd); read(response); signal(VERIFY); } void comBot() _task_ VERIFY{ // match up resp. and commds wait(K_SIG); verify(response); updateDB(response); } Slave void mainTask() _task_ manageLoad(mode); } void comTop() _task_ TO read(master,cmd); write(master,respons signal(DO); }// could be ISR void comBot() _task_ DO wait(K_SIG); response = do(cmd); // set local mode } commands and responses are packets not single byte responses are for previous command mode is NOT a global variable

Upload: rodrigo-lovell

Post on 15-Dec-2015

221 views

Category:

Documents


1 download

TRANSCRIPT

CSE 466 – Fall 2000 - Introduction - 1

COMMANDS

RESPONSES

Master/Slave Software Architecture

Mastervoid master() _task_ MAST{ Button(mode); // enq(cmd) checkDB(mode); // enq(cmd)}void comTop() _task_ COM{ wait(K_TMO, 1); if (!deq(cmd)) { cmd = pollCmd(next++); slave = next; } else slave = toWho(cmd); write(slave, cmd); read(response); signal(VERIFY);} void comBot() _task_ VERIFY{ // match up resp. and commds wait(K_SIG); verify(response); updateDB(response);}

Slavevoid mainTask() _task_ SL{ manageLoad(mode);}

void comTop() _task_ TOP{ read(master,cmd); write(master,response); //prev signal(DO);}// could be ISR

void comBot() _task_ DO { wait(K_SIG); response = do(cmd); // set local mode}

commands and responses are packets not single bytes

responses are forprevious command

mode is NOT a global variable

CSE 466 – Fall 2000 - Introduction - 2

Sockets are a logical constructs

Master

slave

slave

slave

socket == 2-way fifo

Socket could be implemented in shared memory, internet, or anything in between.

High level architecture can be independent of implementation choices.

CSE 466 – Fall 2000 - Introduction - 3

Physical Network

MCU1

MCU2

Device1

Device2

Bus

CSE 466 – Fall 2000 - Introduction - 4

ISO Network Layers – modularity/interop.

Physical Layer: What physically moves a bit/byte from one place to another (ethernet). Devices have a local physical address. Voltage Current Photons Radio Sonar

Data Link Layer: Guarantees delivery of “frames” over the physical layer, to the physical address. Assembles/dissembles packets from/to frames. Address (Source and Destination) Checksum Data Usually a fixed size or maximum size.

Network Layer: Primarily responsible for routing of network packets Maps packet destination address from/to local physical address Adds network layer header to packet Gives packets w/ header to data link layer, along with physical address.

CSE 466 – Fall 2000 - Introduction - 5

ISO Layers Continued Transport Layer: responsible for end-to-end protocol of user data buffer transmissions.

Source and destination addresses are private – host to host. Maps application space channel (socket) name to network address. makes network packets w/ transport header and communicates w/ network layer.

Each layer has a peer-to-peer and an intra-stack protocol

Transport -- TCP

Network -- IP

Datalink -- Ether

Physical -- Ether ethernet fiber

Datalink -- Ether

Network -- IP

fiber ethernet

Datalink -- Ether

Network -- IP

Transport -- TCP

Network -- IP

Datalink -- Ether

Physical -- Ether

write(s, buf,n); read(s, buf,n );

Application Application

CSE 466 – Fall 2000 - Introduction - 6

Transport

Network -- IP Network -- IP

Transport

Network -- IP Network -- IP

Embedded Networking: Simplest Case Simple case: socket name is the same as physical address. No mapping, we just need

to break our message into frames…maybe

Physical Layer – typically low bandwidth, serial, byte oriented

Data link layer – read/write interface to the application

frames: destination address, data, checksum. No mapping from sockets to network address No mapping from network address to physical address (no routing)

Datalink

Physical ethernet fiber

Datalink -- Ether

fiber ethernet

Datalink -- Ether Datalink

Physical

write(s, buf,n); read(s, buf,n );

Application Application

CSE 466 – Fall 2000 - Introduction - 7

Example of Physical Layer: SPI Bus

Master Slave

SCK

SDO

SDI

SCK

SDI

SDO

void isr() interrupt TIMER { SDR = S; while(!SPF); R = SDR;}

void isr() interrupt SPF{ R = SDR; SDR = S signal(RECV);}

1 0 0 1 1 1 1 0

shift reg

0 0 0 1 1 0 0 0

shift reg

CSE 466 – Fall 2000 - Introduction - 8

Multiple Slave Configuration

Master Slave

SCK

SDO

SDI

SCK

SDI

SDO

Slave

SCK

SDI

SDO

CSE 466 – Fall 2000 - Introduction - 9

Master Slave Data Link Protocol

As an example frame is [destination address, command, data]

An acknowledgement frame is [address, data, checksum]

Master Slave

SCK

SDO

SDI

SCK

SDI

SDO

Slave

SCK

SDI

SDO

mux

dst cmd data dst type data

addr data sum type data sum

mux x x x 1 1 1 2 2 2

CSE 466 – Fall 2000 - Introduction - 10

Data Link Layer (Master/Slave)

void physical() interrupt TIMER { S = deq() setMux(S); SDR = S while (!SDF); R = SDR; signal(DLIN);}void datalink() _task_ DLIN { while(1) { wait(); frame[i++] = R; if (i == 3) { i = 0; process(frame); } }}

void physical() interrupt SF { R = SDR; SDR = deq(); signal(DLIN);}void datalink _task_ DLIN { while (1) { wait(); frame[i++] = R; if (i == 3) { i = 0; process(frame); } }}

longer packets =less overhead but longer latency (responsetime)

loadtable slave110cont. slave115end slave130 o o o

write(slave1, “loadtable 10 15 25 30”); //transport interface

verify checksumupdate local DBwith data in the ACKframe. Handle error.

if for me, prepare ACKassemble into packets andsignal app when packetcomplete

not shown: synchronizingdealing w/ errors

CSE 466 – Fall 2000 - Introduction - 11

Application Interface to Data Link Layer

void mast() _task_ app { … // application layer protocol defines meaning write(SLAVE1, “loadtable 10 15 20 25 30”); //blocking …}void write(int dst, char *command{ // transport interface frame_array = mkFrames(dst,command); for (each byte in frame array) enq(byte);}

loadtableslave1 10

cont.slave1 15

endslave1 30

void slave()_task_ app( while(1) { if (!read(master, cmd)) do(cmd); other_processing() }}int read() { if (test(READ)) { sprintf(cmd,”%s”,deq()) return(0); } return(-1)}void process(char *frame) { response = resp(frame); for (each byte) enq(response); if (addframe(p,frame)) { enq(p); p = new packet(); signal(READ); } }

CSE 466 – Fall 2000 - Introduction - 12

Trade-off Between Frame Size and Overhead

write(p1, “loadtable 10 15 25 30”); //transport interface

loadtablep1 10

cont.p1 15

endp1 30

or

loadtablep1 10 15 20 25 30 end

Frame: bus is dedicated to that transmission duringthe entire frame

similar to the OS time slice problem: efficiency v. responsiveness

CSE 466 – Fall 2000 - Introduction - 13

Another Physical Layer – I2C

Multi-mastered

Send and receive

Two wire (plus ground)

Packet oriented (block send)

CSE 466 – Fall 2000 - Introduction - 14

Major Features of I2C

CSE 466 – Fall 2000 - Introduction - 15

Physical Layer

CSE 466 – Fall 2000 - Introduction - 16

Bit Transfer

Transmitter

Master

CSE 466 – Fall 2000 - Introduction - 17

Who gets to be master

The one who initiates a frame:

A frame is:<Start><addr><data>…<data><Stop> OR<Start><addr><data>…<data><R_Start><addr><data>…<Stop>

CSE 466 – Fall 2000 - Introduction - 18

An I2C Byte Transfer

Tx Device Rx Device

master

slave slave

Rx

MSB First

MSB……………….LSB

CSE 466 – Fall 2000 - Introduction - 19

“Bit Banging” v. Bus Controller

Bit Bangingdo all signal transitions in SWvery difficult

IC Interface:Mem Mapped device:

set your addressinitiate transferservice the device on interrupt

byte receivedtransmission complete

CSE 466 – Fall 2000 - Introduction - 20

Schematic from App Note

Something is wrong with this picture…but its close

CSE 466 – Fall 2000 - Introduction - 21

Arbitration

what’s the backoff rule?

CSE 466 – Fall 2000 - Introduction - 22

A Complete Frame

MSB……..LSB

CSE 466 – Fall 2000 - Introduction - 23