Skip to content

Commit 8b9d39b

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1571 from ARMmbed/fhss_callback_update
Fhss callback update
2 parents db1ded0 + 316b007 commit 8b9d39b

File tree

10 files changed

+90
-147
lines changed

10 files changed

+90
-147
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,16 @@ void fhss_failed_list_free(fhss_structure_t *fhss_structure)
728728
}
729729
}
730730

731-
static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id)
731+
static void fhss_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
732732
{
733+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
734+
if (!fhss_structure) {
735+
return;
736+
}
733737
// State is already set
734738
if (fhss_structure->fhss_state == fhss_state) {
735739
tr_debug("Synch same state %u", fhss_state);
736-
return -1;
740+
return;
737741
}
738742

739743
if (fhss_state == FHSS_UNSYNCHRONIZED) {
@@ -747,12 +751,12 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
747751
// Do not synchronize to current pan
748752
if (fhss_structure->synch_panid == pan_id) {
749753
tr_debug("Synch same panid %u", pan_id);
750-
return -1;
754+
return;
751755
}
752756
if (fhss_structure->fhss_scramble_table == NULL) {
753757
if (fhss_generate_scramble_table(fhss_structure)) {
754758
tr_error("Failed to generate scramble table");
755-
return -1;
759+
return;
756760
}
757761
}
758762
uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api);
@@ -778,10 +782,11 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
778782
fhss_start_timer(fhss_structure, fhss_structure->synch_configuration.fhss_superframe_length, fhss_superframe_handler);
779783
} else {
780784
tr_error("Synch info not found");
781-
return -1;
785+
return;
782786
}
783787
}
784-
return 0;
788+
fhss_structure->fhss_state = fhss_state;
789+
return;
785790
}
786791

787792
static void fhss_destroy_scramble_table(fhss_structure_t *fhss_structure)
@@ -914,6 +919,42 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
914919
}
915920
}
916921

922+
static int16_t fhss_write_synch_info_callback(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time)
923+
{
924+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
925+
(void) frame_type_id;
926+
(void) tx_time;
927+
if (!fhss_structure) {
928+
return -1;
929+
}
930+
if (info_type == FHSS_PLAIN_SYNCH_INFO) {
931+
if (!info_ptr) {
932+
return -1;
933+
}
934+
fhss_beacon_build(fhss_structure, info_ptr);
935+
return FHSS_SYNCH_INFO_LENGTH;
936+
}
937+
return -1;
938+
}
939+
940+
static void fhss_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle)
941+
{
942+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
943+
if (!fhss_structure) {
944+
return;
945+
}
946+
if (waiting_ack == false) {
947+
fhss_change_to_rx_channel(fhss_structure);
948+
}
949+
// Buffer was successfully transmitted. Remove stored failure handle if exists.
950+
if (tx_completed == true) {
951+
fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle);
952+
if (fhss_failed_tx) {
953+
fhss_failed_handle_remove(fhss_structure, handle);
954+
}
955+
}
956+
}
957+
917958
int fhss_set_callbacks(fhss_structure_t *fhss_structure)
918959
{
919960
// Set external API
@@ -922,17 +963,16 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure)
922963
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback;
923964
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_callback;
924965
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
925-
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
966+
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_callback;
926967
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
927-
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
968+
fhss_structure->fhss_api->synch_state_set = &fhss_handle_state_set;
928969
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
929970
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
930-
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
971+
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_callback;
931972
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
932973
// Set internal API
933974
fhss_structure->update_channel = fhss_update_channel_callback;
934975
fhss_structure->update_superframe = fhss_superframe_callback;
935976
fhss_structure->read_superframe_timeout = fhss_get_sf_timeout_callback;
936-
fhss_structure->handle_state_set = fhss_handle_state_set;
937977
return 0;
938978
}

