brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #include <intLib.h> |
| 2 | #include <logLib.h> |
| 3 | |
| 4 | namespace aos { |
| 5 | namespace crio { |
| 6 | |
| 7 | template<typename T> |
| 8 | InterruptNotifier<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 | |
| 15 | template<typename T> |
| 16 | InterruptNotifier<T>::~InterruptNotifier() { |
| 17 | sensor_->CancelInterrupts(); |
| 18 | } |
| 19 | |
| 20 | template<typename T> |
| 21 | void InterruptNotifier<T>::Start() { |
| 22 | this->StartTask(); |
| 23 | sensor_->EnableInterrupts(); |
| 24 | } |
| 25 | |
| 26 | template<typename T> |
| 27 | void 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. |
| 33 | template<typename T> |
| 34 | void 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 |