blob: 65c59b83d8da58da2bf05d4906c580d43bdce40a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#ifndef _L1_TDMA_SCHED_H
#define _L1_TDMA_SCHED_H
#include <stdint.h>
/* TDMA scheduler */
/* The idea of this scheduler is that we have a circular buffer of buckets,
* where each bucket corresponds to one future TDMA frame [interrupt]. Each
* bucket contains of a list of callbacks which are executed when the bucket
* index reaches that particular bucket. */
#define TDMASCHED_NUM_FRAMES 25
#define TDMASCHED_NUM_CB 5
typedef int tdma_sched_cb(uint16_t p1, uint16_t p2);
/* A single item in a TDMA scheduler bucket */
struct tdma_sched_item {
tdma_sched_cb *cb;
uint16_t p1;
uint16_t p2;
};
/* A bucket inside the TDMA scheduler */
struct tdma_sched_bucket {
struct tdma_sched_item item[TDMASCHED_NUM_CB];
uint8_t num_items;
};
/* The scheduler itself, consisting of buckets and a current index */
struct tdma_scheduler {
struct tdma_sched_bucket bucket[TDMASCHED_NUM_FRAMES];
uint8_t cur_bucket;
};
/* Schedule an item at 'frame_offset' TDMA frames in the future */
int tdma_schedule(uint8_t frame_offset, tdma_sched_cb *cb, uint16_t p1, uint16_t p2);
/* Schedule a set of items starting from 'frame_offset' TDMA frames in the future */
int tdma_schedule_set(uint8_t frame_offset, const struct tdma_sched_item *item_set, uint8_t num_items);
/* Execute pre-scheduled events for current frame */
int tdma_sched_execute(void);
/* reset the scheduler; erase all scheduled items */
void tdma_sched_reset(void);
/* debug function: print number of entries of all TDMA buckets */
void tdma_sched_dump(void);
#endif /* _L1_TDMA_SCHED_H */
|