ghf / fructose Goto Github PK
View Code? Open in Web Editor NEW๐ฝ Simple sugar for microcontrollers in unapologetic C++17 ๐ฏ
๐ฝ Simple sugar for microcontrollers in unapologetic C++17 ๐ฏ
Add a data structure primitive that performs non-blocking FIFO access to a fixed circular buffer.
To avoid template instantiation code size overhead, this should provide raw byte access (or perhaps equal-sized chunks) as views into the internal storage.
This will be used as the backing buffer for the dispatch queue (#5) and data queue (#8), which are multiple-producer, single-consumer abstractions in this system. As such, it needs to be safe to write from privileged interrupts, DMA, and regular threads. To enable multiple producers, writers write in two stages:
There's no requirement that the caller had actually written any data to the buffer between these two calls, nor will the buffer perform any implicit copying. This allows for e.g. DMA copying.
The dispatch queue use case requires that writers be able to allocate a contiguous range of bytes, so it needs to return both the desired buffer that was allocated and if the writer pointer had wrapped, the "garbage" bytes that were allocated at the end of the circular buffer.
So the final interface might look something like:
AllocateBack
AllocateContiguousBack
CommitBack
PeekFront
PopFront
Create a logging API that can defer the formatting and transmission of logs. It should have all the usual features:
Create a dispatch queue that executes tasks by order of their deadlines.
When #1 is usable, add runtime checks to all the integer math utilities.
The code needs a runtime condition-checking facility like assert
or CHECK
/DCHECK
. Requirements for the assert call:
Would be nice:
CHECK(pointer);
Looking at third party libraries:
DEBUG_ASSERT(1 + 1 == 2, my_module{});
as the most basic invocation (the tag looks to be bending over backwards to avoid relying on macro definitions), which is pretty verbose, and it also always calls std::abort
, which might be OK but isn't ideal.ASSERT
and VERIFY
in macro name space.So far, all code has been written to run on a host AMD64 workstation under unit testing and not for a microcontroller target.
Any code that uses this assumption should be marked by a switch somewhere so that this is behavior that isn't painful to strip out when porting. This might just be a preprocessor macro, or it might be combined with selecting which source files get built, but it should be visible to the code.
Visibility to the code is important for behaviors that rely on host libraries and/or feature, e.g. where logs should be output by default.
MapRange, the [base] utility for linearly mapping ranges, usually has fixed input and output ranges and deadband. That means that its repeated invocation performs a lot of redundant work and is not too readable (because it requires six arguments).
Split the API into a precompute step that creates a "range mapper" and an evaluate step that does the mapping. The construction of the mapper should hoist the precompute math like making the scaling ratio (including a ratio simplification using std::gcd
), and should be constexpr
friendly so that the mapper can be created at compile time if the scaling is already known.
Additionally, it might be nice to split the input and output types so the invocation requires less casting. This might lead to additional enhancements like supporting floating-point types.
Finally, range mapping needs tests.
Add a queue of equal-sized objects that allows non-blocking multi-producer, single-consumer FIFO access to underlying fixed storage.
Writing (pushing) new objects can be performed by regular threads, privileged interrupts, and DMA access. An example writer that needs to be supported would be an ADC sampling group that writes the same series of samples repeatedly into a fixed circular buffer, raising an interrupt with each series. The interrupt does not write data to the buffer, but it does tell the queue that data has been written.
This needs to support element types that are not power-of-two sizes, which probably constrains the byte size of the buffer to be an integer multiple of element size.
Need to define types for representing points in time and durations of time. Options:
std::chrono
route, which involves defining a Clock and probably new types for time_point
and duration
(to use 32-bit types). The helpers might be reusable for constants.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.