1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

first-in first-out program

Discussion in 'Microcontrollers' started by Parth86, Oct 3, 2017.

  1. Parth86

    Parth86 Member

    Joined:
    Dec 25, 2011
    Messages:
    546
    Likes:
    5
  2. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    470
    Likes:
    37
    maybe http://www.tenouk.com/ModuleZ.html -- about memory allocation functions
    http://www.csd.uoc.gr/~hy534/00a/sec3.html#s34.data_str -- harware implemented but the basic ideas apply also to programmed data structures
    http://ciechanowski.me/blog/2014/03/05/exposing-nsmutablearray/ -- educational extending the scope

    you better exact at what platform in which environment e.c. and how (what exactly) you need to implement
    (usually there is no questions if you have these points set clear to yourself)
     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    You're running again... I told you to learn the small stuff first!!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    470
    Likes:
    37

    as function names and syntax

    . . . at the i made a major step forward getting started with graphics program though my experience at that time about the particular programming language was near zero -- it's that the step wise achieved output motivated to complete this complex starter project (it's not where you start (not much) but that you do and keep going)
     
  6. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    470
    Likes:
    37
    what exactly you want to do
    ? in which c
    ? in which os/platform
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    ONLINE
    I have yet to understand a single post of your's ci139.

    Mike.
     
  8. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    470
    Likes:
    37
    [...about.txt] -- a documentation of need to know stuff
    for implementing
    a stupid javascript fifo [...TEST-1.html] which i doubt does (in a sense of memory allocation) what i think it should (but will do as a poor and impossible for you to grasp example . . . . . . . . . . . . haa , haa , haa , haa )

    // tested in Opera and IE for now also MZ.FF -- PS! -- but since it late here , i do not dispose my objects correctly -- as in about.txt -- all data fields of the popped elements must be cleared and their references set to undefined or deleted -- the proper structure/method would be reading all data into some permanent or temporary fetch variable from the element popped from the FiFo then erasing the popped Element ...
     

    Attached Files:

    Last edited: Oct 8, 2017
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    ONLINE
    I often use a fifo to store received characters via serial interrupt.
    This is how I implement it in C.
    Code (text):

    #include <xc.h>
    #include "fifo.h"

    #define FifoLength 32
    unsigned char FifoBuffer[FifoLength];
    unsigned char *FifoStart;
    unsigned char *FifoEnd;
    unsigned char count;


    void InitFifo(void){
        FifoStart=FifoBuffer;
        FifoEnd=FifoBuffer;
        count=0;
    }

    void PutFifo(unsigned char chr){
        *FifoEnd++=chr;
        count++;
        if(FifoEnd==FifoBuffer+FifoLength)      //reached end
            FifoEnd=FifoBuffer;                 //yes so wrap
        if(count=FifoLength){                   //is head eating tail?
            //fifo full so deal with it!!
        }
    }

    unsigned char GetFifo(void){
    unsigned char chr;
        while(FifoStart==FifoEnd);              //if fifo empty then wait
        chr=*FifoStart++;
        count--;
        if(FifoStart==FifoBuffer+FifoLength)    //wrapped?
            FifoStart=FifoBuffer;               //yes
        return(chr);
    }

    unsigned char FifoCount(void){
        return(count);
    }
     
    Mike.
     

Share This Page