Skip to content

Commit 0cc1889

Browse files
author
Jarkko Paso
committed
FHSS: Moved external API set to fhss and fhss_ws
1 parent c6cfb6c commit 0cc1889

File tree

10 files changed

+81
-77
lines changed

10 files changed

+81
-77
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "nsdynmemLIB.h"
2626
#include "fhss_beacon.h"
2727
#include "fhss_statistics.h"
28+
#include "fhss_mac_interface.h"
2829
#include "ns_trace.h"
2930
#include "eventOS_event.h"
3031
#include "eventOS_callback_timer.h"
@@ -780,8 +781,22 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
780781
}
781782
}
782783

783-
int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure)
784+
int fhss_set_callbacks(fhss_structure_t *fhss_structure)
784785
{
786+
// Set external API
787+
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
788+
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
789+
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_cb;
790+
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
791+
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
792+
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
793+
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
794+
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
795+
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
796+
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
797+
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
798+
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
799+
// Set internal API
785800
fhss_structure->update_channel = fhss_update_channel_callback;
786801
fhss_structure->update_superframe = fhss_superframe_callback;
787802
fhss_structure->read_compensation = fhss_get_compensation;

source/Service_Libs/fhss/fhss.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int fhss_failed_handle_add(fhss_structure_t *fhss_structure, uint8_t handle);
7171
int fhss_failed_handle_remove(fhss_structure_t *fhss_structure, uint8_t handle);
7272
void fhss_failed_list_free(fhss_structure_t *fhss_structure);
7373
int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor);
74-
int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure);
74+
int fhss_set_callbacks(fhss_structure_t *fhss_structure);
7575

7676
/**
7777
* Calculate time in microseconds to start of next superframe.

source/Service_Libs/fhss/fhss_configuration_interface.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@
2929

3030
#define TRACE_GROUP "fhss"
3131

32-
static void fhss_set_api_callbacks(fhss_api_t *fhss_api)
33-
{
34-
fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
35-
fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
36-
fhss_api->tx_handle = &fhss_tx_handle_cb;
37-
fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
38-
fhss_api->receive_frame = &fhss_receive_frame_cb;
39-
fhss_api->data_tx_done = &fhss_data_tx_done_cb;
40-
fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
41-
fhss_api->synch_state_set = &fhss_synch_state_set_cb;
42-
fhss_api->read_timestamp = &fhss_read_timestamp_cb;
43-
fhss_api->get_retry_period = &fhss_get_retry_period_cb;
44-
fhss_api->write_synch_info = &fhss_write_synch_info_cb;
45-
fhss_api->init_callbacks = &fhss_init_callbacks_cb;
46-
}
47-
4832
fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics)
4933
{
5034
fhss_api_t *this = ns_dyn_mem_alloc(sizeof(fhss_api_t));
@@ -58,8 +42,7 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
5842
ns_dyn_mem_free(this);
5943
return NULL;
6044
}
61-
fhss_set_api_callbacks(this);
62-
fhss_set_internal_callbacks(fhss_struct);
45+
fhss_set_callbacks(fhss_struct);
6346
return this;
6447
}
6548

@@ -76,8 +59,7 @@ fhss_api_t *ns_fhss_ws_create(const fhss_configuration_t *fhss_configuration, co
7659
ns_dyn_mem_free(this);
7760
return NULL;
7861
}
79-
fhss_set_api_callbacks(this);
80-
fhss_ws_set_internal_callbacks(fhss_struct);
62+
fhss_ws_set_callbacks(fhss_struct);
8163
return this;
8264
}
8365

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "fhss_common.h"
2323
#include "channel_functions.h"
2424
#include "fhss_ws.h"
25+
#include "fhss_mac_interface.h"
2526
#include "nsdynmemLIB.h"
2627
#include "ns_trace.h"
2728
#include <string.h>
@@ -67,8 +68,22 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
6768
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
6869
}
6970

70-
int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure)
71+
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
7172
{
73+
// Set external API
74+
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
75+
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
76+
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_cb;
77+
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
78+
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
79+
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
80+
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
81+
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
82+
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
83+
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
84+
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
85+
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
86+
// Set internal API
7287
fhss_structure->update_channel = fhss_ws_update_channel_callback;
7388
fhss_structure->update_superframe = fhss_ws_superframe_callback;
7489
fhss_structure->read_compensation = NULL;

source/Service_Libs/fhss/fhss_ws.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ struct fhss_ws
2929
uint16_t slot;
3030
};
3131

32-
int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure);
32+
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure);
3333

3434
#endif /*FHSS_WS_H_*/

