]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
more stack space; expose trig to algorithms
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 4 Feb 2021 01:39:15 +0000 (20:39 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 4 Feb 2021 01:39:15 +0000 (20:39 -0500)
Makefile
STM32H723xG.ld
gui/wxmain.cpp
source/main.cpp
source/samplebuffer.cpp

index 178b026c95a95a4f8d2ec3b7c5f8ea43a756a19e..53340e4fcad358be193f32b87088f1e2893325b3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -55,13 +55,13 @@ endif
 # Stack size to be allocated to the Cortex-M process stack. This stack is
 # the stack used by the main() thread.
 ifeq ($(USE_PROCESS_STACKSIZE),)
-  USE_PROCESS_STACKSIZE = 0x400
+  USE_PROCESS_STACKSIZE = 0x1000
 endif
 
 # Stack size to the allocated to the Cortex-M main/exceptions stack. This
 # stack is used for processing interrupts and exceptions.
 ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
-  USE_EXCEPTIONS_STACKSIZE = 0x400
+  USE_EXCEPTIONS_STACKSIZE = 0x1000
 endif
 
 # Enables the use of FPU (no, softfp, hard).
@@ -134,10 +134,10 @@ ASMXSRC = $(ALLXASMSRC)
 INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
 
 # Define C warning options here.
-CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
+CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes -pedantic
 
 # Define C++ warning options here.
-CPPWARN = -Wall -Wextra -Wundef
+CPPWARN = -Wall -Wextra -Wundef -pedantic
 
 #
 # Project, target, sources and paths
index e59c9001e65b85b4ea7e458dc44aad64d80b2734..7d5bafb7050c3dcf567e0917e6ab736d0d281eff 100644 (file)
  * SRAM1        - SIGGEN.\r
  * SRAM2        - DAC.\r
  * SRAM4        - ADC.\r
- * DTCM-RAM     - Unprivileged Stack, Main Stack, Process Stack.\r
+ * DTCM-RAM     - Process stacks.\r
  * ITCM-RAM     - STMDSP Algorithm.\r
  * BCKP SRAM    - None.\r
  */\r
 MEMORY\r
 {\r
     flash0 (rx) : org = 0x08000000, len = 1M       /* Flash bank1 + bank2 */\r
-    flashc (rx) : org = 0x0807F000, len = 4K       /* Unprivileged firmware */\r
-    flash1 (rx) : org = 0x08000000, len = 512K     /* Flash bank 1 */\r
+    flash1 (rx) : org = 0x08000000, len = 510K     /* Flash bank 1 */\r
+    flashc (rx) : org = 0x0807F800, len = 2K       /* Unprivileged firmware */\r
     flash2 (rx) : org = 0x08080000, len = 512K     /* Flash bank 2 */\r
     flash3 (rx) : org = 0x00000000, len = 0\r
     flash4 (rx) : org = 0x00000000, len = 0\r
@@ -39,8 +39,8 @@ MEMORY
     ram2   (wx) : org = 0x30004000, len = 16K      /* AHB SRAM2 */\r
     ram3   (wx) : org = 0x38000000, len = 16K      /* AHB SRAM4 */\r
     ram4   (wx) : org = 0x00000000, len = 0\r
-    ramc   (wx) : org = 0x20000000, len = 4K       /* Unprivileged data */\r
-    ram5   (wx) : org = 0x20001000, len = 124K     /* DTCM-RAM */\r
+    ramc   (wx) : org = 0x20000000, len = 64K      /* Unprivileged data */\r
+    ram5   (wx) : org = 0x20010000, len = 64K      /* DTCM-RAM */\r
     ram6   (wx) : org = 0x00000000, len = 64K      /* ITCM-RAM */\r
     ram7   (wx) : org = 0x38800000, len = 4K       /* BCKP SRAM */\r
 }\r
@@ -100,6 +100,12 @@ SECTIONS
         . = ALIGN(4);\r
     } > ramc\r
 \r
