nqtronix / fifofast Goto Github PK
View Code? Open in Web Editor NEWA fast, generic fifo for MCUs.
License: MIT License
A fast, generic fifo for MCUs.
License: MIT License
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);
}
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!
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!
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.