-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (55 loc) · 1.84 KB
/
main.cpp
File metadata and controls
84 lines (55 loc) · 1.84 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include "pico/stdlib.h"
extern "C" {
#include "kernel.h"
#include "klogging.h"
}
void thread0(void* args) {
const char* TAG = "thread0";
while(1) {
LOGI(TAG, "this is a message from thread 0!");
threadtime_t t_preyield = thread_gettime();
thread_yield(thread_ustotime(1000000));
threadtime_t t_postyield = thread_gettime();
LOGI(TAG, "I was yielded for %llu uS", thread_timetous(t_postyield - t_preyield));
}
}
void thread1(void* args) {
const char* TAG = "thread1";
while(1) {
LOGI(TAG, "this is a message from thread 1!");
threadtime_t t_preyield = thread_gettime();
thread_yield(thread_ustotime(500000));
threadtime_t t_postyield = thread_gettime();
LOGI(TAG, "I was yielded for %llu uS", thread_timetous(t_postyield - t_preyield));
}
}
void thread2(void* args) {
const char* TAG = "thread2";
while(1) {
LOGI(TAG, "this is a message from thread 2!");
threadtime_t t_preyield = thread_gettime();
thread_yield(thread_ustotime(100000));
threadtime_t t_postyield = thread_gettime();
LOGI(TAG, "I was yielded for %llu uS", thread_timetous(t_postyield - t_preyield));
}
}
void threadidle(void* args) {
while(1) {
thread_yield(0);
}
}
int main()
{
stdio_init_all();
getchar();
thread_create(thread0, NULL, (threadpriority_t)thread_idle_priority + 1, "task0");
thread_create(thread1, NULL, (threadpriority_t)thread_idle_priority + 1, "task1");
thread_create(thread2, NULL, (threadpriority_t)thread_idle_priority + 1, "task2");
thread_create(threadidle, NULL, (threadpriority_t)thread_idle_priority + 1, "idle");
thread_begin();
while (true) {
printf("erm...\n");
sleep_ms(1000);
}
}