+    .stacks : ALIGN(4)\r
+    {\r
+        *(.stacks)\r
+        . = ALIGN(4);\r
+    } > ram5\r
+\r
     .convcode : ALIGN(4)\r
     {\r
         *(.convcode)\r
index 86807ab64d6d0fd321af1aea35fc4429b6bbfdd8..10e5d7a40c3007db86611278fd4abc8d22805155 100644 (file)
@@ -65,14 +65,50 @@ static const char *file_header = R"cpp(
 
 using adcsample_t = uint16_t;
 constexpr unsigned int SIZE = $0;
-
 adcsample_t *process_data(adcsample_t *samples, unsigned int size);
-
 extern "C" void process_data_entry()
 {
     ((void (*)())process_data)();
 }
 
+constexpr double PI = 3.14159265358979323846L;
+__attribute__((naked))
+auto sin(double x) {
+asm("vmov.f64 r1, r2, d0;"
+    "eor r0, r0;"
+    "svc 1;"
+    "vmov.f64 d0, r1, r2;"
+    "bx lr");
+return 0;
+}
+__attribute__((naked))
+auto cos(double x) {
+asm("vmov.f64 r1, r2, d0;"
+       "mov r0, #1;"
+       "svc 1;"
+       "vmov.f64 d0, r1, r2;"
+       "bx lr");
+return 0;
+}
+__attribute__((naked))
+auto tan(double x) {
+asm("vmov.f64 r1, r2, d0;"
+       "mov r0, #2;"
+       "svc 1;"
+       "vmov.f64 d0, r1, r2;"
+       "bx lr");
+return 0;
+}
+__attribute__((naked))
+auto sqrt(double x) {
+asm("vmov.f64 r1, r2, d0;"
+       "mov r0, #3;"
+       "svc 1;"
+       "vmov.f64 d0, r1, r2;"
+       "bx lr");
+return 0;
+}
+
 // End stmdspgui header code
 
 )cpp";
@@ -223,11 +259,12 @@ MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50)
 void MainFrame::onCloseEvent(wxCloseEvent& event)
 {
     SetMenuBar(nullptr);
-    delete m_menu_bar->Remove(2);
-    delete m_menu_bar->Remove(1);
-    delete m_menu_bar->Remove(0);
-    delete m_menu_bar;
+    //delete m_menu_bar->Remove(2);
+    //delete m_menu_bar->Remove(1);
+    //delete m_menu_bar->Remove(0);
+    //delete m_menu_bar;
     delete m_measure_timer;
+    delete m_device;
 
     Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY,         wxID_ANY);
     Unbind(wxEVT_BUTTON,   &MainFrame::onRunCompile,        this, Id::MCodeCompile, wxID_ANY);
index 1a89c935805ee1ed6439eea01b5c69b9fe102972..d94f6942696d492cb01225dec12334a1b6061294 100644 (file)
@@ -50,16 +50,19 @@ static msg_t conversionMBBuffer[2];
 static MAILBOX_DECL(conversionMB, conversionMBBuffer, 2);
 
 // Thread for LED status and wakeup hold
-static THD_WORKING_AREA(monitorThreadWA, 128);
+__attribute__((section(".stacks")))
+static THD_WORKING_AREA(monitorThreadWA, 1024);
 static THD_FUNCTION(monitorThread, arg);
 // Thread for managing the conversion task
-static THD_WORKING_AREA(conversionThreadMonitorWA, 128);
+__attribute__((section(".stacks")))
+static THD_WORKING_AREA(conversionThreadMonitorWA, 1024);
 static THD_FUNCTION(conversionThreadMonitor, arg);
 // Thread for unprivileged algorithm execution
-static THD_WORKING_AREA(conversionThreadWA, 128);
+__attribute__((section(".stacks")))
+static THD_WORKING_AREA(conversionThreadWA, 1024);
 static THD_FUNCTION(conversionThread, arg);
 __attribute__((section(".convdata")))
