krnl 1
Loading...
Searching...
No Matches
manyinone.ino
Go to the documentation of this file.
1
2/* k02
3 One task printing own usage of stak
4*/
5
6#include <krnl.h>
7
8#define STKSIZE 100
9
10#define TASKPRIO 10
11
13struct k_t * pTask,*pTask2;
14
15void task()
16{
17 int unusedStak;
18 while (1) {
19 // k_eat_msec(10); // consume 10 millisec of CPU time
20 // k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
21 }
22}
23
24
25void task2()
26{
27 int unusedStak;
28 while (1) {
29 // k_eat_msec(3); // consume 10 millisec of CPU time
30 // k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
31 }
32}
33
34
35void setup() {
36 // for debugging
37 for (int i = 8; i < 14; i++)
38 pinMode(i, OUTPUT);
39
40 Serial.begin(9600);
41
42 k_init(2, 0, 0); // 1 task, 0 semaphores, 0 messaegQueues */
45 k_start(); /* start krnl timer speed 1 milliseconds*/
46
47 Serial.println("If you see this then krnl didnt start :-( ");
48}
49
50void loop() {}
51
52/***** DEBUGGING PART - LED ON 8-12**********/
53/************************ DEBUG CALLBACK BREAKOUT PART ****************/
54// must be extern C ! its not mandatory to supply with these functions - only if you need
55
56extern "C" {
57
58 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
59 unsigned char led13;
60 void k_sem_clip(unsigned char nr, int i)
61 {
62 return;
63 if (nr == 2)
64 led13 |= 0x20;
65 }
66
67 void k_sem_unclip(unsigned char nr)
68 {
69 return;
70 if (nr == 2)
71 led13 = 0x00;
72 }
73
74
75 /* void k_send_Q_clip(unsigned char nr, int i) {} */
76
77 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
78 void k_breakout() // called every task shift from dispatcher
79 {
80 unsigned char c;
81 PORTB = (1 << pRun->nr); // arduino uno !! specific usage of PORTB
82 }
83 // for a MEGA you have to find another port :-)
84 // port K (adc8-15) seems feasible
85 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
86}
87
88
89
90
91
92/* k03
93 two tasks multitasing same priority
94*/
95
96#include <krnl.h>
97
98#define STKSIZE 100
99
100#define TASKPRIO 10
101
102char stak[STKSIZE], stak2[STKSIZE];
103struct k_t * pTask, *pTask2;
104
105void task()
106{
107 int unusedStak;
108 while (1) {
109 k_eat_msec(10); // consume 10 millisec of CPU time
110 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
111 }
112}
113
114
115void task2()
116{
117 int unusedStak;
118 while (1) {
119 k_eat_msec(3); // consume 10 millisec of CPU time
120 k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
121 }
122}
123
124
125void setup() {
126 // for debugging
127 for (int i = 8; i < 14; i++)
128 pinMode(i, OUTPUT);
129
130 Serial.begin(9600);
131
132 k_init(2, 0, 0); // 1 task, 0 semaphores, 0 messaegQueues */
135 k_start(); /* start krnl timer speed 1 milliseconds*/
136
137 Serial.println("If you see this then krnl didnt start :-( ");
138}
139
140void loop() {}
141
142/***** DEBUGGING PART - LED ON 8-12**********/
143/************************ DEBUG CALLBACK BREAKOUT PART ****************/
144// must be extern C ! its not mandatory to supply with these functions - only if you need
145
146extern "C" {
147
148 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
149 unsigned char led13;
150 void k_sem_clip(unsigned char nr, int i)
151 {
152 return;
153 if (nr == 2)
154 led13 |= 0x20;
155 }
156
157 void k_sem_unclip(unsigned char nr)
158 {
159 return;
160 if (nr == 2)
161 led13 = 0x00;
162 }
163
164
165 /* void k_send_Q_clip(unsigned char nr, int i) {} */
166
167 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
168 void k_breakout() // called every task shift from dispatcher
169 {
170 unsigned char c;
171 PORTB = (1 << pRun->nr); // arduino uno !! specific usage of PORTB
172 }
173 // for a MEGA you have to find another port :-)
174 // port K (adc8-15) seems feasible
175 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
176}
177
178
179
180
181
182/* k04
183 * as k03 but now task has higher priority so it can take cpu from task2 when needed :-)
184*/
185
186#include <krnl.h>
187
188#define STKSIZE 100
189
190#define TASKPRIO 10
191
192char stak[STKSIZE], stak2[STKSIZE];
193struct k_t * pTask, *pTask2;
194
195void task()
196{
197 int unusedStak;
198 while (1) {
199 k_eat_msec(10); // consume 10 millisec of CPU time
200 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
201 }
202}
203
204
205void task2()
206{
207 int unusedStak;
208 while (1) {
209 k_eat_msec(3); // consume 10 millisec of CPU time
210 k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
211 }
212}
213
214
215void setup() {
216 // for debugging
217 for (int i = 8; i < 14; i++)
218 pinMode(i, OUTPUT);
219
220 Serial.begin(9600);
221
222 k_init(2, 0, 0); // 1 task, 0 semaphores, 0 messaegQueues */
224 pTask2 = k_crt_task(task2, TASKPRIO+1, stak2, STKSIZE); // +1 == lower priority
225 k_start(); /* start krnl timer speed 1 milliseconds*/
226
227 Serial.println("If you see this then krnl didnt start :-( ");
228}
229
230void loop() {}
231
232/***** DEBUGGING PART - LED ON 8-12**********/
233/************************ DEBUG CALLBACK BREAKOUT PART ****************/
234// must be extern C ! its not mandatory to supply with these functions - only if you need
235
236extern "C" {
237
238 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
239 unsigned char led13;
240 void k_sem_clip(unsigned char nr, int i)
241 {
242 return;
243 if (nr == 2)
244 led13 |= 0x20;
245 }
246
247 void k_sem_unclip(unsigned char nr)
248 {
249 return;
250 if (nr == 2)
251 led13 = 0x00;
252 }
253
254
255 /* void k_send_Q_clip(unsigned char nr, int i) {} */
256
257 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
258 void k_breakout() // called every task shift from dispatcher
259 {
260 unsigned char c;
261 PORTB = (1 << pRun->nr); // arduino uno !! specific usage of PORTB
262 }
263 // for a MEGA you have to find another port :-)
264 // port K (adc8-15) seems feasible
265 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
266}
267
268
269
270
271
272/* k05
273 Critical region by semaphore
274 task update data and task2 use them
275
276*/
277
278#include <krnl.h>
279
280#define STKSIZE 100
281
282#define TASKPRIO 10
283
284char stak[STKSIZE], stak2[STKSIZE];
285struct k_t * pTask, *pTask2, *sem1;
286
287volatile char reg = 0;
288
289void task()
290{
291 int res;
292 while (1) {
293 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
294
295 DI(); // just for setting bit for critical region for osc
296 reg = 0x08;
297 PORTB = (1 << pRun->nr) | reg;
298 EI();
299
300 k_eat_msec(10); // consume 10 millisec of CPU time
301
302 DI();
303 reg = 0; // reset crit reg pin
304 PORTB = (1 << pRun->nr) | reg;
305 EI();
306
307 k_signal(sem1);
308
309 k_sleep(1);
310 k_eat_msec(3);
311 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
312 }
313}
314
315void task2()
316{
317 int res;
318 while (1) {
319 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 menans forever
320 DI(); // just for setting bit for critical region for osc
321 reg = 0x10;
322 PORTB = (1 << pRun->nr) | reg;
323 EI();
324
325 k_eat_msec(3); // consume 10 millisec of CPU time
326
327 DI();
328 reg = 0;
329 PORTB = (1 << pRun->nr) | reg;
330 EI();
331
332 k_signal(sem1);
333 k_sleep(1);
334 k_eat_msec(1);
335
336 k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
337 }
338}
339
340
341void setup() {
342 // for debugging
343 for (int i = 8; i < 14; i++)
344 pinMode(i, OUTPUT);
345
346 Serial.begin(9600);
347
348 k_init(2, 2, 0); // 2 task, 1 semaphores, 0 messaegQueues */
350 pTask2 = k_crt_task(task2, TASKPRIO, stak2, STKSIZE); // +1 == lower priority
351
352 sem1 = k_crt_sem(1, 10); // 1: start value, 10: max value (clipping)
353 k_start(); /* start krnl timer speed 1 milliseconds*/
354
355 Serial.println("If you see this then krnl didnt start :-( ");
356}
357
358void loop() {}
359
360/***** DEBUGGING PART - LED ON 8-12**********/
361/************************ DEBUG CALLBACK BREAKOUT PART ****************/
362// must be extern C ! its not mandatory to supply with these functions - only if you need
363
364extern "C" {
365
366 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
367 unsigned char led13;
368 ;
369 void k_sem_clip(unsigned char nr, int i)
370 {
371 return;
372 if (nr == 2)
373 led13 |= 0x20;
374 }
375
376 void k_sem_unclip(unsigned char nr)
377 {
378 return;
379 if (nr == 2)
380 led13 = 0x00;
381 }
382
383
384 /* void k_send_Q_clip(unsigned char nr, int i) {} */
385
386 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
387 void k_breakout() // called every task shift from dispatcher
388 {
389 unsigned char c;
390 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
391 }
392 // for a MEGA you have to find another port :-)
393 // port K (adc8-15) seems feasible
394 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
395}
396
397
398
399
400
401/* k06
402 Critical region by semaphore
403 task update data and task2 use them
404 task has higher priority than task 2
405
406*/
407
408#include <krnl.h>
409
410#define STKSIZE 100
411
412#define TASKPRIO 10
413
414char stak[STKSIZE], stak2[STKSIZE];
415struct k_t * pTask, *pTask2, *sem1;
416
417volatile char reg = 0;
418
419void task()
420{
421 int res;
422 while (1) {
423 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
424
425 DI(); // just for setting bit for critical region for osc
426 reg = 0x08;
427 PORTB = (1 << pRun->nr) | reg;
428 EI();
429
430 k_eat_msec(10); // consume 10 millisec of CPU time
431
432 DI();
433 reg = 0; // reset crit reg pin
434 PORTB = (1 << pRun->nr) | reg;
435 EI();
436
437 k_signal(sem1);
438
439 k_sleep(1);
440 k_eat_msec(3);
441 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
442 }
443}
444
445void task2() // lower prority than task above
446{
447 int res;
448 while (1) {
449 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 menans forever
450 DI(); // just for setting bit for critical region for osc
451 reg = 0x10;
452 PORTB = (1 << pRun->nr) | reg;
453 EI();
454
455 k_eat_msec(3); // consume 10 millisec of CPU time
456
457 DI();
458 reg = 0;
459 PORTB = (1 << pRun->nr) | reg;
460 EI();
461
462 k_signal(sem1);
463 k_sleep(1);
464 k_eat_msec(1);
465
466 k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
467 }
468}
469
470
471void setup() {
472 // for debugging
473 for (int i = 8; i < 14; i++)
474 pinMode(i, OUTPUT);
475
476 Serial.begin(9600);
477
478 k_init(2, 2, 0); // 2 task, 1 semaphores, 0 messaegQueues */
480 pTask2 = k_crt_task(task2, TASKPRIO+1, stak2, STKSIZE); // +1 == lower priority
481
482 sem1 = k_crt_sem(1, 10); // 1: start value, 10: max value (clipping)
483 k_start(); /* start krnl timer speed 1 milliseconds*/
484
485 Serial.println("If you see this then krnl didnt start :-( ");
486}
487
488void loop() {}
489
490/***** DEBUGGING PART - LED ON 8-12**********/
491/************************ DEBUG CALLBACK BREAKOUT PART ****************/
492// must be extern C ! its not mandatory to supply with these functions - only if you need
493
494extern "C" {
495
496 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
497 unsigned char led13;
498 ;
499 void k_sem_clip(unsigned char nr, int i)
500 {
501 return;
502 if (nr == 2)
503 led13 |= 0x20;
504 }
505
506 void k_sem_unclip(unsigned char nr)
507 {
508 return;
509 if (nr == 2)
510 led13 = 0x00;
511 }
512
513
514 /* void k_send_Q_clip(unsigned char nr, int i) {} */
515
516 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
517 void k_breakout() // called every task shift from dispatcher
518 {
519 unsigned char c;
520 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
521 }
522 // for a MEGA you have to find another port :-)
523 // port K (adc8-15) seems feasible
524 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
525}
526
527
528
529
530
531/* k07
532 Critical region by semaphore
533 task has higher priority than task 2
534
535*/
536
537#include <krnl.h>
538
539#define STKSIZE 110
540
541#define TASKPRIO 10
542
543char stak[STKSIZE], stak2[STKSIZE];
544struct k_t * pTask, *pTask2, *sem1;
545
546volatile char reg = 0;
547
548void task()
549{
550 int res;
551 while (1) {
552 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
553
554 DI(); // just for setting bit for critical region for osc
555 reg = 0x08;
556 PORTB = (1 << pRun->nr) | reg;
557 EI();
558
559 k_eat_msec(10); // consume 10 millisec of CPU time
560
561 DI();
562 reg = 0; // reset crit reg pin
563 PORTB = (1 << pRun->nr) | reg;
564
565 k_signal(sem1);
566
567 k_sleep(1);
568 k_eat_msec(3);
569 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
570 }
571}
572
573void task2() // same priority
574{
575 int res;
576 while (1) {
577 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 menans forever
578 DI(); // just for setting bit for critical region for osc
579 reg = 0x10;
580 PORTB = (1 << pRun->nr) | reg;
581 EI();
582
583 k_eat_msec(3); // consume 10 millisec of CPU time
584
585 DI();
586 reg = 0;
587 PORTB = (1 << pRun->nr) | reg;
588
589 k_signal(sem1);
590 k_sleep(1);
591 k_eat_msec(1);
592
593 k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
594 }
595}
596
597
598void setup() {
599 // for debugging
600 for (int i = 8; i < 14; i++)
601 pinMode(i, OUTPUT);
602
603 Serial.begin(9600);
604
605 k_init(2, 2, 0); // 2 task, 1 semaphores, 0 messaegQueues */
607 pTask2 = k_crt_task(task2, TASKPRIO, stak2, STKSIZE); // +1 == lower priority
608
609 sem1 = k_crt_sem(1, 10); // 1: start value, 10: max value (clipping)
610 k_start(); /* start krnl timer speed 1 milliseconds*/
611
612 Serial.println("If you see this then krnl didnt start :-( ");
613}
614
615void loop() {}
616
617/***** DEBUGGING PART - LED ON 8-12**********/
618/************************ DEBUG CALLBACK BREAKOUT PART ****************/
619// must be extern C ! its not mandatory to supply with these functions - only if you need
620
621extern "C" {
622
623 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
624 unsigned char led13;
625 ;
626 void k_sem_clip(unsigned char nr, int i)
627 {
628 return;
629 if (nr == 2)
630 led13 |= 0x20;
631 }
632
633 void k_sem_unclip(unsigned char nr)
634 {
635 return;
636 if (nr == 2)
637 led13 = 0x00;
638 }
639
640
641 /* void k_send_Q_clip(unsigned char nr, int i) {} */
642
643 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
644 void k_breakout() // called every task shift from dispatcher
645 {
646 unsigned char c;
647 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
648 }
649 // for a MEGA you have to find another port :-)
650 // port K (adc8-15) seems feasible
651 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
652}
653
654
655
656
657
658/* k08
659 Critical region by semaphore
660 task update data and task2 use them
661 task has higher priority than task 2
662
663*/
664
665#include <krnl.h>
666
667#define STKSIZE 100
668
669#define TASKPRIO 10
670
671char stak[STKSIZE], stak2[STKSIZE];
672struct k_t * pTask, *pTask2, *sem1;
673
674volatile char reg = 0;
675
676void task()
677{
678 int res;
679 while (1) {
680 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
681
682 DI(); // just for setting bit for critical region for osc
683 reg = 0x08;
684 PORTB = (1 << pRun->nr) | reg;
685 EI();
686
687 k_eat_msec(10); // consume 10 millisec of CPU time
688
689 DI();
690 reg = 0; // reset crit reg pin
691 PORTB = (1 << pRun->nr) | reg;
692
693 k_signal(sem1);
694
695 k_sleep(1);
696 k_eat_msec(3);
697 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
698 }
699}
700
701void task2() // lower prority than task above
702{
703 int res;
704 while (1) {
705 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 menans forever
706 DI(); // just for setting bit for critical region for osc
707 reg = 0x10;
708 PORTB = (1 << pRun->nr) | reg;
709 EI();
710
711 k_eat_msec(3); // consume 10 millisec of CPU time
712
713 DI();
714 reg = 0;
715 PORTB = (1 << pRun->nr) | reg;
716
717 k_signal(sem1);
718 k_sleep(1);
719 k_eat_msec(1);
720
721 k_sleep(20); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
722 }
723}
724
725
726void setup() {
727 // for debugging
728 for (int i = 8; i < 14; i++)
729 pinMode(i, OUTPUT);
730
731 Serial.begin(9600);
732
733 k_init(2, 2, 0); // 2 task, 1 semaphores, 0 messaegQueues */
735 pTask2 = k_crt_task(task2, TASKPRIO+1, stak2, STKSIZE); // +1 == lower priority
736
737 sem1 = k_crt_sem(1, 10); // 1: start value, 10: max value (clipping)
738 k_start(); /* start krnl timer speed 1 milliseconds*/
739
740 Serial.println("If you see this then krnl didnt start :-( ");
741}
742
743void loop() {}
744
745/***** DEBUGGING PART - LED ON 8-12**********/
746/************************ DEBUG CALLBACK BREAKOUT PART ****************/
747// must be extern C ! its not mandatory to supply with these functions - only if you need
748
749extern "C" {
750
751 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
752 unsigned char led13;
753 ;
754 void k_sem_clip(unsigned char nr, int i)
755 {
756 return;
757 if (nr == 2)
758 led13 |= 0x20;
759 }
760
761 void k_sem_unclip(unsigned char nr)
762 {
763 return;
764 if (nr == 2)
765 led13 = 0x00;
766 }
767
768
769 /* void k_send_Q_clip(unsigned char nr, int i) {} */
770
771 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
772 void k_breakout() // called every task shift from dispatcher
773 {
774 unsigned char c;
775 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
776 }
777 // for a MEGA you have to find another port :-)
778 // port K (adc8-15) seems feasible
779 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
780}
781
782
783
784
785
786/* k09
787
788 sampling with fixed frequency with timer on sempahore
789
790*/
791
792#include <krnl.h>
793
794#define STKSIZE 100
795
796#define TASKPRIO 10
797
798char stak[STKSIZE], stak2[STKSIZE];
799struct k_t * pTask, *pTask2, *sem1;
800
801volatile char reg = 0;
802
803void task()
804{
805 int res;
806
807 k_set_sem_timer(sem1, 10); // krnl signals every 10 msec
808
809 while (1) {
810 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
811 k_eat_msec(3);
812 }
813}
814
815
816void setup() {
817 // for debugging
818 for (int i = 8; i < 14; i++)
819 pinMode(i, OUTPUT);
820
821 Serial.begin(9600);
822
823 k_init(1, 1, 0); // 2 task, 1 semaphores, 0 messaegQueues */
825
826 sem1 = k_crt_sem(0, 10); // 1: start value, 10: max value (clipping)
827 k_start(); /* start krnl timer speed 1 milliseconds*/
828
829 Serial.println("If you see this then krnl didnt start :-( ");
830}
831
832void loop() {}
833
834/***** DEBUGGING PART - LED ON 8-12**********/
835/************************ DEBUG CALLBACK BREAKOUT PART ****************/
836// must be extern C ! its not mandatory to supply with these functions - only if you need
837
838extern "C" {
839
840 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
841 unsigned char led13;
842 ;
843 void k_sem_clip(unsigned char nr, int i)
844 {
845 return;
846 if (nr == 2)
847 led13 |= 0x20;
848 }
849
850 void k_sem_unclip(unsigned char nr)
851 {
852 return;
853 if (nr == 2)
854 led13 = 0x00;
855 }
856
857
858 /* void k_send_Q_clip(unsigned char nr, int i) {} */
859
860 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
861 void k_breakout() // called every task shift from dispatcher
862 {
863 unsigned char c;
864 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
865 }
866 // for a MEGA you have to find another port :-)
867 // port K (adc8-15) seems feasible
868 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
869}
870
871
872
873
874
875/* k10
876
877 sampling with fixed frequency with timer on sempahore
878 two tasks !
879*/
880
881#include <krnl.h>
882
883#define STKSIZE 200
884
885#define TASKPRIO 10
886
887char stak[STKSIZE], stak2[STKSIZE];
888struct k_t * pTask, *pTask2, *sem1, *sem2;
889
890volatile char reg = 0;
891
892void task()
893{
894 int res;
895
896 k_set_sem_timer(sem1, 15); // krnl signals every 10 msec
897
898 while (1) {
899 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
900 if (res == 0) {
901 DI();
902 reg = reg | 0x08; // reset crit reg pin
903 PORTB = (1 << pRun->nr) | reg;
904 EI();
905
906 k_eat_msec(4);
907
908 DI();
909 reg = reg & 0xf7; // reset crit reg pin
910 PORTB = (1 << pRun->nr) | reg;
911 EI();
912 }
913 }
914}
915
916void task2()
917{
918 int res;
919
920 k_set_sem_timer(sem2, 10); // krnl signals every 10 msec
921
922 while (1) {
923 res = k_wait(sem2, 0); // knock knock at sem1. timeout = 0 means forever
924 if (res == 0) {
925 DI(); // just for setting bit for critical region for osc
926 reg = reg | 0x10;
927 PORTB = (1 << pRun->nr) | reg;
928 EI();
929
930 k_eat_msec(3);
931
932 DI();
933 reg = reg & 0xef; // reset crit reg pin
934 PORTB = (1 << pRun->nr) | reg;
935 EI();
936 }
937 }
938}
939
940
941void setup() {
942 // for debugging
943 for (int i = 8; i < 14; i++)
944 pinMode(i, OUTPUT);
945
946 Serial.begin(9600);
947
948 k_init(2, 2, 0); // 2 task, 1 semaphores, 0 messageQueues */
951 sem1 = k_crt_sem(0, 0); // 1: start value, 10: max value (clipping)
952 sem2 = k_crt_sem(0, 0); // 1: start value, 10: max value (clipping)k_start(); /* start krnl timer speed 1 milliseconds*/
953
954 k_start();
955 Serial.println("If you see this then krnl didnt start :-( ");
956}
957
958void loop() {}
959
960/***** DEBUGGING PART - LED ON 8-12**********/
961/************************ DEBUG CALLBACK BREAKOUT PART ****************/
962// must be extern C ! its not mandatory to supply with these functions - only if you need
963
964extern "C" {
965
966 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
967 unsigned char led13;
968
969 void k_sem_clip(unsigned char nr, int i)
970 {
971 return;
972 if (nr == 2)
973 led13 |= 0x20;
974 }
975
976 void k_sem_unclip(unsigned char nr)
977 {
978 return;
979 if (nr == 2)
980 led13 = 0x00;
981 }
982
983
984 /* void k_send_Q_clip(unsigned char nr, int i) {} */
985
986 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
987 void k_breakout() // called every task shift from dispatcher
988 {
989 unsigned char c;
990 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
991 }
992 // for a MEGA you have to find another port :-)
993 // port K (adc8-15) seems feasible
994 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
995}
996
997
998
999
1000
1001/* k10
1002
1003 sampling with fixed frequency with timer on sempahore
1004 two tasks !
1005*/
1006
1007#include <krnl.h>
1008
1009#define STKSIZE 200
1010
1011#define TASKPRIO 10
1012
1013char stak[STKSIZE], stak2[STKSIZE];
1014struct k_t * pTask, *pTask2, *sem1, *sem2;
1015
1016volatile char reg = 0;
1017
1018void task()
1019{
1020 int res;
1021
1022 k_set_sem_timer(sem1, 15); // krnl signals every 10 msec
1023
1024 while (1) {
1025 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
1026 if (res == 0) {
1027 DI();
1028 reg = reg | 0x08; // reset crit reg pin
1029 PORTB = (1 << pRun->nr) | reg;
1030 EI();
1031
1032 k_eat_msec(4);
1033
1034 DI();
1035 reg = reg & 0xf7; // reset crit reg pin
1036 PORTB = (1 << pRun->nr) | reg;
1037 EI();
1038 }
1039 }
1040}
1041
1042void task2()
1043{
1044 int res;
1045
1046 k_set_sem_timer(sem2, 10); // krnl signals every 10 msec
1047
1048 while (1) {
1049 res = k_wait(sem2, 0); // knock knock at sem1. timeout = 0 means forever
1050 if (res == 0) {
1051 DI(); // just for setting bit for critical region for osc
1052 reg = reg | 0x10;
1053 PORTB = (1 << pRun->nr) | reg;
1054 EI();
1055
1056 k_eat_msec(3);
1057
1058 DI();
1059 reg = reg & 0xef; // reset crit reg pin
1060 PORTB = (1 << pRun->nr) | reg;
1061 EI();
1062 }
1063 }
1064}
1065
1066
1067void setup() {
1068 // for debugging
1069 for (int i = 8; i < 14; i++)
1070 pinMode(i, OUTPUT);
1071
1072 Serial.begin(9600);
1073
1074 k_init(2, 2, 0); // 2 task, 1 semaphores, 0 messageQueues */
1077 sem1 = k_crt_sem(0, 0); // 1: start value, 10: max value (clipping)
1078 sem2 = k_crt_sem(0, 0); // 1: start value, 10: max value (clipping)k_start(); /* start krnl timer speed 1 milliseconds*/
1079
1080 k_start();
1081 Serial.println("If you see this then krnl didnt start :-( ");
1082}
1083
1084void loop() {}
1085
1086/***** DEBUGGING PART - LED ON 8-12**********/
1087/************************ DEBUG CALLBACK BREAKOUT PART ****************/
1088// must be extern C ! its not mandatory to supply with these functions - only if you need
1089
1090extern "C" {
1091
1092 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
1093 unsigned char led13;
1094
1095 void k_sem_clip(unsigned char nr, int i)
1096 {
1097 return;
1098 if (nr == 2)
1099 led13 |= 0x20;
1100 }
1101
1102 void k_sem_unclip(unsigned char nr)
1103 {
1104 return;
1105 if (nr == 2)
1106 led13 = 0x00;
1107 }
1108
1109
1110 /* void k_send_Q_clip(unsigned char nr, int i) {} */
1111
1112 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
1113 void k_breakout() // called every task shift from dispatcher
1114 {
1115 unsigned char c;
1116 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
1117 }
1118 // for a MEGA you have to find another port :-)
1119 // port K (adc8-15) seems feasible
1120 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
1121}
1122
1123
1124
1125
1126// 220216 -
1127#include <krnl.h>
1128
1129
1130struct k_t *pTask; // pointer to task descriptor
1131
1132// stak to be used by task
1133#define STK 150
1134unsigned char taskStak[STK];
1135
1136void t1 ()
1137{
1138 int cnt = 0;
1139
1140 while (1) // your task loop - forever
1141 {
1142 Serial.println(cnt++);
1143 k_sleep(500);
1144 }
1145}
1146
1147void setup ()
1148{
1149 int res;
1150 Serial.begin (115200);
1151 while (!Serial);
1152 Serial.println ("k01myfirsttask");
1153
1154 pinMode (13, OUTPUT); // for debug
1155
1156 k_init (1, 0, 0); // init with space for one task
1157 // ^------- number of message queues
1158 // ^--------- number of semaphores
1159 // ^------- number of tasks
1160 // RETURNS 0 is all went ok
1161
1162 // priority low number higher priority than higher number
1163 pTask = k_crt_task (t1, 10, taskStak, STK); // t1 as task, priority 10, 100 B stak
1164 // ^-- array used for stak
1165 // ^--- stak size in bytes
1166 // ^---------- task priority 1 is highest
1167 // ^------------- function to be used as body for tas
1168 // return NULL ptr if something went wrong
1169
1170 res = k_start (1); // 1 milli sec tick speed ALWAYS Parameter is ignored
1171 // you will never return from k_start
1172 // if you come here is it bq krnl has not started due to an error
1173 // ret vakue is negative and is a count of initalisation errors like
1174 // no slot for tasks etc
1175 // see krnl.c approx line ++1270
1176
1177 Serial.print ("ups an error occured: ");
1178 Serial.println (res);
1179 while (1);
1180}
1181
1182void loop () {} // is NEVER used
1183
1184/*
1185 * README README
1186 * In task t1 we are waiting 500 msec in each loop by calling k_eat_msec
1187 * This is busy waiting so t1 is running on CPU all time
1188 * The debug k_break function below turn led13 on when dummy is running (dummey has pRun->nr == 0)
1189 * But led 13 never light up - meaning 100% usage of cpu :-(
1190 *
1191 * Changing from k_eat_msec(500) to k_sleep(500) in t1 we still are waiting 500 msec but now in passive mode
1192 * So try do remove comment from k_sleep and comment out k_eat_msec
1193 * Now you will observe that led13 is ON all time.
1194 * Why?
1195 * Because printing an integer takes nearly no time compared to sleeping in 500 msec
1196 * It you observe by a logic analyser on pin13 you will see it goes low for a very sjort amount of time and
1197 * then high for 500 msec. So we dont use the CPU for just waiting -
1198 *
1199 * 2)
1200 * Try to change k_eat_msec and k_sleep to (and no comment in from of no one ot them
1201 * k_eat_msec(500);
1202 * k_sleep(2000);
1203 *
1204 * Then will observe the led13 is off foo 500 msec (when printing and running k_eat_msec)
1205 * and led13 is ON for 2000 msec(when we are sleeping in k_sleep(2000)
1206 *
1207 * You can see when your are printing becasue the led marked TX is ON when the uno is doing serial printing
1208 */
1209
1210extern "C" {
1211
1212 void k_breakout() // called every task shift from dispatcher
1213 {
1214
1215
1216 if (pRun->nr == 0) // 0 is dummy task - the eater of excessive CPU when all user tasks are idling
1217 {
1218 PORTB = PORTB | B00100000; // led13 (bit 5) on let the rest be untouched
1219 }
1220 else {
1221 PORTB = PORTB & B11011111; // led13 off uno
1222 }
1223 }
1224}
1225
1226// on MEGA led13 is on PORTB bit 7. so use B10000000 instead of B00100000 and B011111111 instead of B11011111
1227//220216
1228#include <krnl.h>
1229
1230// A small krnl program with two independent tasks
1231// They run at same priority so krnl will do timeslicing between them
1232// Watch LED and Serial TX
1233
1234// NB only one task must use print if you dont protect the serial port by a critical section
1235
1236// This is a very basic rt progarm, but there might be some hidden "figures"
1237
1238// ?1: observe how much stak there is used
1239//
1240
1241#define STKSZ 200
1242
1243struct k_t *pt1, // pointer to hold reference
1244*pt2; // to taskdescriptor for t1 and t2
1245
1246unsigned char stak1[STKSZ], stak2[STKSZ];
1247
1248
1249volatile int i = 0;
1250void t1(void)
1251{
1252 while (1) {
1253
1254 Serial.println(i++);
1255 k_eat_msec(1000); // eat 1000 msec time
1256 //k_sleep(1000); // sleep for 1000 msec
1257
1258 } // lenght of ticks in millisec is specified in
1259} // k_start call called from setup - USE 1 msec :-)
1260
1261void t2(void)
1262{
1263 // and task body for task 2
1264 // runs independent of task t1
1265 while (1) {
1266 k_eat_msec(1000); // simulating algorithms running for 1 sec
1267 //k_sleep(1000); // sleep for 1 sec
1268 }
1269}
1270
1271void setup()
1272{
1273 Serial.begin(115200); // for output from task 1
1274 while (! Serial) ;
1275 Serial.println("k02twotasks");
1276
1277 pinMode(13, OUTPUT); // for debug - ON when dummy is running
1278
1279 /* using ananlyser D8 will be dummy running, D9 when first created task is running ,... */
1280 /* remember to change in k_breakout*/
1281 /* for (int i=8; i< 14; i++) { pinMode(i,OUTPUT); digitalWrite(i,LOW); } */
1282
1283
1284 // init krnl so you can create 2 tasks, no semaphores and no message queues
1285 k_init(2, 0, 0);
1286
1287 // two task are created
1288 // |------------ function used for body code for task
1289 // | |--------- priority (lower number= higher prio
1290 // | | |----- staksize for array s1
1291 // |-- array used for stak
1292 pt1 = k_crt_task(t1, 11, stak1, STKSZ);
1293 //pt2 = k_crt_task(t2, 11, stak2, STKSZ);
1294
1295
1296 // NB-1 remember an Arduino has only 2-8 kByte RAM
1297 // NB-2 remember that stak is used in function calls for
1298 // - return address
1299 // - registers stakked
1300 // - local variabels in a function
1301 // So having 200 Bytes of stak excludes a local variable like ...
1302 // int arr[400];
1303 // krnl call k_unused_stak returns size of unused stak
1304 // Both task has same priority so krnl will shift between the
1305 // tasks every 10 milli second (speed set in k_start)
1306
1307 k_start(); // start kernel with tick speed 1 milli seconds
1308}
1309
1310void loop() {
1311 /* loop will never be called */
1312}
1313
1314
1315
1316extern "C" {
1317
1318 void k_breakout() // called every task shift from dispatcher
1319 {
1320
1321
1322 if (pRun->nr == 0) // 0 is dummy task - the eater of excessive CPU when all user tasks are idling
1323 {
1324 PORTB = PORTB | B00100000; // led13 (bit 5) on let the rest be untouched
1325 }
1326 else {
1327 PORTB = PORTB & B11011111; // led13 off uno
1328 }
1329 /* using D8-D13 use following instead of teh code above*/
1330 /* PORTB = (1 << pRun->nr); */
1331 }
1332
1333}
1334
1335/*
1336 * README README
1337 * LED 13 will be ON when dummy is running and OFF when all other tasks are running
1338 * See k_breakout function above
1339 *
1340 * 0) Cleanup
1341 * CODE for task t1 and t2 to begin with - here is the code for teh two functions and
1342 * k_crt_task calls in setup - if you have changed it/played with the code
1343 *
1344 *
1345 *
1346 * void t1(void)
1347 * {
1348 * while (1) {
1349 *
1350 * Serial.println(i++);
1351 * k_eat_msec(1000); // eat 1000 msec time
1352 * //k_sleep(1000); // sleep for 1000 msec
1353 *
1354 * } // lenght of ticks in millisec is specified in
1355 * } // k_start call called from setup - USE 1 msec :-)
1356 *
1357 * void t2(void)
1358 * {
1359 * // and task body for task 2
1360 * // runs independent of task t1
1361 * while (1) {
1362 * k_eat_msec(1000); // simulating algorithms running for 1 sec
1363 * //k_sleep(1000); // sleep for 1 sec
1364 * }
1365 * }
1366 *
1367 * and in setup:
1368 *
1369 * pt1 = k_crt_task(t1, 11, STKSZ, stak1);
1370 * //pt2 = k_crt_task(t2, 11, STKSZ, stak2);
1371 *
1372 *
1373 ********************************
1374 *
1375 * 1) Run code. You will see LED13 is OFF
1376 * Why ? because t1 is running all the time
1377 *
1378 * 2) remove comment in front of k_sleep(1000) in t1
1379 * Now LED13 will be ON for 1sec and off for 1sec bq whenin k_sleep t1 is not in active Q
1380 * and dummy task will run
1381 *
1382 * You will see when LED13 is going OFF there is a short blink on TX LED.
1383 * This is because t1 is printing an int just after comming back from k_sleep(1000) and looping arounf in the while loop
1384 *
1385 * 3) Go back and comment out k_sleep in t1 and remove comment in front of pt2 = k_crt_task(t2 - so you will now have two tasks
1386 * Both are doing a k_eat_msec and t1 is also printing.
1387 * LED13 will never be ON.
1388 * TX LED will blink every 2 sec not every 1 sec
1389 * Why? because we all the time has two task wanting to use the CPU
1390 * So eating 1000 msec takes 2000 msec because they run 1 msec each and then do round robbin
1391 * So we are basicly wasting more than 99% of the CPU
1392 *
1393 * 4) In t1 and t2 comment out k_eat_msec and active (remove comment) from k_sleep
1394 * Now LED 13 will be ON all time (if looking in logic analyser you can see that LED 13 will be OFF very shortly when t1 is printing
1395 * and when t2 is leaving k_sleep and loop arouond in the while loop and again calling k_sleep)
1396 * you cant see it on LED13 with you eye bq it is so short in time
1397 * An now TX LED is blinking every 1 sec so task t1 is doing what we want it to do . print and sleep for 1 sec over and over
1398 *
1399 * Change from k_eat_msec to k_sleep
1400 * What do we see
1401 *
1402 * 5) Change task priority
1403 * Go back and comment out k_sleep in t1 and remove comment in front of pt2 = k_vcrt_task(t2 - so you will now have two tasks
1404 * Both are doing a k_eat_msec and t1 is also printing.
1405 * Change task t2 priority to 8
1406 * You will see t1 stops printg == stops running
1407 * Why ? because t2 has highest priority
1408 *
1409 *
1410 * ON when task t1 i in k_sleep(1000) then no load on CPU for 1sec
1411 * OFF when task t1 is either printing or eating CPU time in k_eat_msec(1000)
1412 * A guess i that printing takes less than 1 msec. so looptime will be 1+1000 [msec]
1413 *
1414 * 2) In function setup remove comment in front of creating of task t2 (pt2 = k_crt_task(t2,...
1415 *
1416 */
1417 //220216
1418 #include <krnl.h>
1419 // one task loops and blink
1420
1421
1422 // hint using k_sleep instead og k_eat_ticks
1423 // k_eat_ticks eat your cpu time
1424
1425 // k_eat_ticks is busy waiting meaning it is using cpu time
1426 // See in krnl.c approx line 597
1427 // In contradition k_sleep deactivate the calling task for the time given as parameter
1428 // and is reactivated (reinserted in the activeQ) after timeout
1429
1430 // ?: how much cputime does t2 used in one loop
1431 // ?: how much time does t1 use in one loop
1432 // ?: what will happen if you increase t1 priority to 9 ?
1433 // ?: why is t2 running in bursts
1434 // ?: Can you predict the minimum time it takes to k_eat_ticks(2000) if you do not know
1435 // what other tasks are doing (a:no)
1436 // ?: Can you predict minimu time it takes to k_sleep(2000); (a: yes)
1437
1438 struct k_t *p1, *p2;
1439 #define STK 110
1440
1441 unsigned char s1[STK], s2[STK];
1442
1443 void t1()
1444 {
1445 int v;
1446
1447 while (1) {
1448 k_eat_msec(2000); // burn of cpu time for 2000 ticks
1449 k_sleep(2000); // sleep - no cpu eat for 2000 ticks
1450 }
1451 }
1452
1453 void t2()
1454 {
1455 int i = 0;
1456 while (1) {
1457 digitalWrite(13, HIGH);
1458 k_sleep(50);
1459 digitalWrite(13, LOW);
1460 //k_sleep(50);
1461 //or
1462 k_eat_msec(50);
1463 }
1464 // do we keep up in pace ?
1465 }
1466
1467
1468 void setup()
1469 {
1470 int res;
1471 Serial.begin(115200);
1472 while (! Serial) ;
1473 pinMode(13, OUTPUT);
1474
1475 k_init(2, 0, 0); // init with space for one task
1476 // |--- no of mg Queues (0)
1477 // |----- no of semaphores (0)
1478 // |------- no of tasks (2)
1479
1480 // priority low number higher priority than higher number
1481 p1 = k_crt_task(t1, 10, s1,STK); // t1 as task, priority 9, 100 B stak
1482 p2 = k_crt_task(t2, 10, s2,STK); // t2 as task, priority 10, 100 B stak
1483
1484 Serial.println("bef start");
1485 res = k_start(); // 1 milli sec tick speed
1486 // you will never return from k_start
1487 Serial.print("ups an error occured: "); Serial.println(res);
1488 while (1) ;
1489 }
1490
1491 void loop() {}
1492
1493//220216
1494#include <krnl.h>
1495//
1496// busy waiting all the way around - like using ya old delay
1497//
1498
1499// Set t1 priority to 9 == highest priority
1500// What will happen ? What do you see on the led and the measurements
1501// REALTIME ?
1502//
1503// gives a guess how cpu time is used in krnl "dummy time eating"
1504
1505struct k_t *p1, *p2;
1506
1507#define SS 110
1508unsigned char s1[SS], s2[SS];
1509
1510
1511void t1()
1512{
1513 int v;
1514
1515 while (1) {
1516 k_eat_msec(2000); // eat time for 2000 ticks so mimic cpu usage == 2000 msec
1517 }
1518}
1519
1520unsigned long tStart,tStop;
1521void t2()
1522{
1523 int i = 0;
1524 while (1) {
1525 Serial.println("start");
1526 tStart = k_millis();
1527 for (int i=0; i < 10 ; i++) { // 10 loops of 100 milliseconds == 1 second ! ?
1528 digitalWrite(13, HIGH);
1529 k_eat_msec(50);
1530 digitalWrite(13, LOW);
1531 k_eat_msec(50);
1532 }
1533 tStop = k_millis();
1534 Serial.print((tStop-tStart)/1000.0);
1535 Serial.print(" sec ");
1536 Serial.println("Did it take 1 second ???- not - why ");
1537 // hint task t1 ies eating 50% of cputime
1538 // the have same priority to you share cpu 50/50
1539 // so it will approx take 100 msec to execut k_eat_msec(50)
1540 }
1541}
1542
1543
1544void setup()
1545{
1546 int res;
1547 Serial.begin(115200);
1548 while (! Serial) ;
1549 pinMode(13, OUTPUT);
1550
1551 k_init(2, 0, 0); // init with space for one task
1552 // |--- no of mg Queues (0)
1553 // |----- no of semaphores (0)
1554 // |------- no of tasks (2)
1555
1556 // priority low number higher priority than higher number
1557 p1 = k_crt_task(t1, 10,s1,SS); // t1 as task, priority 9, 100 B stak
1558 p2 = k_crt_task(t2, 10, s2,SS); // t2 as task, priority 10, 100 B stak
1559
1560 Serial.println("bef start");
1561 res = k_start(); // 1 milli sec tick speed
1562 // you will never return from k_start
1563 Serial.print("ups an error occured: "); Serial.println(res);
1564 while (1) ;
1565}
1566
1567void loop() {}
1568//220216
1569#include <krnl.h>
1570
1571#define STK 110
1572struct k_t *p1, *p2, *sem1, *sem2;
1573
1574char st1[STK], st2[STK];
1575
1576// HERE WE WILL LIGNT ON LED IF OVERFLOW ON sem1 == tperiodic is behind
1577
1578int x = 0;
1581{
1582 // simple periodic sampler/controller/...
1583 k_set_sem_timer(sem1, 200);
1584
1585 while (1) {
1586 k_wait(sem1, 0);
1587
1588 k_eat_msec(140); // we eat cpu time
1589
1590 Serial.print(x++);
1591 Serial.print(" nr of clip on sem1 ");
1592
1593 DI(); // silencio disable interrupt
1594 clipp = sem1->clip;
1595 EI();
1596
1597 Serial.println(clipp);
1598
1599 // reset bit 5 LED13 if there has been an overflow on the semaphore
1600 DI();
1601 PORTB &= B11011111; // reset bit 5 == led13 on uno (on mega its bit7) 0x80 or B10000000
1602 EI();
1603 }
1604}
1605
1606
1607// sem->clip
1608
1610{
1611 while (1) {
1612 k_eat_msec( 600 ); // we eat between 30 and 200 msec of time
1613 k_sleep(1000); // and sleep for 500 msec
1614 }
1615}
1616
1618
1619void setup()
1620{
1621
1622 for (int i = 8; i < 14; i++) {
1623 pinMode(i, OUTPUT);
1624 digitalWrite(i, LOW);
1625 }
1626
1627 Serial.begin(115200);
1628
1629 k_init(2, 1, 0); // init with space for three tasks
1630
1631 // priority low number higher priority than higher number
1632 //Task 1
1633 p1 = k_crt_task(tperiodic, 10, st1, STK);
1634
1635 //Task 2
1636 p2 = k_crt_task(tnoise, 11 , st2, STK);
1637
1638 sem1 = k_crt_sem(0, 1);
1639
1640 err = k_start(); // 1 milli sec tick speed
1641
1642 Serial.print("start error ");
1643 Serial.print(err); // if error is in -1 to -20 its because you need to adjust in k_init
1644
1645}
1646
1647
1648// LED13 will go ON if overflow på semaphore sem1
1649// YOU can see nr of clip/saturatino situation in the printotu (terminal)
1650
1651// FOr tnoise:
1652// prio = 11 no overflow bq tperodic has highest prio
1653// prio =10 overflow willl occur bq tnoise is eating 600 msec and therefore share CPU
1654// 50/50 with tperiodic so eating 140 msec in every 200 msec period can take up to 280 msec(guessing) and therfore its are being
1655// tnoise prio < 10 makes even worse
1656
1657// Hack in tperiodic: switch off led 13 by PORTB = .... so we can observe reoccurence of clip
1658
1659
1660
1661
1662void loop() {}
1663
1664
1665extern "C" {
1666
1667 void k_sem_clip(unsigned char nr, int nrClip)
1668 {
1669 PORTB = 0x20; //led13
1670 /* mega PORTB=0x80; // bit 7 */
1671 }
1672}
1673//220216
1674#include <krnl.h>
1675
1676#define STK 110
1677struct k_t *p1, *p2, *sem1, *sem2;
1678
1679char st1[STK], st2[STK];
1680
1681void tperiodic()
1682{
1683 // simple periodic sampler/controller/...
1684 k_set_sem_timer(sem1, 100);
1685
1686 while (1) {
1687 k_wait(sem1, 0);
1688 k_eat_msec(70); // we eat 70% of cpu time
1689 }
1690}
1691
1692
1693void tnoise()
1694{
1695 while (1) {
1696 k_eat_msec( random(30, 200) ); // we eat between 30 and 200 msec of time
1697 k_sleep(500); // and sleep for 500 msec
1698 }
1699}
1700
1701int err;
1702
1703void setup()
1704{
1705 for (int i = 8; i < 14; i++) // using PORTB 0..5: d8..d13
1706 pinMode(i, OUTPUT);
1707 Serial.begin(115200);
1708
1709 k_init(2, 1, 0); // init with space for three tasks
1710
1711 // priority low number higher priority than higher number
1712 //Task 1
1713 p1 = k_crt_task(tperiodic, 10, st1, STK); // t1 as task, priority 10, 100 B stak
1714 //Task 2
1715 p2 = k_crt_task(tnoise, 11 , st2, STK); // t1 as task, priority 10, 100 B stak
1716
1717 sem1 = k_crt_sem(0,5);
1718
1719 err = k_start(); // 1 milli sec tick speed
1720 Serial.print("start error ");
1721 Serial.print(err);
1722
1723}
1724
1725void loop() {}
1726
1727
1728extern "C" {
1729
1730 void k_breakout() // called every task shift from dispatcher
1731 {
1732 PORTB = (1 << pRun->nr);
1733 // on MEGA use PORTA
1734 }
1735}
1736
1737// D8 ON dummy eating cpu
1738// D9 ON Task 1 (the first created
1739// D10 ON Task 2
1740// ...
1741// only one led ON at a time
1742//220216
1743#include <krnl.h>
1744// one task loops and blink
1745// k_wait on a semaphore ensures proper timing
1746
1747// task2 is using partly k_eat_ticks in the loop
1748// Try to lower tasl2 priority to 11 and see what happens
1749//?: what do you observe ?
1750// hint k_eat_ticks mimic cpu usage so if a task uses 2000 ticks cpu time then it should not
1751// have high(est) priority because lower priority task will then starve: not getting cpu time
1752//
1753// If you as starting point gives all same prioriryt there is a high chance taht all will more or less get
1754// what the need.
1755
1756// even better is to give high priority task (like sampling and control) a high priority
1757//
1758// you can mimic high cpu usage for task1 with insertion of a k_eat_ticks in the code below (is commented out)
1759
1760// The commented out eat uses 90 ticks so task1 will use 90 out of 100 (the time in loop) of the CPU
1761// or 90% of cpu power ...
1762// Beware of high prority task using a lot of cpu power
1763// life is life
1764
1765// ?: what will happen if equal priorities and the k_eat_ticks(90) in task1 ?
1766// when task2 is u´ni the k_eat_ticks(2000) then it will be in competition with task1
1767// the have same priority so they will share cpu time (round robbin)
1768// So it will take 180 ticks for task1 to execute k_eat_ticks(90) and at same time task2 will et 90 ticks
1769//
1770// At the same time the krnl signals to semaphore s1 every 100 ticks. But a loop will take 180 ticks. So
1771// will will come behind with 80 ticks for every loop(when task2 i in k_eat_ticks(2000)
1772
1773// you can see than k_Semval will never pass 50. This is because k_crt_sem is called with 50 as max.
1774//
1775// ?: can you model it ?
1776
1777
1778struct k_t *p1, *p2 , *s1;
1779
1780
1782
1784void task1()
1785{
1786
1787 //let krnl send a signal to the semaphore every 100 ticks
1788 // ensure real time capabilities
1789
1790 k_set_sem_timer(s1, 200);
1791
1792 while (1) {
1793
1794 loopCnt++;
1795
1796
1797 // play with second parameter: timeout value 0, -1, pos value
1798 // 2nd parm, 0: wait forever,
1799 // pos num: timeout
1800 // neg num : we will not just only eat a signal if one is already present
1801 // second parameter is timeout: 0: wait forever if needed, -1 : no wait at all, pos int wat up until <value> ticks
1802
1803
1804 // Question are we behind the period : timer generated signal to semaphore did occur before we entered the wait call waiting
1805 // on next tick
1806 //
1807 // so return values:
1808 // 0: we came before signal so we has been sleeping a bit - so we did arrive before the timer generated signal too the semaphore
1809 // we are NOT behind
1810
1811 // 1: there was a signal(key) waiting on us - we did eat it - but we arrived after signal - we were behind ...
1812
1813 // -1: did not get a signal before timeout (if it was k_wait(s1,22) : we will at most 22 ticks before timeout
1814
1815 // -2: we will not wait and there was no signal for us: k_wait(s1,-1)
1816
1817
1818
1819 er2 = k_wait(s1, 100);
1820
1821
1822 Serial.print(loopCnt);
1823
1824 Serial.print(" - ret from k_wait: "); Serial.println(er2);
1825
1826
1827 k_eat_msec(100);
1828
1829 }
1830}
1831
1832
1833void task2()
1834{
1835 unsigned int loopNrCpy;
1836 unsigned long tt;
1837 while (1) {
1838
1839 k_sleep(200); // just eating time
1840 k_eat_msec(150); // nasty !!! yo are requesting a heavy load on the processor
1841 }
1842}
1843
1844
1845#define STK 110
1846char a1[STK], a2[STK];
1847
1848void setup()
1849{
1850 int res;
1851 Serial.begin(115200);
1852 while (! Serial) ;
1853 for (int i = 8 ; i < 14; i++) {
1854 pinMode(i, OUTPUT);
1855 digitalWrite(i, LOW);
1856 }
1857
1858 k_init(2, 1, 0); // init with space for two tasks and one semaphore
1859 // |--- no of mg Queues (0)
1860 // |----- no of semaphores (0)
1861 // |------- no of tasks (2)
1862
1863 // priority low number higher priority than higher number
1864 p1 = k_crt_task(task1, 10, a1, STK); // task1 as task, priority 10, 100 B stak
1865 p2 = k_crt_task(task2, 11, a2, STK); // task2 as task, priority 11 == lower than t1, 100 B stak
1866
1867 s1 = k_crt_sem(0, 1); // crt sem
1868
1869 res = k_start(); // 1 milli sec tick speed
1870 // you will never return from k_start
1871 Serial.print("ups an error occured: "); Serial.println(res);
1872 while (1) ;
1873}
1874
1875// TRY TO SET PRIORITIES EQUAL
1876// TRY TO SET task2 higher thatn t1 (priority) stil at right time in task1 ?
1877
1878void loop() {}
1879
1880
1881extern "C" {
1882 void k_breakout() // called every task shift from dispatcher
1883 {
1884 PORTB = (1 << pRun->nr);
1885 // on MEGA use PORTA
1886 }
1887}
1888// 220216
1889#include <krnl.h>
1890
1891
1892struct k_t *p1, *p2, *s1, *semmutex;
1893
1894// shared data
1895struct shDataTp {
1896 int v;
1897 int counter;
1898};
1899
1900struct shDataTp sharedData = {0, 0};
1901
1902volatile int noDataDelivered = 0;
1903
1904
1905void saveDataInCritRegion(int v) // save data from critical region protected by a semaphore
1906{
1907 k_wait(semmutex, 0);
1908 {
1909 sharedData.v = v;
1910 sharedData.counter ++;
1911
1912 }
1914}
1915
1916int saveDataInCritRegionNoWait(int v) // picjk up data from critical region protected by a semaphore
1917{
1918 int x;
1919 x = k_wait(semmutex, -1);
1920
1921 if (0 <= x) { // yes
1922 sharedData.v = v;
1923 sharedData.counter ++;
1925 }
1926
1927 return x; // 1: ok we had to wait, 1: ok no wait, -1: timeout, -2: no wait and we wil not wait (k_wait(<sem>,-1))
1928}
1929
1930
1931
1933{
1934 struct shDataTp tmp;
1935 k_wait(semmutex, 0);
1936
1937 k_eat_msec(70); // to block region some time so teh other cant get it at once
1938 sharedData.counter--;
1939 tmp = sharedData;
1940
1942 return tmp;
1943}
1944
1945// the sampler task
1946
1947
1948void t1()
1949{
1950 int v;
1951
1952 k_set_sem_timer(s1, 100);
1953
1954 while (1) {
1955
1956 k_wait(s1, 0); //wait until a kick comes
1957
1958 v = analogRead(A0); // just to get some noise
1959 if (0 > saveDataInCritRegionNoWait(v)) { // or saveDataInCritRegion(v); if you can afford to wait - may become late
1960 DI();
1962 EI();
1963 }
1964 }
1965}
1966
1967void t2()
1968{
1969 int ll;
1970 static struct shDataTp v;
1971 while (1) {
1972
1973
1974 k_sleep(300);
1976 Serial.print(v.v);
1977 Serial.print(" ");
1978 Serial.print(v.counter);
1979 DI();
1980 ll = noDataDelivered;
1981 EI();
1982 Serial.print(" nodata dlv ");
1983 Serial.println(ll);
1984 } // do we keep up in pace ?
1985}
1986
1987#define STK 150
1988char a1[STK], a2[STK];
1989
1990void setup()
1991{
1992 int res;
1993 Serial.begin(115200);
1994 while (! Serial) ;
1995 pinMode(13, OUTPUT);
1996
1997 k_init(2, 2, 0); // init with space for one task
1998 // |--- no of mg Queues (0)
1999 // |----- no of semaphores (0)
2000 // |------- no of tasks (2)
2001
2002 // priority low number higher priority than higher number
2003 p1 = k_crt_task(t1, 10, a1, STK); // t1 as task, priority 10, 100 B stak
2004 p2 = k_crt_task(t2, 10, a2, STK); // t1 as task, priority 10, 100 B stak
2005
2006 s1 = k_crt_sem(0, 10);
2007
2008 semmutex = k_crt_sem(1, 10); // must be 1 otherwise no one can come inside
2009
2010 Serial.println("bef start");
2011 res = k_start(); // 1 milli sec tick speed
2012 // you will never return from k_start
2013 Serial.print("ups an error occured: "); Serial.println(res);
2014 while (1) ;
2015}
2016
2017void loop() {}
2018//220116
2019
2020#include <krnl.h>
2021
2022#define STK 150
2023char a1[STK], a2[STK];
2024
2025#define TASKPRIO 10
2026
2027
2028struct k_t * pTask1, *pTask2;
2029
2031
2032int dataBufForMsgQ[10]; // 10 ints,..
2033
2035
2036volatile int t2Missed = 0, t2Hit = 0;;
2037
2038
2039
2040// mutSem for protecting Serial print
2041
2042void task1()
2043{
2044 int i = 0;
2045 char res;
2046 int lI, lII;
2047
2048 k_set_sem_timer(timedSem1, 80); // 100 tick aka 100 msec realtime signal from krnl
2049
2050 while (1) {
2051
2052 k_wait(timedSem1, 0); // wait untilkick - realtime
2053
2054 i++;
2055 res = k_send(msgQ, &i);
2056
2057 k_eat_msec(20);
2058
2059 k_wait(mutSem, 0);
2060 {
2061 if (0 <= res) {
2062 Serial.print("1: did deliver "); Serial.println(i);
2063 }
2064 else {
2065 Serial.print("1: no deliver:>>>>>>>>>>>>>>>>>< "); Serial.println(i);
2066 }
2067 }
2069 k_eat_msec(2);
2070 }
2071}
2072
2073void task2()
2074{
2075 char res;
2076 int ii, lostM;
2077 k_set_sem_timer(timedSem2, 100); // 100 tick aka 100 msec realtime signal from krnl
2078
2079 while (1) {
2080
2081 k_wait(timedSem2, 0);
2082
2083 k_wait(mutSem, 0);
2084 Serial.println("2: bef rcv");
2086
2087
2088 res = k_receive(msgQ, &ii, 0, &lostM);
2089
2090 k_wait(mutSem, 0);
2091 {
2092 Serial.print("2: received "); Serial.print( ii);
2093 Serial.print(" lost: "); Serial.println(lostM);
2094 }
2096 }
2097}
2098
2099void setup() {
2100 Serial.begin(115200);
2101 delay(2000);
2102
2103 Serial.println("just bef init part");
2104
2105 k_init(2, 3, 1); // 2 task, 1 semaphores, 0 messaegQueues */
2106
2107 msgQ = k_crt_send_Q (10, sizeof(int), dataBufForMsgQ); // 10 elements of size
2108
2109 pTask1 = k_crt_task(task1, 15, a1, STK);
2110 pTask2 = k_crt_task(task2, 15 , a2, STK);
2111
2112 timedSem1 = k_crt_sem(0, 1); // 1: start value, 10: max value (clipping)
2113 timedSem2 = k_crt_sem(0, 1); // 1: start value, 10: max value (clipping)
2114
2115 mutSem = k_crt_sem(1, 1); // 1: start value, 10: max value (clipping)
2116
2117 Serial.println("just bef k_start");
2118
2119 k_start(); /* start krnl timer speed 1 milliseconds*/
2120
2121 Serial.println("If you see this then krnl didnt start :-( ");
2122}
2123
2124void loop() {}
2125#include <krnl.h>
2126
2127// LED13 on i dummy is runningg
2128
2129struct k_t *p1, *p2, *p3;
2130
2131#define STK 110
2132char st1[STK], st2[STK], st3[STK];
2133
2134// LED 13 not used from user space bq we use led for indicating dummy i srunning
2135// when dummy is running it indicates enough cpu power
2136// if dummy is not running for a longer time you may have problems ....
2137void t1()
2138{
2139 while (1) {
2140
2141 Serial.print(pRun->nr);
2142 Serial.println(" I am running");
2143 k_eat_msec_time(500); // you are running
2144 Serial.println("dummy is now running");
2145 k_sleep(2000); // you are NOT running so dummmy is running
2146 }
2147}
2148
2149void setup()
2150{
2151
2152 Serial.begin(115200);
2153 pinMode(13, OUTPUT); // for debug
2154
2155 k_init(3, 0, 0); // init with space for three tasks
2156
2157 // priority low number higher priority than higher number
2158 p1 = k_crt_task(t1, 10, st1, STK); // t1 as task, priority 10, 100 B stak
2159 p2 = k_crt_task(t1, 11, st2, STK); // t1 as task, priority 10, 100 B stak
2160// p3 = k_crt_task(t1, 12, st3, STK); // t1 as task, priority 10, 100 B stak
2161
2162 k_start(); // 1 milli sec tick speed
2163}
2164
2165void loop() {}
2166
2167/*
2168 #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
2169 for (int i = 8; i < 8+6; i++)
2170 pinMode(i, OUTPUT); // PORTB
2171
2172 #elif defined (__AVR_ATmega2560__) || defined (__AVR_ATmega1280__) || defined(__AVR_ATmega2561__)
2173 for (int i = 22; i < 22+6; i++)
2174 pinMode(i, OUTPUT); // PORTA
2175 #endif
2176
2177*/
2178extern "C" {
2179
2180 void k_breakout() // called every task shift from dispatcher
2181 {
2182 // https://arduino.stackexchange.com/questions/19892/list-of-arduino-board-preprocessor-defines
2183
2184 // FOR UNO
2185
2186#if defined (ARDUINO_AVR_UNO)
2187
2188 if (pRun->nr == 0)
2189 {
2190 PORTB = PORTB | B00100000; // led13 (bit 5) on let the rest be untouched
2191 }
2192 else {
2193 PORTB = PORTB & B11011111; // led off uno
2194 }
2195#endif
2196
2197#if ( defined (ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) )
2198 if (pRun->nr == 0)
2199 {
2200 PORTB = PORTB | B10000000; // led13 (bit 7) on let the rest be untouched
2201 }
2202 else {
2203 PORTB = PORTB & B01111111; // led off mega
2204 }
2205#endif
2206
2207 }
2208}
2209
2210
2211/* or just LED13 if dummy ...
2212
2213 YOu can test for board by #ifdef ARDUINO_AVR_UNO etc
2214 see list below
2215
2216 AVR_ADK
2217 AVR_BT
2218 AVR_DUEMILANOVE
2219 AVR_ESPLORA
2220 AVR_ETHERNET
2221 AVR_FIO
2222 AVR_GEMMA
2223 AVR_LEONARDO
2224 AVR_LILYPAD
2225 AVR_LILYPAD_USB
2226 AVR_MEGA
2227 AVR_MEGA2560
2228 AVR_MICRO
2229 AVR_MINI
2230 AVR_NANO
2231 AVR_NG
2232 AVR_PRO
2233 AVR_ROBOT_CONTROL
2234 AVR_ROBOT_MOTOR
2235 AVR_UNO
2236 AVR_YUN
2237
2238 both: pinMode(13,OUTPUT);
2239 uno mega
2240
2241 if (pRun->nr == 0)
2242 PORTB = PORTB | B00100000; // led on uno
2243 | B10000000; // mega
2244
2245 else
2246
2247 PORTB = PORTB & B11011111; // led off uno
2248 & B01111111; / mega
2249
2250 mega
2251
2252*/
2253
2254/*
2255
2256 Suggested PORTS TO USE
2257
2258 UNO
2259 pin port
2260 8 PB0
2261 9 PB1
2262 10 PB2
2263 11 PB3
2264 12 PB4
2265 13 PB5 LED13
2266 PB6 and 7 etc not to be used !
2267
2268
2269 MEGA
2270 pin port
2271 78 PA0
2272 77 PA1
2273 76 PA2
2274 75 PA3
2275 74 PA4
2276 73 PA5
2277 72 PA6
2278 71 PA7
2279 13 PB7 LED13
2280
2281 MICRO
2282 8 PB4
2283 9 PB5
2284 10 PB6
2285 11 PB7
2286 13 PC7 LED13
2287
2288 NANO
2289 D8 PD0
2290 D9 PD1
2291 D2 PD2
2292 D3 PD3
2293 D4 PD4
2294 D5 PD5
2295 D6 PD6
2296 D7 PD7
2297 13 PB5 LED13
2298
2299 PRO MINI
2300 2 PD2
2301 3 PD3
2302 4 PD4
2303 5 PD5
2304 6 PD6
2305 13 PB5 LED13
2306
2307 * */
2308//220216
2309#include <krnl.h>
2310
2311#define STK 110
2312struct k_t *p1, *p2, *p3;
2313char st1[STK], st2[STK], st3[STK];
2314
2316{
2317 while (1) {
2318 k_eat_msec(pRun->nr * 100); // tasks has 1,2,3 so mul by 100 gives 100msec,...
2319 k_sleep(1000);
2320 }
2321}
2322
2323void setup()
2324{
2325
2326 Serial.begin(115200);
2327
2328 for (int i = 8; i < 14; i++) // using PORTB 0..5: d8..d13
2329 pinMode(i, OUTPUT);
2330 /* MEGA PORTA (int i=22; i < 30; i++) pinMode(i,OUTPUT); */
2331
2332 k_init(3, 0, 0); // init with space for three tasks2
2333
2334 // priority low number higher priority than higher number
2335 //Task 1
2336 p1 = k_crt_task(tgeneric, 10, st1, STK); // t1 as task, priority 10, 100 B stak
2337 //Task 2
2338 p2 = k_crt_task(tgeneric, 11, st2, STK); // t1 as task, priority 10, 100 B stak
2339 //Task 3
2340 p3 = k_crt_task(tgeneric, 12, st3, STK); // t1 as task, priority 10, 100 B stak
2341
2342 k_start(); // 1 milli sec tick speed
2343}
2344
2345void loop() {}
2346
2347extern "C" {
2348
2349 void k_breakout() // called every task shift from dispatcher
2350 {
2351 PORTB = (1 << pRun->nr); // D8: dummy running, D9 first task created running,...
2352 // on MEGA use PORTA
2353 }
2354}
2355
2356// D8 ON dummy eating cpu
2357// D9 ON Task 1 (the first created
2358// D10 ON Task 2
2359// ...
2360// only one led ON at a time
2361// dont use led 13 for othe stuff bq it s cleared her
2362// can be fixed - just ask me
#define STKSIZE
Definition k02.ino:8
char stak[100]
Definition k02.ino:12
unsigned char led13
Definition k02.ino:59
volatile char reg
Definition k05.ino:17
unsigned char taskStak[150]
#define STK
struct k_t * pTask
char stak1[STKSZ]
volatile int i
struct k_t * pt2
struct k_t * pt1
char stak2[STKSZ]
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
unsigned long tStart
#define SS
unsigned long tStop
void tnoise()
struct k_t * sem1
char st2[110]
int x
int err
char st1[110]
void tperiodic()
struct k_t * sem2
int clipp
char a2[110]
int er2
int loopCnt
char a1[110]
int pendingWait
void task2()
void task1()
struct shDataTp sharedData
struct shDataTp getDataInCritRegion(void)
struct k_t * semmutex
volatile int noDataDelivered
struct k_t * mutSem
Definition k08isrsem.ino:19
struct k_t * timedSem1
Definition k08isrsem.ino:21
#define TASKPRIO
Definition k08isrsem.ino:14
volatile int t2Missed
Definition k08isrsem.ino:23
struct k_t * timedSem2
Definition k08isrsem.ino:21
volatile int t2Hit
Definition k08isrsem.ino:23
struct k_t * pTask1
Definition k08isrsem.ino:17
struct k_t * pTask2
Definition k09msgq.ino:11
int dataBufForMsgQ[10]
Definition k09msgq.ino:15
struct k_msg_t * msgQ
Definition k09msgq.ino:13
unsigned long k_millis(void)
return no of millisec sincs start NB no leap seconds - its clean
Definition krnl.c:1247
int k_signal(struct k_t *sem)
Signal a semaphore w eventually task shift.
Definition krnl.c:636
void k_eat_msec(unsigned int eatTime)
eat milliseconds - to mimik time consuming code
Definition krnl.c:246
struct k_t * pRun
Definition krnl.c:148
char k_receive(struct k_msg_t *pB, void *el, int timeout, int *lost_msg)
Definition krnl.c:991
int k_sleep(int time)
let task sleep for a number of milliseconds
Definition krnl.c:445
int k_wait(struct k_t *sem, int timeout)
stand wait on semaphore call with timeout facility
Definition krnl.c:683
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_set_sem_timer(struct k_t *sem, int val)
attach a periodic timer to a semaphore, to be used for realtime
Definition krnl.c:586
char k_send(struct k_msg_t *pB, void *el)
Definition krnl.c:944
struct k_t * k_crt_sem(int init_val, int maxvalue)
change task priority and reinserts it in task Q and do a task shift
Definition krnl.c:544
int k_init(int nrTask, int nrSem, int nrMsg)
Definition krnl.c:1108
struct k_msg_t * k_crt_send_Q(int nr_el, int el_size, void *pBuf)
Definition krnl.c:841
int k_start()
Definition krnl.c:1149
#define DI()
Definition krnl.h:478
#define EI()
Definition krnl.h:479
char st3[110]
struct k_t * p3
void tgeneric()
void tnoise()
void setup()
Definition manyinone.ino:35
void k_breakout()
Definition manyinone.ino:78
void t2(void)
void t1()
void tperiodic()
void k_sem_clip(unsigned char nr, int i)
Definition manyinone.ino:60
void task()
Definition manyinone.ino:15
void saveDataInCritRegion(int v)
void k_sem_unclip(unsigned char nr)
Definition manyinone.ino:67
#define STKSZ
void tgeneric()
struct shDataTp getDataInCritRegion(void)
int saveDataInCritRegionNoWait(int v)
void task2()
Definition manyinone.ino:25
void task1()
void loop()
Definition manyinone.ino:50
volatile int cnt
struct k_t * task
struct k_t * t1
Definition krnlgen.ino:3
struct k_t * t2
Definition krnlgen.ino:3
Definition krnl.h:323
unsigned char nr
Definition krnl.h:327