test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ static protocol_interface_rf_mac_setup_s * test_mac_rf_mac_class_allocate(void)
261261
return rf_mac_setup;
262262
}
263263

264+
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
265+
{
266+
return 0;
267+
}
268+
static bool fhss_tx_condition = true;
269+
static bool fhss_check_tx_conditions_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
270+
{
271+
if (frame_type == FHSS_SYNCH_REQUEST_FRAME) {
272+
return false;
273+
}
274+
return fhss_tx_condition;
275+
}
276+
264277
static uint8_t expect_data_confirmation_status = 0;
265278
static bool data_confirm_valid = false;
266279

@@ -447,7 +460,7 @@ bool test_mcps_sap_trig_tx()
447460

448461
// FHSS is on broadcast channel and tx conditions are fine
449462
fhss_mac_interface_stub.channel_bool_value = true;
450-
fhss_mac_interface_stub.cond_bool_value = true;
463+
fhss_tx_condition = true;
451464

452465
mcps_sap_trig_tx(rf_mac_setup);
453466
// Active data request should be buf
@@ -775,7 +788,7 @@ bool test_mac_mcps_data_confirmation()
775788
rf_mac_setup->fhss_api = ns_fhss_create(0, 0);
776789
nsdynmemlib_stub.returnCounter = 3;
777790
data_req.TxAckReq = true;
778-
fhss_mac_interface_stub.cond_bool_value = true;
791+
fhss_tx_condition = true;
779792
mcps_sap_data_req_handler(rf_mac_setup, &data_req);
780793
rf_mac_setup->mac_tx_result = MAC_TX_FAIL;
781794
mcps_sap_pd_confirm(rf_mac_setup);
@@ -1865,7 +1878,7 @@ bool test_mac_mcps_data_indication()
18651878
buffer->mac_class_ptr = rf_mac_setup;
18661879
mcps_sap_pd_ind(buffer);
18671880
if (start_value != (fhss_mac_interface_stub.int8_value - 1)) {
1868-
return false;
1881+
return false;
18691882
}
18701883

18711884
test_mac_rf_mac_class_free(rf_mac_setup);
@@ -2009,7 +2022,7 @@ bool test_mcps_sap_pd_req_queue_write()
20092022

