-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathp2G4_func_queue.h
113 lines (98 loc) · 2.62 KB
/
p2G4_func_queue.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright 2019 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef P2G4_FUNC_QUEUE_H
#define P2G4_FUNC_QUEUE_H
#include "bs_types.h"
#ifdef __cplusplus
extern "C"{
#endif
typedef void (*queable_f)(uint dev_nbr);
/**
* Functions (types of events) which can be queued
* Ordered by priority: last to first */
typedef enum {
State_None = 0,
Wait_Done,
Tx_End,
Tx_Packet_End,
Rx_CCA_meas,
RSSI_Meas,
Rx_Found,
Rx_Sync,
Rx_Header,
Rx_Payload,
Tx_Abort_Reeval,
Tx_Packet_Start,
Rx_Search_reeval,
Rx_Search_start,
Tx_Start, /* For a piggybacking/prelocked Rx to work without pretruncation, we need its Tx to start first */
N_funcs //Minor issue: one too many
} f_index_t;
//Note: We need to use these indexes, instead of just keeping the function pointers
//to be able to set the order between the functions
/* Queue element time */
typedef struct {
bs_time_t time; /* Simualted time when the call should be done */
f_index_t f_index; /* Function type to be called */
} fq_element_t;
/**
* @brief Initialize the function queue
*
* @param n_devs Number of devices we are connected to
*/
void fq_init(uint32_t n_devs);
/**
* Register which function will be called for a type of event
*
* @param index Type of event/function for which to register
* @param fptr Function pointer to call when that event is due
*/
void fq_register_func(f_index_t index, queable_f fptr);
/**
* Add (modify) an entry in the queue for a given device
*
* @param time When is the function meant to be run
* @parm index Which function to run
* @param dev_nbr For which device interface
*/
void fq_add(bs_time_t time, f_index_t index, uint32_t dev_nbr);
/**
* Get the simulated time, in microseconds, of the next scheduled function
*/
bs_time_t fq_get_next_time();
/**
* Call the next function in the queue
* Note: The function itself is left in the queue.
*/
void fq_call_next();
/**
* Find and update the next function which should be executed
*/
void fq_find_next();
/**
* Remove whichever entry may be queued for this interface
* (and find the next one)
*
* It is safe to call it on an interface which does not have anything queued
*
* Note that it is the responsibility of the user to either update an entry
* after it has triggered, or to remove it. Otherwise the same entry will
* stay on the top, being the next one all the time.
*
* @param dev_nbr Which device interface
*/
void fq_remove(uint32_t dev_nbr);
/**
* Free resources allocated by the function queue
*
* This must be called before exiting to clean up any memory allocated by the
* queue
*/
void fq_free();
#ifdef __cplusplus
}
#endif
#endif