fixed an error when exiting the task function

main
Vladimir Kutkovoy 8 months ago
parent b55a2b4d12
commit 1f2df066e5
  1. 19
      main.cpp

@ -1,4 +1,4 @@
#define MAX_TASKS 2 #define MAX_TASKS 3
#define TASK_STACK_SIZE 256 #define TASK_STACK_SIZE 256
#include "stm32g431xx.h" #include "stm32g431xx.h"
@ -101,7 +101,7 @@ void __stackless PendSV_mainHandler()
else else
myTask->isFirstRun = false; myTask->isFirstRun = false;
asm("mov LR, #0xFFFFFFFD"); asm volatile("mov LR, #0xFFFFFFFD"); // LR - 0xFFFFFFFD (Возвращаемся в Thread режим, используем стек процесса PSP)
stop = false; stop = false;
@ -126,6 +126,7 @@ int func2();
uint func1Stack[TASK_STACK_SIZE]; uint func1Stack[TASK_STACK_SIZE];
uint func2Stack[TASK_STACK_SIZE]; uint func2Stack[TASK_STACK_SIZE];
uint func3Stack[TASK_STACK_SIZE];
int a, b, c; int a, b, c;
@ -135,9 +136,6 @@ int func1()
while (1) while (1)
{ {
a++; a++;
// asm("mov R4, #0x12");
// asm("mov R5, #0x34");
// asm("mov R6, #0x56");
} }
} }
@ -146,10 +144,14 @@ int func2()
while (1) while (1)
{ {
b++; b++;
// asm("mov R5, #0x79");
} }
} }
int func3()
{
a = 778;
}
int mute() int mute()
{ {
while (1) while (1)
@ -175,7 +177,7 @@ int newTask(int (*new_task)(), uint *stack, uint size)
cx->PC = (uint)new_task; cx->PC = (uint)new_task;
cx->xPSR = 0x01000000; cx->xPSR = 0x01000000;
cx->LR = 0x0800029b; // LR - 0xFFFFFFFD (Возвращаемся в Thread режим, используем стек процесса PSP) cx->LR = (uint)mute;
task_index++; task_index++;
@ -197,7 +199,7 @@ void zeroTask(int (*new_task)(), uint *stack, uint size)
cx->PC = (uint)new_task; cx->PC = (uint)new_task;
cx->xPSR = 0x01000000; cx->xPSR = 0x01000000;
cx->LR = 0x0800029b; cx->LR = (uint)mute;
} }
int main() int main()
@ -213,6 +215,7 @@ int main()
newTask(func1, func1Stack, TASK_STACK_SIZE); newTask(func1, func1Stack, TASK_STACK_SIZE);
newTask(func2, func2Stack, TASK_STACK_SIZE); newTask(func2, func2Stack, TASK_STACK_SIZE);
newTask(func3, func3Stack, TASK_STACK_SIZE);
while (true) while (true)
{ {

Loading…
Cancel
Save