Skip to content

Commit

Permalink
FHSS: Moved external API set to fhss and fhss_ws
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jan 29, 2018
1 parent c6cfb6c commit 0cc1889
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 77 deletions.
17 changes: 16 additions & 1 deletion source/Service_Libs/fhss/fhss.c
Expand Up @@ -25,6 +25,7 @@
#include "nsdynmemLIB.h"
#include "fhss_beacon.h"
#include "fhss_statistics.h"
#include "fhss_mac_interface.h"
#include "ns_trace.h"
#include "eventOS_event.h"
#include "eventOS_callback_timer.h"
Expand Down Expand Up @@ -780,8 +781,22 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
}
}

int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure)
int fhss_set_callbacks(fhss_structure_t *fhss_structure)
{
// Set external API
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_cb;
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
// Set internal API
fhss_structure->update_channel = fhss_update_channel_callback;
fhss_structure->update_superframe = fhss_superframe_callback;
fhss_structure->read_compensation = fhss_get_compensation;
Expand Down
2 changes: 1 addition & 1 deletion source/Service_Libs/fhss/fhss.h
Expand Up @@ -71,7 +71,7 @@ int fhss_failed_handle_add(fhss_structure_t *fhss_structure, uint8_t handle);
int fhss_failed_handle_remove(fhss_structure_t *fhss_structure, uint8_t handle);
void fhss_failed_list_free(fhss_structure_t *fhss_structure);
int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor);
int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure);
int fhss_set_callbacks(fhss_structure_t *fhss_structure);

/**
* Calculate time in microseconds to start of next superframe.
Expand Down
22 changes: 2 additions & 20 deletions source/Service_Libs/fhss/fhss_configuration_interface.c
Expand Up @@ -29,22 +29,6 @@

#define TRACE_GROUP "fhss"

static void fhss_set_api_callbacks(fhss_api_t *fhss_api)
{
fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
fhss_api->tx_handle = &fhss_tx_handle_cb;
fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
fhss_api->receive_frame = &fhss_receive_frame_cb;
fhss_api->data_tx_done = &fhss_data_tx_done_cb;
fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
fhss_api->synch_state_set = &fhss_synch_state_set_cb;
fhss_api->read_timestamp = &fhss_read_timestamp_cb;
fhss_api->get_retry_period = &fhss_get_retry_period_cb;
fhss_api->write_synch_info = &fhss_write_synch_info_cb;
fhss_api->init_callbacks = &fhss_init_callbacks_cb;
}

fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics)
{
fhss_api_t *this = ns_dyn_mem_alloc(sizeof(fhss_api_t));
Expand All @@ -58,8 +42,7 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
ns_dyn_mem_free(this);
return NULL;
}
fhss_set_api_callbacks(this);
fhss_set_internal_callbacks(fhss_struct);
fhss_set_callbacks(fhss_struct);
return this;
}

Expand All @@ -76,8 +59,7 @@ fhss_api_t *ns_fhss_ws_create(const fhss_configuration_t *fhss_configuration, co
ns_dyn_mem_free(this);
return NULL;
}
fhss_set_api_callbacks(this);
fhss_ws_set_internal_callbacks(fhss_struct);
fhss_ws_set_callbacks(fhss_struct);
return this;
}

Expand Down
17 changes: 16 additions & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Expand Up @@ -22,6 +22,7 @@
#include "fhss_common.h"
#include "channel_functions.h"
#include "fhss_ws.h"
#include "fhss_mac_interface.h"
#include "nsdynmemLIB.h"
#include "ns_trace.h"
#include <string.h>
Expand Down Expand Up @@ -67,8 +68,22 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
}

int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure)
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
{
// Set external API
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_cb;
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
// Set internal API
fhss_structure->update_channel = fhss_ws_update_channel_callback;
fhss_structure->update_superframe = fhss_ws_superframe_callback;
fhss_structure->read_compensation = NULL;
Expand Down
2 changes: 1 addition & 1 deletion source/Service_Libs/fhss/fhss_ws.h
Expand Up @@ -29,6 +29,6 @@ struct fhss_ws
uint16_t slot;
};

int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure);
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure);

#endif /*FHSS_WS_H_*/
47 changes: 31 additions & 16 deletions test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c
Expand Up @@ -261,6 +261,19 @@ static protocol_interface_rf_mac_setup_s * test_mac_rf_mac_class_allocate(void)
return rf_mac_setup;
}

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)
{
return 0;
}
static bool fhss_tx_condition = true;
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)
{
if (frame_type == FHSS_SYNCH_REQUEST_FRAME) {
return false;
}
return fhss_tx_condition;
}

