Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mac_timer.c Source File

mac_timer.c

00001 /*
00002  * Copyright (c) 2014-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 #include "nsconfig.h"
00018 #include "ns_types.h"
00019 #include "ns_trace.h"
00020 #include "eventOS_callback_timer.h"
00021 #include "platform/arm_hal_interrupt.h"
00022 #include "MAC/IEEE802_15_4/sw_mac_internal.h"
00023 #include "MAC/IEEE802_15_4/mac_pd_sap.h"
00024 #include "MAC/IEEE802_15_4/mac_timer.h"
00025 #include "sw_mac.h"
00026 
00027 
00028 /*-------------------MAC TIMER FUNCTIONS--------------------------*/
00029 
00030 
00031 /**
00032  * \brief Function starts MAC timer.
00033  *
00034  * \param event MAC event to timeout
00035  * \param slots Number of MAC ticks (50us)
00036  *
00037  * \return none
00038  */
00039 void timer_mac_start(protocol_interface_rf_mac_setup_s *rf_ptr, mac_event_t event, uint16_t slots)
00040 {
00041     /*Save MAC event*/
00042     if (rf_ptr->mac_timer_id != -1) {
00043         rf_ptr->timer_mac_event = event;
00044         eventOS_callback_timer_start(rf_ptr->mac_timer_id, slots);
00045     }
00046 }
00047 
00048 /**
00049  * \brief Function stops MAC timer.
00050  *
00051  * \param none
00052  *
00053  * \return none
00054  */
00055 void timer_mac_stop(protocol_interface_rf_mac_setup_s *rf_ptr)
00056 {
00057     platform_enter_critical();
00058     if (rf_ptr->mac_timer_id != -1) {
00059         eventOS_callback_timer_stop(rf_ptr->mac_timer_id);
00060         rf_ptr->timer_mac_event = MAC_STATE_IDLE;
00061     }
00062     platform_exit_critical();
00063 }
00064 
00065 void timer_mac_interrupt(int8_t timer_id, uint16_t slots)
00066 {
00067     (void)slots;
00068 
00069     protocol_interface_rf_mac_setup_s *rf_mac_setup = get_sw_mac_ptr_by_timer(timer_id, ARM_NWK_MAC_TIMER);
00070 
00071     if (rf_mac_setup) {
00072         //SET State
00073         rf_mac_setup->mac_tx_result = rf_mac_setup->timer_mac_event;
00074         rf_mac_setup->timer_mac_event = MAC_STATE_IDLE;
00075         mac_pd_sap_state_machine(rf_mac_setup);
00076     }
00077 }