### Compile and Link zscilib Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/standalone/svd_pinv/README.md This command shows the compilation and linking process for the zscilib example, including compiler flags and include paths. ```bash gcc obj/main.o obj/matrices.o obj/vectors.o obj/zsl.o obj/atomic.o obj/dynamics.o obj/eleccomp.o obj/electric.o obj/energy.o obj/fluids.o obj/gases.o obj/gravitation.o obj/kinematics.o obj/magnetics.o obj/mass.o obj/misc.o obj/momentum.o obj/optics.o obj/photons.o obj/projectiles.o obj/relativity.o obj/rotation.o obj/sound.o obj/thermo.o obj/waves.o obj/work.o -o bin/zscilib -Wall -Wconversion -Wno-sign-conversion -I. -I../../include -lm ``` -------------------------------- ### Build and Run Standalone zscilib Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md This snippet shows how to build and run a standalone zscilib example using make. Ensure you have a GNU toolchain and build tools installed. ```bash cd samples/standalone/svd_pinv make bin/zscilib ``` -------------------------------- ### Run the zscilib Example Binary Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/standalone/vector/README.md Execute the compiled zscilib binary to see its output. This demonstrates the basic functionality of the library. ```bash bin/zscilib ``` -------------------------------- ### Build the Standalone zscilib Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/standalone/vector/README.md Clean the project and build the zscilib example using make. This command compiles the source files and links them into an executable binary. ```bash make clean make ``` -------------------------------- ### Build API Documentation Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/README.md Run this command to build the HTML version of the API documentation using Doxygen. Ensure Doxygen is installed and the Doxyfile is correctly configured. ```bash $ doxygen doc/Doxyfile ``` -------------------------------- ### CMake Project Setup Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/momentum/CMakeLists.txt Configures the CMake version, finds the Zephyr build system, and sets the project name. This is a standard setup for Zephyr-based projects. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(momentum) ``` -------------------------------- ### Start GDB Debug Server Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md Starts a GDB server on the default socket (1234) after building the application. Navigate to the build directory first. ```bash cd build $ ninja debugserver ``` -------------------------------- ### Function Implementation Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Implement the function in the appropriate source module file. Ensure the order matches the header file. Include bounds checking if necessary. ```c int zsl_mtx_get(struct zsl_mtx *m, size_t i, size_t j, zsl_real_t *x) { #if CONFIG_ZSL_BOUNDS_CHECKS if ((i >= m->sz_rows) || (j >= m->sz_cols)) { return -EINVAL; } #endif *x = m->data[(i * m->sz_cols) + j]; return 0; } ``` -------------------------------- ### Example Build Failure Log Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md This is an example of a build error log from the Twister test run, indicating a compilation problem. Examine the specified build log file for details. ```text qemu_cortex_m3 zsl.core.thumb2.double FAILED: handler_crash see: twister-out/qemu_cortex_m3/zsl.core.thumb2.double/build.log ``` -------------------------------- ### GDB Debugging Session Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md An example of a GDB debugging session, including setting breakpoints, continuing execution, stepping through code, and quitting the session. ```gdb (gdb) b main (gdb) c Continuing. Breakpoint 1, main () at modules/lib/zscilib/samples/matrix/pinv/src/main.c:70 70 printf("\n\nzscilib pseudo-inverse demo\n\n"); (gdb) n 72 pinv_demo(); (gdb) step pinv_demo () at modules/lib/zscilib/samples/matrix/pinv/src/main.c:25 25 zsl_real_t vi[18 * 3] = { (gdb) n ... (gdb) quit ``` -------------------------------- ### Sample Benchmark Output Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/benchmarking/README.rst Example output from the zscilib benchmark sample, showing system configuration and execution times for vector addition in cycles. This output can be used to compare performance across different configurations or hardware. ```text ***** Booting Zephyr OS zephyr-v1.14.0-39-ge03905354671 ***** zscilib benchmark BOARD: nrf52840dk ZSL VERSION: 0.1.0-prerelease (Apr 29 2019) CONFIG_ZSL_PLATFORM_OPT: 2 CONFIG_ZSL_SINGLE_PRECISION: False CONFIG_ZSL_VECTOR_INLINE: False CONFIG_ZSL_MATRIX_INLINE: False CONFIG_ZSL_BOUNDS_CHECKS: True zsl_vec_add : 333 cycles zsl_vec_add : 339 cycles zsl_vec_add : 339 cycles ``` -------------------------------- ### Build and Flash on nRF52840dk using west Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/shell/README.rst Compile and flash the zscilib shell example onto the nRF52840dk hardware using the west command. This is an alternative to using CMake directly. ```console $ west build -p -b nrf52840dk/nrf52840 samples/shell/ ``` -------------------------------- ### Linker Command for zscilib Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/standalone/vector/README.md The GCC linker command used to build the zscilib executable, showing object files and include paths. ```bash gcc obj/main.o obj/matrices.o obj/vectors.o obj/zsl.o -o bin/zscilib -Wall -Wconversion -Wno-sign-conversion -I. -I../../../include -lm ``` -------------------------------- ### Build and Run on Cortex M3 Emulator using west Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/shell/README.rst Compile and run the zscilib shell example on the Cortex M3 emulator using the west command. This is an alternative to using CMake directly. ```console $ west build -p -b qemu_cortex_m3 samples/shell/ -t run ``` -------------------------------- ### Build and Flash on nRF52840dk using CMake Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/shell/README.rst Compile and flash the zscilib shell example onto the nRF52840dk hardware using CMake. For real hardware, CONFIG_STDOUT_CONSOLE should typically be set to 'n'. ```console $ cd samples/shell $ mkdir b && cd b $ cmake -GNinja -DBOARD=nrf52840dk/nrf52840 .. $ ninja $ ninja flash ``` -------------------------------- ### Clobber List Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/arm_asm_gnu_inline.md Example of a clobber list indicating that the condition register is modified and that memory locations may be altered by the assembly instructions. ```c : "cc", "memory" ``` -------------------------------- ### Input Operand Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/arm_asm_gnu_inline.md Example of an input operand declaration, specifying a symbolic name, a constraint for Thumb state general purpose registers, and association with a C expression. ```c : [value] "l" (x) ``` -------------------------------- ### HWtester Sample Output Format Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/hwtester/README.rst Example output from the HWtester sample, showing sensor readings including timestamp, accelerometer (ax, ay, az), magnetometer (mx, my, mz), gyroscope (gx, gy, gz), and temperature (temp_c). ```console ***** Booting Zephyr OS zephyr-v1.14.0-39-ge03905354671 ***** ns, ax, ay, az, mx, my, mz, gz, gy, gz, temp_c 161, 0.819, 0.716, 9.634, 0.000, 0.000, 0.000, 0.042, 0.086, 0.008, 23.04 171, 0.819, 0.716, 9.634, 0.000, 0.000, 0.000, 0.043, 0.087, 0.008, 23.04 ``` -------------------------------- ### Output Operand Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/arm_asm_gnu_inline.md Example of an output operand declaration, specifying a symbolic name, a readwrite constraint for Thumb state registers R0-R7, and association with a C expression. ```c : [dptr] "+l" (result) ``` -------------------------------- ### Build and Run on Cortex M3 Emulator using CMake Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/shell/README.rst Compile and run the zscilib shell example on the Cortex M3 emulator using CMake. Ensure CONFIG_STDOUT_CONSOLE is set to 'y' for emulator usage. ```console $ cd samples/shell $ mkdir b && cd b $ cmake -GNinja -DBOARD=qemu_cortex_m3 .. $ ninja $ ninja run ``` -------------------------------- ### Example Handler Failure Log Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md This is an example of a handler error log from the Twister test run, indicating a test assertion failure. Examine the specified handler log file for details. ```text qemu_cortex_m3 zsl.core.thumb2.double FAILED: failed see: twister-out/qemu_cortex_m3/zsl.core.thumb2.double/handler.log ``` -------------------------------- ### Partial Output: Pseudoinverse Test Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/standalone/svd_pinv/README.md Displays a portion of the output from the zscilib example, specifically the input matrix and its calculated Moore-Penrose pseudoinverse. ```text ... PSEUDOINVERSE TEST ------------------ INPUT (18x3 MATRIX) ------------------ 3.200000 5.000000 -4.200000 -3.100000 5.400000 -2.200000 7.700000 8.700000 9.900000 8.900000 0.600000 5.400000 3.700000 -3.300000 7.200000 -5.400000 -0.600000 8.400000 2.400000 5.100000 -5.700000 6.900000 -2.100000 0.400000 6.400000 -9.100000 -4.400000 0.100000 7.400000 0.000000 6.100000 -2.300000 5.500000 6.100000 -8.400000 -6.600000 7.100000 2.300000 4.100000 -0.800000 -4.700000 9.900000 -3.100000 1.200000 5.200000 6.400000 -6.300000 5.200000 8.800000 7.300000 4.200000 -4.700000 0.000000 -0.400000 PSEUDOINVERSE (3x18 MATRIX) -------------------------- 0.008305 -0.004161 0.011124 0.014273 0.003411 -0.013626 0.007470 0.012358 0.012618 0.001077 0.008695 0.013077 0.011694 -0.006234 -0.007796 0.008896 0.015403 -0.008536 0.011157 0.010817 0.016409 0.001246 -0.007502 -0.003439 0.011544 -0.003434 -0.016550 0.014775 -0.004896 -0.014773 0.004667 -0.011349 0.001035 -0.012783 0.014828 -0.000490 -0.009946 -0.003717 0.013118 0.005953 0.012168 0.017688 -0.012357 -0.001791 -0.008991 -0.001445 0.007869 -0.013002 0.004026 0.019251 0.010549 0.007954 0.002542 0.001259 ``` -------------------------------- ### CMake Project Setup Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/projectiles/CMakeLists.txt Configures the CMake build for the projectiles project. It specifies the minimum required CMake version, finds the Zephyr build system, and sets the project name. This is essential for building Zephyr applications. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(projectiles) ``` -------------------------------- ### ARM Assembly: Absolute Value Example Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/arm_asm_primer.md This snippet demonstrates the use of the 'MI' conditional instruction to find the absolute value of a number. It uses 'MOVS' to set flags and 'RSBMI' to conditionally negate the value if it's negative. ```armasm MOVS R0, R1 ; R0 = R1, setting flags IT MI ; skipping next instruction if value 0 or positive RSBMI R0, R0, #0 ; If negative, R0 = -R0 ``` -------------------------------- ### Build and Run in QEMU Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/apitest/README.rst Builds and runs the orientation API test sample in the QEMU emulator. ```console $ west build -p auto -b mps2/an521/cpu0 \ modules/lib/zscilib/samples/orientation/apitest/ -t run ``` -------------------------------- ### Build, Flash, and Debug on nRF52840dk Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/pinv/README.rst Prepare the pinv sample for debugging on the nRF52840dk using GDB. ```console $ west build -p -b nrf52840/nrf52840dk samples/matrix/pinv $ west flash $ west debug --runner jlink ``` -------------------------------- ### Build and Run on QEMU Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/kinematics/README.rst Commands to compile and run the kinematics sample on the QEMU Cortex M3 emulator. Output is directed to the console. ```console $ rm -rf build $ west build -b qemu_cortex_m3 modules/lib/zscilib/samples/physics/kinematics/ -t run ``` -------------------------------- ### Build for Real Hardware (nRF52840dk) Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/pinv/README.rst Compile the pinv sample for the nRF52840dk. Output is typically sent to the serial port. ```console $ west build -p -b nrf52840/nrf52840dk samples/matrix/pinv $ west flash ``` -------------------------------- ### Build Benchmark for Real Hardware (nRF52840dk) Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/benchmarking/README.rst Builds the zscilib benchmark sample for the nRF52840dk hardware. This command prepares the application for flashing onto the target device. Adjust the board flag (-b) for different hardware. ```console $ west build -b nrf52840dk/nrf52840 samples/benchmarking/ ``` -------------------------------- ### Build Zephyr Application Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md Builds the zscilib matrix pinv sample application for the mps2/an521/cpu0 board. ```bash $ west build -p auto -b mps2/an521/cpu0 modules/lib/zscilib/samples/matrix/pinv ``` -------------------------------- ### Build and Run on Real Hardware (nRF52840dk) Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/mult/README.rst Compiles and flashes the application to real hardware, typically outputting results to a serial port. Ensure CONFIG_STDOUT_CONSOLE is disabled for real hardware targets. Adjust the board flag (-b BOARD) as necessary. ```console $ rm -rf build $ west build -b nrf52840dk/nrf52840 samples/matrix/mult $ west flash ``` -------------------------------- ### Build and Run on QEMU Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/projectiles/README.rst Compile and run the projectiles sample on the Cortex M3 emulator. Output is sent to the console. ```console $ rm -rf build $ west build -b qemu_cortex_m3 modules/lib/zscilib/samples/physics/projectiles/ -t run ``` -------------------------------- ### Build and Run on Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/pinv/README.rst Compile and run the pinv sample on the Cortex M3 emulator. The results are sent to the console. ```console $ west build -p -b mps2/an521/cpu0 samples/matrix/pinv -t run ``` -------------------------------- ### Run Zephyr zscilib Matrix Multiplication Sample Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md This snippet demonstrates how to build and run a zscilib matrix multiplication sample application within the Zephyr RTOS environment using west and qemu. Ensure Zephyr environment is sourced and qemu-system-arm is available. ```bash west build -p -b mps2/an521/cpu0 \ modules/lib/zscilib/samples/matrix/mult -t run ``` -------------------------------- ### Build and Flash HWtester Sample Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/hwtester/README.rst Commands to build and flash the HWtester sample for the frdm_k64f target using west. Ensure you have the Zephyr development environment set up. ```console $ west build -p auto -b frdm_k64f samples/orientation/hwtester $ west flash ``` -------------------------------- ### Build and Run SVD Sample on Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/svd/README.rst Compile and run the SVD sample application on the Cortex M3 emulator. Output will be sent to the console. ```console rm -rf build west build -b mps2/an521/cpu0 samples/matrix/svd -t run ``` -------------------------------- ### Build and Flash on nRF52840dk Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/kinematics/README.rst Commands to build and flash the kinematics sample onto the nRF52840dk hardware. Results are typically output to the serial port. ```console $ west build -p -b nrf52840dk/nrf52840 modules/lib/zscilib/samples/physics/kinematics/ $ west flash ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/benchmarking/CMakeLists.txt Sets up the build environment for the benchmarking project using CMake. It specifies the required CMake version, finds the Zephyr build system, and defines the project name and source files. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(benchmarking) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Build and Run on Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/gravitation/README.rst Compile and run the gravitation sample on the Cortex M3 emulator. Results are sent to the console. ```console $ rm -rf build $ west build -b qemu_cortex_m3 modules/lib/zscilib/samples/physics/gravitation/ -t run ``` -------------------------------- ### Build for nRF52840dk Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/apitest/README.rst Builds the orientation API test sample for the nRF52840dk hardware. ```console $ west build -b nrf52840dk/nrf52840 \ modules/lib/zscilib/samples/orientation/apitest/ ``` -------------------------------- ### Build SVD Sample for nRF52840dk Hardware Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/svd/README.rst Compile the SVD sample application for the nRF52840dk hardware. Results are typically output to the serial port. ```console rm -rf build west build -b nrf52840dk/nrf52840 samples/matrix/svd west flash ``` -------------------------------- ### Build and Run on nRF52840dk Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/momentum/README.rst Compiles and flashes the Momentum sample application to the nRF52840dk. Results are typically output to the serial port. ```console $ west build -p -b nrf52840dk/nrf52840 modules/lib/zscilib/samples/physics/momentum/ $ west flash ``` -------------------------------- ### Build and Run Benchmark on Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/benchmarking/README.rst Compiles and runs the zscilib benchmark sample on the Cortex M3 emulator, outputting results to the console. Ensure you have the Zephyr development environment set up. ```console $ west build -b qemu_cortex_m3 samples/benchmarking/ -t run ``` -------------------------------- ### Build and Run on nRF52840dk Hardware Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/projectiles/README.rst Compile and flash the projectiles sample to the nRF52840dk. Results are typically output to the serial port. ```console $ west build -p -b nrf52840dk/nrf52840 modules/lib/zscilib/samples/physics/projectiles/ $ west flash ``` -------------------------------- ### Basic CMakeLists.txt Configuration Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/kinematics/CMakeLists.txt Sets the minimum CMake version, finds the Zephyr package, and defines the project name. It also specifies the source file for the application. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(kinematics) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Build and Flash for nRF52840dk Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/gravitation/README.rst Compile and flash the gravitation sample to the nRF52840dk. Results are typically sent to the serial port. ```console $ west build -p -b nrf52840dk/nrf52840 modules/lib/zscilib/samples/physics/gravitation/ $ west flash ``` -------------------------------- ### Basic CMakeLists.txt for Zephyr Project Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/hwtester/CMakeLists.txt This snippet shows the fundamental structure of a CMakeLists.txt file for a Zephyr RTOS application. It ensures the Zephyr build system is found and sets up the project's source files. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(orientation_api) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/gravitation/CMakeLists.txt This snippet shows the basic CMake configuration for the Gravitation project. It sets the minimum required CMake version, finds the Zephyr build system, and names the project. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(gravitation) ``` -------------------------------- ### Connect to GDB Server Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md Connects to the running GDB server using arm-none-eabi-gdb-py. Ensure you are in the Zephyr project path and specify the correct ELF file. ```bash cd $ arm-none-eabi-gdb-py \ --eval-command="target remote localhost:1234" \ --se=build/zephyr/zephyr.elf ``` -------------------------------- ### Define Project and Include Directories Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/tests/CMakeLists.txt Sets the project name and adds the 'include' directory to Zephyr's include paths. ```cmake project(zsl) zephyr_include_directories(include) ``` -------------------------------- ### Build and Run on Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/momentum/README.rst Compiles and runs the Momentum sample application on the Cortex M3 emulator. Output is directed to the console. ```console $ rm -rf build $ west build -b qemu_cortex_m3 modules/lib/zscilib/samples/physics/momentum/ -t run ``` -------------------------------- ### Build and Run on Cortex M3 Emulator Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/mult/README.rst Compiles the application and runs it on the emulator, outputting results to the console. Ensure CONFIG_STDOUT_CONSOLE is enabled for emulator targets. ```console $ rm -rf build $ west build -b qemu_cortex_m3 samples/matrix/mult -t run ``` -------------------------------- ### Add Unit Test Reference in main.c Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Add a function prototype for the new unit test in `tests/src/main.c`. ```c extern void test_matrix_get(void); ``` -------------------------------- ### CMakeLists.txt Configuration for Zephyr Shell Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/shell/CMakeLists.txt This snippet shows the basic CMake configuration for a Zephyr project, including finding the Zephyr SDK and setting up the application source file. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(shell) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Function Prototype with Doxygen Documentation Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Define the function prototype in a header file using doxygen syntax. Document all parameters and return values, especially error codes. ```c /** * @brief Gets a single value from the specified row (i) and column (j). * * @param m Pointer to the zsl_mtx to use. * @param i The row number to read (0-based). * @param j The column number to read (0-based). * @param x Pointer to where the value should be stored. * * @return 0 if everything executed correctly, or -EINVAL on an out of * bounds error. */ int zsl_mtx_get(struct zsl_mtx *m, size_t i, size_t j, zsl_real_t *x); ``` -------------------------------- ### New Source Module Template Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Use this template when creating a new source module (.c file) for zscilib. Include necessary headers and placeholders for implementations. ```c /* * Copyright (c) 2019 Author Name Here * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include #include #include /* TODO: Insert function implementations, etc., here. */ ``` -------------------------------- ### Implement Unit Test for zsl_mtx_get Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md This C function demonstrates how to test the `zsl_mtx_get` function by creating a matrix, retrieving elements, and checking for out-of-bounds errors using Zephyr's assertion macros. ```c void test_matrix_get(void) { int rc; zsl_real_t x; zsl_real_t data[9] = { 1.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.1 }; struct zsl_mtx m = { .sz_rows = 3, .sz_cols = 3, .data = data }; /* Read values from the matrix above. */ rc = zsl_mtx_get(&m, 0, 0, &x); zassert_equal(rc, 0, NULL); zassert_true(val_is_equal(x, 1.0, 1E-5), NULL); rc = zsl_mtx_get(&m, 1, 0, &x); zassert_equal(rc, 0, NULL); zassert_equal(x, 0.0, NULL); rc = zsl_mtx_get(&m, 2, 2, &x); zassert_equal(rc, 0, NULL); zassert_true(val_is_equal(x, 0.1, 1E-5), NULL); /* Check for out of bounbds error. */ zassert_true(zsl_mtx_get(&m, 3, 3, &x) == -EINVAL, NULL); } ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/mult/CMakeLists.txt Configures the build for the matrix multiplication project using CMake and Zephyr's build system. It specifies the minimum CMake version, finds the Zephyr package, sets the project name, and includes the main source file. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(mtxmult) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Run zscilib tests with twister Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/tests/README.md Execute this command to run the zscilib unit tests using the `twister` test runner. Ensure your Zephyr environment is sourced first. Append `-vv` for verbose output. ```bash $ twister --inline-logs -p mps2/an521/cpu0 -T [zscilib_tests_folder] ``` -------------------------------- ### Flash nRF52840dk Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/apitest/README.rst Flashes the built orientation API test sample to the nRF52840dk hardware. ```console $ west flash ``` -------------------------------- ### Glob and Target Sources Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/tests/CMakeLists.txt Finds all .c files in the src directory and adds them as private sources to the 'app' target. ```cmake FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) ``` -------------------------------- ### Useful GDB Commands Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/pinv/README.rst A list of common GDB commands for debugging. ```gdb break [filename:line/function] info variables | locals | args | stack | break | registers continue (c) step next (n) list print [var] bt ``` -------------------------------- ### Run zscilib Unit Tests with Twister Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md This command executes the unit tests for the zscilib library using the twister test runner. It specifies the target board and the test directory. ```bash twister --inline-logs -p mps2/an521/cpu0 -T modules/lib/zscilib/tests ``` -------------------------------- ### Basic CMake Configuration for SVD Matrix Library Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/svd/CMakeLists.txt Configures the minimum CMake version, finds the Zephyr package, and sets the project name. It also specifies the main application source file. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(mtxsvd) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Initialize and Feed Madgwick Filter Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md Initialize the Madgwick filter with a specified sample rate and feed it sensor data. Ensure the driver struct is correctly pointed to. ```c struct zsl_fus_drv *drv = &madgwick_drv; /* Init filter at 100 Hz. */ drv->init_handler(100, drv->config); /* Start feeding the filter data. */ drv->feed_handler(&a, &m, &g, &q, drv->config); ``` -------------------------------- ### Enable Optimized ARM THUMB-2 Assembly Functions Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/standalone/vector/README.md Set the CONFIG_ZSL_PLATFORM_OPT=2 flag in the Makefile to use optimized ARM assembly versions of vector functions. ```makefile # Optionally enable ARM THUMB-2 ASM optimised functions CFLAGS += -DCONFIG_ZSL_PLATFORM_OPT=2 ``` -------------------------------- ### Run ZSL Unit Tests with Twister Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Execute unit tests for the ZSL library using the Twister framework. Ensure the Zephyr environment is sourced before running this command. ```bash $ twister -p qemu_cortex_m3 -T modules/lib/zscilib/tests ``` -------------------------------- ### Application Source Files Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/physics/gravitation/CMakeLists.txt This snippet specifies the source file for the application. It uses target_sources to add src/main.c as a private source file to the 'app' target. ```cmake target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Configure Madgwick Fusion Driver Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md Instantiate and configure the Madgwick algorithm's parameters and handler functions. ```c static struct zsl_fus_madg_cfg madg_cfg = { .beta = 0.018, }; static struct zsl_fus_drv madgwick_drv = { .init_handler = zsl_fus_madg_init, .feed_handler = zsl_fus_madg_feed, .error_handler = zsl_fus_madg_error, .config = &madg_cfg, }; ``` -------------------------------- ### Call Unit Test in test_main Function Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Include a call to the new unit test function within the `test_main` function in `tests/src/main.c`. Ensure a trailing comma is present if it's not the last entry. ```c void test_main(void) { ... ztest_unit_test(test_matrix_get), ... } ``` -------------------------------- ### Run Zephyr Compliance Tests for zscilib Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/README.md This command runs compliance tests for submitted code against Zephyr PR requirements. Adjust the commit range (e.g., HEAD~2 or origin/master..) as needed. ```bash ../../../zephyr/scripts/ci/check_compliance.py \ -m Gitlint -m Identity -m Nits -m pylint -m checkpatch \ -c HEAD~2.. ``` -------------------------------- ### New Header File Template for zscilib Group Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/adding_funcs.md Create a new header file for a new logical organization block in zscilib. Follow the provided template for copyright, SPDX-License-Identifier, group documentation, and API declarations. ```c /* * Copyright (c) 2019 Author Name Here * * SPDX-License-Identifier: Apache-2.0 */ /** * \defgroup GROUPNAME Group name * * @brief Group name functions. */ /** * @file * @brief API header file for group name in zscilib. * * This file contains the zscilib group name APIs */ #ifndef ZEPHYR_INCLUDE_ZSL_GROUPNAME_H_ #define ZEPHYR_INCLUDE_ZSL_GROUPNAME_H_ #include #ifdef __cplusplus extern "C" { #endif /* TODO: Insert structs, enums and function prototypes here. */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_ZSL_GROUPNAME_H_ */ /** @} */ /* End of group name group */ ``` -------------------------------- ### GDB Breakpoint and Execution Control Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/matrix/pinv/README.rst Set a breakpoint at the main function, reset the device, and continue program execution within GDB. ```gdb # Set a breakpoint at main in main.c (gdb) break main.c:main Breakpoint 1 at 0xFFFF: ... main.c, line xx. # Reset the device (gdb) monitor reset Resetting target # Continue program execution (gdb) c Continuing. Breakpoint 1, main () at .../main.c:69 69 { ``` -------------------------------- ### Connect to Serial Port with Minicom Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/samples/orientation/hwtester/README.rst Command to open a serial port connection using minicom. Replace '/dev/tty.usbmodem14302' with your actual serial port device. ```console $ minicom -D /dev/tty.usbmodem14302 ``` -------------------------------- ### zsl_fus_init_cb_t Function Signature Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md Defines the callback function signature for initializing an orientation fusion algorithm. It takes a frequency and a configuration pointer. ```c typedef int (*zsl_fus_init_cb_t)(uint32_t freq, void* cfg); ``` -------------------------------- ### GNU Inline Assembly Format Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/doc/arm_asm_gnu_inline.md The general structure for inline assembly in GNU C/C++ includes the assembly code, output operands, input operands, and a clobber list. ```c __asm__ volatile ( code : output operand list : input operand list : clobber list ); ``` -------------------------------- ### Find Zephyr Package Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/tests/CMakeLists.txt Locates the Zephyr build system. Ensure the ZEPHYR_BASE environment variable is set. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) ``` -------------------------------- ### zsl_fus_feed_cb_t Function Signature Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md Defines the callback function signature for feeding sensor data to an orientation fusion algorithm. It accepts accelerometer, magnetometer, and gyroscope vectors, a quaternion for output, and a configuration pointer. ```c typedef int (*zsl_fus_feed_cb_t)(struct zsl_vec *accel, struct zsl_vec *mag, struct zsl_vec *gyro, struct zsl_quat *q, void* cfg); ``` -------------------------------- ### Sensor Calibration Formula Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md This formula describes how to obtain calibrated sensor outputs for linear sensors, accounting for scale factor and offset errors. ```text output = scale_factor * input + offset ``` -------------------------------- ### Conditional Single-Precision Constant Compiler Option Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/tests/CMakeLists.txt Applies the -fsingle-precision-constant flag for GCC or -cl-single-precision-constant for ARMClang when CONFIG_ZSL_SINGLE_PRECISION is enabled. ```cmake if (CONFIG_ZSL_SINGLE_PRECISION) target_compile_options(app PRIVATE $<$:-fsingle-precision-constant>) target_compile_options(app PRIVATE $<$:-cl-single-precision-constant>) endif() ``` -------------------------------- ### zsl_fus_error_cb_t Function Signature Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md Defines the callback function signature for handling errors that occur during the initialization or feeding of an orientation fusion algorithm. ```c typedef void (*zsl_fus_error_cb_t)(int error); ``` -------------------------------- ### zsl_fus_drv Struct Definition Source: https://github.com/zephyrproject-rtos/zscilib/blob/master/src/orientation/fusion/README.md Defines the structure for an orientation fusion driver, containing handlers for initialization, feeding data, error reporting, and a pointer to the algorithm's custom configuration. ```c struct zsl_fus_drv { zsl_fus_init_cb_t init_handler; zsl_fus_feed_cb_t feed_handler; zsl_fus_error_cb_t error_handler; void *config; }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.