@@ -31,7 +31,7 @@ using namespace utest::v1;
31
31
using ble::vendor::cordio::CordioHCIDriver;
32
32
using ble::vendor::cordio::CordioHCITransportDriver;
33
33
34
- extern ble::vendor::cordio::CordioHCIDriver& ble_cordio_get_hci_driver ();
34
+ extern ble::vendor::cordio::CordioHCIDriver & ble_cordio_get_hci_driver ();
35
35
36
36
#if CORDIO_ZERO_COPY_HCI
37
37
#error [NOT_SUPPORTED] Test not relevant for zero copy hci.
@@ -42,15 +42,18 @@ namespace vendor {
42
42
namespace cordio {
43
43
44
44
struct CordioHCIHook {
45
- static CordioHCIDriver& get_driver () {
45
+ static CordioHCIDriver &get_driver ()
46
+ {
46
47
return ble_cordio_get_hci_driver ();
47
48
}
48
49
49
- static CordioHCITransportDriver& get_transport_driver () {
50
+ static CordioHCITransportDriver &get_transport_driver ()
51
+ {
50
52
return get_driver ()._transport_driver ;
51
53
}
52
54
53
- static void set_data_received_handler (void (*handler)(uint8_t *, uint8_t )) {
55
+ static void set_data_received_handler (void (*handler)(uint8_t *, uint8_t ))
56
+ {
54
57
get_transport_driver ().set_data_received_handler (handler);
55
58
}
56
59
};
@@ -75,22 +78,24 @@ static const uint32_t WAITING_FLAGS =
75
78
76
79
static rtos::EventFlags event_channel;
77
80
78
- static void signal_flag (uint32_t flag) {
81
+ static void signal_flag (uint32_t flag)
82
+ {
79
83
if (!(event_channel.get () & flag)) {
80
84
event_channel.set (flag);
81
85
}
82
86
}
83
87
84
- uint32_t wait_for_event () {
88
+ uint32_t wait_for_event ()
89
+ {
85
90
// clear reception flags
86
91
uint32_t flags = event_channel.get ();
87
92
event_channel.clear (flags & ~RESET_RECEIVED_FLAG);
88
93
89
94
return event_channel.wait_any (
90
- WAITING_FLAGS,
91
- /* timeout */ RESET_COMMAND_TIMEOUT,
92
- /* clear */ false
93
- );
95
+ WAITING_FLAGS,
96
+ /* timeout */ RESET_COMMAND_TIMEOUT,
97
+ /* clear */ false
98
+ );
94
99
}
95
100
96
101
//
@@ -104,7 +109,8 @@ uint32_t wait_for_event() {
104
109
#define RESET_PACKET_LENGTH (1 + HCI_EVT_HDR_LEN + RESET_PARAMETER_LENGTH)
105
110
#define RESET_STATUS_INDEX 6
106
111
107
- static bool is_reset_event (const uint8_t * data, uint16_t len) {
112
+ static bool is_reset_event (const uint8_t *data, uint16_t len)
113
+ {
108
114
if (len != RESET_PACKET_LENGTH) {
109
115
return false ;
110
116
}
@@ -135,7 +141,8 @@ static bool is_reset_event(const uint8_t* data, uint16_t len) {
135
141
return true ;
136
142
}
137
143
138
- static void hci_driver_rx_reset_handler (uint8_t * data, uint8_t len) {
144
+ static void hci_driver_rx_reset_handler (uint8_t *data, uint8_t len)
145
+ {
139
146
enum packet_state_t {
140
147
WAITING_FOR_PACKET_TYPE,
141
148
WAITING_FOR_HEADER_COMPLETE,
@@ -166,19 +173,20 @@ static void hci_driver_rx_reset_handler(uint8_t* data, uint8_t len) {
166
173
167
174
case WAITING_FOR_HEADER_COMPLETE:
168
175
case WAITING_FOR_DATA_COMPLETE: {
169
- uint16_t step = std::min ((uint16_t ) len, (uint16_t ) (packet_length - position));
176
+ uint16_t step = std::min ((uint16_t ) len, (uint16_t )(packet_length - position));
170
177
memcpy (packet + position, data, step);
171
- position+= step;
178
+ position += step;
172
179
data += step;
173
180
len -= step;
174
181
175
182
if (reception_state == WAITING_FOR_HEADER_COMPLETE &&
176
- position == packet_length
177
- ) {
183
+ position == packet_length
184
+ ) {
178
185
reception_state = WAITING_FOR_DATA_COMPLETE;
179
186
packet_length += packet[HCI_EVT_HDR_LEN];
180
187
}
181
- } break ;
188
+ }
189
+ break ;
182
190
183
191
184
192
// dead end; we never exit from the error state; just asignal it again.
@@ -192,7 +200,7 @@ static void hci_driver_rx_reset_handler(uint8_t* data, uint8_t len) {
192
200
}
193
201
194
202
bool packet_complete = (reception_state == WAITING_FOR_DATA_COMPLETE) &&
195
- (position == packet_length);
203
+ (position == packet_length);
196
204
197
205
if (packet_complete) {
198
206
if (is_reset_event (packet, packet_length)) {
@@ -217,9 +225,10 @@ static uint8_t reset_cmd[] = {
217
225
0 // parameter length
218
226
};
219
227
220
- void test_reset_command () {
221
- CordioHCIDriver& driver = CordioHCIHook::get_driver ();
222
- CordioHCITransportDriver& transport_driver = CordioHCIHook::get_transport_driver ();
228
+ void test_reset_command ()
229
+ {
230
+ CordioHCIDriver &driver = CordioHCIHook::get_driver ();
231
+ CordioHCITransportDriver &transport_driver = CordioHCIHook::get_transport_driver ();
223
232
224
233
driver.initialize ();
225
234
@@ -235,9 +244,10 @@ void test_reset_command() {
235
244
236
245
#define EXPECTED_CONSECUTIVE_RESET 10
237
246
238
- void test_multiple_reset_command () {
239
- CordioHCIDriver& driver = CordioHCIHook::get_driver ();
240
- CordioHCITransportDriver& transport_driver = CordioHCIHook::get_transport_driver ();
247
+ void test_multiple_reset_command ()
248
+ {
249
+ CordioHCIDriver &driver = CordioHCIHook::get_driver ();
250
+ CordioHCITransportDriver &transport_driver = CordioHCIHook::get_transport_driver ();
241
251
242
252
driver.initialize ();
243
253
@@ -260,14 +270,16 @@ Case cases[] = {
260
270
Case (" Test multiple reset commands" , test_multiple_reset_command)
261
271
};
262
272
263
- utest::v1::status_t greentea_test_setup (const size_t number_of_cases) {
273
+ utest::v1::status_t greentea_test_setup (const size_t number_of_cases)
274
+ {
264
275
GREENTEA_SETUP (15 , " default_auto" );
265
276
return verbose_test_setup_handler (number_of_cases);
266
277
}
267
278
268
279
Specification specification (greentea_test_setup, cases, greentea_test_teardown_handler);
269
280
270
- int main () {
281
+ int main ()
282
+ {
271
283
return !Harness::run (specification);
272
284
}
273
285
#endif // CORDIO_ZERO_COPY_HCI
0 commit comments