Skip to content

Commit

Permalink
Fixed delayed interrupt (ARMmbed#2596)
Browse files Browse the repository at this point in the history
* Unit tests for delayed interrupts

* Fixed delayed interrupt on broadcast channel

* Updated change log
  • Loading branch information
Jarkko Paso authored Mar 22, 2021
1 parent 1fca2c1 commit aecadc4
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Bugfix
* All MAC TX failure causes now trigger target change on supplicant EAPOL inititial-key sending
* Fixed compensating delayed interrupt on broadcast channel.

## Release v12.8.1 (22-01-2021)

Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
fhss_structure->ws->is_on_bc_channel = false;
}
delay_us %= MS_TO_US(fhss_structure->ws->fhss_configuration.fhss_broadcast_interval);
delay_us %= MS_TO_US(fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval);
}

if (fhss_structure->ws->fhss_configuration.ws_bc_channel_function == WS_TR51CF) {
Expand Down
1 change: 1 addition & 0 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static fhss_api_t *test_generate_fhss_api(void)
FHSS.callbacks.synch_lost_notification = &mac_synch_lost;
FHSS.callbacks.broadcast_notify = &mac_broadcast_notification;
FHSS.callbacks.read_timestamp = &mac_read_phy_timestamp;
fhss_callbacks_stub.datarate = 250000;
test_set_fhss_default_configs();
test_set_platform_api(&FHSS.platform_functions);
fhss_set_callbacks(&FHSS);
Expand Down
182 changes: 182 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ static bool test_ufsi(uint8_t *ufsi_ptr, uint_fast24_t test_value)
return true;
}

static void test_set_interrupt_delay_us(uint32_t delay_us, bool bc)
{
fhss_callbacks_stub.uint32_value = delay_us + 15752684;
if (bc) {
fhss_common_stub.fhss_struct.ws->next_bc_timeout = fhss_callbacks_stub.uint32_value - delay_us;
} else {
fhss_common_stub.fhss_struct.ws->next_uc_timeout = fhss_callbacks_stub.uint32_value - delay_us;
}
}

static void test_set_platform_api(fhss_timer_t *fhss_timer)
{
fhss_timer->fhss_resolution_divider = 1;
Expand Down Expand Up @@ -158,6 +168,48 @@ static fhss_api_t *test_generate_fhss_api(void)
return &fhss_api;
}

static fhss_api_t *test_generate_fhss_api_default_settings(void)
{
memset(&ws, 0, sizeof(fhss_ws_t));
memset(&fhss_callbacks_stub, 0, sizeof(fhss_callbacks_stub_def));
memset(&fhss_common_stub, 0, sizeof(fhss_common_stub_def));
neighbor_info.uc_timing_info.ufsi = 1000000;
neighbor_info.uc_timing_info.unicast_channel_function = WS_DH1CF;
neighbor_info.uc_timing_info.unicast_dwell_interval = 200;
neighbor_info.uc_timing_info.utt_rx_timestamp = 100000;
fhss_common_stub.fhss_struct.fhss_api = &fhss_api;
fhss_common_stub.fhss_struct.ws = &ws;
fhss_common_stub.fhss_struct.ws->uc_slot = 3;
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_DH1CF;
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_bc_channel_function = WS_DH1CF;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_uc_dwell_interval = 255;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 255;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1020;
fhss_common_stub.fhss_struct.ws->get_neighbor_info = &app_get_neighbor_info;
fhss_common_stub.fhss_struct.number_of_channels = 35;
fhss_common_stub.fhss_struct.number_of_uc_channels = 35;
fhss_common_stub.fhss_struct.number_of_bc_channels = 35;
fhss_common_stub.fhss_struct.ws->fhss_configuration.unicast_channel_mask[1] = 0x00000007;
fhss_common_stub.fhss_struct.ws->fhss_configuration.unicast_channel_mask[0] = 0xffffffff;
fhss_common_stub.fhss_struct.ws->fhss_configuration.channel_mask[1] = 0x00000007;
fhss_common_stub.fhss_struct.ws->fhss_configuration.channel_mask[0] = 0xffffffff;
fhss_common_stub.fhss_struct.rx_channel = DEFAULT_CHANNEL;
fhss_common_stub.fhss_struct.fhss_state = FHSS_UNSYNCHRONIZED;
fhss_common_stub.fhss_struct.own_hop = 0xff;
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
fhss_common_stub.fhss_struct.optimal_packet_length = OPTIMAL_PACKET_LENGTH;
fhss_common_stub.fhss_struct.callbacks.change_channel = &mac_set_channel;
fhss_common_stub.fhss_struct.callbacks.read_mac_address = &mac_read_64bit_mac_address;
fhss_common_stub.fhss_struct.callbacks.read_tx_queue_size = &mac_read_tx_queue_sizes;
fhss_common_stub.fhss_struct.callbacks.read_timestamp = &mac_read_phy_timestamp;
fhss_common_stub.fhss_struct.callbacks.read_datarate = &mac_read_phy_datarate;
fhss_common_stub.fhss_struct.callbacks.tx_poll = &mac_poll_tx_queue;
fhss_callbacks_stub.datarate = 150000;
test_set_platform_api(&fhss_common_stub.fhss_struct.platform_functions);
fhss_ws_set_callbacks(&fhss_common_stub.fhss_struct);
return &fhss_api;
}

