
Print Fixed-Point Values Without printf Float Support
Print Q15 and Q16.16 numbers as decimals in C with integer arithmetic only: split, round, pad the fraction, carry, handle the sign, skip printf float code.
Tag
445 posts

Print Q15 and Q16.16 numbers as decimals in C with integer arithmetic only: split, round, pad the fraction, carry, handle the sign, skip printf float code.

Convert floats to Q15 and back in C with rounding, saturation and NaN handling, build compile-time Q15 constants, and convert whole sample blocks safely.

Learn what Q15, Q31 and Q16.16 mean, how a stored integer maps to a real value, and how to compute the range and resolution of any Q format in C.

A tour of the RISC-V supervisor CSRs a kernel touches: sstatus, sie, stvec, scause, sepc, stval, satp and sscratch, with instructions and exact bits.

Drive the NS16550A UART at 0x10000000 on QEMU's RISC-V virt machine with volatile MMIO in C: initialize it, send and poll bytes, then add receive interrupts.

Learn what machine, supervisor and user mode each control on RISC-V, how traps are delegated between them, and how firmware drops into S mode with mret.

Install Alire, select the gnat_arm_elf toolchain, create a crate, add a board support crate and run alr build to produce an ARM Cortex-M firmware ELF.

Write a build.zig that targets thumb-freestanding for a Cortex-M4, add a linker script and vector table, and produce a flashable ELF and binary with Zig 0.14.

Install TinyGo 0.37, write a Go blinky for the Raspberry Pi Pico, put the board in BOOTSEL mode and flash it with tinygo flash -target=pico.

Read kernel and driver messages on macOS 15 with log show and log stream, using predicates on process, subsystem and message text, plus time ranges and levels.

Read macOS kernel state from Terminal with sysctl and ioreg: hardware sizes, boot time, the device registry, USB devices, and how to filter the output.

Set probe-rs run as the Cargo runner, add defmt and defmt-rtt, and read log lines from a running Cortex-M board in your terminal with panic-probe.