Continue to Site

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.

  • 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.

first-in first-out program

Status
Not open for further replies.

Parth86

Member
Hi
I want to make simple C program for first-in first-out algorithm. I have gone through below links to understand basic of queue in programming
https://en.wikibooks.org/wiki/A-level_Computing/AQA/Paper_1/Fundamentals_of_data_structures/Queues
https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
upload_2017-10-3_19-2-27.png

How to make c program for given table ?
 
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)
 
small stuff
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)
 
[...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 ...
 

Attachments

  • jsObjPTR~about.txt
    5.3 KB · Views: 193
  • jsObjPTR-TEST-1.html.txt
    2.9 KB · Views: 222
Last edited:
I often use a fifo to store received characters via serial interrupt.
This is how I implement it in C.
Code:
#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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top