forked from BabbleSim/ext_2G4_libPhyComv1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bs_pc_2G4.h
145 lines (129 loc) · 6.36 KB
/
bs_pc_2G4.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright 2018 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BS_COM_2G4_H
#define _BS_COM_2G4_H
#include "bs_pc_2G4_types.h"
#include "bs_pc_base.h"
#include <stddef.h>
#ifdef __cplusplus
extern "C"{
#endif
/**
* Note: 4 sets of functions are provided for devices to interact with the phy
* Although the provided functionality is very similar, each of these sets allow
* to quickly build different types of device HW models.
* Note that this functions do not change the underlying API/ABI to the phy.
*
* These sets are divided as follows:
* With vs without callbacks:
* With callbacks: (_c)
* The set with callbacks allows for simpler devices models.
* All phy-device protocol handshakes are hidden inside libCom calls.
* When a device decision is needed in the middle of a handshake, a
* callback in the device is called.
* But, registering the callbacks is optional, in which case either that
* device decision is assumed always positive (evaluation of an ongoing
* reception) or the functionality is just not used (abort reevaluation)
*
* With callbacks: (_nc):
* The device must handle on its own all possible responses from the
* phy and call the appropriate function afterwards to continue the
* handshakes.
*
* State-less vs with memory:
* State-less (_s) calls rely on the device keeping and owning the
* structure with the link state.
* The APi "with memory" is just a convenience, where the state is kept
* internally in libCom
*
* Note that calls to these 4 sets canNOT be mixed
*
* Note: Not all version have functions for the whole device-phy API.
*
* The functions which are blocking until a phy response is received are suffixed with _b.
* Except the initcom functions which are always blocking
*/
/*
* API with call-backs and memory
*/
/* Function prototype for the device callback mechanism to reevaluate the abort
* during Tx or Rx abort_s is the original one sent with the Tx or Rx request.
* Therefore the current time == abort_s.recheck_time
*
* Returns 0 if everything went ok, -1 otherwise (=> disconnect)
*/
typedef int (*dev_abort_reeval_f)(p2G4_abort_t* abort_s);
/* Function prototype for the device to evaluate if it wants to accept an
* incoming packet or not (doesn't like the sync word and or header)
* This function shall return 1 if it accepts the packet, 0 otherwise
*/
typedef int (*device_eval_rx_f)(p2G4_rx_done_t* rx_done, uint8_t *buff);
int p2G4_dev_initcom_c(uint d, const char* s, const char* p, dev_abort_reeval_f abort_f);
int p2G4_dev_req_rx_c_b(p2G4_rx_t *rx_s, p2G4_rx_done_t *rx_done_s, uint8_t **rx_buf, size_t buf_size, device_eval_rx_f fptr);
int p2G4_dev_req_RSSI_c_b(p2G4_rssi_t *RSSI_s, p2G4_rssi_done_t *RSSI_done_s);
int p2G4_dev_req_tx_c_b(p2G4_tx_t *tx_s, uint8_t *buf, p2G4_tx_done_t *tx_done_s);
int p2G4_dev_req_wait_c_b(pb_wait_t *wait_s);
void p2G4_dev_disconnect_c();
void p2G4_dev_terminate_c();
/*
* API without call-backs and memory
*/
int p2G4_dev_initcom_nc(uint d, const char* s, const char* p);
int p2G4_dev_req_tx_nc_b(p2G4_tx_t *tx_s, uint8_t *buf, p2G4_tx_done_t *tx_done_s);
int p2G4_dev_provide_new_tx_abort_nc_b(p2G4_abort_t * abort);
int p2G4_dev_req_rx_nc_b(p2G4_rx_t *rx_s, p2G4_rx_done_t *rx_done_s, uint8_t **rx_buf, size_t buf_size);
int p2G4_dev_rx_cont_after_addr_nc_b(bool accept);
int p2G4_dev_provide_new_rx_abort_nc_b(p2G4_abort_t * abort);
int p2G4_dev_req_RSSI_nc_b(p2G4_rssi_t *RSSI_s, p2G4_rssi_done_t *RSSI_done_s);
int p2G4_dev_req_wait_nc_b(pb_wait_t *wait_s);
void p2G4_dev_terminate_nc();
void p2G4_dev_disconnect_nc();
/*
* API without call-backs and without memory
*/
//in the communication with the device, are we in the middle of a transaction (!Nothing_2G4), and if so, what
typedef enum { Nothing_2G4 = 0, Tx_Abort_Reeval_2G4 , Rx_Abort_Reeval_2G4 , Rx_Header_Eval_2G4 } p2G4_t_ongoing_transaction_t;
typedef struct {
pb_dev_state_t pb_dev_state;
p2G4_t_ongoing_transaction_t ongoing; //just as a safety check against bugy devices (only used in the version without callbacks)
p2G4_tx_done_t *tx_done_s;
p2G4_rx_done_t *rx_done_s;
uint8_t **rxbuf;
size_t bufsize;
bool WeGotAddress;
} p2G4_dev_state_nc_t;
int p2G4_dev_initCom_s_nc(p2G4_dev_state_nc_t *p2G4_dev_st, uint d, const char* s, const char* p);
int p2G4_dev_req_tx_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, p2G4_tx_t *tx_s, uint8_t *buf, p2G4_tx_done_t *tx_done_s);
int p2G4_dev_provide_new_tx_abort_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, p2G4_abort_t * abort);
int p2G4_dev_req_rx_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, p2G4_rx_t *rx_s, p2G4_rx_done_t *rx_done_s, uint8_t **rx_buf, size_t bus_size);
int p2G4_dev_rx_cont_after_addr_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, bool accept);
int p2G4_dev_provide_new_rx_abort_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, p2G4_abort_t * abort);
int p2G4_dev_req_RSSI_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, p2G4_rssi_t *RSSI_s, p2G4_rssi_done_t *RSSI_done_s);
int p2G4_dev_req_wait_s_nc_b(p2G4_dev_state_nc_t *p2G4_dev_st, pb_wait_t *wait_s);
void p2G4_dev_terminate_s_nc(p2G4_dev_state_nc_t *p2G4_dev_st);
void p2G4_dev_disconnect_s_nc(p2G4_dev_state_nc_t *p2G4_dev_st);
/*
* API with call-backs and without memory
*/
typedef struct {
dev_abort_reeval_f abort_f;
pb_dev_state_t pb_dev_state;
} p2G4_dev_state_s_t;
int p2G4_dev_initcom_s_c(p2G4_dev_state_s_t *p2G4_dev_st, uint d, const char* s, const char* p, dev_abort_reeval_f fptr);
int p2G4_dev_req_tx_s_c_b(p2G4_dev_state_s_t *p2G4_dev_st, p2G4_tx_t *tx_s, uint8_t *buf, p2G4_tx_done_t *tx_done_s);
int p2G4_dev_req_tx_s_c(p2G4_dev_state_s_t *p2G4_dev_st, p2G4_tx_t *tx_s, uint8_t *buf);
int p2G4_dev_pick_txresp_s_c_b(p2G4_dev_state_s_t *p2G4_dev_st, p2G4_tx_done_t *tx_done_s);
int p2G4_dev_req_rx_s_c_b(p2G4_dev_state_s_t *p2G4_dev_st, p2G4_rx_t *rx_s, p2G4_rx_done_t *rx_done_s, uint8_t **rx_buf, size_t buf_size, device_eval_rx_f fptr);
int p2G4_dev_req_RSSI_s_c_b(p2G4_dev_state_s_t *p2G4_dev_st, p2G4_rssi_t *RSSI_s, p2G4_rssi_done_t *RSSI_done_s);
int p2G4_dev_req_wait_s_c_b(p2G4_dev_state_s_t *p2G4_dev_st, pb_wait_t *wait_s);
int p2G4_dev_req_wait_s_c(p2G4_dev_state_s_t *p2G4_dev_st, pb_wait_t *wait_s);
int p2G4_dev_pick_wait_resp_s_c_b(p2G4_dev_state_s_t *p2G4_dev_st);
void p2G4_dev_disconnect_s_c(p2G4_dev_state_s_t *p2G4_dev_st);
void p2G4_dev_terminate_s_c(p2G4_dev_state_s_t *p2G4_dev_st);
#ifdef __cplusplus
}
#endif
#endif