]> code.bitgloo.com Git - bitgloo/dsp-paw.git/commitdiff
add to firmware documentation
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 8 Oct 2023 20:32:23 +0000 (16:32 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 8 Oct 2023 20:32:23 +0000 (16:32 -0400)
16 files changed:
firmware/source/communication.hpp
firmware/source/conversion.hpp
firmware/source/elf.h
firmware/source/elfload.hpp
firmware/source/error.hpp
firmware/source/handlers.hpp
firmware/source/monitor.hpp
firmware/source/periph/adc.hpp
firmware/source/periph/cordic.cpp
firmware/source/periph/cordic.hpp
firmware/source/periph/dac.hpp
firmware/source/periph/usbserial.hpp
firmware/source/runstatus.hpp
firmware/source/samplebuffer.hpp
firmware/source/samples.hpp
firmware/source/sclock.hpp

index 03220b83342aefbb442a70aa2496730d54b7ae22..a4f818abeb483a37ed01df11e2b690834fa0f25b 100644 (file)
@@ -2,7 +2,7 @@
  * @file communication.hpp
  * @brief Manages communication with the host computer.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
 class CommunicationManager
 {
 public:
+    /**
+     * Starts the communication manager thread (threadComm).
+     */
     static void begin();
 
 private:
+    /**
+     * Continuously polls the USB serial connection, handling received commands
+     * as necessary.
+     * Does not return.
+     */
     static void threadComm(void *);
 
     static std::array<char, 4096> m_thread_stack;
index ca0054a2d79d7473c1c16cb83f0be02c94a81599..75d644e9cb1247a2ac45c5d103c0dc3b4ee1f845 100644 (file)
@@ -2,7 +2,7 @@
  * @file conversion.hpp
  * @brief Manages algorithm application (converts input samples to output).
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -27,6 +27,10 @@ constexpr unsigned int CONVERSION_THREAD_STACK_SIZE =
 class ConversionManager
 {
 public:
+    /**
+     * Starts two threads: the privileged monitor thread and the unprivileged
+     * algorithm execution thread.
+     */
     static void begin();
 
     // Begins sample conversion.
index 998356dde667a8fbad23d1a91df67616cbbf7c41..fe817e1e564575ee637688883eb199025dec19d9 100644 (file)
@@ -2,7 +2,7 @@
  * @file elf.h
  * @brief Defines ELF binary format info.
  *
- * Free to use, written by Clyne Sullivan.
+ * Public domain, written by Clyne Sullivan.
  */
 
 #ifndef STMDSP_ELF_HPP
index 10d95d7831cae397861d0ee42c7e8f433df7f8d7..9cfcbf941613977f0bfd0e388cf40652c2e33b05 100644 (file)
@@ -2,7 +2,7 @@
  * @file elfload.hpp
  * @brief Loads ELF binary data into memory for execution.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -24,9 +24,26 @@ class ELFManager
 public:
     using EntryFunc = Sample *(*)(Sample *, size_t);
     
+    /**
+     * Attempts to parse the ELF binary loaded in the file buffer.
+     * Returns true if successful.
+     */
     static bool loadFromInternalBuffer();
+
+    /**
+     * Returns a function pointer to the loaded ELF's entry point.
+     * Returns nullptr if a valid ELF is not loaded.
+     */
     static EntryFunc loadedElf();
+
+    /**
+     * Returns the address of the ELF file buffer (copy ELF binary to here).
+     */
     static unsigned char *fileBuffer();
+
+    /**
+     * "Unloads" the loaded binary by invalidating the entry pointer.
+     */
     static void unload();
 
 private:
index c6a7f5c45f277e18448510fbdd4bd6403dd20b77..07651678b3f9025c7906249ac9e7ba607edd2b4f 100644 (file)
@@ -2,7 +2,7 @@
  * @file error.hpp
  * @brief Tracks and reports non-critical errors.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -31,9 +31,25 @@ class ErrorManager
     constexpr static unsigned int MAX_ERROR_QUEUE_SIZE = 8;
 
 public:
+    /**
+     * Adds the given error to the error queue.
+     */
     void add(Error error);
+
+    /**
+     * If condition is false, add the given error to the error queue.
+     * Returns condition.
+     */
     bool assert(bool condition, Error error);
+
+    /**
+     * Returns true if the error queue is not empty.
+     */
     bool hasError();
+
+    /**
+     * Returns the oldest error queue entry after removing it from the queue.
+     */
     Error pop();
 
 private:
index fd7e10cd1a9df078b1a898956a9b7b24f94c673e..9aa87b5623098e40ec633d9698d3ae117211e007 100644 (file)
@@ -2,7 +2,7 @@
  * @file handlers.hpp
  * @brief Interrupt service routine handlers.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
 
 extern "C" {
 
+// Service call handler ("svc" calls)
 __attribute__((naked))
 void port_syscall(struct port_extctx *ctxp, uint32_t n);
 
+// Handle memory faults possibly caused by the algorithm.
 __attribute__((naked))
 void MemManage_Handler();
 
+// Handle execution faults possibly caused by the algorithm.
 __attribute__((naked))
 void HardFault_Handler();
 
index 93f75e37a4d7ae8f1baf12fd16cc408e39d833eb..500fbbb700d8163096fefa10a717483f4460c3a5 100644 (file)
@@ -2,7 +2,7 @@
  * @file monitor.hpp
  * @brief Manages the device monitoring thread (status LEDs, etc.).
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
 class Monitor
 {
 public:
+    /**
+     * Starts the monitor thread.
+     */
     static void begin();
 
 private:
+    /**
+     * Updates status LEDs. Does not return.
+     */
     static void threadMonitor(void *);
 
     static std::array<char, THD_WORKING_AREA_SIZE(256)> m_thread_stack;
index 5f7fa08ff4ba8ab5444930f8fd5feddbc0e07508..ae2e88155ae5d4b7fdd8b028de1177d21f61149f 100644 (file)
@@ -2,7 +2,7 @@
  * @file adc.hpp
  * @brief Manages signal reading through the ADC.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -22,18 +22,47 @@ class ADC
 public:
     using Operation = void (*)(adcsample_t *buffer, size_t count);
 
+    /**
+     * Initializes analog input pins and the microcontoller's ADC peripheral.
+     */
     static void begin();
 
+    /**
+     * Begins continuous ADC sampling triggered by SClock at the set sampling
+     * rate.
+     * @param buffer Pointer to buffer for sample data.
+     * @param count Number of samples that the buffer can hold.
+     * @param operation Handler function to operate on filled half-buffers.
+     */
     static void start(adcsample_t *buffer, size_t count, Operation operation);
+
+    /**
+     * Stops the continuous ADC sampling.
+     */
     static void stop();
 
+    /**
+     * Runs a single conversion on the "alt" inputs (parameter knobs).
+     * @param id The ID of the desired "alt" input (zero or one).
+     * @return The sampled value for the given input.
+     */
     static adcsample_t readAlt(unsigned int id);
 
+    /**
+     * Sets the desired sampling rate for the ADC to operate at.
+     */
     static void setRate(SClock::Rate rate);
+
+    /**
+     * Used to override the handler function for the currently running
+     * conversion.
+     */
     static void setOperation(Operation operation);
 
 private:
+    // ADC driver for signal input.
     static ADCDriver *m_driver;
+    // ADC driver for "alt" inputs.
     static ADCDriver *m_driver2;
 
     static const ADCConfig m_config;
index 29ee068a5a28d0858b98d0d6a298f305065b0ac1..b6a9d7eaa45feffb8a27e49f3f33a77f2786f6d1 100644 (file)
@@ -1,3 +1,14 @@
+/**
+ * @file cordic.cpp
+ * @brief Provides mathematical functions for algorithms.
+ *
+ * Copyright (C) 2023 Clyne Sullivan
+ *
+ * Distributed under the GNU GPL v3 or later. You should have received a copy of
+ * the GNU General Public License along with this program.
+ * If not, see <https://www.gnu.org/licenses/>.
+ */
+
 #include "cordic.hpp"
 #include "hal.h"
 
index 5d640cca627f1b33e8dbe56ddb4bfcba386bb9f9..a9a046605ea0ff0d34b39a363c604b3fb717e36d 100644 (file)
@@ -1,11 +1,33 @@
+/**
+ * @file cordic.hpp
+ * @brief Provides mathematical functions for algorithms.
+ *
+ * Copyright (C) 2023 Clyne Sullivan
+ *
+ * Distributed under the GNU GPL v3 or later. You should have received a copy of
+ * the GNU General Public License along with this program.
+ * If not, see <https://www.gnu.org/licenses/>.
+ */
+
 #ifndef CORDIC_HPP_
 #define CORDIC_HPP_
 
+/**
+ * Named after the hardware CORDIC peripheral even though software
+ * implementations may be used.
+ */
 namespace cordic {
+    // Provides pi in case cordic functions require it.
     constexpr double PI = 3.1415926535L;
 
+    /**
+     * Prepares cordic functions for use.
+     */
     void init();
 
+    // mod - Calculates remainder for given fraction.
+    // cos, sin, tan - The trig functions.
+
 #if !defined(TARGET_PLATFORM_L4)
     double mod(double n, double d);
 
index 7250a529e34d0866f718fea344123f871e3257ac..f4266c732fb9a0dd6f0115e23db98560b7ead1d8 100644 (file)
@@ -2,7 +2,7 @@
  * @file dac.hpp
  * @brief Manages signal creation using the DAC.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
 class DAC
 {
 public:
+    /**
+     * Initializes DAC output pins and peripheral.
+     */
     static void begin();
 
+    /**
+     * Begins continuous DAC conversion on the given channel, running at the
+     * current SClock sampling rate.
+     * @param channel Selected output channel (0 = sig. out, 1 = sig. gen.).
+     * @param buffer Buffer of sample data to output.
+     * @param count Number of samples in sample buffer.
+     */
     static void start(int channel, dacsample_t *buffer, size_t count);
+
+    /**
+     * Stops DAC conversion on the given channel.
+     */
     static void stop(int channel);
 
+    /**
+     * Determines if signal generator needs more sample data for streamed
+     * output (i.e. audio file streaming).
+     * @return >0 if samples needed, <0 on initial run.
+     */
     static int sigGenWantsMore();
+
+    /**
+     * Returns true if signal generator is currently running.
+     */
     static int isSigGenRunning();
 
 private:
index 58113c95dd85e456633fa2372d2b9056e6034466..85da470660cbc2db1626de69b326b4958e7738e2 100644 (file)
@@ -2,7 +2,7 @@
  * @file usbserial.hpp
  * @brief Wrapper for ChibiOS's SerialUSBDriver.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
 class USBSerial
 {
 public:
+    /**
+     * Prepares for USB serial communication.
+     */
     static void begin();
 
+    /**
+     * Returns true if input data has been received.
+     */
     static bool isActive();
 
+    /**
+     * Reads received input data into the given buffer.
+     * @param buffer Buffer to store input data.
+     * @param count Number of bytes to read.
+     * @return Number of bytes actually read.
+     */
     static size_t read(unsigned char *buffer, size_t count);
+
+    /**
+     * Writes data to serial output.
+     * @param buffer Buffer of output data.
+     * @param count Number of bytes to write.
+     * @return Number of bytes actually written.
+     */
     static size_t write(const unsigned char *buffer, size_t count);
 
 private:
index ab269b46537ff44c5b7b308bd8eac444bd132056..18fe2e60c6dff871026802a6731bd9994203f7d1 100644 (file)
@@ -1,5 +1,4 @@
 // Run status
-//
 enum class RunStatus : char
 {
     Idle = '1',
index d13023aebed1d3e9f0a8f6a1b4acfc4793533544..83287701e0c448ac3365b85fb45768c3983dd33d 100644 (file)
@@ -2,7 +2,7 @@
  * @file samplebuffer.hpp
  * @brief Manages ADC/DAC buffer data.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -20,25 +20,79 @@ using Sample = uint16_t;
 constexpr unsigned int MAX_SAMPLE_BUFFER_BYTESIZE = sizeof(Sample) * 8192;
 constexpr unsigned int MAX_SAMPLE_BUFFER_SIZE = MAX_SAMPLE_BUFFER_BYTESIZE / sizeof(Sample);
 
+/**
+ * Manages a buffer of sample data from the ADC or DAC with facilities to
+ * work with separate halves of the total buffer (which is necessary when
+ * streaming data to or from the buffer).
+ */
 class SampleBuffer
 {
 public:
+    // Manage the sample data memory at 'buffer'.
     SampleBuffer(Sample *buffer);
 
+    /**
+     * Fill the current buffer with midpoint (2048/0V) values.
+     */
     void clear();
 
+    /**
+     * Copy 'srcsize' samples from 'data' into the first half of the current
+     * buffer. Also do equivalent of setModified().
+     */
     void modify(Sample *data, unsigned int srcsize);
+
+    /**
+     * Copy 'srcsize' samples from 'data' into the second half of the current
+     * buffer. Also do equivalent of setMidmodified().
+     */
     void midmodify(Sample *data, unsigned int srcsize);
+
+    /**
+     * Set modified buffer pointer to first half of the current buffer.
+     */
     void setModified();
+
+    /**
+     * Set modified buffer pointer to second half of the current buffer.
+     */
     void setMidmodified();
+
+    /**
+     * Return pointer to most recently modified buffer portion.
+     * Clears this internal pointer when called.
+     */
     Sample *modified();
 
+    /**
+     * Returns pointer to first half of current buffer.
+     */
     Sample *data();
+
+    /**
+     * Returns pointer to second half of current buffer.
+     */
     Sample *middata();
+
+    /**
+     * Returns uint8_t-casted pointer to the current buffer.
+     */
     uint8_t *bytedata();
 
+    /**
+     * Sets the total working size of the current buffer. Current buffer must
+     * be able to accommodate.
+     */
     void setSize(unsigned int size);
+
+    /**
+     * Returns the current total working size (number of samples).
+     */
     unsigned int size() const;
+
+    /**
+     * Returns the current total working size (number of bytes).
+     */
     unsigned int bytesize() const;
 
 private:
index 6551e25a8abafd04fe11146346c1945a169599f5..8e60775ef30b89810b0905f92b5477b6f69f6db5 100644 (file)
@@ -2,7 +2,7 @@
  * @file samples.hpp
  * @brief Provides sample buffers for inputs and outputs.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -14,6 +14,8 @@
 
 #include "samplebuffer.hpp"
 
+// Define sample buffers for the input and output signals and the signal
+// generator.
 class Samples
 {
 public:
index d5b93df095b35e794af7ded107aaf18aa28d5212..c72805ddc626b41aa89a7d22b80a6f07cfd5deef 100644 (file)
@@ -2,7 +2,7 @@
  * @file sclock.hpp
  * @brief Manages sampling rate clock speeds.
  *
- * Copyright (C) 2021 Clyne Sullivan
+ * Copyright (C) 2023 Clyne Sullivan
  *
  * Distributed under the GNU GPL v3 or later. You should have received a copy of
  * the GNU General Public License along with this program.
@@ -19,6 +19,7 @@
 class SClock
 {
 public:
+    // These are the supported sampling rates. GUI keeps its own enumeration.
     enum class Rate : unsigned int {
         R8K = 0,
         R16K,
@@ -28,11 +29,32 @@ public:
         R96K
     };
 
+    /**
+     * Initializes the sample clock hardware.
+     */
     static void begin();
+
+    /**
+     * Starts the sample rate clock if it is not already running.
+     */
     static void start();
+
+    /**
+     * Indicate that the caller no longer needs the sample clock.
+     * This decrements an internal counter that is incremented by start()
+     * calls; if the counter reaches zero, the clock will actually stop.
+     */
     static void stop();
 
+    /**
+     * Sets the desired sampling rate, used for the next start() call.
+     */
     static void setRate(Rate rate);
+
+    /**
+     * Gets the desired sampling rate (SClock::Rate value) casted to an
+     * unsigned int.
+     */
     static unsigned int getRate();
 
 private: