Skip to content

Commit

Permalink
Implemented optimal packet size test api (ARMmbed#2292)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso authored Feb 4, 2020
1 parent 87ee16a commit 4f27500
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
46 changes: 46 additions & 0 deletions nanostack/fhss_test_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2020, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* \file fhss_test_api.h
* \brief
*/

#ifndef FHSS_TEST_API_H
#define FHSS_TEST_API_H


#ifdef __cplusplus
extern "C" {
#endif

/**
* \brief Set optimal packet length
*
* \param fhss_api FHSS instance.
* \param packet_length Optimal packet length
*
* \return 0 Success
* \return -1 Failure
*/
int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packet_length);

#ifdef __cplusplus
}
#endif

#endif // FHSS_TEST_API_H
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct fhss_structure {
int8_t fhss_event_timer;
uint8_t active_fhss_events;
uint16_t number_of_channels;
uint16_t optimal_packet_length;
fhss_states fhss_state;
uint32_t fhss_timeout;
uint32_t fhss_timer;
Expand Down
42 changes: 42 additions & 0 deletions source/Service_Libs/fhss/fhss_test_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "nsconfig.h"
#include "ns_types.h"
#include "ns_trace.h"
#include "fhss_api.h"
#include "fhss_config.h"
#include "fhss.h"
#include "fhss_common.h"
#include "fhss_ws.h"
#include "fhss_statistics.h"
#include "fhss_channel.h"
#include "channel_list.h"
#include <string.h>

#define TRACE_GROUP "fhta"

int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packet_length)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
if (!fhss_structure) {
return -1;
}
fhss_structure->optimal_packet_length = packet_length;
fhss_set_txrx_slot_length(fhss_structure);
tr_debug("Setting FHSS optimal packet length to: %u", fhss_structure->optimal_packet_length);
return 0;
}
6 changes: 3 additions & 3 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots);
static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure);
static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay);
static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure);
static void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);

// This function supports rounding up
static int64_t divide_integer(int64_t dividend, int32_t divisor)
Expand Down Expand Up @@ -147,6 +146,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
fhss_struct->fhss_event_timer = eventOS_callback_timer_register(fhss_event_timer_cb);
fhss_struct->ws->fhss_configuration = *fhss_configuration;
fhss_struct->number_of_channels = channel_count;
fhss_struct->optimal_packet_length = OPTIMAL_PACKET_LENGTH;
fhss_ws_set_hop_count(fhss_struct, 0xff);
fhss_struct->rx_channel = fhss_configuration->unicast_fixed_channel;
fhss_struct->ws->min_synch_interval = DEFAULT_MIN_SYNCH_INTERVAL;
Expand All @@ -172,7 +172,7 @@ static int fhss_ws_manage_channel_table_allocation(fhss_structure_t *fhss_struct
return 0;
}

static void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
{
// No broadcast schedule, no TX slots
if (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval == 0 || fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval == 0) {
Expand All @@ -198,7 +198,7 @@ static void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
*/
uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api);
if (datarate) {
txrx_slot_length_ms_tmp = ((OPTIMAL_PACKET_LENGTH * 2) * (8000000 / datarate)) / 1000;
txrx_slot_length_ms_tmp = ((fhss_structure->optimal_packet_length * 2) * (8000000 / datarate)) / 1000;
// Do not allow using too high TX slot length.
if (txrx_slot_length_ms_tmp > WS_TXRX_SLOT_LEN_MS) {
tr_debug("TX slot length setting too high %"PRIu32"ms, using %"PRIu32"ms", txrx_slot_length_ms_tmp, (uint32_t)WS_TXRX_SLOT_LEN_MS);
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
int fhss_ws_remove_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8]);
int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_configuration_t *fhss_configuration);
int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_count);
void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);

#endif /*FHSS_WS_H_*/
1 change: 1 addition & 0 deletions sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ SRCS += \
source/Service_Libs/fhss/fhss_common.c \
source/Service_Libs/fhss/channel_functions.c \
source/Service_Libs/fhss/channel_list.c \
source/Service_Libs/fhss/fhss_test_api.c \
source/Service_Libs/fnv_hash/fnv_hash.c \
source/Service_Libs/hmac/hmac_sha1.c \
source/Service_Libs/ieee_802_11/ieee_802_11.c \
Expand Down

0 comments on commit 4f27500

Please sign in to comment.