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