This repository uses an OSEK-like OS on bare-metal RISC-V FE310 to calculate
Osek_pi_crunch_riscv is a fascinating, educational and fun project
that computes a up to
The board is driven in bottom-to-top, hand-written, bare-metal mode. The software upper layers including algorithms and SRAM communication are chip-independent and portable.
The backbone real-time operating system is taken directly from the OSEK-like OS for RISC-V implemented in Chalandi/OSEK_RISC-V_SiFive_FE310_SoC
Spigot-type algorithms are known for various mathematical constants
including logarithms and
The basic spigot algorithm for computing digits of
In the code, this equation is primarily implemented in the
calculate()
method of the
pi_spigot
template class,
which resides in namespace math::constants
.
This algorithm is written in portable, (somewhat) advanced C++.
- The original publication of the description of the spigot algorithm can be found in [1].
- The expression of this algorithm (as used in this repository) has been further influenced by descriptions in [2].
- The pi_spigot implementation in C++ code in this repository has been inspired by Section 10.8 of [3].
- A PC-only realization of the pi_spigot algorithm can be found in imahjoub/pi_spigot
As mentioned above,
to compute
The required memory grows linearly with the digit count.
Approximately 1.4 Mbyte RAM are needed for the full
GNU/GCC riscv32-unknown-elf
is used for target system
development on *nix
. The build system is based on
Standard GNUmake/shell-script.
Build on *nix*
is easy using an installed riscv32-unknown-elf
cd Osek_pi_crunch_riscv
./Build.sh
The build results including ELF-file, HEX-mask, MAP-file
can be found in the Output
directory following the GNUmake build.
If riscv32-unknown-elf
is not installed nor present,
then it can be obtained (if needed) with wget
, e.g. from
Embecosm.
When doing this, remember also to add the directory of the extracted toolchain locally
to PATH
for the build.
wget --no-check-certificate https://buildbot.embecosm.com/job/riscv32-gcc-ubuntu2004/169/artifact/riscv32-embecosm-gcc-ubuntu2004-20230507.tar.gz
tar -xvzf riscv32-embecosm-gcc-ubuntu2004-20230507.tar.gz
PATH=./riscv32-embecosm-gcc-ubuntu2004-20230507/bin:$PATH
This repo features a fully-worked-out prototype example project. The prototype runs on a RISC-V FE310 controller fitted on the SparkFun Red Thing RISC-V FE310 Board.
The Idle
). Upon successful calculation completion,
the pin on port0.19
is toggled.
Simultaneously task T1
exercises a perpetual, simple blinky show
featuring a self-fitted LED on port0.0
toggling at 1/2 Hz.
This provides clear visual measure of both system-OK as well as
numerical correctness of the most-recently finished spigot calculation.
The hardware setup is pictured in the image below.
We emphasize that the blinky LED-toggle show is carried out
with a self-fitted LED on port0.0
.
Consider, in particular, the on-board, blue user-LED found default-fitted
on port0.5
. As is usual for Arduino-compatible pinouts,
this port pin is needed for the SPI serial-clock signal (SCK).
But this should be routed to the SCK signal of the external SRAM.
So the blue LED on port0.5
cannot be used for the blinky show on the user-LED.
For this reason, a self-fitted, port0.0
. This self-fitted,
green LED on port0.0
is used for the blinky show.
The breadboard layout (without the microcontroller board) is shown below.
The operating system OSEK and the self-written files in the MCAL are licensed under GPL. This is consistent with the licensing found in and adopted from Chalandi/OSEK_RISC-V_SiFive_FE310_SoC.
The supporting files in ref_app and the pi_spigot application itself are licensed under BSL.
The file riscv-csr.h originates from Five EmbedDev and is (as originally found there) provided with no license.
[1] S. Rabinowitz and S. Wagon: A Spigot Algorithm for the Digits of Pi, American Mathematical Monthly 102: 195-203, 1995
[2] J. Arndt and C. Haenel:
[3] C.M. Kormanyos: Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming, 4th Edition (Springer Verlag, Heidelberg, 2021). ISBN 9783662629956.