general: update zephyr libraries
many include macros have outdated header files and many samples are not running as expected. Also, void main() was changed to int main() to avoid warning during compilation
Signed-off-by: Nicolas Moreno niko722795@gmail.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
Zephyr Scientific Library (zscilib)
The Zephyr Scientific Library (zscilib) is an attempt to provide a set of functions useful for scientific computing, data analysis and data manipulation in the context of resource constrained embedded hardware devices.
It is written entirely in C, and while the main development target for the library is the Zephyr Project, it tries to be as portable as possible, and a standalone reference project is included to use this library in non-Zephyr-based projects.
This version of zscilib has been developed and tested against Zephyr 3.3.0.
Motivation
As the processing power of small, embedded MCUs increases and costs fall, more computation can be done on the endnode itself. This allows for more of the ‘complex’ data analysis that used to take place at the PC or server level (data aggregation, statistical analysis, etc.) to be done in less time, using less data storage, and at a lower overall processing cost on small, embedded devices.
By generating scientifically-relevant data points (standard SI units, pre-filtered data, etc.) directly on the endnode, zscilib aims to be a bridge between raw data and more numerically complex toolkits like
gsl,numpyorR.What makes zscilib distinct?
Numerous high quality, mature, open source scientific libraries already exist:
Despite the wealth of mature functions in these existing libraries, though, they tend to have the following two problems in an embedded context:
The second item is of particular importance, since the goal of embedded systems is often ‘sensing’ via raw data, correlating that data, and acting on the final data points or passing them on for further analysis.
CMSIS-DSP contains a number of highly efficient algorithms for filtering raw sensor data, but it doesn’t offer any domain-specific assistance converting filtered accelerometer vectors into orientation data, for example, or reading a set of photodiodes and converting that data into a useful photometric value like lux. It is excellent at ‘conditioning’ data, but not at ‘understanding’ it.
zscilib aims to find a middle ground between these two, allowing for richer processing of raw data, but within the confines and limitations of the class of microcontrollers commonly used on low-cost sensor endnodes.
Quick Start: Standalone
A few makefile-based projects are included in
samples/standaloneshowing how zscilib can be used independent of Zephyr.If you already have an appropriate GNU toolchain and build tools (
make, etc.) installed, you can simply execute the following commands:Quick Start: Zephyr RTOS
Running a sample application
To run one of the sample applications using qemu, run the following commands:
Press
CTRL+Athenxto quit qemu.Running Unit Tests
To run the unit tests for this library, run the following command:
See the
testsfolder for further details.To run compliance tests to make sure submitted code matches Zephyr PR requirements, run this (updating
HEAD~2for the number of commits to check, or setting it toorigin/master..to check everything):Debugging with QEMU
If you wish to debug using QEMU (and with minor variation actual hardware), you can run the following commands to start a new GDB debug session.
In one terminal window, run:
Once the ELF file has been built, we can start a GDB server on the default
1234socket, and wait for a new connection via:In a new terminal window, connect to the GDB server via:
From here, you can start debugging with the
(gdb)prompt.For example:
Floating-Point Usage
zscilib can be configured to make use of single-precision (32-bit) or double-precision (64-bit) floating point values via the
CONFIG_ZSL_SINGLE_PRECISIONflag, which will determine the size ofzsl_real_tused throughout the library. The default setting for this flag isn, meaning 64-bit values are used by default.There is a tradeoff between the added range and precision that 64-bit (double-precision) floating point values offer, and the memory and performance gains of the smaller, less-precise but faster 32-bit (single-precision) operations.
Comparison
Single-Precision (32-bit) Floats
Double-Precision (64-bit) Floats
Float Stack Usage in Zephyr
The sample code in this library typically has the
CONFIG_FPUoption set, meaning that floating-point support is configured for Unshared FP registers mode. This mode is used when the application has a single thread that uses floating point registers.If your application makes use of multiple threads, and more than one of these threads uses floating-point operations, you should also enable the
CONFIG_FPU_SHARINGconfig flag, which configures the kernel for Shared FP registers mode. In this mode, the floating point registers are saved and restored during each context switch, even when the associated threads are not using them. This feature comes at the expense of an extra 72 bytes of stack memory per stack frame (s0..s15+FPCSR, plus an alignment word to ensure that the stack pointer is double-word aligned).Current Features
Linear Algebra
Vector Operations
zsl_vec_from_arrzsl_vec_copyzsl_vec_get_subsetzsl_vec_addzsl_vec_subzsl_vec_negzsl_vec_sumzsl_vec_scalar_addzsl_vec_scalar_multzsl_vec_scalar_divzsl_vec_distzsl_vec_dotzsl_vec_normzsl_vec_projectzsl_vec_to_unitzsl_vec_crosszsl_vec_sum_of_sqrszsl_vec_meanzsl_vec_ar_meanzsl_vec_revzsl_vec_ztezsl_vec_is_equalzsl_vec_is_nonnegzsl_vec_containszsl_vec_sortzsl_vec_printMatrix Operations
zsl_mtx_from_arrzsl_mtx_copyzsl_mtx_getzsl_mtx_setzsl_mtx_get_rowzsl_mtx_set_rowzsl_mtx_get_colzsl_mtx_set_colzsl_mtx_addzsl_mtx_add_dzsl_mtx_sum_rows_dzsl_mtx_sum_rows_scaled_dzsl_mtx_subzsl_mtx_sub_dzsl_mtx_multzsl_mtx_mult_dzsl_mtx_scalar_mult_dzsl_mtx_scalar_mult_row_dzsl_mtx_transzsl_mtx_adjoint_3x3zsl_mtx_adjointzsl_mtx_vec_wedgezsl_mtx_reducezsl_mtx_reduce_iterzsl_mtx_augm_diagzsl_mtx_deter_3x3zsl_mtx_deterzsl_mtx_gauss_elimzsl_mtx_gauss_elim_dzsl_mtx_gauss_reduczsl_mtx_cols_normzsl_mtx_gram_schmidtzsl_mtx_norm_elemzsl_mtx_norm_elem_dzsl_mtx_inv_3x3zsl_mtx_invzsl_mtx_balancezsl_mtx_householderzsl_mtx_qrdzsl_mtx_qrd_iterzsl_mtx_eigenvalueszsl_mtx_eigenvectorszsl_mtx_svdzsl_mtx_pinvzsl_mtx_minzsl_mtx_maxzsl_mtx_min_idxzsl_mtx_max_idxzsl_mtx_is_equalzsl_mtx_is_notnegzsl_mtx_is_symzsl_mtx_printUnary matrix operations
The following component-wise unary operations can be executed on a matrix using the
zsl_mtx_unary_opfunction:++)--)-)!)Binary matrix operations
The following component-wise binary operations can be executed on a pair of symmetric matrices using the
zsl_mtx_binary_opfunction:a + b)a - b)a * b)a / b)mean(a, b)a^b)min(a, b))max(a, b))a == b)a != b)a < b)a > b)a <= b)a >= b)Numerical Analysis
Statistics
[1] Only available in double-precision
Probability Operations
Interpolation
Physics
Atomic
Dynamics
Electrical Components
Electric
Electricity
Energy
Fluids
Gases
Gravitation
Kinematics
Magnetics
Mass
Momentum
Optics
Photons
Projectiles
Relativity (v0.3.0)
Rotation
Sound
Thermodynamics
Waves
Work
Motion and Orientation
AHRS/Attitude (Degrees)
Compass
Euler Angles (Radians)
Gravity
Quaternions
Sensor Fusion
Colorimetry
Types/Structs
Functions
Color Data
Illuminants
CIE Standard Observer Models
CIE Luminous Efficiency Functions
XYZ to RGB Color Space Correlation Matrices
Chemistry
Measurement API (v0.2.0)
The
zsl_measurementstruct is a proof of concept attempt at representing measurements in a concise but unambiguous manner.It consists of:
There is an option to adjust the measurement’s scale in +/- 10^n steps (Scale Factor) from the default SI unit and scale indicated by the SI Unit Type. For example, if ‘Ampere’ is indicated as the SI unit, the measurement could indicate that the value is in uA by setting the scale factor to -6.
zsl_measurement)Longer Term Planned Features
Help is welcome on the following planned or desirable features.
Scalar Operations
Digital Signal Processing (v0.3.0)
Spectrometry
Calibration
Architecture-Specific Optimisations
Basic tooling has been added to allow for optimised architecture-specific implementations of key functions in assembly.
At present, this feature isn’t being actively used or developed, but an aim of zscilib is to add optimised versions of key functions to try to get the best possible performance out of limited resources.
Initial optimisation will target the Arm Cortex-M family of devices and the Thumb and Thumb-2 instruction sets, though other architectures can be accommodated if necessary or useful.
Code Style
Since the primary target of this codebase is running as a module in Zephyr OS, it follows the same coding style, which is itself based on the Linux kernel coding style.
You can format the source code to match this style automatically using the uncrustify command line tool, which has plugins available for many common text editors (Atom Beautify, for example).
Contributing
If you wish to contribute to this library, you can raise a PR as follows:
git cloneyour forked repository.Also have a look at the Issues page to see if there is any outstanding work or issues that you might be able to help with!
License
Apache 2.0.