static uint8_t expect_data_confirmation_status = 0;
static bool data_confirm_valid = false;

Expand Down Expand Up @@ -447,7 +460,7 @@ bool test_mcps_sap_trig_tx()

// FHSS is on broadcast channel and tx conditions are fine
fhss_mac_interface_stub.channel_bool_value = true;
fhss_mac_interface_stub.cond_bool_value = true;
fhss_tx_condition = true;

mcps_sap_trig_tx(rf_mac_setup);
// Active data request should be buf
Expand Down Expand Up @@ -775,7 +788,7 @@ bool test_mac_mcps_data_confirmation()
rf_mac_setup->fhss_api = ns_fhss_create(0, 0);
nsdynmemlib_stub.returnCounter = 3;
data_req.TxAckReq = true;
fhss_mac_interface_stub.cond_bool_value = true;
fhss_tx_condition = true;
mcps_sap_data_req_handler(rf_mac_setup, &data_req);
rf_mac_setup->mac_tx_result = MAC_TX_FAIL;
mcps_sap_pd_confirm(rf_mac_setup);
Expand Down Expand Up @@ -1865,7 +1878,7 @@ bool test_mac_mcps_data_indication()
buffer->mac_class_ptr = rf_mac_setup;
mcps_sap_pd_ind(buffer);
if (start_value != (fhss_mac_interface_stub.int8_value - 1)) {
return false;
return false;
}

test_mac_rf_mac_class_free(rf_mac_setup);
Expand Down Expand Up @@ -2009,7 +2022,7 @@ bool test_mcps_sap_pd_req_queue_write()

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

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

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

// Buffer has broadcast destination and TX conditions are bad
buffer->fcf_dsn.ackRequested = false;
fhss_mac_interface_stub.cond_bool_value = false;
fhss_tx_condition = false;
// Higher priority for this buffer
buffer->priority = 2;
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
Expand All @@ -2064,7 +2077,7 @@ bool test_mcps_sap_pd_req_queue_write()

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

// Buffer has broadcast destination and TX conditions are bad
buffer->fcf_dsn.ackRequested = false;
fhss_mac_interface_stub.cond_bool_value = false;
fhss_tx_condition = false;
// Beacon request should go to unicast queue
buffer->fcf_dsn.frametype = FC_CMD_FRAME;
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
Expand All @@ -2102,7 +2115,7 @@ bool test_mcps_sap_pd_req_queue_write()
mcps_sap_pd_req_queue_write(rf_mac_setup, buffer);
// Should be first in a BC queue, 1 buffer in a BC queue
if ((rf_mac_setup->pd_data_request_bc_queue_to_go != buffer) || (rf_mac_setup->broadcast_queue_size != 1)) {
return false;
return false;
}

mac_mcps_buffer_queue_free(rf_mac_setup);
Expand Down Expand Up @@ -2697,15 +2710,17 @@ bool test_mac_mcps_trig_buffer_from_queue()
}
mac_mcps_buffer_queue_free(rf_mac_setup);

// FHSS TESTS START
// FHSS TESTS START
rf_mac_setup->fhss_api = ns_fhss_create(0, 0);
fhss_config_stub.fhss_api_ptr.tx_handle = &fhss_tx_handle_callback;
fhss_config_stub.fhss_api_ptr.check_tx_conditions = &fhss_check_tx_conditions_callback;
buf = tes_mac_mcps_temporary_buffer_get(0);
rf_mac_setup->pd_data_request_bc_queue_to_go = buf;
rf_mac_setup->broadcast_queue_size = 1;

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

