blob: 78e7ca892088184c81b002b0cfdb18402558d6e0 [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(
9 typename InterruptBridge<T>::Handler handler,
10 InterruptableSensorBase *sensor, T *param, int priority)
11 : InterruptBridge<T>(handler, param, priority), sensor_(sensor) {
12 sensor_->RequestInterrupts(StaticNotify, this);
13}
14
15template<typename T>
16InterruptNotifier<T>::~InterruptNotifier() {
17 sensor_->CancelInterrupts();
18}
19
20template<typename T>
21void InterruptNotifier<T>::Start() {
22 this->StartTask();
23 sensor_->EnableInterrupts();
24}
25
26template<typename T>
27void InterruptNotifier<T>::StopNotifications() {
28 sensor_->DisableInterrupts();
29}
30
31// WARNING: This IS called from an ISR. Don't use floating point. Look in
32// interrupt_bridge-tmpl.h for details.
33template<typename T>
34void InterruptNotifier<T>::StaticNotify(uint32_t, void *self_in) {
35 ASM_COMMENT("beginning of InterruptNotifier::StaticNotify");
36 if (!intContext()) { // if we're not in an actual ISR
37 logMsg(const_cast<char *>("WPILib is not calling callbacks"
38 " in actual ISRs any more!!\n"),
39 0, 0, 0, 0, 0, 0);
40 }
41 InterruptNotifier<T> *const self =
42 static_cast<InterruptNotifier<T> *>(self_in);
43 self->Notify();
44 ASM_COMMENT("end of InterruptNotifier::StaticNotify");
45}
46
47} // namespace crio
48} // namespace aos