bool test_fhss_ws_enable()
{
fhss_api_t fhss_api;
Expand Down Expand Up @@ -565,6 +617,107 @@ bool test_fhss_broadcast_handler()
// Test when FHSS struct not found
disable_fhss_struct();
fhss_common_stub.callback[1](fhss_common_stub.fhss_struct.fhss_api, DEFAULT_TIMER_DELAY);
// Test delayed interrupts
api = test_generate_fhss_api_default_settings();
enable_fhss_struct();
// Test when broadcast channel enabled
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
test_set_interrupt_delay_us(1000000, true);
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 20000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != true) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60002)) {
return false;
}
test_set_interrupt_delay_us(1985000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 65535;
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 55000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != true) || (fhss_common_stub.fhss_struct.ws->bc_slot != 2)) {
return false;
}
test_set_interrupt_delay_us(2905000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 155000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != true) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60004)) {
return false;
}
test_set_interrupt_delay_us(500000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 265000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != false) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60000)) {
return false;
}
test_set_interrupt_delay_us(1720000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 65000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != false) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60001)) {
return false;
}
test_set_interrupt_delay_us(2340000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 465000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != false) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60002)) {
return false;
}
// Test when broadcast channel disabled
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
test_set_interrupt_delay_us(100000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 155000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != true) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60001)) {
return false;
}
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
test_set_interrupt_delay_us(1220000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 55000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != true) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60002)) {
return false;
}
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
test_set_interrupt_delay_us(2280000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 15000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != true) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60003)) {
return false;
}
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
test_set_interrupt_delay_us(555000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 465000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != false) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60001)) {
return false;
}
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
test_set_interrupt_delay_us(1975000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 65000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != false) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60002)) {
return false;
}
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
test_set_interrupt_delay_us(2395000, true);
fhss_common_stub.fhss_struct.ws->bc_slot = 60000;
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if ((fhss_common_stub.fhss_struct.ws->next_bc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 665000)) ||
(fhss_common_stub.fhss_struct.ws->is_on_bc_channel != false) || (fhss_common_stub.fhss_struct.ws->bc_slot != 60003)) {
return false;
}
return true;
}

Expand Down Expand Up @@ -734,6 +887,35 @@ bool test_fhss_unicast_handler()
// Test when FHSS struct not found
disable_fhss_struct();
fhss_common_stub.callback[0](fhss_common_stub.fhss_struct.fhss_api, DEFAULT_TIMER_DELAY);
// Test delayed interrupts
api = test_generate_fhss_api_default_settings();
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 0;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 0;
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_DH1CF;
enable_fhss_struct();
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);

fhss_common_stub.fhss_struct.ws->uc_slot = 10000;
test_set_interrupt_delay_us(100000, false);
fhss_common_stub.callback[0](fhss_common_stub.fhss_struct.fhss_api, DEFAULT_TIMER_DELAY);
if ((fhss_common_stub.fhss_struct.ws->next_uc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 155000)) ||
fhss_common_stub.fhss_struct.ws->uc_slot != 10001) {
return false;
}
fhss_common_stub.fhss_struct.ws->uc_slot = 10000;
test_set_interrupt_delay_us(405000, false);
fhss_common_stub.callback[0](fhss_common_stub.fhss_struct.fhss_api, DEFAULT_TIMER_DELAY);
if ((fhss_common_stub.fhss_struct.ws->next_uc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 105000)) ||
fhss_common_stub.fhss_struct.ws->uc_slot != 10002) {
return false;
}
fhss_common_stub.fhss_struct.ws->uc_slot = 10000;
test_set_interrupt_delay_us(1835000, false);
fhss_common_stub.callback[0](fhss_common_stub.fhss_struct.fhss_api, DEFAULT_TIMER_DELAY);
if ((fhss_common_stub.fhss_struct.ws->next_uc_timeout != (fhss_common_stub.fhss_struct.callbacks.read_timestamp(fhss_common_stub.fhss_struct.fhss_api) + 205000)) ||
fhss_common_stub.fhss_struct.ws->uc_slot != 10008) {
return false;
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/fhss_callbacks_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int mac_read_64bit_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address)

uint32_t mac_read_phy_datarate(const fhss_api_t *fhss_api)
{
return 250000;
return fhss_callbacks_stub.datarate;
}

uint32_t mac_read_phy_timestamp(const fhss_api_t *fhss_api)
Expand Down
1 change: 1 addition & 0 deletions test/nanostack/unittest/stub/fhss_callbacks_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct {
uint8_t uint8_value;
int8_t int8_value;
uint32_t uint32_value;
uint32_t datarate;
uint8_t address[8];
} fhss_callbacks_stub_def;

Expand Down

0 comments on commit aecadc4

Please sign in to comment.