source/Service_Libs/fhss/fhss_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
152152
if (!fhss_structure) {
153153
return -1;
154154
}
155-
fhss_structure->handle_state_set(fhss_structure, FHSS_UNSYNCHRONIZED, 0);
155+
fhss_structure->fhss_api->synch_state_set(fhss_structure->fhss_api, FHSS_UNSYNCHRONIZED, 0);
156156
ns_dyn_mem_free(fhss_structure->ws);
157157
ns_dyn_mem_free(fhss_structure);
158158
fhss_structure = 0;

source/Service_Libs/fhss/fhss_common.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ typedef void fhss_update_superframe_cb(fhss_structure_t *fhss_structure);
4343
*/
4444
typedef uint32_t fhss_read_superframe_timeout_cb(fhss_structure_t *fhss_structure);
4545

46-
/**
47-
* @brief Set FHSS state.
48-
* @param fhss_structure FHSS structure.
49-
* @param fhss_state FHSS state to set.
50-
* @param pan_id Network PAN id.
51-
* @return 0 Success, -1 Failure.
52-
*/
53-
typedef int fhss_handle_state_set_cb(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id);
54-
5546
union fhss_conf {
5647
fhss_configuration_t fhss_configuration;
5748
fhss_ws_configuration_t fhss_ws_configuration;
@@ -121,7 +112,6 @@ struct fhss_structure
121112
fhss_update_channel_cb *update_channel; /**< Update listening channel */
122113
fhss_update_superframe_cb *update_superframe; /**< Update superframe */
123114
fhss_read_superframe_timeout_cb *read_superframe_timeout; /**< Read next FHSS superframe timeout length */
124-
fhss_handle_state_set_cb *handle_state_set; /**< Set FHSS state */
125115
};
126116

127117
fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer);

source/Service_Libs/fhss/fhss_mac_interface.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,6 @@ void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *sour
8989
}
9090
}
9191

92-
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle)
93-
{
94-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
95-
if (!fhss_structure) {
96-
return;
97-
}
98-
if (waiting_ack == false) {
99-
fhss_change_to_rx_channel(fhss_structure);
100-
}
101-
// Buffer was successfully transmitted. Remove stored failure handle if exists.
102-
if (tx_completed == true) {
103-
fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle);
104-
if (fhss_failed_tx) {
105-
fhss_failed_handle_remove(fhss_structure, handle);
106-
}
107-
}
108-
}
109-
11092
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type)
11193
{
11294
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
@@ -141,18 +123,6 @@ bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type)
141123
return true;
142124
}
143125

144-
void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
145-
{
146-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
147-
if (!fhss_structure) {
148-
return;
149-
}
150-
if (fhss_structure->handle_state_set) {
151-
fhss_structure->handle_state_set(fhss_structure, fhss_state, pan_id);
152-
}
153-
fhss_structure->fhss_state = fhss_state;
154-
}
155-
156126
uint32_t fhss_read_timestamp_cb(const fhss_api_t *api)
157127
{
158128
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
@@ -205,24 +175,6 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad
205175
return retry_period;
206176
}
207177

208-
int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time)
209-
{
210-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
211-
(void) frame_type_id;
212-
(void) tx_time;
213-
if (!fhss_structure) {
214-
return -1;
215-
}
216-
if (info_type == FHSS_PLAIN_SYNCH_INFO) {
217-
if (!info_ptr) {
218-
return -1;
219-
}
220-
fhss_beacon_build(fhss_structure, info_ptr);
221-
return FHSS_SYNCH_INFO_LENGTH;
222-
}
223-
return -1;
224-
}
225-
226178

227179
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks)
228180
{

source/Service_Libs/fhss/fhss_mac_interface.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
2222
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
2323
void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
24-
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
2524
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);
26-
void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
2725
uint32_t fhss_read_timestamp_cb(const fhss_api_t *api);
2826
uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
29-
int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time);
3027
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks);
3128

3229
#endif /* FHSS_MAC_INTERFACE_H_ */

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ static uint32_t fhss_ws_get_sf_timeout_callback(fhss_structure_t *fhss_structure
153153
return fhss_structure->fhss_conf.fhss_ws_configuration.fhss_uc_dwell_interval * 1000;
154154
}
155155

156-
static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id)
156+
static void fhss_ws_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
157157
{
158158
(void) pan_id;
159+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
160+
if (!fhss_structure) {
161+
return;
162+
}
159163
if (fhss_state == FHSS_SYNCHRONIZED) {
160164
uint32_t fhss_broadcast_interval = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_broadcast_interval;
161165
uint8_t fhss_bc_dwell_interval = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_bc_dwell_interval;
@@ -169,7 +173,7 @@ static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_state
169173
}
170174

171175
fhss_structure->fhss_state = fhss_state;
172-
return 0;
176+
return;
173177
}
174178

175179
static void fhss_ws_superframe_callback(fhss_structure_t *fhss_structure)
@@ -216,6 +220,9 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
216220
if (!fhss_structure) {
217221
return -1;
218222
}
223+
if (is_broadcast_addr) {
224+
return 0;
225+
}
219226
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
220227
int32_t tx_channel;
221228
//TODO: Get destination UFSI, timestamp and dwell time from neighbour table
@@ -247,6 +254,31 @@ static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_
247254
return true;
248255
}
249256

257+
static int16_t fhss_ws_write_synch_info_callback(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time)
258+
{
259+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
260+
(void) frame_type_id;
261+
(void) tx_time;
262+
(void) info_ptr;
263+
(void) info_type;
264+
if (!fhss_structure) {
265+
return -1;
266+
}
267+
268+
return -1;
269+
}
270+
271+
static void fhss_ws_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle)
272+
{
273+
(void) waiting_ack;
274+
(void) tx_completed;
275+
(void) handle;
276+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
277+
if (!fhss_structure) {
278+
return;
279+
}
280+
}
281+
250282
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
251283
{
252284
// Set external API
@@ -255,18 +287,17 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
255287
fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback;
256288
fhss_structure->fhss_api->check_tx_conditions = &fhss_ws_check_tx_conditions_callback;
257289
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
258-
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
290+
fhss_structure->fhss_api->data_tx_done = &fhss_ws_data_tx_done_callback;
259291
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
260-
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
292+
fhss_structure->fhss_api->synch_state_set = &fhss_ws_handle_state_set;
261293
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
262294
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
263-
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
295+
fhss_structure->fhss_api->write_synch_info = &fhss_ws_write_synch_info_callback;
264296
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
265297
// Set internal API
266298
fhss_structure->update_channel = fhss_ws_update_uc_channel_callback;
267299
fhss_structure->update_superframe = fhss_ws_superframe_callback;
268300
fhss_structure->read_superframe_timeout = fhss_ws_get_sf_timeout_callback;
269-
fhss_structure->handle_state_set = fhss_ws_handle_state_set;
270301
fhss_structure->ws = ns_dyn_mem_alloc(sizeof(fhss_ws_t));
271302
if (!fhss_structure->ws) {
272303
return -1;

test/nanostack/unittest/service_libs/fhss_mac_interface/fhssmaciftest.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,11 @@ TEST(fhss_mac_if, test_fhss_receive_frame_cb)
4444
CHECK(test_fhss_receive_frame_cb());
4545
}
4646

47-
TEST(fhss_mac_if, test_fhss_data_tx_done_cb)
48-
{
49-
CHECK(test_fhss_data_tx_done_cb());
50-
}
51-
5247
TEST(fhss_mac_if, test_fhss_data_tx_fail_cb)
5348
{
5449
CHECK(test_fhss_data_tx_fail_cb());
5550
}
5651

57-
TEST(fhss_mac_if, test_fhss_synch_state_set_cb)
58-
{
59-
CHECK(test_fhss_synch_state_set_cb());
60-
}
61-
6252
TEST(fhss_mac_if, test_fhss_read_timestamp_cb)
6353
{
6454
CHECK(test_fhss_read_timestamp_cb());

0 commit comments

Comments
 (0)