20102023
// Buffer has broadcast destination and TX conditions are fine
20112024
buffer->fcf_dsn.ackRequested = false;
2012-
fhss_mac_interface_stub.cond_bool_value = true;
2025+
fhss_tx_condition = true;
20132026
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
20142027
// Should be sent immediately
20152028
if (rf_mac_setup->active_pd_data_request != buffer) {
@@ -2022,7 +2035,7 @@ bool test_mcps_sap_pd_req_queue_write()
20222035

20232036
// Buffer has broadcast destination and TX conditions are bad
20242037
buffer->fcf_dsn.ackRequested = false;
2025-
fhss_mac_interface_stub.cond_bool_value = false;
2038+
fhss_tx_condition = false;
20262039
fhss_mac_interface_stub.queue_bool_value = true;
20272040
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
20282041
// Should be first in BC queue, one buffer in a bc queue
@@ -2036,7 +2049,7 @@ bool test_mcps_sap_pd_req_queue_write()
20362049

20372050
// Buffer has broadcast destination and TX conditions are bad
20382051
buffer->fcf_dsn.ackRequested = false;
2039-
fhss_mac_interface_stub.cond_bool_value = false;
2052+
fhss_tx_condition = false;
20402053
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
20412054
// Should be second in BC queue, two buffers in a bc queue
20422055
if ((rf_mac_setup->pd_data_request_bc_queue_to_go->next != buffer) || (rf_mac_setup->broadcast_queue_size != 2)) {
@@ -2049,7 +2062,7 @@ bool test_mcps_sap_pd_req_queue_write()
20492062

20502063
// Buffer has broadcast destination and TX conditions are bad
20512064
buffer->fcf_dsn.ackRequested = false;
2052-
fhss_mac_interface_stub.cond_bool_value = false;
2065+
fhss_tx_condition = false;
20532066
// Higher priority for this buffer
20542067
buffer->priority = 2;
20552068
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
@@ -2064,7 +2077,7 @@ bool test_mcps_sap_pd_req_queue_write()
20642077

20652078
// Buffer has unicast destination and TX conditions are bad
20662079
buffer->fcf_dsn.ackRequested = true;
2067-
fhss_mac_interface_stub.cond_bool_value = false;
2080+
fhss_tx_condition = false;
20682081
fhss_mac_interface_stub.queue_bool_value = false;
20692082
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
20702083
// Should be first in a UC queue, 1 buffer in a uc queue
@@ -2080,7 +2093,7 @@ bool test_mcps_sap_pd_req_queue_write()
20802093

20812094
// Buffer has broadcast destination and TX conditions are bad
20822095
buffer->fcf_dsn.ackRequested = false;
2083-
fhss_mac_interface_stub.cond_bool_value = false;
2096+
fhss_tx_condition = false;
20842097
// Beacon request should go to unicast queue
20852098
buffer->fcf_dsn.frametype = FC_CMD_FRAME;
20862099
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
@@ -2102,7 +2115,7 @@ bool test_mcps_sap_pd_req_queue_write()
21022115
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
21032116
// Should be first in a BC queue, 1 buffer in a BC queue
21042117
if ((rf_mac_setup->pd_data_request_bc_queue_to_go != buffer) || (rf_mac_setup->broadcast_queue_size != 1)) {
2105-
return false;
2118+
return false;
21062119
}
21072120

21082121
mac_mcps_buffer_queue_free(rf_mac_setup);
@@ -2697,15 +2710,17 @@ bool test_mac_mcps_trig_buffer_from_queue()
26972710
}
26982711
mac_mcps_buffer_queue_free(rf_mac_setup);
26992712

2700-
// FHSS TESTS START
2713+
// FHSS TESTS START
27012714
rf_mac_setup->fhss_api = ns_fhss_create(0, 0);
2715+
fhss_config_stub.fhss_api_ptr.tx_handle = &fhss_tx_handle_callback;
2716+
fhss_config_stub.fhss_api_ptr.check_tx_conditions = &fhss_check_tx_conditions_callback;
27022717
buf = tes_mac_mcps_temporary_buffer_get(0);
27032718
rf_mac_setup->pd_data_request_bc_queue_to_go = buf;
27042719
rf_mac_setup->broadcast_queue_size = 1;
27052720

27062721
// FHSS is not on broadcast channel and tx conditions are fine
27072722
fhss_mac_interface_stub.channel_bool_value = false;
2708-
fhss_mac_interface_stub.cond_bool_value = true;
2723+
fhss_tx_condition = true;
27092724
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
27102725
if (!rf_mac_setup->pd_data_request_bc_queue_to_go) {
27112726
test_mac_rf_mac_class_free(rf_mac_setup);
@@ -2714,7 +2729,7 @@ bool test_mac_mcps_trig_buffer_from_queue()
27142729

27152730
// FHSS is on broadcast channel and tx conditions are bad
27162731
fhss_mac_interface_stub.channel_bool_value = true;
2717-
fhss_mac_interface_stub.cond_bool_value = false;
2732+
fhss_tx_condition = false;
27182733
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
27192734
if (!rf_mac_setup->pd_data_request_bc_queue_to_go) {
27202735
test_mac_rf_mac_class_free(rf_mac_setup);
@@ -2723,7 +2738,7 @@ bool test_mac_mcps_trig_buffer_from_queue()
27232738

27242739
// FHSS is on broadcast channel and tx conditions are fine
27252740
fhss_mac_interface_stub.channel_bool_value = true;
2726-
fhss_mac_interface_stub.cond_bool_value = true;
2741+
fhss_tx_condition = true;
27272742
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
27282743
if (!rf_mac_setup->active_pd_data_request || rf_mac_setup->pd_data_request_bc_queue_to_go || rf_mac_setup->broadcast_queue_size) {
27292744
test_mac_rf_mac_class_free(rf_mac_setup);
@@ -2741,7 +2756,7 @@ bool test_mac_mcps_trig_buffer_from_queue()
27412756
rf_mac_setup->pd_data_request_queue_to_go->next = buf2;
27422757
rf_mac_setup->unicast_queue_size = 2;
27432758
fhss_mac_interface_stub.channel_bool_value = false;
2744-
fhss_mac_interface_stub.cond_bool_value = true;
2759+
fhss_tx_condition = true;
27452760
// Should trig second packet from queue
27462761
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
27472762
// First packet should still be the Beacon request
@@ -2750,7 +2765,7 @@ bool test_mac_mcps_trig_buffer_from_queue()
27502765
return false;
27512766
}
27522767
mac_mcps_buffer_queue_free(rf_mac_setup);
2753-
// Free test setup struct
2768+
// Free test setup struct
27542769
test_mac_rf_mac_class_free(rf_mac_setup);
27552770
return true;
27562771
}

test/nanostack/unittest/mac/mac_pd_sap/test_mac_pd_sap.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "mac_mcps_sap_stub.h"
2929
#include "nsdynmemLIB_stub.h"
3030
#include "fhss_mac_interface_stub.h"
31+
#include "fhss_config_stub.h"
3132
#include <string.h>
3233

3334
static int8_t tx_return = -1;
@@ -50,6 +51,15 @@ static int8_t test_rf_virtual_tx(const virtual_data_req_t *data_req,int8_t drive
5051
return 0;
5152
}
5253

54+
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
55+
{
56+
return 0;
57+
}
58+
59+
static bool fhss_check_tx_conditions_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
60+
{
61+
return true;
62+
}
5363

5464
bool test_mac_pd_sap_req()
5565
{
@@ -688,6 +698,8 @@ bool test_mac_pd_sap_state_machine()
688698
// FHSS TESTS START
689699
mac_pre_build_frame_t temp_buf;
690700
rf_ptr.fhss_api = ns_fhss_create(0, 0);
701+
fhss_config_stub.fhss_api_ptr.tx_handle = &fhss_tx_handle_callback;
702+
fhss_config_stub.fhss_api_ptr.check_tx_conditions = &fhss_check_tx_conditions_callback;
691703
rf_ptr.mac_tx_result = MAC_TIMER_CCA;
692704
rf_ptr.macTxProcessActive = true;
693705
rf_ptr.active_pd_data_request = &temp_buf;

test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,41 +54,6 @@ bool test_ns_fhss_create()
5454
if (!api) {
5555
return false;
5656
}
57-
// Test calling all functions
58-
fhss_mac_interface_stub.int8_value = 0;
59-
api->receive_frame(api, 0, NULL, 0, NULL, FHSS_SYNCH_FRAME);
60-
if (fhss_mac_interface_stub.int8_value != 1) {
61-
return false;
62-
}
63-
api->check_tx_conditions(api, true, 0, FHSS_DATA_FRAME, 100, 0, 0);
64-
if (fhss_mac_interface_stub.int8_value != 2) {
65-
return false;
66-
}
67-
api->data_tx_done(api, true, true, 0);
68-
if (fhss_mac_interface_stub.int8_value != 3) {
69-
return false;
70-
}
71-
api->data_tx_fail(api, 0, FHSS_DATA_FRAME);
72-
if (fhss_mac_interface_stub.int8_value != 4) {
73-
return false;
74-
}
75-
api->is_broadcast_channel(api);
76-
if (fhss_mac_interface_stub.int8_value != 5) {
77-
return false;
78-
}
79-
api->read_timestamp(api);
80-
if (fhss_mac_interface_stub.int8_value != 6) {
81-
return false;
82-
}
83-
api->synch_state_set(api, FHSS_UNSYNCHRONIZED, 0);
84-
if (fhss_mac_interface_stub.int8_value != 7) {
85-
return false;
86-
}
87-
api->tx_handle(api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0);
88-
if (fhss_mac_interface_stub.int8_value != 8) {
89-
return false;
90-
}
91-
9257
free(api);
9358
return true;
9459
}

test/nanostack/unittest/stub/fhss_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_sta
200200
return 0;
201201
}
202202

203-
int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure)
203+
int fhss_set_callbacks(fhss_structure_t *fhss_structure)
204204
{
205205

206206
}

test/nanostack/unittest/stub/fhss_ws_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "Service_Libs/fhss/fhss_common.h"
2424
#include "Service_Libs/fhss/fhss_beacon.h"
2525

26-
int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure)
26+
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
2727
{
2828

2929
}

0 commit comments

Comments
 (0)