OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [lwip_tcpip/] [current/] [src/] [netif/] [ppp/] [timesys.c] - Blame information for rev 865

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/**
2
 * @file
3
 * System time and timeout system
4
 *
5
 */
6
 
7
/*
8
 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9
 * All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in the
18
 *    documentation and/or other materials provided with the distribution.
19
 * 3. Neither the name of the Institute nor the names of its contributors
20
 *    may be used to endorse or promote products derived from this software
21
 *    without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
 * SUCH DAMAGE.
34
 *
35
 * Author: Simon Kallweit <simon.kallweit(at)intefo.ch>
36
 */
37
 
38
#include "lwip/mem.h"
39
 
40
#include "netif/ppp/ppp.h"
41
#include "netif/ppp/timesys.h"
42
 
43
/* Milliseconds per jiffy */
44
#define MS_PER_JIFFY    10
45
 
46
/* PPP timeout */
47
struct ppp_timeout {
48
  struct ppp_timeout *next;
49
  ppp_timeout_handler_t handler;
50
  void *arg;
51
  u32_t timeout;
52
};
53
 
54
/* Current system time in ms */
55
static u32_t current_time;
56
 
57
/* Linked list of timeouts */
58
static struct ppp_timeout *timeouts;
59
 
60
 
61
 
62
/*
63
 * Initialize the timesys.
64
 */
65
err_t
66
ppp_timesys_init(void)
67
{
68
  return ERR_OK;
69
}
70
 
71
/*
72
 * Reset the timesys. Removes all timeouts from the list.
73
 */
74
void
75
ppp_timesys_reset(void)
76
{
77
  struct ppp_timeout *t;
78
 
79
  for (t = timeouts; t; t = t->next)
80
    t->handler = NULL;
81
}
82
 
83
/*
84
 * Update the timesys.
85
 */
86
void
87
ppp_timesys_update(u32_t delta)
88
{
89
  struct ppp_timeout *t;
90
 
91
  current_time += delta;
92
 
93
  /* Update timeouts */
94
  for (t = timeouts; t; t = t->next)
95
    if (t->handler) {
96
      if (t->timeout > delta) {
97
        t->timeout -= delta;
98
      } else {
99
        t->handler(t->arg);
100
        t->handler = NULL;
101
      }
102
    }
103
}
104
 
105
/*
106
 * Returns the current time.
107
 */
108
u32_t
109
ppp_jiffies(void)
110
{
111
  return current_time / MS_PER_JIFFY;
112
}
113
 
114
/*
115
 * Setup a timeout.
116
 */
117
void
118
ppp_timeout(ppp_timeout_handler_t handler, void *arg, int timeout)
119
{
120
  struct ppp_timeout *t;
121
 
122
  /* Reuse timeout slot if possible */
123
  for (t = timeouts; t; t = t->next)
124
    if (!t->handler) {
125
      goto setup_timeout;
126
    }
127
 
128
  /* Allocate new timeout */
129
  t = mem_malloc(sizeof(struct ppp_timeout));
130
  LWIP_ASSERT("ppp_timeout: t != NULL", t != NULL);
131
 
132
  /* Append to list */
133
  t->next = timeouts;
134
  timeouts = t;
135
 
136
setup_timeout:
137
  t->handler = handler;
138
  t->arg = arg;
139
  t->timeout = timeout * 1000;
140
}
141
 
142
/*
143
 * Clear a timeout.
144
 */
145
void
146
ppp_untimeout(ppp_timeout_handler_t handler, void *arg)
147
{
148
  struct ppp_timeout *t;
149
 
150
  /* Reuse timeout slot if possible */
151
  for (t = timeouts; t; t = t->next)
152
    if ((t->handler == handler) && (t->arg == arg)) {
153
      t->handler = NULL;
154
    }
155
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.