Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
protocol_core_sleep.c
00001 /* 00002 * Copyright (c) 2015-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 00019 /* 00020 * \file protocol_core_sleep.c 00021 * \brief Add short description about this file!!! 00022 * 00023 */ 00024 #include "nsconfig.h" 00025 #include "string.h" 00026 #include "ns_types.h" 00027 #include "ns_trace.h" 00028 #include "eventOS_callback_timer.h" 00029 #include "NWK_INTERFACE/Include/protocol.h" 00030 #include "NWK_INTERFACE/Include/protocol_timer.h" 00031 #include "common_functions.h" 00032 #include "platform/arm_hal_interrupt.h" 00033 #include "6LoWPAN/ND/nd_router_object.h" 00034 #include "6LoWPAN/Thread/thread_common.h" 00035 #include "6LoWPAN/MAC/mac_data_poll.h" 00036 #include "sw_mac.h" 00037 00038 #define TRACE_GROUP "pCor" 00039 00040 00041 static void protocol_timer_balance(uint32_t time_in_ms) 00042 { 00043 protocol_timer_sleep_balance(time_in_ms); 00044 } 00045 00046 static int protocol_stack_interface_disable_poll(protocol_interface_info_entry_t *cur) 00047 { 00048 int ret_val = -1; 00049 platform_enter_critical(); 00050 if (cur->if_stack_buffer_handler && cur->rfd_poll_info) { 00051 if (!cur->rfd_poll_info->pollActive) { 00052 ret_val = 0; 00053 } 00054 00055 } 00056 platform_exit_critical(); 00057 return ret_val; 00058 } 00059 00060 uint32_t arm_net_check_enter_deep_sleep_possibility(void) 00061 { 00062 protocol_interface_info_entry_t *cur = protocol_stack_interface_sleep_possibility(); 00063 00064 if (!cur) { 00065 return 0; 00066 } 00067 00068 //Calculate sleeping time 00069 uint32_t current_sleep_time = mac_data_poll_get_max_sleep_period(cur); 00070 if (current_sleep_time) { 00071 uint32_t alternative_sleep = 0; 00072 //core_poll_timer_disable(); 00073 current_sleep_time *= 10; 00074 //Check ND time 00075 alternative_sleep = nd_object_time_to_next_nd_reg(); 00076 if (alternative_sleep) { 00077 if (alternative_sleep < current_sleep_time) { 00078 current_sleep_time = alternative_sleep; 00079 } 00080 } 00081 return current_sleep_time; 00082 } 00083 00084 return 0; 00085 } 00086 00087 00088 int arm_net_enter_sleep(void) 00089 { 00090 int ret_val = -1; 00091 protocol_interface_info_entry_t *cur = 0; 00092 cur = protocol_stack_interface_sleep_possibility(); 00093 if (cur) { 00094 if (protocol_stack_interface_disable_poll(cur) == 0) { 00095 platform_enter_critical(); 00096 clear_power_state(SLEEP_MODE_REQ); 00097 platform_exit_critical(); 00098 ret_val = 0; 00099 } 00100 } 00101 return ret_val; 00102 } 00103 00104 int arm_net_wakeup_and_timer_synch(uint32_t sleeped_time_in_ms) 00105 { 00106 int ret_val = -1; 00107 protocol_interface_info_entry_t *cur = 0; 00108 cur = protocol_stack_interface_sleep_possibility(); 00109 00110 if (cur) { 00111 if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) { 00112 //Update MS to 10ms ticks 00113 //uint32_t sleep_time_in_10ms = (sleeped_time_in_ms + 9) / 10 ; 00114 //Enable Data Polling after sleep 00115 //protocol_stack_interface_info_wake_for_polling_interfaces(sleep_time_in_10ms, cur); 00116 protocol_timer_balance(sleeped_time_in_ms); 00117 00118 } 00119 } 00120 return ret_val; 00121 }
Generated on Fri Jul 22 2022 04:53:59 by
 1.7.2
 1.7.2 
    