-static THD_WORKING_AREA(conversionThreadUPWA, 256);
+static THD_WORKING_AREA(conversionThreadUPWA, 62 * 1024);
 
 static thread_t *conversionThreadHandle = nullptr;
 __attribute__((section(".convdata")))
@@ -98,13 +101,13 @@ int main()
     mpuConfigureRegion(MPU_REGION_2,
                        0x20000000,
                        MPU_RASR_ATTR_AP_RW_RW | MPU_RASR_ATTR_NON_CACHEABLE |
-                       MPU_RASR_SIZE_4K |
+                       MPU_RASR_SIZE_64K |
                        MPU_RASR_ENABLE);
     // Region 3: Code for algorithm manager thread
     mpuConfigureRegion(MPU_REGION_3,
-                       0x08080000,
+                       0x0807F800,
                        MPU_RASR_ATTR_AP_RO_RO | MPU_RASR_ATTR_NON_CACHEABLE |
-                       MPU_RASR_SIZE_4K |
+                       MPU_RASR_SIZE_2K |
                        MPU_RASR_ENABLE);
     // Region 4: Algorithm code
     mpuConfigureRegion(MPU_REGION_4,
@@ -408,10 +411,12 @@ THD_FUNCTION(monitorThread, arg)
         if (run_status == RunStatus::Idle && palReadLine(LINE_BUTTON)) {
             palSetLine(LINE_LED_RED);
             palSetLine(LINE_LED_YELLOW);
-            asm("cpsid i");
+            chSysLock();
+            while (palReadLine(LINE_BUTTON))
+                asm("nop");
             while (!palReadLine(LINE_BUTTON))
                 asm("nop");
-            asm("cpsie i");
+            chSysUnlock();
             palClearLine(LINE_LED_RED);
             palClearLine(LINE_LED_YELLOW);
             chThdSleepMilliseconds(500);
@@ -433,15 +438,33 @@ __attribute__((naked))
 void port_syscall(struct port_extctx *ctxp, uint32_t n)
 {
     switch (n) {
-    case 0: {
-        chSysLock();
-        chMsgWaitS();
-        auto msg = chMsgGet(conversionThreadMonitorHandle);
-        chMsgReleaseS(conversionThreadMonitorHandle, MSG_OK);
-        //chSchDoYieldS();
-        chSysUnlock();
-        ctxp->r0 = msg;
+    case 0:
+        {
+            chSysLock();
+            chMsgWaitS();
+            auto msg = chMsgGet(conversionThreadMonitorHandle);
+            chMsgReleaseS(conversionThreadMonitorHandle, MSG_OK);
+            chSysUnlock();
+            ctxp->r0 = msg;
+        }
+        break;
+    case 1:
+        {
+            using mathcall = void (*)();
+            static mathcall funcs[4] = {
+                reinterpret_cast<mathcall>(math::sin),
+                reinterpret_cast<mathcall>(math::cos),
+                reinterpret_cast<mathcall>(math::tan),
+                reinterpret_cast<mathcall>(math::sqrt),
+            };
+            asm("vmov.f64 d0, %0, %1" :: "r" (ctxp->r1), "r" (ctxp->r2));
+            if (ctxp->r0 < 4) {
+                funcs[ctxp->r0]();
+                asm("vmov.f64 %0, %1, d0" : "=r" (ctxp->r1), "=r" (ctxp->r2));
+            } else {
+                asm("eor r0, r0; vmov.f64 d0, r0, r0");
             }
+        }
         break;
     default:
         while (1);
index 69323925ed308b2cad0c4c1627c1f1da329ead74..55ebc8156c5aad28eca093d4590433a35c153215 100644 (file)
@@ -1,4 +1,4 @@
-#include "common.hpp"
+#include "samplebuffer.hpp"
 
 SampleBuffer::SampleBuffer(Sample *buffer) :
     m_buffer(buffer) {}