blob: 819e55273a485317d535557d31a964760ffdba31 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include <intLib.h>
2#include <logLib.h>
3
4namespace aos {
5namespace crio {
6
7template<typename T>
8InterruptNotifier<T>::InterruptNotifier(
brians56032682013-03-02 21:00:17 +00009 Handler handler,
10 InterruptableSensorBase *sensor, T *param)
11 : handler_(handler), param_(param), sensor_(sensor) {
brians343bc112013-02-10 01:53:46 +000012 sensor_->RequestInterrupts(StaticNotify, this);
13}
14
15template<typename T>
16InterruptNotifier<T>::~InterruptNotifier() {
17 sensor_->CancelInterrupts();
18}
19
20template<typename T>
21void InterruptNotifier<T>::Start() {
brians343bc112013-02-10 01:53:46 +000022 sensor_->EnableInterrupts();
23}
24
25template<typename T>
26void InterruptNotifier<T>::StopNotifications() {
27 sensor_->DisableInterrupts();
28}
29
brians343bc112013-02-10 01:53:46 +000030template<typename T>
31void InterruptNotifier<T>::StaticNotify(uint32_t, void *self_in) {
brians56032682013-03-02 21:00:17 +000032 if (intContext()) { // if we are in an actual ISR
33 logMsg(const_cast<char *>("WPILib is calling callbacks"
34 " in actual ISRs now!!\n"),
brians343bc112013-02-10 01:53:46 +000035 0, 0, 0, 0, 0, 0);
brians56032682013-03-02 21:00:17 +000036 return;
brians343bc112013-02-10 01:53:46 +000037 }
38 InterruptNotifier<T> *const self =
39 static_cast<InterruptNotifier<T> *>(self_in);
brians56032682013-03-02 21:00:17 +000040 self->handler_(self->param_);
brians343bc112013-02-10 01:53:46 +000041}
42
43} // namespace crio
44} // namespace aos