Slide 1'&$%ECE/CE 3720: Embedded System Design(ECE 6960/2 and CS 6968)Chris J. MyersLecture 5: Interfacing MethodsSlide 2'&$%Introduction1. Embedded systems often have many special I/O devices,so I/O interfacing is a critical task.2. I/O interfacing includes both physical connections andsoftware routines that affect information exchange.3. Chapter 3 introduces basic interfacing methods.4. Chapter 4 introduces interfacing using interrupts.1Slide 3'&$%Performance Measures1. Latency is the delay from when an I/O device needsservice until the service is initiated.2. It includes both hardware and software delays.3. A real-time systems guarantees a worst-case latency.4. Throughput or bandwidth is maximum rate data can beprocessed by the system.5. Can be limited by I/O device or the software.6. Priority determines order of service when two or morerequests are made at the same time.7. Soft real time system is one that supports priority.Slide 4'&$%Synchronizing the Software with the State of the I/O1. Hardware is in 1 of 3 states: idle, busy, or done.2. When working, device alternates between busy and done.3. I/O devices usually much slower than software, sosynchronization is required for proper transmission.4. When an I/O device is slower than software, it is I/Obound, otherwise it is CPU bound.5. Interface can be buffered or unbuffered.2Slide 5'&$%Synchronizing Software with an Input DeviceSlide 6'&$%Synchronizing Software with an Output Device3Slide 7'&$%Synchronization Mechanisms1. Blind cycle - software simply waits a fixed amount oftime for the I/O to complete.2. Gadfly or busy waiting - software loops checking the I/Ostatus waiting for the done state.3. Interrupt - I/O device causes special software executionwhen it requires service.4. Periodic polling - clock interrupt periodically checks I/Ostatus.5. Direct memory access - I/O device directly transfers datato/from memory.Slide 8'&$%Parallel I/O Control Register (PIOC)• STAF - Strobe A Flag• STAI - Strobe A Interrupt Enable Bit• CWOM - Port C Wired-OR Mode Bit• HNDS - Handshake/Simple Strobe Mode Select Bit• OIN - Output/Input Handshake Select Bit• PLS - Strobe B Pulse Mode Select Bit• EGA - Edge Select for Strobe A Bit• INVB - Invert Strobe B Bit4Slide 9'&$%Blind Cycle Printer InterfaceSlide 10'&$%Idealized Timing for Strobe OutputINVB=1, PIOC=$015Slide 11'&$%Initialize and Output to a PrinterInit clr PIOCrtsOut staa PORTBldd #2857 ;wait 10msOLoop subd #1bne OLooprts--------------------------void Init(void){PIOC=0x00;}void Out(unsigned char value){unsigned int n;PORTB=value;for(n=0;n<2857;n++);}Slide 12'&$%Blind Cycle ADC Interface6Slide 13'&$%Initialize and Read from an ADCInit ldaa #$01 ;INVB=1staa PIOCclr DDRCrtsIn staa PORTB ;GO pulsemul ;[10]ldaa PORTCrts------------------------void Init(void){PIOC=0x01; // GO=STRBDDRC=0;} // PORTC is dataunsigned char In(void){ int n;PORTB=value; // GO pulsefor(n=0;n<1;n++);return(PORTC);}Slide 14'&$%Accurate Time Delays• Counting cycles is tedious and must be redone when:– Software algorithm changes– Computer speed changes– Computer is upgraded– Compiler is upgraded• It is inaccurate when interrupts can occur.• 68HC11 includes fixed rate 16-bit counter, TCNT.• Operates correctly in presence of overflow.7Slide 15'&$%Accurate Time Delays; Reg D is the number of cycles to wait; can range from 25 to 32767Wait addd TCNT time at the end of delayLoop cpd TCNT wait for Endt-TCNT>0bpl Looprts---------------------------------------void Wait(short numCycles){short EndT; // TCNT at the end of the delayEndT=TCNT+numCycles;while(EndT-(short)TCNT>0);}Slide 16'&$%Gadfly or Busy Waiting Synchronization8Slide 17'&$%Multiple Gadfly OutputsSlide 18'&$%Multiple Gadfly Inputs and Outputs9Slide 19'&$%Gadfly Keyboard Interface Using Latched InputSlide 20'&$%Idealized Timing for Latched InputEGA=1, PIOC=$0210Slide 21'&$%Initialize and Read from a Keyboard; PortC=DATA, STRA=STROBEInit ldaa #$02 ;EGA=1staa PIOCldaa #$80 ;PC7=outputstaa DDRCldaa PIOC ;STAF=0ldaa PORTCLclr PORTC ;PC7=0rtsIn ldaa PIOC ; wait for STAFbpl Inldaa PORTCLrtsSlide 22'&$%Initialize and Read from a Keyboardvoid Init(void){// PC6-0 is DATAunsigned char dummy;PIOC=0x02; // EGA=1DDRC=0x80; // STRA=STROBEPORTC=0x00; // PC7=0dummy=PIOC;dummy=PORTCL;}unsigned char In(void){while ((PIOC & STAF) == 0);return(PORTCL); }11Slide 23'&$%Gadfly ADC Interface Using Simple InputSlide 24'&$%Initialize and Read from an ADCInit ldaa #$03 ;EGA=1, INVB=1staa PIOCldaa #$00 ;PC=inputstaa DDRCldaa PIOC ;STAF=0ldaa PORTCLrtsIn staa PORTB ;GO pulseloop ldaa PIOC ;wait for STAFbita #$80beq loopldaa PORTCLrts12Slide 25'&$%Initialize and Read from an ADCvoid Init(void){// PortC=DATA STRA=DONE STRB=GOunsigned char dummy;PIOC=0x03; // EGA=1 INVB=1DDRC=0x00; // PC inputsdummy=PIOC;dummy=PORTCL;} // clear STAFunsigned char In(void){PORTB=0; // GO pulsewhile ((PIOC & STAF) == 0);return(PORTCL); }Slide 26'&$%Gadfly External Sensor Interface Using InputHandshake13Slide 27'&$%Idealized Timing for Full-Input HandshakeHNDS=1, OIN=0, PLS=0/1, EGA=1, INVB=1, PIOC=$13/$17Slide 28'&$%Comment for PIOC Register; PortC ritual, Set PC7-PC0 inputs = sensor DATA; PIOC ($1002); 7 STAF Read Only Set on rise of STRA; 6 STAI 0 Gadfly, no interrupts; 5 CWOM 0 Normal outputs; 4 HNDS 1 Input handshake; 3 OIN 0; 2 PLS 0 ACK=STRB goes to 0 on rise of READY; 1 EGA 1 STAF set on rise of READY=STRA; 0 INVB 1 ACK=STRB goes to 1 on a ReadCL; STRB=ACK status 0 means busy,1 means done; STRA=READY rising edge when new data is ready14Slide 29'&$%Initialize and Read from a Sensor; PortC=DATA STRA=READY STRB=ACKInit ldaa #$13 ;Input hndshakestaa PIOCldaa #$00 ;PC=inputstaa DDRCldaa PIOC ;STAF=0ldaa PORTCLrtsIn ldaa PIOC ;wait for STAFbita #$80beq Inldaa PORTCL ;read DATArtsSlide 30'&$%Initialize and Read from a Sensorvoid Init(void){// PortC=DATA STRA=READY STRB=ACKunsigned char dummy;PIOC=0x13; // EGA=1 INVB=1DDRC=0x00; // PC inputsdummy=PIOC;dummy=PORTCL;} // clear STAFunsigned char In(void){while ((PIOC & STAF) == 0);return(PORTCL); }15Slide 31'&$%Gadfly Printer Interface Using Output HandshakeSlide 32'&$%Idealized Timing for Full-Output HandshakeHNDS=1, OIN=1, PLS=0/1, EGA=1, INVB=1, PIOC=$1B/$1F16Slide 33'&$%Initialize and Write to a Printer; PC=DATA STRA=READY STRB=STARTInit ldaa #$1E ;Output hndshkestaa PIOCldaa #$FF ;PC=outputstaa DDRCrtsOut staa PORTCL ;out, pulsewait ldab PIOC ;wait for STAFbitb #$80beq waitrtsSlide 34'&$%Initialize and Write to a Printervoid
View Full Document