230 likes | 243 Views
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);
E N D
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); } commands and responses are packets not single bytes mode is NOT a global variable Slave void 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 RESPONSES responses are for previous command CSE 466 – Fall 2000 - Introduction - 1
Sockets are a logical constructs 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. slave Master slave slave CSE 466 – Fall 2000 - Introduction - 2
Physical Network MCU2 MCU1 Bus Device1 Device2 CSE 466 – Fall 2000 - Introduction - 3
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 - 4
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 Application Application write(s, buf,n); read(s, buf,n ); Transport -- TCP Transport -- TCP Network -- IP Network -- IP Network -- IP Network -- IP Datalink -- Ether Datalink -- Ether Datalink -- Ether Datalink -- Ether Physical -- Ether ethernet fiber fiber ethernet Physical -- Ether CSE 466 – Fall 2000 - Introduction - 5
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) Application Application write(s, buf,n); read(s, buf,n ); Transport Transport Network -- IP Network -- IP Network -- IP Network -- IP Datalink Datalink -- Ether Datalink -- Ether Datalink Physical ethernet fiber fiber ethernet Physical CSE 466 – Fall 2000 - Introduction - 6
Example of Physical Layer: SPI Bus Master Slave SCK SCK SDO SDI 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 0 0 0 1 1 0 0 0 shift reg shift reg CSE 466 – Fall 2000 - Introduction - 7
Multiple Slave Configuration Master Slave SCK SCK SDO SDI SDI SDO Slave SCK SDI SDO CSE 466 – Fall 2000 - Introduction - 8
Master Slave Data Link Protocol • As an example frame is [destination address, command, data] • An acknowledgement frame is [address, data, checksum] Master Slave SCK SCK SDO SDI SDI SDO mux Slave SCK dst cmd data dst type data SDI addr data sum type data sum SDO mux x x x 1 1 1 2 2 2 CSE 466 – Fall 2000 - Introduction - 9
o o o slave1 loadtable 10 slave1 cont. 15 slave1 end 30 Data Link Layer (Master/Slave) write(slave1, “loadtable 10 15 25 30”); //transport interface 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); } } } 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); } } } longer packets = less overhead but longer latency (response time) if for me, prepare ACK assemble into packets and signal app when packet complete not shown: synchronizing dealing w/ errors verify checksum update local DB with data in the ACK frame. Handle error. CSE 466 – Fall 2000 - Introduction - 10
slave1 loadtable 10 slave1 cont. 15 slave1 end 30 Application Interface to Data Link Layer 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); } } 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); } CSE 466 – Fall 2000 - Introduction - 11
Trade-off Between Frame Size and Overhead write(p1, “loadtable 10 15 25 30”); //transport interface p1 loadtable 10 p1 cont. 15 Frame: bus is dedicated to that transmission during the entire frame p1 end 30 or p1 loadtable 10 15 20 25 30 end similar to the OS time slice problem: efficiency v. responsiveness CSE 466 – Fall 2000 - Introduction - 12
Another Physical Layer – I2C • Multi-mastered • Send and receive • Two wire (plus ground) • Packet oriented (block send) CSE 466 – Fall 2000 - Introduction - 13
Major Features of I2C CSE 466 – Fall 2000 - Introduction - 14
Physical Layer CSE 466 – Fall 2000 - Introduction - 15
Bit Transfer Transmitter Master CSE 466 – Fall 2000 - Introduction - 16
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 - 17
An I2C Byte Transfer MSB First Rx MSB……………….LSB slave slave Tx Device Rx Device master CSE 466 – Fall 2000 - Introduction - 18
“Bit Banging” v. Bus Controller Bit Banging do all signal transitions in SW very difficult IC Interface: Mem Mapped device: set your address initiate transfer service the device on interrupt byte received transmission complete CSE 466 – Fall 2000 - Introduction - 19
Schematic from App Note Something is wrong with this picture…but its close CSE 466 – Fall 2000 - Introduction - 20
Arbitration what’s the backoff rule? CSE 466 – Fall 2000 - Introduction - 21
A Complete Frame MSB……..LSB CSE 466 – Fall 2000 - Introduction - 22