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
# 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

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

@ -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);

@ -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,16 +438,34 @@ __attribute__((naked))
void port_syscall(struct port_extctx *ctxp, uint32_t n)
{
switch (n) {
case 0: {
case 0:
{
chSysLock();
chMsgWaitS();
auto msg = chMsgGet(conversionThreadMonitorHandle);
chMsgReleaseS(conversionThreadMonitorHandle, MSG_OK);
//chSchDoYieldS();
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);
break;

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

Loading…
Cancel
Save