C library for common real-time embedded tasks

There are many features that are commonly used for real-time embedded systems that are pretty simple ... but it still seems silly to remodel them when they have been used around the world for decades. Of course, there are many situations where it costs, and wide optimization (based on specific applications or hardware features) is a good choice. On the other hand, when using embedded systems of a smaller volume, the development and testing time is a more significant part of the cost of the product, and a basic embedded system with several optimization options (size of the trigger search table and accuracy) will be sufficient.

Which C libraries would you recommend for such:

  • Timers
  • Speed-optimized trigonometry
  • Interpolation
  • Check sum
  • Geometry
  • (or anything else you like)
+4
source share
2 answers

Embedded systems with C compilers should provide almost everything in the C standard library , including trigger functions in math.h. Top-level embedded systems may even support the POSIX API.

I think you will find that there are some elements from your list, such as a checksum, that have many open, portable ANSI C implementations that you can use if they are not already present on the platform.

Other elements, such as timers, must interact with the main equipment and are therefore not portable.

If the standard API has not been defined, you end up with a mess of implementations. This is true for non-embedded systems.

Of course, it’s difficult to work with several built-in platforms and spend time learning their unique serial communication APIs (or SPI or I2C), but until someone creates a standard API with incentives to support providers that you are stuck with.

+1
source

I am making real-time functional security-critical applications in C for life at the moment. I am constantly trying to expand my library with the good modules that are commonly used. At the moment, I have a library consisting of:

  • General / miscellaneous. (short macros, semahpore'd enable / disable IRQ, etc.).
  • Timer lib with API for time and resolution time ms and ΞΌs ("stopwatch")
  • Buffer Ring, I am using a modified version of Adam Dunkel from Contiki-OS
  • CRC32, select any implementation from the Internet (preferably using word-size processing instead of bytes) and check it against something!
  • AES128 / 192/256, I have an implementation of CBC + ECB mode in Github that supports code size in speed, I feel free to use it.
  • Bit array module
  • Data routing and final data processing ala .NET BitConverter class, for example. read U32 from a pointer
  • Filtering / Debugging
  • Validation / logging module, nice for setting breakpoints and detecting runtime errors during debugging

Most of the material in my library has now been contributed by my colleagues, so I cannot release it because I am not asking anyone.

I have not used trigonometric functionality yet, but there is a ton of code that makes a quick approximation using polynomials obtained through the Chebyshev approximation or the Remez algorithm (here's a blog about this) . Avoid implementations using the Taylor series. One of the reasons is that it is believed that it converges more slowly than the methods mentioned above, and there are also problems of accuracy. CORDIC can also be fast. Depends a little on HW.

Here is a trigger library with various speed / accuracy options, shamelessly stolen from the Ganssle group: http://www.ganssle.com/approx/sincos.cpp - It compiles as C code with minor modifications.

If you have room for it, you can consider lookup tables and interpolation (for example, 1-3 iterations of the Newton-Raphson method).

In addition, many built-in objects have an HW circuit for calculating CRC, etc. Most HW-CRC32 peripherals implement an "Ethernet" / IEEE polynomial, usually among others.

+1
source

Source: https://habr.com/ru/post/1439187/


All Articles