summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-02-27 21:20:42 +0100
committerHarald Welte <laforge@gnumonks.org>2010-02-27 21:20:42 +0100
commitc468741500790d975422b45f32333c92549dc397 (patch)
treede694fcaf4b62b228cf66248ec75bda42b5f6386
parentf6c0bba6dd2ef0bb87dedc6276c2c62285324f56 (diff)
explicitly terminate the TDMA scheduler set with SCHED_END_SET()
This has the advantage that any caller or other reference does not need to know the size of the set, which makes it simpler to use the sched_set as a constant initializer in some other const/static data structure.
-rw-r--r--src/target/firmware/include/layer1/tdma_sched.h8
-rw-r--r--src/target/firmware/layer1/sync.c9
-rw-r--r--src/target/firmware/layer1/tdma_sched.c20
3 files changed, 26 insertions, 11 deletions
diff --git a/src/target/firmware/include/layer1/tdma_sched.h b/src/target/firmware/include/layer1/tdma_sched.h
index 65c59b83..67676d34 100644
--- a/src/target/firmware/include/layer1/tdma_sched.h
+++ b/src/target/firmware/include/layer1/tdma_sched.h
@@ -38,7 +38,7 @@ struct tdma_scheduler {
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);
+int tdma_schedule_set(uint8_t frame_offset, const struct tdma_sched_item *item_set);
/* Execute pre-scheduled events for current frame */
int tdma_sched_execute(void);
@@ -49,4 +49,10 @@ void tdma_sched_reset(void);
/* debug function: print number of entries of all TDMA buckets */
void tdma_sched_dump(void);
+
+extern void tdma_end_set(uint16_t p1, uint16_t p2);
+#define SCHED_ITEM(x, y, z) { .cb = x, .p1 = y, .p2 = z }
+#define SCHED_END_FRAME() { .cb = NULL, .p1 = 0, .p2 = 0 }
+#define SCHED_END_SET() { .cb = &tdma_end_set, .p1 = 0, .p2 = 0 }
+
#endif /* _L1_TDMA_SCHED_H */
diff --git a/src/target/firmware/layer1/sync.c b/src/target/firmware/layer1/sync.c
index a4d48a57..001f995b 100644
--- a/src/target/firmware/layer1/sync.c
+++ b/src/target/firmware/layer1/sync.c
@@ -539,9 +539,6 @@ static int l1s_fbdet_resp(uint16_t p1, uint16_t attempt)
return 0;
}
-#define SCHED_ITEM(x, y, z) { .cb = x, .p1 = y, .p2 = z }
-#define SCHED_END_FRAME() { .cb = NULL, .p1 = 0, .p2 = 0 }
-
/* we don't really use this because we need to configure the fb_mode! */
static const struct tdma_sched_item fb_sched_set[] = {
SCHED_ITEM(l1s_fbdet_cmd, 0, 0), SCHED_END_FRAME(),
@@ -558,6 +555,7 @@ static const struct tdma_sched_item fb_sched_set[] = {
SCHED_ITEM(l1s_fbdet_resp, 0, 10), SCHED_END_FRAME(),
SCHED_ITEM(l1s_fbdet_resp, 0, 11), SCHED_END_FRAME(),
SCHED_ITEM(l1s_fbdet_resp, 0, 12), SCHED_END_FRAME(),
+ SCHED_END_SET()
};
void l1s_fb_test(uint8_t base_fn, uint8_t fb_mode)
@@ -575,7 +573,7 @@ void l1s_fb_test(uint8_t base_fn, uint8_t fb_mode)
#else
/* use the new scheduler 'set' and simply schedule the whole set */
/* WARNING: we cannot set FB_MODE_1 this way !!! */
- tdma_schedule_set(base_fn, fb_sched_set, ARRAY_SIZE(fb_sched_set));
+ tdma_schedule_set(base_fn, fb_sched_set);
#endif
}
@@ -882,12 +880,13 @@ static const struct tdma_sched_item nb_sched_set[] = {
SCHED_ITEM(l1s_nb_resp, 0, 1), SCHED_ITEM(l1s_nb_cmd, 0, 3), SCHED_END_FRAME(),
SCHED_ITEM(l1s_nb_resp, 0, 2), SCHED_END_FRAME(),
SCHED_ITEM(l1s_nb_resp, 0, 3), SCHED_END_FRAME(),
+ SCHED_END_SET()
};
void l1s_nb_test(uint8_t base_fn)
{
puts("Starting NB\n");
- tdma_schedule_set(base_fn, nb_sched_set, ARRAY_SIZE(nb_sched_set));
+ tdma_schedule_set(base_fn, nb_sched_set);
}
/* Interrupt handler */
diff --git a/src/target/firmware/layer1/tdma_sched.c b/src/target/firmware/layer1/tdma_sched.c
index 097e9a42..56174a90 100644
--- a/src/target/firmware/layer1/tdma_sched.c
+++ b/src/target/firmware/layer1/tdma_sched.c
@@ -32,6 +32,12 @@
#include <calypso/dsp.h>
+/* dummy function to mark end of set */
+void tdma_end_set(uint16_t p1, uint16_t p2)
+{
+
+}
+
static uint8_t wrap_bucket(uint8_t offset)
{
uint16_t bucket;
@@ -65,17 +71,21 @@ int tdma_schedule(uint8_t frame_offset, tdma_sched_cb *cb, uint16_t p1, uint16_t
}
/* 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)
+int tdma_schedule_set(uint8_t frame_offset, const struct tdma_sched_item *item_set)
{
struct tdma_scheduler *sched = &l1s.tdma_sched;
uint8_t bucket_nr = wrap_bucket(frame_offset);
- int i;
+ int i = 0;
- for (i = 0; i < num_items; i++) {
+ for (i = 0; 1; i++) {
const struct tdma_sched_item *sched_item = &item_set[i];
struct tdma_sched_bucket *bucket = &sched->bucket[bucket_nr];
+ if (sched_item->cb == &tdma_end_set) {
+ /* end of scheduler set, return */
+ break;
+ }
+
if (sched_item->cb == NULL) {
/* advance to next bucket (== TDMA frame) */
bucket_nr = wrap_bucket(++frame_offset);
@@ -90,7 +100,7 @@ int tdma_schedule_set(uint8_t frame_offset, const struct tdma_sched_item *item_s
memcpy(&bucket->item[bucket->num_items++], sched_item, sizeof(*sched_item));
}
- return num_items;
+ return i;
}
/* Execute pre-scheduled events for current frame */