dit projekt
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 
13 struct k_t *p1, *p2;
14 
15 #define SS 110
16 unsigned char s1[SS], s2[SS];
17 
18 
19 void 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 
28 unsigned long tStart,tStop;
29 void 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 
52 void 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 
75 void loop() {}
volatile int i
Definition: k02twotasks.ino:29
void setup()
void t2()
void t1()
unsigned long tStart
#define SS
unsigned char s1[SS]
struct k_t * p1
unsigned long tStop
struct k_t * p2
unsigned char s2[SS]
void loop()
unsigned long k_millis(void)
Definition: krnl.c:1322
void k_eat_msec(unsigned int eatTime)
Definition: krnl.c:292
struct k_t * k_crt_task(void(*pTask)(void), char prio, char *pStk, int stkSize)
Definition: krnl.c:374
int k_init(int nrTask, int nrSem, int nrMsg)
Definition: krnl.c:1152
int k_start()
Definition: krnl.c:1192
Definition: krnl.h:334