NetBurner 3.5.0
PDF Version
 
nettimer.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5/* Definitions for various IP definitions and structures. */
6#ifndef _NB_NETTIMER_H
7#define _NB_NETTIMER_H
8#include <buffers.h>
9#include <utils.h>
10//#define NETTIMER_DIAG (1)
11
12class TimeOutManager;
13
14class TimeOutElement
15{
16 private:
17 TimeOutElement *volatile pNext;
18
19 TimeOutElement *volatile pPrev;
20
21protected:
22 TimeOutManager *volatile pOwner;
23
24 volatile uint32_t NextTime;
25 uint32_t Interval;
26
27#ifdef NETTIMER_DIAG
28 uint32_t seq_check;
29 uint32_t sentinel;
30#endif
31
32 public:
33 virtual void TimeElementEvent() = 0;
34 TimeOutElement(); // Constructor
35 ~TimeOutElement(); // Destructor
36 inline uint32_t GetNextTime() { return NextTime; };
37 inline void ChangeNextInterval(uint32_t nt) { Interval = nt; };
38 inline uint32_t GetInterval() { return Interval; }
39 void SetNextTime(uint32_t nextTime);
40 friend class TimeOutManager;
41} __attribute__((packed));
42
43class TimeOutManager
44{
45 OS_CRIT ManagerCrit;
46 TimeOutElement *volatile pElHead;
47 TimeOutElement *volatile pElTail;
48 volatile uint32_t NextTime;
49 volatile uint32_t LastRun;
50 OS_TCB * OwningTaskTcb;
51
52 void Remove(TimeOutElement &te);
53 void Insert(TimeOutElement &te);
54 void CheckTime(TimeOutElement &te);
55
56#ifdef NETTIMER_DIAG
57 void CheckList(const char *msg, TimeOutElement *pte);
58 void DumpList(uint32_t n);
59 volatile uint32_t entries;
60#endif
61 public:
62 TimeOutManager(); // Constructor
63
64 void InitTaskOwner();
65
66#ifdef NETTIMER_DIAG
67 void Report();
68#endif
69
70 // Cause a repetitive event to happen every TickInterval ticks...
71 // OK to spread allows the system to spread out things like 1 sec ticks uniformly among tick intervals.
72 void RegisterInterval(TimeOutElement &te, uint16_t TickInterval, const char *fromwhere, bool OkToSpread = false);
73
74 // Cause an event to trigger at a specific time.
75 void RegisterTriggerAt(TimeOutElement &te, uint32_t TriggerTime);
76
77 void RegisterTriggerAt(TimeOutElement &te, TickTimeout & tt);
78
79
80 // Remove either a At or interval event from the time manager...
81 void DeRegister(TimeOutElement &te);
82
83 // Returns the time ticks till the next event...
84 // Ok to call this function when no events are due...
85
86 uint32_t ProcessEvents();
87
88 void CoreProcessEvents();
89};
90
91inline void TimeOutElement::SetNextTime(uint32_t nextTime)
92{
93 if (pOwner) pOwner->RegisterTriggerAt(*this, nextTime);
94}
95
96
97
98typedef void(ActionFunction)();
99
100extern TimeOutManager NetTimeOutManager;
101
102class IntervalAction : public TimeOutElement
103{
104 private:
105 ActionFunction *m_pFunc;
106
107 public:
108 IntervalAction(ActionFunction *pf);
109 virtual void TimeElementEvent();
110};
111
112typedef void(DHCPProcessFunction)(PoolPtr p);
113extern DHCPProcessFunction *pDHCPProcessFunction;
114
115typedef void(MULTICastProcessFunction)(PoolPtr p, uint16_t csum);
116extern MULTICastProcessFunction *pMultiCastFunc;
117
118#ifdef IPV6
119#include <udp.h>
120typedef void(DHCPv6ProcessFunction)(UDPPacket *pkt);
121extern DHCPv6ProcessFunction *pDHCPv6ClientProcessFunction;
122#endif
123#endif
NetBurner Buffers API.
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:157
UDP Packet Class.
Definition udp.h:81
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1084
NetBurner User Datagram Protocol Header File.