Skip to content

Commit

Permalink
Merge pull request ARMmbed#1571 from ARMmbed/fhss_callback_update
Browse files Browse the repository at this point in the history
Fhss callback update
  • Loading branch information
Jarkko Paso authored Feb 14, 2018
2 parents db1ded0 + 316b007 commit 8b9d39b
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 147 deletions.
60 changes: 50 additions & 10 deletions source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,16 @@ void fhss_failed_list_free(fhss_structure_t *fhss_structure)
}
}

static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id)
static void fhss_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
}
// State is already set
if (fhss_structure->fhss_state == fhss_state) {
tr_debug("Synch same state %u", fhss_state);
return -1;
return;
}

if (fhss_state == FHSS_UNSYNCHRONIZED) {
Expand All @@ -747,12 +751,12 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
// Do not synchronize to current pan
if (fhss_structure->synch_panid == pan_id) {
tr_debug("Synch same panid %u", pan_id);
return -1;
return;
}
if (fhss_structure->fhss_scramble_table == NULL) {
if (fhss_generate_scramble_table(fhss_structure)) {
tr_error("Failed to generate scramble table");
return -1;
return;
}
}
uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api);
Expand All @@ -778,10 +782,11 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
fhss_start_timer(fhss_structure, fhss_structure->synch_configuration.fhss_superframe_length, fhss_superframe_handler);
} else {
tr_error("Synch info not found");
return -1;
return;
}
}
return 0;
fhss_structure->fhss_state = fhss_state;
return;
}

static void fhss_destroy_scramble_table(fhss_structure_t *fhss_structure)
Expand Down Expand Up @@ -914,6 +919,42 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
}
}

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)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
(void) frame_type_id;
(void) tx_time;
if (!fhss_structure) {
return -1;
}
if (info_type == FHSS_PLAIN_SYNCH_INFO) {
if (!info_ptr) {
return -1;
}
fhss_beacon_build(fhss_structure, info_ptr);
return FHSS_SYNCH_INFO_LENGTH;
}
return -1;
}

static void fhss_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
}
if (waiting_ack == false) {
fhss_change_to_rx_channel(fhss_structure);
}
// Buffer was successfully transmitted. Remove stored failure handle if exists.
if (tx_completed == true) {
fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle);
if (fhss_failed_tx) {
fhss_failed_handle_remove(fhss_structure, handle);
}
}
}

int fhss_set_callbacks(fhss_structure_t *fhss_structure)
{
// Set external API
Expand All @@ -922,17 +963,16 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure)
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback;
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_callback;
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_done = &fhss_data_tx_done_callback;
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->synch_state_set = &fhss_handle_state_set;
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->write_synch_info = &fhss_write_synch_info_callback;
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_superframe_timeout = fhss_get_sf_timeout_callback;
fhss_structure->handle_state_set = fhss_handle_state_set;
return 0;
}
2 changes: 1 addition & 1 deletion source/Service_Libs/fhss/fhss_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
if (!fhss_structure) {
return -1;
}
fhss_structure->handle_state_set(fhss_structure, FHSS_UNSYNCHRONIZED, 0);
fhss_structure->fhss_api->synch_state_set(fhss_structure->fhss_api, FHSS_UNSYNCHRONIZED, 0);
ns_dyn_mem_free(fhss_structure->ws);
ns_dyn_mem_free(fhss_structure);
fhss_structure = 0;
Expand Down
10 changes: 0 additions & 10 deletions source/Service_Libs/fhss/fhss_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ typedef void fhss_update_superframe_cb(fhss_structure_t *fhss_structure);
*/
typedef uint32_t fhss_read_superframe_timeout_cb(fhss_structure_t *fhss_structure);

/**
* @brief Set FHSS state.
* @param fhss_structure FHSS structure.
* @param fhss_state FHSS state to set.
* @param pan_id Network PAN id.
* @return 0 Success, -1 Failure.
*/
typedef int fhss_handle_state_set_cb(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id);

union fhss_conf {
fhss_configuration_t fhss_configuration;
fhss_ws_configuration_t fhss_ws_configuration;
Expand Down Expand Up @@ -121,7 +112,6 @@ struct fhss_structure
fhss_update_channel_cb *update_channel; /**< Update listening channel */
fhss_update_superframe_cb *update_superframe; /**< Update superframe */
fhss_read_superframe_timeout_cb *read_superframe_timeout; /**< Read next FHSS superframe timeout length */
fhss_handle_state_set_cb *handle_state_set; /**< Set FHSS state */
};

fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer);
Expand Down
48 changes: 0 additions & 48 deletions source/Service_Libs/fhss/fhss_mac_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *sour
}
}

