Skip to content

Commit f1a65ec

Browse files
author
Jarkko Paso
authored
Mode switch PHY API (ARMmbed#2663)
1 parent e54231b commit f1a65ec

File tree

8 files changed

+165
-0
lines changed

8 files changed

+165
-0
lines changed

nanostack/platform/arm_hal_phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ typedef struct phy_signal_info_s {
143143
typedef struct phy_csma_params {
144144
uint32_t backoff_time; /**< CSMA Backoff us time before start CCA & TX. 0 should disable current backoff*/
145145
bool cca_enabled; /**< True will affect CCA check false start TX direct after backoff */
146+
bool mode_switch_phr; /**< True - Frame is a mode switch PHR. In this case PHY driver should skip FCS and send two byte PHR as it is given by TX callback */
146147
} phy_csma_params_t;
147148

148149
/** PHY modulation scheme */

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, bool in
20872087
phy_csma_params_t csma_params;
20882088
csma_params.backoff_time = 0;
20892089
csma_params.cca_enabled = false;
2090+
csma_params.mode_switch_phr = false;
20902091
rf_ptr->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t *) &csma_params);
20912092
if (rf_ptr->active_pd_data_request) {
20922093
timer_mac_stop(rf_ptr);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2021, Pelion and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "string.h"
19+
#include "nsconfig.h"
20+
#include "ns_types.h"
21+
#include "ns_trace.h"
22+
#include "MAC/IEEE802_15_4/mac_defines.h"
23+
#include "MAC/IEEE802_15_4/mac_mode_switch.h"
24+
25+
#define TRACE_GROUP "mswc"
26+
27+
#define PHR_LEN 2
28+
29+
30+
int8_t ms_build_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t *data_ptr, uint8_t phy_mode_id)
31+
{
32+
(void) rf_ptr, (void) phy_mode_id;
33+
if (!data_ptr) {
34+
return -1;
35+
}
36+
37+
// - Write mode switch and PHY mode id fields
38+
// - Calculate checksum
39+
// - Calculate parity
40+
41+
// - With successful return value, MAC should start CSMA-CA for a mode switch PHR
42+
return 0;
43+
}
44+
45+
int8_t ms_parse_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, const uint8_t *data_ptr, uint16_t data_len)
46+
{
47+
(void) rf_ptr;
48+
if (data_len != PHR_LEN) {
49+
return -1;
50+
}
51+
if (!data_ptr) {
52+
return -1;
53+
}
54+
tr_info("Received mode switch PHR %s", trace_array(data_ptr, data_len));
55+
56+
// - Validate checksum
57+
// - Validate parity
58+
// - Read PHY mode id
59+
// - Store current configuration
60+
// - Resolve new configuration
61+
// - Set new configuration
62+
// - Set timer/timeout for waiting the frame with new PHY mode
63+
64+
// - With successful return value, MAC should not start new transmissions until a packet is received or reception timed out
65+
return 0;
66+
}
67+
68+
void ms_update_mode_switch_state(protocol_interface_rf_mac_setup_s *rf_ptr)
69+
{
70+
(void) rf_ptr;
71+
// MAC should call this after any transmission (TX done) and reception
72+
// When mode switch PHR was sent, change new configuration here before transmitting data packet
73+
// When data packet was sent, switch back to original configuration
74+
// When packet was received in new configuration, switch back to original configuration
75+
// When reception timeout occurs, switch back to original configuration
76+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021, Pelion and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef MAC_MODE_SWITCH_H_
19+
#define MAC_MODE_SWITCH_H_
20+
21+
/**
22+
* @brief Build mode switch PHR.
23+
* @param rf_ptr Pointer to MAC instance.
24+
* @param data_ptr Pointer to data buffer.
25+
* @param phy_mode_id Used PHY mode id.
26+
* @return 0 - success, -1 - failure.
27+
*/
28+
int8_t ms_build_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t *data_ptr, uint8_t phy_mode_id);
29+
30+
/**
31+
* @brief Parse mode switch PHR.
32+
* @param rf_ptr Pointer to MAC instance.
33+
* @param data_ptr Pointer to data buffer.
34+
* @param data_len Data length.
35+
* @return 0 - mode switch PHR found, -1 - mode switch PHR not found.
36+
*/
37+
int8_t ms_parse_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, const uint8_t *data_ptr, uint16_t data_len);
38+
39+
#endif /* MAC_MODE_SWITCH_H_ */

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "MAC/IEEE802_15_4/mac_filter.h"
3636
#include "MAC/IEEE802_15_4/mac_mcps_sap.h"
3737
#include "MAC/IEEE802_15_4/mac_cca_threshold.h"
38+
#include "MAC/IEEE802_15_4/mac_mode_switch.h"
3839
#include "MAC/rf_driver_storage.h"
3940
#include "Core/include/ns_monitor.h"
4041
#include "ns_trace.h"
@@ -232,6 +233,7 @@ void mac_pd_abort_active_tx(protocol_interface_rf_mac_setup_s *rf_mac_setup)
232233
phy_csma_params_t csma_params;
233234
// Set TX time to 0 to abort current transmission
234235
csma_params.backoff_time = 0;
236+
csma_params.mode_switch_phr = false;
235237
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t *) &csma_params);
236238
}
237239

