Giter Site home page Giter Site logo

yhcasey / fifo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from geekfactory/fifo

0.0 0.0 0.0 30 KB

Generic FIFO buffer implementation written in C language

Home Page: https://www.geekfactory.mx

License: GNU General Public License v3.0

C 100.00%

fifo's Introduction

Geek Factory FIFO Library

This is a generic FIFO buffer that can be used to store any kind of items. It is written in C language and can be compiled and used on almost any architecture. It was designed to be used on memory limited architectures such as microcontrollers. Examples of the applications that can be built with this library include:

  • Work queues.
  • Message queues.
  • FIFO buffers for data I/O.
  • Program synchronization.
  • Any other applications that requires FIFO style data storage.

As with most of our libraries, it is designed to run on the popular Arduino platform as well as other common architectures, such as the PIC16 and PIC 18 microcontrollers from Microchip.

Basic library usage

The following example ilustrates the library usage.

/**
   GeekFactory - "INNOVATING TOGETHER"
   Distribucion de materiales para el desarrollo e innovacion tecnologica
   www.geekfactory.mx

   This example shows the basic usage of the FIFO library. We create a FIFO,
   then we fill it with some data and then dump the data to the serial monitor.
*/
#include "FIFO.h"

// array of test data
char data[] = "Hola Mundo!!!!";
// type to store a FIFO reference
fifo_t myfifo;

void setup() {
  // prepare serial interface
  Serial.begin(115200);
  while (!Serial);

  // show message on serial monitor
  Serial.println(F("----------------------------------------------------"));
  Serial.println(F("             FIFO LIBRARY TEST PROGRAM              "));
  Serial.println(F("             https://www.geekfactory.mx             "));
  Serial.println(F("----------------------------------------------------"));

  // create a FIFO (queue) capable of storing 10 items
  myfifo = fifo_create(10, sizeof(char));

  // check if FIFO was created
  if (myfifo == NULL) {
    Serial.println(F("Cannot create FIFO... halting!"));
    for (;;);
  } else {
    Serial.println(F("FIFO created successfully"));
  }

  // put some data on the fifo buffer
  Serial.println(F("\r\nFILLING FIFO WITH DATA..."));
  for (unsigned int i = 0; i < sizeof(data); i++)
  {
    Serial.print(F("Add item to FIFO: "));
    Serial.print(data[i]);
    if (fifo_add(myfifo, &data[i])) {
      Serial.println(F(" (OK)"));
    } else {
      Serial.println(F(" (FAIL)"));
    }
  }

  // get data from FIFO
  Serial.println(F("\r\nGETTING DATA FROM FIFO..."));
  // dump data from FIFO to serial monitor
  while (!fifo_is_empty(myfifo)) {
    char c;
    fifo_get(myfifo, &c);
    Serial.print(c);
  }

  // end of test program
  Serial.println(F("DONE"));
}

void loop() {
  // Do nothing here

}

Project objectives

  • Improve program modularity and reliability by creating common data structures.
  • Provide a portable implementation of a FIFO data structure.
  • Strong portability, especially on embedded systems, by using C language.
  • Provide functions for static memory allocation applications.
  • Easy to configure, use and understand.

Supported devices

This library was developed/tested on the following boards

  • Arduino UNO R3
  • Arduino Mega 2560 R3

Contact me

fifo's People

Contributors

geekfactory avatar ruben219 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.