Code Monkey home page Code Monkey logo

fifofast's People

Contributors

bamkrs avatar nqtronix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fifofast's Issues

Special Considerations for Very Large FIFOs?

Are there any special considerations that should be kept in mind if attempting to declare and use a very large (e.g. 262144 elements) FIFO? Do I need to be using any low-level compiler instructions, like __DSB(); or __ISB(); or cache-flushing operations when working with the fifofast library to ensure data is handled correctly?

I'm using this fifofast library to create a FIFO to hold data to later write out to flash. I've encountered some intermittent data corruption issues in my written flash, and I am trying to narrow down where in my code that the corruption is occurring.

My issues are likely completely unrelated to my implementation of the fifofast library, but I don't have a strong enough grasp of how this library is working under the hood with relation to compiler optimizations, memory alignment, DCache/ICache, etc. to know if I'm doing something dangerous/out of spec with your library, so I thought I'd ask if there are any constraints or limitations to be aware of when using very large FIFOs.

If it helps, this is my current implementation, which seems to generally work fine:

Here is my declaration in an H file (with include guards) that is included in all my C files that access the FIFO:
_fff_declare(volatile uint8_t __attribute__((aligned(16))), fifo_sram_data_storage, 262144);

(Note that I am not very confident in my alignment keyword usage here...I wasn't sure if I need to explicitly tell the compiler an alignment, but I assume it won't hurt anything either...)

Here is my initialization in main.c (but outside of main()):
_fff_init(fifo_sram_data_storage);

I have a small temporary holding buffer (g_data_temp_buffer_sram[] consisting of g_current_byte elements) that I store data in, before stuffing its contents into the FIFO. To write this data to the FIFO, I first check to ensure enough free space remains using:
if (g_current_byte < _fff_mem_free(fifo_sram_data_storage))

And then I write my data from my temporary buffer:

// Store in FIFO
for (ind_fifo=0;ind_fifo<g_current_byte;ind_fifo++)
{
    _fff_write_lite(fifo_sram_data_storage,g_data_temp_buffer_sram[ind_fifo]);
}

Then later I read data out from the FIFO into a buffer that I can write to my flash chip:

// Reading a single chunk of the Fast FIFO data
for (j=0;j<16;j++)
{
    // Read out the remaining bytes from the Fast FIFO into the temporary read buffer
    temp_flash_write_buffer[j] = _fff_read_lite(fifo_sram_data_storage);
}

Use of (unsigned long long) in _log2 macro?

In macro_math.h, line 48 causes a number of compiler warnings in my project:
#define _log2(n) ((unsigned) (8*sizeof (unsigned long long) - __builtin_clzll((n)) - 1))

The compiler warnings received are:
ISO C90 does not support 'long long' [-Wlong-long]

Replacing the (unsigned long long) with the (uint64_t) type fixes the compiler warnings in my project:
#define _log2(n) ((unsigned) (8*sizeof (uint64_t) - __builtin_clzll((n)) - 1))

Note that the following flag is set (by default in my Atmel Studio project--I haven't changed it...) in the "Miscellaneous" section of ARM/GNU C Compiler flags:
-std=gnu99

Is my substitution of (uint64_t) for (unsigned long long) a valid change? Thanks!

Calling _fff_read and other macros from within a function / accessing a FIFO from other functions

I am trying to declare a FIFO in main.c (outside of the main() function as in the fifofast code example), then access that FIFO with functions in other *.c files which are themselves called from main(). I figured out how to get the inline function forms of the fifofast functions working (compiling) in other functions by including a *.h file with the following line:

extern volatile fff_proto_t fifo_name;

But there's not an inline function for the read macro. I am receiving a compiler error when I attempt to call one of the macro based functions (e.g. _fff_read) from a function, instead of calling directly in main().

I'm not sure what I'm doing wrong... What is the proper way to call the fifofast functions from within functions other than main?

On the line that I call _fff_read from within another function, I get this error:

[N] 2849 : invalid application of 'sizeof' to an incomplete type 'uint8_t volatile[]'

and on line 14 of \fifofast\utility\macros\com\macro_array.h, I get this error:

invalid application of 'sizeof' to incomplete type 'volatile uint8_t[] {aka volatile unsigned char[]}'	

For what it's worth, I can compile a form of your "minimal code example" in my Atmel Studio 7 C project, albeit with a few warnings.

Something like this works:

#include "fifofast.h"
_fff_declare(uint8_t, fifo_name, 16);

int main(void)
{
    volatile uint8_t temp_byte = 0;

    _fff_init(fifo_name);
    _fff_write(fifo_name, 42);

    temp_byte = _fff_read(fifo_name);

    while(1);
}

However, I cannot get the macro based fifofast commands to compile when called from within a function.

Something like this yields the above errors:

#include "fifofast.h"
#include "misc.h"
_fff_declare(uint8_t, fifo_name, 16);

int main(void)
{
    volatile uint8_t temp_byte = 0;

    _fff_init(fifo_name);
    _fff_write(fifo_name, 42);

    fifo_test();

    while(1);
}

Where misc.c:

#include "misc.h"

// Simple test function to show the compiler error
void fifo_test(void)
{
    volatile uint8_t    temp_byte = 0;
    temp_byte = _fff_read_lite(fifo_name);
}

And misc.h:

#ifndef MISC_H_
#define MISC_H_

void fifo_test(void);

#endif

Any insight as to what I'm doing wrong or how to better use this library? Thanks!

"Declaration of '_return' shadows a previous local" warning

When I use the _fff_read macro more than once in the same function, I get the following error:

Warning: declaration of '_return' shadows a previous local [-Wshadow]
...\src\external\fifofast\fifofast.h	334

Is there a recommended workaround / mitigation, or is it a non-issue?

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.