Download
chat application n.
Skip this Video
Loading SlideShow in 5 Seconds..
Chat Application PowerPoint Presentation
Download Presentation
Chat Application

Chat Application

95 Vues Download Presentation
Télécharger la présentation

Chat Application

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. 2 1 A B 3 4 Chat Application 1 (no event) || (getchar(&c) && !call(c) ) / if (c) echo c, print failure message 2 (getchar(&c) && call(c)) || recv(&c) / echo c, print success message, call accept() if from network 3 (no event) || (getchar(&c) && c!=ESC) || (recv(&c) && (c!= ESC)) / if (c) putchar(c), if from term, send(c). 4 (getchar(&c) && c==ESC) || (recv(&c) && (c== ESC)) / call close(), print message Transport Layer Services: call(); accept(); send(); recv(); close(); CSE 466 – Fall 2000 - Introduction - 1

  2. Complete the Stack the weather? User User dial tone dial tone message semantics / telephone model Application Application call() accept() send()… call() accept() send()… connection management / security Transport Transport ? ? I2C frames Physical I2C Physical I2C Describe the API that the physical layer has to provide to the transport layer. Try writing call(), accept(), send(), recv(), close() functions using that API. Find out what functions you want the physical layer to provide. CSE 466 – Fall 2000 - Introduction - 2

  3. New Versions of the App BUSY AVAIL void stateB() _task_ B { while(1) { if (!busy) wait(K_SIG); busy = 1; if (g=getchar(&c) || (recv(CHAT,&c)) { if (c != ESC) { putchar(c); if (g) send(CHAT,c); } else { close(CHAT); busy = 0; os_signal_task(A); } } } } can close if undesired caller void stateA() _task_ A{ while(1) { if (!avail) wait(K_SIG); avail = 1; if ((getchar(&c) && call(CHAT, c)) || accept(CHAT,&c)) { sprint(“connected to: ”); putchar(c); avail = 0; os_signal_task(B); } } } generic transport layer interface: > call(port, address) // blocking > accept(port, *address) // non-blocking > send(port, data) // blocking > recv(port, data) // non-blocking > close(port, data) // non-blocking CSE 466 – Fall 2000 - Introduction - 3

  4. My Attempt • Data Queues • Allocated by transport • layer as needed for application requests. Has Port and Dst attributes • Physical Layer • Stuffs incoming data into matching queue • Stuffs control info into control queue • Makes and sends control and data frames • data frame • [s, dst, src, port, data, …, data, p] • control frame • [s, dst, 0, src, port, cmd, p] call(), accept(), close(), send(), recv() Transport control adr port cmd adr port cmd … data data data data … Control queue (transport to transport communication) dst Port Physical CSE 466 – Fall 2000 - Introduction - 4

  5. The Transport Layer Protocol User User dial tone dial tone Application Application call() accept() send()… call() accept() send()… call() accept() Transport Transport ? ? Physical I2C Physical I2C CSE 466 – Fall 2000 - Introduction - 5

  6. A look at Call() int call(int port, int dst) { // establish a connection to specified port on dst system queue *inq, *outq; int count ; if (status[port] == BUSY) return 0; else (status[port] == BUSY); outq = outQueues[port] ; inq = inQueues[port]; // static allocation of queues…could be dynamic inq->addr = outq->addr = c; inq->port = outq->port = port; enq(outCtlQ,c); enq(outCtlQ,port); // put call into control queue enq(outCtlQ,CALL); while (ack = scan(inCtlQ,c,port,ACK) && count++<=MAX); if (ack) return port; status[port] = AVAIL; return 0; } CSE 466 – Fall 2000 - Introduction - 6

  7. A look at Accept() int accept(int port, char c) { queue *inq, *outq; if (status[port] == BUSY) return 0; if (scan(inCtlQ, &c, port, CALL)) { status[port] == BUSY; outq = outQueues[port] inq = inQueues[port]; // static allocation inq->src = outq->dst = c; inq->port = outq->port = port; enq(outCtlQ, c); enq(outCtlQ, port); enq(outCtlQ, ACK); // send an acknowledgement } return port; } CSE 466 – Fall 2000 - Introduction - 7

  8. The rest of the Functions int send(char port, char c) { queue *outq; if (status[port] == AVAIL) return 0; outq = outQueues[port]; enq(outq,c); //blocking } int recv(char port, char *c) { queue *inq; if (status[port] == AVAIL) { return 0; } inq = inQueues[port]; return(deq(inq, c)); //non blocking } int close(char port) { queue *outq; if (status[port] == AVAIL) return 0; outq = outQueues[port]; while(!empty(outq)); enq(outCtlQ, outQueues[port]->dst); enq(port); enq(outCtlQ, CLOSE) ; status[port] = AVAIL; return 1; } physical/datalink layer has to provide flow control guarantees security/validation I2C does not enforce indentification of the sender! CSE 466 – Fall 2000 - Introduction - 8

  9. Physical Layer API (same as Lab) • enq(), deq(), scan() • Periodically • if not currently master and there is a non-empty outgoing queue • select non-empty outgoing queue and attempt to become bus master by sending start condition • On Interrupt • if bus master and not end of frame (data queue empty, control queue new command) send next byte, otherwise send stop condition • if currently bus slave • get byte and place into appropriate queue based on frame header info • Deal w/ flow control somehow (control frames for acknowledgement) • Deal w/ Security Function Calls dst port Timer Interrupt and External Interrupt Routines CSE 466 – Fall 2000 - Introduction - 9

  10. Phew…is it just TCP? • Probably. I tried to find a TCP/I2C stack but no hits on the web. Its probably been done • What’s the embedded way? • Get an OS w/ a built in stack…you can get these • Give up on layers… write a non-layered special purpose protocol • Most companies with a product line will • develop a hardware platform • develop kernel and networking infrastructure • churn out products by writing primarily at the application layer CSE 466 – Fall 2000 - Introduction - 10

  11. A simple monolithic solution • Keep same frame specification, except all data packets are one byte • On I2C Interrupt • if master send next byte frame or stop • if slave, get next byte of frame. • If complete frame received • if NACK frame from dst set avail • if call and busy, queue up NACK frame • if data and avail ignore • if call and avail set busy, set dst, queue up ACK frame • if data and busy and wrong dst ignore • if data and busy and right dst display • On keypress • if not busy queue up CALL frame, signal initMaster • if busy, queue up data frame, signal initMaster • No flow control or error handling CSE 466 – Fall 2000 - Introduction - 11

  12. Finishing out the Term • Option 1: A final lab assignment … to be negotiated. • Some improvement on music player (I think we can do 20K music at 11 MHz anyway). Maybe Streaming from NT through one player to another player over I2C. No upload needed. • Chat • A PCB for the Music Player w/I2C and Serial ports • Option 2: A report/presentation • design approaches for some existing system • fuzzy logic controller for people movers • automotive apps and networking (ECU, Airbag, CAN) • Embedded TCP (IP?/I2C?) • Embedded web-servers • Robots • Convergence devices • hw that we didn’t cover • motors • watchdog circuits • DAC, ADC • display…vga/lcd • radios • flash • audio codec CSE 466 – Fall 2000 - Introduction - 12

  13. CSE 466 – Fall 2000 - Introduction - 13