Skip to content

Commit 7237796

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1545 from ARMmbed/IOTTHD-2097
Iotthd 2097
2 parents c6cfb6c + f794990 commit 7237796

20 files changed

+273
-241
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 67 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"
@@ -759,6 +760,57 @@ static void fhss_superframe_callback(fhss_structure_t *fhss_structure)
759760
}
760761
}
761762

763+
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)
764+
{
765+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
766+
if (!fhss_structure) {
767+
return -2;
768+
}
769+
// TODO: needs some more logic to push buffer back to queue
770+
if (frame_type == FHSS_DATA_FRAME) {
771+
if (is_broadcast_addr == true) {
772+
if (fhss_is_current_channel_broadcast(fhss_structure) == false) {
773+
tr_info("Broadcast on UC channel -> Back to queue");
774+
return -3;
775+
}
776+
}
777+
}
778+
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
779+
return -1;
780+
}
781+
// If sending Beacon request on parents Unicast channel
782+
if (frame_type == FHSS_SYNCH_REQUEST_FRAME && fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
783+
fhss_change_to_parent_channel(fhss_structure);
784+
} else if (frame_type == FHSS_DATA_FRAME) {
785+
fhss_change_to_tx_channel(fhss_structure, destination_address);
786+
}
787+
return 0;
788+
}
789+
790+
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)
791+
{
792+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
793+
if (!fhss_structure) {
794+
return false;
795+
}
796+
// This condition will check that message is not sent on bad channel
797+
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
798+
return false;
799+
}
800+
801+
// This condition will check that broadcast messages are sent only broadcast channels
802+
if (fhss_check_channel_type(fhss_structure, is_broadcast_addr, frame_type) == false) {
803+
return false;
804+
}
805+
806+
// This condition will check that FHSS is on TX slot and there is enough time to transmit before channel or slot change
807+
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
808+
return false;
809+
}
810+
811+
return true;
812+
}
813+
762814
static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
763815
{
764816
if (fhss_structure->current_channel_index == 0) {
@@ -780,8 +832,22 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
780832
}
781833
}
782834

783-
int fhss_set_internal_callbacks(fhss_structure_t *fhss_structure)
835+
int fhss_set_callbacks(fhss_structure_t *fhss_structure)
784836
{
837+
// Set external API
838+
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
839+
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
840+
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback;
841+
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_callback;
842+
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
843+
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
844+
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
845+
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
846+
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
847+
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
848+
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
849+
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
850+
// Set internal API
785851
fhss_structure->update_channel = fhss_update_channel_callback;
786852
fhss_structure->update_superframe = fhss_superframe_callback;
787853
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_mac_interface.c

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -58,57 +58,6 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
5858
return is_broadcast_addr;
5959
}
6060

61-
int fhss_tx_handle_cb(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)
62-
{
63-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
64-
if (!fhss_structure) {
65-
return -2;
66-
}
67-
// TODO: needs some more logic to push buffer back to queue
68-
if (frame_type == FHSS_DATA_FRAME) {
69-
if (is_broadcast_addr == true) {
70-
if (fhss_is_current_channel_broadcast(fhss_structure) == false) {
71-
tr_info("Broadcast on UC channel -> Back to queue");
72-
return -3;
73-
}
74-
}
75-
}
76-
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
77-
return -1;
78-
}
79-
// If sending Beacon request on parents Unicast channel
80-
if (frame_type == FHSS_SYNCH_REQUEST_FRAME && fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
81-
fhss_change_to_parent_channel(fhss_structure);
82-
} else if (frame_type == FHSS_DATA_FRAME) {
83-
fhss_change_to_tx_channel(fhss_structure, destination_address);
84-
}
85-
return 0;
86-
}
87-
88-
bool fhss_check_tx_conditions_cb(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)
89-
{
90-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
91-
if (!fhss_structure) {
92-
return false;
93-
}
94-
// This condition will check that message is not sent on bad channel
95-
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
96-
return false;
97-
}
98-
99-
// This condition will check that broadcast messages are sent only broadcast channels
100-
if (fhss_check_channel_type(fhss_structure, is_broadcast_addr, frame_type) == false) {
101-
return false;
102-
}
103-
104-
// This condition will check that FHSS is on TX slot and there is enough time to transmit before channel or slot change
105-
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
106-
return false;
107-
}
108-
109-
return true;
110-
}
111-
11261
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)
11362
{
11463
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);