// FHSS is on broadcast channel and tx conditions are bad
fhss_mac_interface_stub.channel_bool_value = true;
fhss_mac_interface_stub.cond_bool_value = false;
fhss_tx_condition = false;
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
if (!rf_mac_setup->pd_data_request_bc_queue_to_go) {
test_mac_rf_mac_class_free(rf_mac_setup);
Expand All @@ -2723,7 +2738,7 @@ bool test_mac_mcps_trig_buffer_from_queue()

// FHSS is on broadcast channel and tx conditions are fine
fhss_mac_interface_stub.channel_bool_value = true;
fhss_mac_interface_stub.cond_bool_value = true;
fhss_tx_condition = true;
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
if (!rf_mac_setup->active_pd_data_request || rf_mac_setup->pd_data_request_bc_queue_to_go || rf_mac_setup->broadcast_queue_size) {
test_mac_rf_mac_class_free(rf_mac_setup);
Expand All @@ -2741,7 +2756,7 @@ bool test_mac_mcps_trig_buffer_from_queue()
rf_mac_setup->pd_data_request_queue_to_go->next = buf2;
rf_mac_setup->unicast_queue_size = 2;
fhss_mac_interface_stub.channel_bool_value = false;
fhss_mac_interface_stub.cond_bool_value = true;
fhss_tx_condition = true;
// Should trig second packet from queue
mac_mcps_trig_buffer_from_queue(rf_mac_setup);
// First packet should still be the Beacon request
Expand All @@ -2750,7 +2765,7 @@ bool test_mac_mcps_trig_buffer_from_queue()
return false;
}
mac_mcps_buffer_queue_free(rf_mac_setup);
// Free test setup struct
// Free test setup struct
test_mac_rf_mac_class_free(rf_mac_setup);
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions test/nanostack/unittest/mac/mac_pd_sap/test_mac_pd_sap.c
Expand Up @@ -28,6 +28,7 @@
#include "mac_mcps_sap_stub.h"
#include "nsdynmemLIB_stub.h"
#include "fhss_mac_interface_stub.h"
#include "fhss_config_stub.h"
#include <string.h>

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

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)
{
return 0;
}

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)
{
return true;
}

bool test_mac_pd_sap_req()
{
Expand Down Expand Up @@ -688,6 +698,8 @@ bool test_mac_pd_sap_state_machine()
// FHSS TESTS START
mac_pre_build_frame_t temp_buf;
rf_ptr.fhss_api = ns_fhss_create(0, 0);
fhss_config_stub.fhss_api_ptr.tx_handle = &fhss_tx_handle_callback;
fhss_config_stub.fhss_api_ptr.check_tx_conditions = &fhss_check_tx_conditions_callback;
rf_ptr.mac_tx_result = MAC_TIMER_CCA;
rf_ptr.macTxProcessActive = true;
rf_ptr.active_pd_data_request = &temp_buf;
Expand Down
Expand Up @@ -54,41 +54,6 @@ bool test_ns_fhss_create()
if (!api) {
return false;
}
// Test calling all functions
fhss_mac_interface_stub.int8_value = 0;
api->receive_frame(api, 0, NULL, 0, NULL, FHSS_SYNCH_FRAME);
if (fhss_mac_interface_stub.int8_value != 1) {
return false;
}
api->check_tx_conditions(api, true, 0, FHSS_DATA_FRAME, 100, 0, 0);
if (fhss_mac_interface_stub.int8_value != 2) {
return false;
}
api->data_tx_done(api, true, true, 0);
if (fhss_mac_interface_stub.int8_value != 3) {
return false;
}
api->data_tx_fail(api, 0, FHSS_DATA_FRAME);
if (fhss_mac_interface_stub.int8_value != 4) {
return false;
}
api->is_broadcast_channel(api);
if (fhss_mac_interface_stub.int8_value != 5) {
return false;
}
api->read_timestamp(api);
if (fhss_mac_interface_stub.int8_value != 6) {
return false;
}
api->synch_state_set(api, FHSS_UNSYNCHRONIZED, 0);
if (fhss_mac_interface_stub.int8_value != 7) {
return false;
}
api->tx_handle(api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0);
if (fhss_mac_interface_stub.int8_value != 8) {
return false;
}

free(api);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/fhss_stub.c
Expand Up @@ -200,7 +200,7 @@ int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_sta
return 0;
}

int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure)
int fhss_set_callbacks(fhss_structure_t *fhss_structure)
{

}
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/fhss_ws_stub.c
Expand Up @@ -23,7 +23,7 @@
#include "Service_Libs/fhss/fhss_common.h"
#include "Service_Libs/fhss/fhss_beacon.h"

int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure)
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
{

}

0 comments on commit 0cc1889

Please sign in to comment.