krnl 1
Loading...
Searching...
No Matches
k09.ino
Go to the documentation of this file.
1
2/* k09
3
4 sampling with fixed frequency with timer on sempahore
5
6*/
7
8#include <krnl.h>
9
10#define STKSIZE 100
11
12#define TASKPRIO 10
13
15struct k_t * pTask, *pTask2, *sem1;
16
17volatile char reg = 0;
18
19void task()
20{
21 int res;
22
23 k_set_sem_timer(sem1, 10); // krnl signals every 10 msec
24
25 while (1) {
26 res = k_wait(sem1, 0); // knock knock at sem1. timeout = 0 means forever
27 k_eat_msec(3);
28 }
29}
30
31
32void setup() {
33 // for debugging
34 for (int i = 8; i < 14; i++)
35 pinMode(i, OUTPUT);
36
37 Serial.begin(9600);
38
39 k_init(1, 1, 0); // 2 task, 1 semaphores, 0 messaegQueues */
41
42 sem1 = k_crt_sem(0, 10); // 1: start value, 10: max value (clipping)
43 k_start(); /* start krnl timer speed 1 milliseconds*/
44
45 Serial.println("If you see this then krnl didnt start :-( ");
46}
47
48void loop() {}
49
50/***** DEBUGGING PART - LED ON 8-12**********/
51/************************ DEBUG CALLBACK BREAKOUT PART ****************/
52// must be extern C ! its not mandatory to supply with these functions - only if you need
53
54extern "C" {
55
56 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
57 unsigned char led13;
58 ;
59 void k_sem_clip(unsigned char nr, int i)
60 {
61 return;
62 if (nr == 2)
63 led13 |= 0x20;
64 }
65
66 void k_sem_unclip(unsigned char nr)
67 {
68 return;
69 if (nr == 2)
70 led13 = 0x00;
71 }
72
73
74 /* void k_send_Q_clip(unsigned char nr, int i) {} */
75
76 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
77 void k_breakout() // called every task shift from dispatcher
78 {
79 unsigned char c;
80 PORTB = (1 << pRun->nr) | reg; // arduino uno !! specific usage of PORTB
81 }
82 // for a MEGA you have to find another port :-)
83 // port K (adc8-15) seems feasible
84 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
85}
86
87
88
89
#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
void setup()
Definition k09.ino:32
void k_breakout()
Definition k09.ino:77
void k_sem_clip(unsigned char nr, int i)
Definition k09.ino:59
void task()
Definition k09.ino:19
void k_sem_unclip(unsigned char nr)
Definition k09.ino:66
void loop()
Definition k09.ino:48
struct k_t * pTask
volatile int i
char stak2[STKSZ]
struct k_t * sem1
#define TASKPRIO
Definition k08isrsem.ino:14
struct k_t * pTask2
Definition k09msgq.ino:11
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_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
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
int k_start()
Definition krnl.c:1149
struct k_t * task
Definition krnl.h:323
unsigned char nr
Definition krnl.h:327