rp2040

RP2040 Programming without SDK
Log | Files | Refs

commit e7760c1a36c1865d4df268b65cd8d53a126a7d3d
parent 2ba7851cb24ada3e4ab910f8822dcb7095b74252
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 22 Mar 2024 08:32:34 +0900

switch context

Diffstat:
Mex3/main.c | 17++++++++++++-----
Mex3/proc.s | 7+++----
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/ex3/main.c b/ex3/main.c @@ -4,7 +4,6 @@ void init(void); int puts(char *); void printh(unsigned int); void set_alarm(unsigned int); -void proc0(void); void halt(void); void wfi(void); void print_sp(void); @@ -26,8 +25,8 @@ void save_context(unsigned int r[17]); extern char proc0_start, proc0_size; extern char proc1_start, proc1_size; -extern char msg0; -extern char msg1; +extern void proc0(void), proc1(void); +extern char msg0, msg1; // A proc_tab is the queue of waiting processes. @@ -54,17 +53,19 @@ main(void) { p0.id = 0; p0.r[13] = 0x20000100; // sp p0.r[14] = (unsigned int) halt; // lr - p0.r[15] = 0x20000001; // pc + p0.r[15] = (unsigned int) proc0 + 1; // pc p0.r[16] = 0; p0.next = &p1; p1.id = 1; p1.r[13] = 0x20000200; // sp p1.r[14] = (unsigned int) halt; // lr - p1.r[15] = 0x20000101; // pc + p1.r[15] = (unsigned int) proc1 + 1; // pc p1.r[16] = 0; p1.next = NULL; + proc0(); + return 0; } @@ -80,6 +81,12 @@ unsigned int * switch_context(unsigned int r[17]) { proc *p; + puts("switch_context:"); + for (int i = 0; i < 17; i++) { + printh(r[i]); + puts(""); + } + // save context int i; for (i = 0; i < 17; i++) { diff --git a/ex3/proc.s b/ex3/proc.s @@ -111,7 +111,6 @@ isr_alarm: bl switch_context // r0 is the r[17] of the next task. add sp, sp, #(17*4) add r2, sp, #4 // for the popped lr -/* ldr r1, [r0, #(0 * 4)] // r0 str r1, [r2, #0] ldr r1, [r0, #(1 * 4)] // r1 @@ -126,9 +125,9 @@ isr_alarm: str r1, [r2, #0x14] ldr r1, [r0, #(15 * 4)] // ReturnAddress str r1, [r2, #0x18] - ldr r1, [r0, #(16 * 4)] // xpsr - str r1, [r2, #0x1c] -*/ +// ldr r1, [r0, #(16 * 4)] // xpsr +// str r1, [r2, #0x1c] + mov r4, r0 ldr r0, =(1000 * 1000)