DOC PREVIEW
U of U ECE 3720 - Lecture 8 - FIFOs
Pages 8

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1'&$%ECE/CS 3720: Embedded System Design(ECE 6960/2 and CS 6968)Chris J. MyersLecture 8: FIFOsSlide 2'&$%Introduction to FIFOs• FIFO circular queue is useful for a buffered I/O interface.• This order-preserving data structure temporarily savesdata created by producer before processed by consumer.• Decouples the producer from the consumer.• Use statically allocated global memory, so they can beshared by threads, but must be accessed carefully.1Slide 3'&$%Produce-Consumer ExamplesSource/producer Sink/consumerKeyboard input Program that interpretsProgram with data Printer outputProgram sends message Program receives messageMicrophone and ADC Program that saves sound dataProgram that has sound data DAC and speakerSlide 4'&$%Two-Pointer FIFO2Slide 5'&$%Basic Idea of FIFOGetPt rmb 2 Ptr to oldest data, next to be removedPutPt rmb 2 Ptr to free memory, place to put next* Reg A contains byte to store into the FIFOPutFifo ldx PutPt Reg X points to free placestaa ,X Store data into FIFOinx Update pointerstx PutPtrts* Reg A returned with byte from FIFOGetFifo ldx GetPt Reg X points to oldest dataldaa ,X Read data from FIFOinx Update pointerstx GetPtrtsSlide 6'&$%Initialization of a Two-Pointer FIFO in AssemblyFifoSize equ 10 Size of FifoPutPt rmb 2 Pointer where to put next */GetPt rmb 2 Pointer where to get next* FIFO is empty if PutPt=GetPt* FIFO is full if PutPt+1=GetPt (with wrap)Fifo rmb FifoSize The fifo dataInitFifo ldx #Fifotpasei entering critical sectionstx PutPtstx GetPt Empty when PutPt=GetPttap end critical sectionrts3Slide 7'&$%Initialization of a Two-Pointer FIFO in C#define FifoSize 10 /* Size of Fifo */char *PutPt; /* Ptr of where to put next */char *GetPt; /* Ptr of where to get next/* FIFO is empty if PutPt=GetPt *//* FIFO is full if PutPt+1=GetPt (with wrap) */char Fifo[FifoSize]; /* The fifo data */void InitFifo(void) { char SaveSP;asm(" tpa\n staa %SaveSP\n sei"); /* critical */PutPt=GetPt=&Fifo[0]; /* Empty when PutPt=GetPt */asm(" ldaa %SaveSP\n tap"); /* end critical */}Slide 8'&$%PutFifo for a Two-Pointer FIFO in Assembly* Input RegA contains 8 bit data to put* Output RegA is -1 if successful, 0 otherwisePutFifo pshatpatabpulapshb save old CCRsei critical sectionldx PutPt Temporary put pointerstaa 0,x Try to put data into fifoinxcpx #Fifo+FifoSize4Slide 9'&$%PutFifo for a Two-Pointer FIFO in Assembly (cont)bne PutNoWrap skip if no wrap neededldx #Fifo WrapPutNoWrap clra assume it will failcpx GetPt Full if now the samebeq PutDonecoma RegA=-1 means OKstx PutPtPutDone tab end critical sectionpulatpa restore CCR to previous valuetbartsSlide 10'&$%PutFifo for a Two-Pointer FIFO in Cint PutFifo (char data) { char *Ppt;char SaveSP;asm(" tpa\n staa %SaveSP\n sei"); /* critical */Ppt=PutPt; /* Copy of put pointer */*(Ppt++)=data; /* Put data into fifo */if (Ppt == &Fifo[FifoSize]) Ppt = &Fifo[0];if (Ppt == GetPt ) {asm(" ldaa %SaveSP\n tap"); /* end critical */return(0);} /* Failed, fifo was full */else{PutPt=Ppt;asm(" ldaa %SaveSP\n tap"); /* end critical */return(-1); } } /* Successful */5Slide 11'&$%GetFifo for a Two-Pointer FIFO in Assembly* Input RegX points to place for 8 bit data* Output RegA is -1 if successful, 0 if Fifo emptyGetFifo tpapsha save old CCRsei critical sectionclra assume it will failldy GetPtcpy PutPt Empty if initially samebeq GetDonecoma RegA=-1 means OKldab 0,y Data from FIFOstab 0,x Return by referenceinySlide 12'&$%GetFifo for a Two-Pointer FIFO in Assembly (cont)cpy #Fifo+FifoSizebne GetNoWrap skip if no wrap neededldy #Fifo WrapGetNoWrap sty GetPtGetDone tab end critical sectionpulatpa restore CCR to previous valuetbarts6Slide 13'&$%GetFifo for a Two-Pointer FIFO in Cint GetFifo (char *datapt) { char SaveSP;if (PutPt == GetPt ) {return(0);} /* Empty if PutPt=GetPt */else{asm(" tpa\n staa %SaveSP\n sei"); /* critical*/*datapt=*(GetPt++);if (GetPt == &Fifo[FifoSize]) GetPt = &Fifo[0];asm(" ldaa %SaveSP\n tap"); /* end critical */return(-1);}}Slide 14'&$%Initialization of a Two-Ptr/Cnt FIFO in AssemblyFifoSize equ 10 Size of FifoPutPt rmb 2 Pointer of where to put nextGetPt rmb 2 Pointer of where to get nextSize rmb 1Fifo rmb FifoSize fifo dataInitFifo tpasei critical sectionldx #Fifostx PutPtstx GetPt Empty when Size == 0clr Sizetap end critical sectionrts7Slide 15'&$%Initialization of a Two-Pointer/Counter FIFO in C#define FifoSize 10 /* Size of Fifo */char *PutPt; /* Ptr of where to put next */char *GetPt; /* Ptr of where to get next */unsigned char Size; /* # of elements in FIFO *//* FIFO is empty if Size=0 *//* FIFO is full if Size=FifoSize */char Fifo[FifoSize]; /* fifo data */void InitFifo(void) { char SaveSP;asm(" tpa\n staa %SaveSP\n sei"); /* critical*/PutPt=GetPt=&Fifo[0]; /* Empty when Size==0 */Size=0;asm(" ldaa %SaveSP\n tap"); /* end critical */}Slide 16'&$%PutFifo for a Two-Ptr/Cnt FIFO in Assembly* Input RegA contains 8 bit data to put* Output RegA is -1 if successful, 0 otherwisePutFifo pshatpatabpulapshb save old CCRsei critical sectionldab Sizecmpb #FifoSize Full if Size==FifoSizebne PutNotFullclrabra PutDone8Slide 17'&$%PutFifo for a Two-Ptr/Cnt FIFO in Assembly (cont)PutNotFull incbstab Size Size++ldx PutPtstaa 0,x Put data into fifoinxcpx #Fifo+FifoSizebne PutNoWrap skip if no wrap neededldx #Fifo WrapPutNoWrap ldaa #-1 success means OKstx PutPtPutDone tab end critical sectionpulatpa restore CCR to previous valuetbartsSlide 18'&$%PutFifo for a Two-Pointer/Counter FIFO in Cint PutFifo (char data) { char SaveSP;if (Size == FifoSize ) {return(0);} /* Failed, fifo was full */else{asm(" tpa\n staa %SaveSP\n sei"); /* critical*/Size++;*(PutPt++)=data; /* put data into fifo */if (PutPt == &Fifo[FifoSize]) PutPt = &Fifo[0];asm(" ldaa %SaveSP\n tap"); /* end critical */return(-1); /* Successful */}}9Slide 19'&$%GetFifo for a Two-Ptr/Cnt FIFO in Assembly* Input RegX points to place for 8 bit data* Output RegA is -1 if successful, 0 if Fifo emptyGetFifo tpapsha save old CCRsei critical sectionclra assume it will failtst Sizebeq GetDonedec Sizeldy GetPtcoma RegA=-1 means OKldab 0,y Data from FIFOstab 0,x Return by referenceSlide 20'&$%GetFifo for a Two-Ptr/Cnt FIFO in Assembly (cont)inycpy #Fifo+FifoSizebne GetNoWrap skip if no wrapping neededldy #Fifo WrapGetNoWrap sty GetPtGetDone tab end critical sectionpulatpa restore CCR to previous valuetbarts10Slide 21'&$%GetFifo for a Two-Pointer/Counter FIFO in Cint GetFifo (char *datapt) { char SaveSP;if (Size == 0 ){return(0);} /* Empty if Size=0 */else{asm(" tpa\n staa


View Full Document

U of U ECE 3720 - Lecture 8 - FIFOs

Course: Ece 3720-
Pages: 8
Download Lecture 8 - FIFOs
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 8 - FIFOs and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 8 - FIFOs 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?