more stack space; expose trig to algorithms

pull/3/head
Clyne 4 years ago
parent a0871d9c96
commit 87851f4e6c

@ -55,13 +55,13 @@ endif
# Stack size to be allocated to the Cortex-M process stack. This stack is # Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread. # the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),) ifeq ($(USE_PROCESS_STACKSIZE),)
USE_PROCESS_STACKSIZE = 0x400 USE_PROCESS_STACKSIZE = 0x1000
endif endif
# Stack size to the allocated to the Cortex-M main/exceptions stack. This # Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions. # stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),) ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
USE_EXCEPTIONS_STACKSIZE = 0x400 USE_EXCEPTIONS_STACKSIZE = 0x1000
endif endif
# Enables the use of FPU (no, softfp, hard). # Enables the use of FPU (no, softfp, hard).
@ -134,10 +134,10 @@ ASMXSRC = $(ALLXASMSRC)
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC) INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
# Define C warning options here. # Define C warning options here.
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes -pedantic
# Define C++ warning options here. # Define C++ warning options here.
CPPWARN = -Wall -Wextra -Wundef CPPWARN = -Wall -Wextra -Wundef -pedantic
# #
# Project, target, sources and paths # Project, target, sources and paths

@ -19,15 +19,15 @@
* SRAM1 - SIGGEN. * SRAM1 - SIGGEN.
* SRAM2 - DAC. * SRAM2 - DAC.
* SRAM4 - ADC. * SRAM4 - ADC.
* DTCM-RAM - Unprivileged Stack, Main Stack, Process Stack. * DTCM-RAM - Process stacks.
* ITCM-RAM - STMDSP Algorithm. * ITCM-RAM - STMDSP Algorithm.
* BCKP SRAM - None. * BCKP SRAM - None.
*/ */
MEMORY MEMORY
{ {
flash0 (rx) : org = 0x08000000, len = 1M /* Flash bank1 + bank2 */ flash0 (rx) : org = 0x08000000, len = 1M /* Flash bank1 + bank2 */
flashc (rx) : org = 0x0807F000, len = 4K /* Unprivileged firmware */ flash1 (rx) : org = 0x08000000, len = 510K /* Flash bank 1 */
flash1 (rx) : org = 0x08000000, len = 512K /* Flash bank 1 */ flashc (rx) : org = 0x0807F800, len = 2K /* Unprivileged firmware */
flash2 (rx) : org = 0x08080000, len = 512K /* Flash bank 2 */ flash2 (rx) : org = 0x08080000, len = 512K /* Flash bank 2 */
flash3 (rx) : org = 0x00000000, len = 0 flash3 (rx) : org = 0x00000000, len = 0
flash4 (rx) : org = 0x00000000, len = 0 flash4 (rx) : org = 0x00000000, len = 0
@ -39,8 +39,8 @@ MEMORY
ram2 (wx) : org = 0x30004000, len = 16K /* AHB SRAM2 */ ram2 (wx) : org = 0x30004000, len = 16K /* AHB SRAM2 */
ram3 (wx) : org = 0x38000000, len = 16K /* AHB SRAM4 */ ram3 (wx) : org = 0x38000000, len = 16K /* AHB SRAM4 */
ram4 (wx) : org = 0x00000000, len = 0 ram4 (wx) : org = 0x00000000, len = 0
ramc (wx) : org = 0x20000000, len = 4K /* Unprivileged data */ ramc (wx) : org = 0x20000000, len = 64K /* Unprivileged data */
ram5 (wx) : org = 0x20001000, len = 124K /* DTCM-RAM */ ram5 (wx) : org = 0x20010000, len = 64K /* DTCM-RAM */
ram6 (wx) : org = 0x00000000, len = 64K /* ITCM-RAM */ ram6 (wx) : org = 0x00000000, len = 64K /* ITCM-RAM */
ram7 (wx) : org = 0x38800000, len = 4K /* BCKP SRAM */ ram7 (wx) : org = 0x38800000, len = 4K /* BCKP SRAM */
} }
@ -100,6 +100,12 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
} > ramc } > ramc
.stacks : ALIGN(4)
{
*(.stacks)
. = ALIGN(4);
} > ram5
.convcode : ALIGN(4) .convcode : ALIGN(4)
{ {
*(.convcode) *(.convcode)

@ -65,14 +65,50 @@ static const char *file_header = R"cpp(
using adcsample_t = uint16_t; using adcsample_t = uint16_t;
constexpr unsigned int SIZE = $0; constexpr unsigned int SIZE = $0;
adcsample_t *process_data(adcsample_t *samples, unsigned int size); adcsample_t *process_data(adcsample_t *samples, unsigned int size);
extern "C" void process_data_entry() extern "C" void process_data_entry()
{ {
((void (*)())process_data)(); ((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 // End stmdspgui header code
)cpp"; )cpp";
@ -223,11 +259,12 @@ MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50)
void MainFrame::onCloseEvent(wxCloseEvent& event) void MainFrame::onCloseEvent(wxCloseEvent& event)
{ {
SetMenuBar(nullptr); SetMenuBar(nullptr);
delete m_menu_bar->Remove(2); //delete m_menu_bar->Remove(2);
delete m_menu_bar->Remove(1); //delete m_menu_bar->Remove(1);
delete m_menu_bar->Remove(0); //delete m_menu_bar->Remove(0);
delete m_menu_bar; //delete m_menu_bar;
delete m_measure_timer; delete m_measure_timer;
delete m_device;
Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY); Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY);
Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY); Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY);

@ -50,16 +50,19 @@ static msg_t conversionMBBuffer[2];
static MAILBOX_DECL(conversionMB, conversionMBBuffer, 2); static MAILBOX_DECL(conversionMB, conversionMBBuffer, 2);
// Thread for LED status and wakeup hold // 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); static THD_FUNCTION(monitorThread, arg);
// Thread for managing the conversion task // 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); static THD_FUNCTION(conversionThreadMonitor, arg);
// Thread for unprivileged algorithm execution // 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); static THD_FUNCTION(conversionThread, arg);
__attribute__((section(".convdata"))) __attribute__((section(".convdata")))
static THD_WORKING_AREA(conversionThreadUPWA, 256); static THD_WORKING_AREA(conversionThreadUPWA, 62 * 1024);
static thread_t *conversionThreadHandle = nullptr; static thread_t *conversionThreadHandle = nullptr;
__attribute__((section(".convdata"))) __attribute__((section(".convdata")))
@ -98,13 +101,13 @@ int main()
mpuConfigureRegion(MPU_REGION_2, mpuConfigureRegion(MPU_REGION_2,
0x20000000, 0x20000000,
MPU_RASR_ATTR_AP_RW_RW | MPU_RASR_ATTR_NON_CACHEABLE | MPU_RASR_ATTR_AP_RW_RW | MPU_RASR_ATTR_NON_CACHEABLE |
MPU_RASR_SIZE_4K | MPU_RASR_SIZE_64K |
MPU_RASR_ENABLE); MPU_RASR_ENABLE);
// Region 3: Code for algorithm manager thread // Region 3: Code for algorithm manager thread
mpuConfigureRegion(MPU_REGION_3, mpuConfigureRegion(MPU_REGION_3,
0x08080000, 0x0807F800,
MPU_RASR_ATTR_AP_RO_RO | MPU_RASR_ATTR_NON_CACHEABLE | MPU_RASR_ATTR_AP_RO_RO | MPU_RASR_ATTR_NON_CACHEABLE |
MPU_RASR_SIZE_4K | MPU_RASR_SIZE_2K |
MPU_RASR_ENABLE); MPU_RASR_ENABLE);
// Region 4: Algorithm code // Region 4: Algorithm code
mpuConfigureRegion(MPU_REGION_4, mpuConfigureRegion(MPU_REGION_4,
@ -408,10 +411,12 @@ THD_FUNCTION(monitorThread, arg)
if (run_status == RunStatus::Idle && palReadLine(LINE_BUTTON)) { if (run_status == RunStatus::Idle && palReadLine(LINE_BUTTON)) {
palSetLine(LINE_LED_RED); palSetLine(LINE_LED_RED);
palSetLine(LINE_LED_YELLOW); palSetLine(LINE_LED_YELLOW);
asm("cpsid i"); chSysLock();
while (palReadLine(LINE_BUTTON))
asm("nop");
while (!palReadLine(LINE_BUTTON)) while (!palReadLine(LINE_BUTTON))
asm("nop"); asm("nop");
asm("cpsie i"); chSysUnlock();
palClearLine(LINE_LED_RED); palClearLine(LINE_LED_RED);
palClearLine(LINE_LED_YELLOW); palClearLine(LINE_LED_YELLOW);
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
@ -433,16 +438,34 @@ __attribute__((naked))
void port_syscall(struct port_extctx *ctxp, uint32_t n) void port_syscall(struct port_extctx *ctxp, uint32_t n)
{ {
switch (n) { switch (n) {
case 0: { case 0:
{
chSysLock(); chSysLock();
chMsgWaitS(); chMsgWaitS();
auto msg = chMsgGet(conversionThreadMonitorHandle); auto msg = chMsgGet(conversionThreadMonitorHandle);
chMsgReleaseS(conversionThreadMonitorHandle, MSG_OK); chMsgReleaseS(conversionThreadMonitorHandle, MSG_OK);
//chSchDoYieldS();
chSysUnlock(); chSysUnlock();
ctxp->r0 = msg; ctxp->r0 = msg;
} }
break; 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: default:
while (1); while (1);
break; break;

@ -1,4 +1,4 @@
#include "common.hpp" #include "samplebuffer.hpp"
SampleBuffer::SampleBuffer(Sample *buffer) : SampleBuffer::SampleBuffer(Sample *buffer) :
m_buffer(buffer) {} m_buffer(buffer) {}

Loading…
Cancel
Save