krnl 1
Loading...
Searching...
No Matches
krnldebugled13.ino
Go to the documentation of this file.
1#include <krnl.h>
2
3// LED13 on i dummy is runningg
4
5struct k_t *p1, *p2, *p3;
6char st1[100], st2[100], st3[100];
7
8// LED 13 not used from user space bq we use led for indicating dummy i srunning
9// when dummy is running it indicates enough cpu power
10// if dummy is not running for a longer time you may have problems ....
11void t1()
12{
13 while (1) {
14
15 Serial.print(pRun->nr);
16 Serial.println(" I am running");
17 k_eat_msec_time(500); // you are running
18 Serial.println("dummy is now running");
19 k_sleep(2000); // you are NOT running so dummmy is running
20 }
21}
22
23void setup()
24{
25
26 Serial.begin(9600);
27 pinMode(13, OUTPUT); // for debug
28
29 k_init(3, 0, 0); // init with space for three tasks
30
31 // priority low number higher priority than higher number
32 p1 = k_crt_task(t1, 10, st1, 100); // t1 as task, priority 10, 100 B stak
33 p2 = k_crt_task(t1, 11, st2, 100); // t1 as task, priority 10, 100 B stak
34 p3 = k_crt_task(t1, 12, st3, 100); // t1 as task, priority 10, 100 B stak
35
36 k_start(1); // 1 milli sec tick speed
37}
38
39void loop() {}
40
41/*
42 #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
43 for (int i = 8; i < 8+6; i++)
44 pinMode(i, OUTPUT); // PORTB
45
46 #elif defined (__AVR_ATmega2560__) || defined (__AVR_ATmega1280__) || defined(__AVR_ATmega2561__)
47 for (int i = 22; i < 22+6; i++)
48 pinMode(i, OUTPUT); // PORTA
49 #endif
50
51*/
52extern "C" {
53
54 void k_breakout() // called every task shift from dispatcher
55 {
56 // https://arduino.stackexchange.com/questions/19892/list-of-arduino-board-preprocessor-defines
57
58 // FOR UNO
59
60#if defined (ARDUINO_AVR_UNO)
61
62 if (pRun->nr == 0)
63 {
64 PORTB = PORTB | B00100000; // led13 (bit 5) on let the rest be untouched
65 }
66 else {
67 PORTB = PORTB & B11011111; // led off uno
68 }
69#endif
70
71#if ( defined (ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) )
72 if (pRun->nr == 0)
73 {
74 PORTB = PORTB | B10000000; // led13 (bit 7) on let the rest be untouched
75 }
76 else {
77 PORTB = PORTB & B01111111; // led off mega
78 }
79#endif
80
81 }
82}
83
84
85/* or just LED13 if dummy ...
86
87 YOu can test for board by #ifdef ARDUINO_AVR_UNO etc
88 see list below
89
90 AVR_ADK
91 AVR_BT
92 AVR_DUEMILANOVE
93 AVR_ESPLORA
94 AVR_ETHERNET
95 AVR_FIO
96 AVR_GEMMA
97 AVR_LEONARDO
98 AVR_LILYPAD
99 AVR_LILYPAD_USB
100 AVR_MEGA
101 AVR_MEGA2560
102 AVR_MICRO
103 AVR_MINI
104 AVR_NANO
105 AVR_NG
106 AVR_PRO
107 AVR_ROBOT_CONTROL
108 AVR_ROBOT_MOTOR
109 AVR_UNO
110 AVR_YUN
111
112 both: pinMode(13,OUTPUT);
113 uno mega
114
115 if (pRun->nr == 0)
116 PORTB = PORTB | B00100000; // led on uno
117 | B10000000; // mega
118
119 else
120
121 PORTB = PORTB & B11011111; // led off uno
122 & B01111111; / mega
123
124 mega
125
126*/
127
128/*
129
130 Suggested PORTS TO USE
131
132 UNO
133 pin port
134 8 PB0
135 9 PB1
136 10 PB2
137 11 PB3
138 12 PB4
139 13 PB5 LED13
140 PB6 and 7 etc not to be used !
141
142
143 MEGA
144 pin port
145 78 PA0
146 77 PA1
147 76 PA2
148 75 PA3
149 74 PA4
150 73 PA5
151 72 PA6
152 71 PA7
153 13 PB7 LED13
154
155 MICRO
156 8 PB4
157 9 PB5
158 10 PB6
159 11 PB7
160 13 PC7 LED13
161
162 NANO
163 D8 PD0
164 D9 PD1
165 D2 PD2
166 D3 PD3
167 D4 PD4
168 D5 PD5
169 D6 PD6
170 D7 PD7
171 13 PB5 LED13
172
173 PRO MINI
174 2 PD2
175 3 PD3
176 4 PD4
177 5 PD5
178 6 PD6
179 13 PB5 LED13
180
181 * */
struct k_t * p1
Definition k03asleep.ino:22
struct k_t * p2
Definition k03asleep.ino:22
char st2[110]
char st1[110]
struct k_t * pRun
Definition krnl.c:148
int k_sleep(int time)
let task sleep for a number of milliseconds
Definition krnl.c:445
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
char st3[110]
void setup()
void k_breakout()
void t1()
struct k_t * p3
void loop()
struct k_t * t1
Definition krnlgen.ino:3
Definition krnl.h:323