CF/BF - Fix HoTT telemetry.
[betaflight.git] / src / main / fc / fc_dispatch.c
blob5080f889119b9898a1f4bbf91f36c2057c9881fc
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdlib.h>
20 #include <stdint.h>
22 #include <platform.h>
24 #include "common/utils.h"
26 #include "drivers/system.h"
27 #include "fc/fc_dispatch.h"
29 static dispatchEntry_t *head = NULL;
30 static bool dispatchEnabled = false;
32 bool dispatchIsEnabled(void)
34 return dispatchEnabled;
37 void dispatchEnable(void)
39 dispatchEnabled = true;
42 void dispatchProcess(uint32_t currentTime)
44 for(dispatchEntry_t **p = &head; *p; ) {
45 if(cmp32(currentTime, (*p)->delayedUntil) < 0)
46 break;
47 // unlink entry first, so handler can replan self
48 dispatchEntry_t *current = *p;
49 *p = (*p)->next;
50 (*current->dispatch)(current);
54 void dispatchAdd(dispatchEntry_t *entry, int delayUs)
56 uint32_t delayedUntil = micros() + delayUs;
57 dispatchEntry_t **p = &head;
58 while(*p && cmp32((*p)->delayedUntil, delayedUntil) < 0)
59 p = &(*p)->next;
60 entry->next = *p;
61 *p = entry;