blob: 76c06b58a864a4d4a944461af693be27f2096b07 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#ifndef NOTIFIER_H
8#define NOTIFIER_H
9
10#include "ChipObject.h"
11#include "ErrorBase.h"
12#include "Synchronized.h"
13
14typedef void (*TimerEventHandler)(void *param);
15
16class Notifier : public ErrorBase
17{
18public:
19 Notifier(TimerEventHandler handler, void *param = NULL);
20 virtual ~Notifier();
21 void StartSingle(double delay);
22 void StartPeriodic(double period);
23 void Stop();
24private:
25 static Notifier *timerQueueHead;
26 static ReentrantSemaphore queueSemaphore;
27 static tAlarm *talarm;
28 static tInterruptManager *manager;
29 static int refcount;
30
31 static const UINT32 kTimerInterruptNumber = 28;
32 static void ProcessQueue(uint32_t mask, void *params); // process the timer queue on a timer event
33 static void UpdateAlarm(); // update the FPGA alarm since the queue has changed
34 void InsertInQueue(bool reschedule); // insert this Notifier in the timer queue
35 void DeleteFromQueue(); // delete this Notifier from the timer queue
36 TimerEventHandler m_handler; // address of the handler
37 void *m_param; // a parameter to pass to the handler
38 double m_period; // the relative time (either periodic or single)
39 double m_expirationTime; // absolute expiration time for the current event
40 Notifier *m_nextEvent; // next Nofifier event
41 bool m_periodic; // true if this is a periodic event
42 bool m_queued; // indicates if this entry is queued
43 SEM_ID m_handlerSemaphore; // held by interrupt manager task while handler call is in progress
44 DISALLOW_COPY_AND_ASSIGN(Notifier);
45};
46
47#endif