void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
}
if (waiting_ack == false) {
fhss_change_to_rx_channel(fhss_structure);
}
// Buffer was successfully transmitted. Remove stored failure handle if exists.
if (tx_completed == true) {
fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle);
if (fhss_failed_tx) {
fhss_failed_handle_remove(fhss_structure, handle);
}
}
}

bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
Expand Down Expand Up @@ -141,18 +123,6 @@ bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type)
return true;
}

void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
}
if (fhss_structure->handle_state_set) {
fhss_structure->handle_state_set(fhss_structure, fhss_state, pan_id);
}
fhss_structure->fhss_state = fhss_state;
}

uint32_t fhss_read_timestamp_cb(const fhss_api_t *api)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
Expand Down Expand Up @@ -205,24 +175,6 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad
return retry_period;
}

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)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
(void) frame_type_id;
(void) tx_time;
if (!fhss_structure) {
return -1;
}
if (info_type == FHSS_PLAIN_SYNCH_INFO) {
if (!info_ptr) {
return -1;
}
fhss_beacon_build(fhss_structure, info_ptr);
return FHSS_SYNCH_INFO_LENGTH;
}
return -1;
}


int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks)
{
Expand Down
3 changes: 0 additions & 3 deletions source/Service_Libs/fhss/fhss_mac_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
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);
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);
void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
uint32_t fhss_read_timestamp_cb(const fhss_api_t *api);
uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
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);
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks);

#endif /* FHSS_MAC_INTERFACE_H_ */
43 changes: 37 additions & 6 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ static uint32_t fhss_ws_get_sf_timeout_callback(fhss_structure_t *fhss_structure
return fhss_structure->fhss_conf.fhss_ws_configuration.fhss_uc_dwell_interval * 1000;
}

static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id)
static void fhss_ws_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
{
(void) pan_id;
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
}
if (fhss_state == FHSS_SYNCHRONIZED) {
uint32_t fhss_broadcast_interval = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_broadcast_interval;
uint8_t fhss_bc_dwell_interval = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_bc_dwell_interval;
Expand All @@ -169,7 +173,7 @@ static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_state
}

fhss_structure->fhss_state = fhss_state;
return 0;
return;
}

static void fhss_ws_superframe_callback(fhss_structure_t *fhss_structure)
Expand Down Expand Up @@ -216,6 +220,9 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
if (!fhss_structure) {
return -1;
}
if (is_broadcast_addr) {
return 0;
}
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
int32_t tx_channel;
//TODO: Get destination UFSI, timestamp and dwell time from neighbour table
Expand Down Expand Up @@ -247,6 +254,31 @@ static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_
return true;
}

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)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
(void) frame_type_id;
(void) tx_time;
(void) info_ptr;
(void) info_type;
if (!fhss_structure) {
return -1;
}

return -1;
}

static void fhss_ws_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle)
{
(void) waiting_ack;
(void) tx_completed;
(void) handle;
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
}
}

int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
{
// Set external API
Expand All @@ -255,18 +287,17 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback;
fhss_structure->fhss_api->check_tx_conditions = &fhss_ws_check_tx_conditions_callback;
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_done = &fhss_ws_data_tx_done_callback;
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->synch_state_set = &fhss_ws_handle_state_set;
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->write_synch_info = &fhss_ws_write_synch_info_callback;
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
// Set internal API
fhss_structure->update_channel = fhss_ws_update_uc_channel_callback;
fhss_structure->update_superframe = fhss_ws_superframe_callback;
fhss_structure->read_superframe_timeout = fhss_ws_get_sf_timeout_callback;
fhss_structure->handle_state_set = fhss_ws_handle_state_set;
fhss_structure->ws = ns_dyn_mem_alloc(sizeof(fhss_ws_t));
if (!fhss_structure->ws) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,11 @@ TEST(fhss_mac_if, test_fhss_receive_frame_cb)
CHECK(test_fhss_receive_frame_cb());
}

TEST(fhss_mac_if, test_fhss_data_tx_done_cb)
{
CHECK(test_fhss_data_tx_done_cb());
}

TEST(fhss_mac_if, test_fhss_data_tx_fail_cb)
{
CHECK(test_fhss_data_tx_fail_cb());
}

TEST(fhss_mac_if, test_fhss_synch_state_set_cb)
{
CHECK(test_fhss_synch_state_set_cb());
}

TEST(fhss_mac_if, test_fhss_read_timestamp_cb)
{
CHECK(test_fhss_read_timestamp_cb());
Expand Down
Loading

0 comments on commit 8b9d39b

Please sign in to comment.