-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
60 lines (48 loc) · 925 Bytes
/
Copy pathmain.c
File metadata and controls
60 lines (48 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdint.h>
#define UART1_RTX ((volatile uint32_t *)0x101f1000)
#define USER_STACK_SIZE 4000
void task_init(char *stack, void (*f)(void))
{
char *top_stack = stack + USER_STACK_SIZE;
*((uint32_t *)(top_stack - 4)) = (uint32_t)f;
}
void printk(const char *str)
{
while (*str) {
*(UART1_RTX) = (*str & 0xFF);
str++;
}
}
void sleep(int count)
{
while(count--);
}
char task_stack[USER_STACK_SIZE];
uint32_t t_sp = (uint32_t)(task_stack + USER_STACK_SIZE - 14 * 4);
void process()
{
while(1) {
printk("process 1\n");
svc_call(t_sp);
}
}
char task_stack2[USER_STACK_SIZE];
uint32_t t_sp2 = (uint32_t)(task_stack2 + USER_STACK_SIZE - 14 * 4);
void process2()
{
while(1) {
printk("process 2\n");
svc_call(t_sp2);
}
}
void main()
{
printk("os start!\n");
task_init(task_stack, process);
task_init(task_stack2, process2);
while(1) {
active(t_sp);
sleep(80000000);
active(t_sp2);
}
}