umts_timer.c 6.1 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/***************************************************************************
                          umts_timer.c  -  description
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier@eurecom.fr



 ***************************************************************************/
//#include "rtos_header.h"
#include "platform_types.h"

#include "list.h"
#include "umts_timer_struct.h"
#include "mem_block.h"
#include "openair_defs.h"
//-----------------------------------------------------------------------------
void
41
umts_timer_check_time_out (list2_t * atimer_listP, uint32_t current_frame_tick_millisecondsP)
42
{
43
  //-----------------------------------------------------------------------------
44 45
  struct timer_unit *timer;
  mem_block_t      *mem_unit;
46
  uint8_t              time_out = 255;
47
  mem_unit = atimer_listP->head;
48

49 50 51
  // do it simple now.
  while ((mem_unit) && (time_out)) {
    timer = (struct timer_unit *) (mem_unit->data);
52

53 54 55 56
    if ((current_frame_tick_millisecondsP - timer->frame_tick_start) >= timer->frame_time_out) {

      mem_unit = list2_remove_head (atimer_listP);
      (*(timer->proc)) (timer->protocol, timer->timer_id);
57
      free_mem_block (mem_unit, __func__);
58 59 60 61 62 63 64 65 66 67 68 69

      mem_unit = atimer_listP->head;
    } else {
      time_out = 0;
    }
  }
}

//-----------------------------------------------------------------------------
void
umts_timer_delete_timer (list2_t * atimer_listP, void *timer_idP)
{
70
  //-----------------------------------------------------------------------------
71 72 73 74 75 76
  mem_block_t      *mem_unit;
  mem_unit = atimer_listP->head;

  while ((mem_unit)) {
    if (((struct timer_unit *) (mem_unit->data))->timer_id == timer_idP) {
      list2_remove_element (mem_unit, atimer_listP);
77
      free_mem_block (mem_unit, __func__);
78 79
      return;
    }
80

81 82 83 84 85 86
    mem_unit = mem_unit->next;
  }
}

//-----------------------------------------------------------------------------
mem_block_t      *
87
umts_add_timer_list_up (list2_t * atimer_listP, void (*procP) (void *, void *), void *protocolP, void *timer_idP, uint32_t frame_time_outP, uint32_t current_frame_tick_millisecondsP)
88
{
89
  //-----------------------------------------------------------------------------
90 91 92
  struct mem_block_t *mb;
  struct timer_unit *timer;
  mem_block_t      *mem_unit;
93 94
  int32_t             remaining_time;
  uint8_t              inserted = 0;
95

96
  mb = get_free_mem_block (sizeof (struct timer_unit), __func__);
97
  if(mb==NULL) return NULL;
98 99 100 101 102 103 104 105
  ((struct timer_unit *) (mb->data))->proc = procP;
  ((struct timer_unit *) (mb->data))->protocol = protocolP;
  ((struct timer_unit *) (mb->data))->timer_id = timer_idP;
  ((struct timer_unit *) (mb->data))->frame_time_out = frame_time_outP;
  ((struct timer_unit *) (mb->data))->frame_tick_start = current_frame_tick_millisecondsP;

  // insert the timer in list in ascending order
  mem_unit = atimer_listP->head;
106

107 108 109 110
  while ((mem_unit) && (!inserted)) {
    timer = (struct timer_unit *) (mem_unit->data);

    remaining_time = timer->frame_time_out - current_frame_tick_millisecondsP + timer->frame_tick_start;
111

112 113 114
    // not timed out
    if ((remaining_time > 0) && (frame_time_outP < remaining_time)) {
      inserted = 255;
115

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
      if (mem_unit == atimer_listP->head) {
#ifdef DEBUG_TIMER
        msg ("[TIMER][CREATION] added timer_id %p at head time out %d current time %d proc %p \n", timer_idP, frame_time_outP, current_frame_tick_millisecondsP, *procP);
#endif
        list2_add_head (mb, atimer_listP);
      } else {
#ifdef DEBUG_TIMER
        msg ("[TIMER][CREATION] inserted timer_id %p  time out %d current time %d proc %p \n", timer_idP, frame_time_outP, current_frame_tick_millisecondsP, *procP);
#endif
        mb->previous = mem_unit->previous;
        mb->next = mem_unit;
        mem_unit->previous->next = mb;
        mem_unit->previous = mb;
      }
    } else {
      mem_unit = mem_unit->next;
    }
  }
134

135 136 137 138 139 140
  if (!inserted) {
#ifdef DEBUG_TIMER
    msg ("[TIMER][CREATION] added timer_id %p at tail time out %d current time %d proc %p \n", timer_idP, frame_time_outP, current_frame_tick_millisecondsP, *procP);
#endif
    list2_add_tail (mb, atimer_listP);
  }
141

142 143 144 145 146 147 148
  return mb;
}

//-----------------------------------------------------------------------------
void
umts_stop_all_timers (list2_t * atimer_listP)
{
149
  //-----------------------------------------------------------------------------
150 151 152 153 154 155 156
  list2_free (atimer_listP);
}

//-----------------------------------------------------------------------------
void
umts_stop_all_timers_except (list2_t * atimer_listP, void (*procP) (void *, void *))
{
157
  //-----------------------------------------------------------------------------
158 159 160 161
  struct timer_unit *timer;
  mem_block_t      *mem_unit;
  mem_block_t      *mem_unit_to_delete;
  mem_unit = atimer_listP->head;
162

163 164
  while ((mem_unit)) {
    timer = (struct timer_unit *) (mem_unit->data);
165

166 167 168 169
    if (timer->proc != procP) {
      mem_unit_to_delete = mem_unit;
      mem_unit = mem_unit->next;
      list2_remove_element (mem_unit_to_delete, atimer_listP);
170
      free_mem_block (mem_unit_to_delete, __func__);
171 172 173 174 175
    } else {
      mem_unit = mem_unit->next;
    }
  }
}