Skip to content

Commit 5759851

Browse files
author
Mika Tervonen
committed
Changed the rate limiting function to calculate the values runtime
This allows changing of memory after calling packet drop threshold
1 parent 899e755 commit 5759851

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void mac_pd_data_confirm_failure_handle(protocol_interface_rf_mac_setup_s
7474

7575
static int8_t mac_tasklet_event_handler = -1;
7676

77-
static ns_mem_heap_size_t ns_dyn_mem_rate_limiting_threshold = 0xFFFFFFFF;
77+
static uint8_t ns_dyn_mem_rate_limiting_threshold_percentage = 0;
7878

7979
/**
8080
* Get PHY time stamp.
@@ -2127,8 +2127,12 @@ mac_pre_parsed_frame_t *mcps_sap_pre_parsed_frame_buffer_get(const uint8_t *data
21272127
{
21282128
// check that system has enough space to handle the new packet
21292129
const mem_stat_t *ns_dyn_mem_stat = ns_dyn_mem_get_mem_stat();
2130-
if (ns_dyn_mem_stat && ns_dyn_mem_stat->heap_sector_allocated_bytes > ns_dyn_mem_rate_limiting_threshold) {
2131-
return NULL;
2130+
2131+
if (ns_dyn_mem_stat && ns_dyn_mem_rate_limiting_threshold_percentage) {
2132+
if (ns_dyn_mem_stat->heap_sector_allocated_bytes > ns_dyn_mem_stat->heap_sector_size / 100 * (100 - ns_dyn_mem_rate_limiting_threshold_percentage)) {
2133+
// Packet is dropped from radio interface because there is not enough memory to handle incoming packets.
2134+
return NULL;
2135+
}
21322136
}
21332137

21342138
mac_pre_parsed_frame_t *buffer = ns_dyn_mem_temporary_alloc(sizeof(mac_pre_parsed_frame_t) + frame_length);
@@ -2365,10 +2369,8 @@ uint8_t mcps_sap_purge_reg_handler(protocol_interface_rf_mac_setup_s *rf_mac_set
23652369

23662370
int mcps_packet_ingress_rate_limit_by_memory(uint8_t free_heap_percentage)
23672371
{
2368-
const mem_stat_t *ns_dyn_mem_stat = ns_dyn_mem_get_mem_stat();
2369-
2370-
if (ns_dyn_mem_stat && free_heap_percentage < 100) {
2371-
ns_dyn_mem_rate_limiting_threshold = ns_dyn_mem_stat->heap_sector_size / 100 * (100 - free_heap_percentage);
2372+
if (free_heap_percentage < 100) {
2373+
ns_dyn_mem_rate_limiting_threshold_percentage = free_heap_percentage;
23722374
return 0;
23732375
}
23742376

0 commit comments

Comments
 (0)