@@ -251,6 +253,7 @@ void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup,
251253
phy_csma_params_t csma_params;
252254
csma_params.backoff_time = tx_time;
253255
csma_params.cca_enabled = cca_enabled;
256+
csma_params.mode_switch_phr = false;
254257
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t *) &csma_params);
255258
}
256259

@@ -1040,6 +1043,11 @@ int8_t mac_pd_sap_data_cb(void *identifier, arm_phy_sap_msg_t *message)
10401043
goto ERROR_HANDLER;
10411044
}
10421045

1046+
if (!ms_parse_mode_switch_phr(rf_ptr, pd_data_ind->data_ptr, pd_data_ind->data_len)) {
1047+
// TODO: mode switch returned 0, needs some logic to wait frame with new mode
1048+
goto ERROR_HANDLER;
1049+
}
1050+
10431051
if (pd_data_ind->data_len < 3) {
10441052
return -1;
10451053
}

sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ SRCS += \
8383
source/MAC/IEEE802_15_4/sw_mac.c \
8484
source/MAC/IEEE802_15_4/mac_fhss_callbacks.c \
8585
source/MAC/IEEE802_15_4/mac_cca_threshold.c \
86+
source/MAC/IEEE802_15_4/mac_mode_switch.c \
8687
source/MAC/ethernet/ethernet_mac_api.c \
8788
source/MAC/serial/serial_mac_api.c \
8889
source/MAC/virtual_rf/virtual_rf_client.c \

test/nanostack/unittest/mac/mac_pd_sap/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TEST_SRC_FILES = \
2222
../../stub/mac_timer_stub.c \
2323
../../stub/mac_filter_stub.c \
2424
../../stub/mac_cca_threshold_stub.c \
25+
../../stub/mac_mode_switch_stub.c \
2526
../../stub/randLIB_stub.c \
2627
../../stub/mac_mlme_stub.c \
2728
../../stub/buffer_dyn_stub.c \
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2021, Pelion and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "nsconfig.h"
19+
#include <string.h>
20+
#include "ns_types.h"
21+
#include "ns_list.h"
22+
#include "ns_trace.h"
23+
#include "mac_defines.h"
24+
25+
int8_t ms_build_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t *data_ptr, uint8_t phy_mode_id)
26+
{
27+
return 0;
28+
}
29+
30+
int8_t ms_parse_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, const uint8_t *data_ptr, uint16_t data_len)
31+
{
32+
return -1;
33+
}
34+
35+
void ms_update_mode_switch_state(protocol_interface_rf_mac_setup_s *rf_ptr)
36+
{
37+
38+
}

0 commit comments

Comments
 (0)