krnl 1
Loading...
Searching...
No Matches
k03priorityequal.ino
Go to the documentation of this file.
1//220216
2#include <krnl.h>
3//
4// busy waiting all the way around - like using ya old delay
5//
6
7// Set t1 priority to 9 == highest priority
8// What will happen ? What do you see on the led and the measurements
9// REALTIME ?
10//
11// gives a guess how cpu time is used in krnl "dummy time eating"
12
13struct k_t *p1, *p2;
14
15#define SS 110
16unsigned char s1[SS], s2[SS];
17
18
19void t1()
20{
21 int v;
22
23 while (1) {
24 k_eat_msec(2000); // eat time for 2000 ticks so mimic cpu usage == 2000 msec
25 }
26}
27
28unsigned long tStart,tStop;
29void t2()
30{
31 int i = 0;
32 while (1) {
33 Serial.println("start");
34 tStart = k_millis();
35 for (int i=0; i < 10 ; i++) { // 10 loops of 100 milliseconds == 1 second ! ?
36 digitalWrite(13, HIGH);
37 k_eat_msec(50);
38 digitalWrite(13, LOW);
39 k_eat_msec(50);
40 }
41 tStop = k_millis();
42 Serial.print((tStop-tStart)/1000.0);
43 Serial.print(" sec ");
44 Serial.println("Did it take 1 second ???- not - why ");
45 // hint task t1 ies eating 50% of cputime
46 // the have same priority to you share cpu 50/50
47 // so it will approx take 100 msec to execut k_eat_msec(50)
48 }
49}
50
51
52void setup()
53{
54 int res;
55 Serial.begin(115200);
56 while (! Serial) ;
57 pinMode(13, OUTPUT);
58
59 k_init(2, 0, 0); // init with space for one task
60 // |--- no of mg Queues (0)
61 // |----- no of semaphores (0)
62 // |------- no of tasks (2)
63
64 // priority low number higher priority than higher number
65 p1 = k_crt_task(t1, 10,s1,SS); // t1 as task, priority 9, 100 B stak
66 p2 = k_crt_task(t2, 10, s2,SS); // t2 as task, priority 10, 100 B stak
67
68 Serial.println("bef start");
69 res = k_start(); // 1 milli sec tick speed
70 // you will never return from k_start
71 Serial.print("ups an error occured: "); Serial.println(res);
72 while (1) ;
73}
74
75void loop() {}
volatile int i
unsigned char s2[110]
Definition k03asleep.ino:25
struct k_t * p1
Definition k03asleep.ino:22
struct k_t * p2
Definition k03asleep.ino:22
unsigned char s1[110]
Definition k03asleep.ino:25
void setup()
void t2()
void t1()
unsigned long tStart
#define SS
unsigned long tStop
void loop()
unsigned long k_millis(void)
return no of millisec sincs start NB no leap seconds - its clean
Definition krnl.c:1247
void k_eat_msec(unsigned int eatTime)
eat milliseconds - to mimik time consuming code
Definition krnl.c:246
struct k_t * k_crt_task(void(*pTask)(void), char prio, char *pStk, int stkSize)
create a task - only to be called before k_start creates a task and put it in the active Q
Definition krnl.c:328
int k_init(int nrTask, int nrSem, int nrMsg)
Definition krnl.c:1108
int k_start()
Definition krnl.c:1149
struct k_t * t1
Definition krnlgen.ino:3
struct k_t * t2
Definition krnlgen.ino:3
Definition krnl.h:323