source/Service_Libs/fhss/fhss_mac_interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

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);
23-
int fhss_tx_handle_cb(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);
24-
bool fhss_check_tx_conditions_cb(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);
2523
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);
2624
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
2725
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 63 additions & 3 deletions
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>
@@ -33,14 +34,17 @@
3334

3435
static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id)
3536
{
37+
(void) fhss_state;
3638
(void) pan_id;
39+
//TODO: Remove hard coded channel function
40+
fhss_structure->ws->channel_function = WS_TR51CF;
3741
fhss_start_timer(fhss_structure, fhss_structure->synch_configuration.fhss_superframe_length, fhss_superframe_handler);
3842
return 0;
3943
}
4044

4145
static void fhss_ws_superframe_callback(fhss_structure_t *fhss_structure)
4246
{
43-
47+
(void) fhss_structure;
4448
}
4549

4650
static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
@@ -62,13 +66,69 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
6266
//TODO: Callback to get channel schedule from application
6367
}
6468
#ifdef FHSS_CHANNEL_DEBUG
65-
tr_info("%"PRIu32" UC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel);
69+
tr_info("%"PRIu32" UC %u %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel, fhss_structure->ws->slot);
6670
#endif /*FHSS_CHANNEL_DEBUG*/
6771
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
6872
}
6973

70-
int fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure)
74+
static int fhss_ws_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)
75+
{
76+
(void) is_broadcast_addr;
77+
(void) frame_type;
78+
(void) frame_length;
79+
(void) phy_header_length;
80+
(void) phy_tail_length;
81+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
82+
if (!fhss_structure) {
83+
return -1;
84+
}
85+
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
86+
int32_t tx_channel;
87+
//TODO: Compute destination slot using neighbour table
88+
uint16_t destination_slot = fhss_structure->ws->slot;
89+
if (fhss_structure->ws->channel_function == WS_TR51CF) {
90+
tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, fhss_structure->number_of_channels);
91+
} else if(fhss_structure->ws->channel_function == WS_DH1CF) {
92+
tx_channel = dh1cf_get_uc_channel_index(destination_slot, destination_address, fhss_structure->number_of_channels);
93+
} else if (fhss_structure->ws->channel_function == WS_VENDOR_DEF_CF) {
94+
95+
}
96+
#ifdef FHSS_CHANNEL_DEBUG
97+
tr_debug("TX channel: %u %u", tx_channel, destination_slot+1);
98+
#endif /*FHSS_CHANNEL_DEBUG*/
99+
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, tx_channel);
100+
}
101+
return 0;
102+
}
103+
104+
static bool fhss_ws_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)
105+
{
106+
(void) api;
107+
(void) is_broadcast_addr;
108+
(void) handle;
109+
(void) frame_type;
110+
(void) frame_length;
111+
(void) phy_header_length;
112+
(void) phy_tail_length;
113+
return true;
114+
}
115+
116+
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
71117
{
118+
// Set external API
119+
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
120+
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
121+
fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback;
122+
fhss_structure->fhss_api->check_tx_conditions = &fhss_ws_check_tx_conditions_callback;
123+
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
124+
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
125+
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
126+
fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb;
127+
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
128+
fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb;
129+
fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb;
130+
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
131+
// Set internal API
72132
fhss_structure->update_channel = fhss_ws_update_channel_callback;
73133
fhss_structure->update_superframe = fhss_ws_superframe_callback;
74134
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_*/

0 commit comments

Comments
 (0)