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