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( |
brians | 5603268 | 2013-03-02 21:00:17 +0000 | [diff] [blame^] | 9 | Handler handler, |
| 10 | InterruptableSensorBase *sensor, T *param) |
| 11 | : handler_(handler), param_(param), sensor_(sensor) { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 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() { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 22 | sensor_->EnableInterrupts(); |
| 23 | } |
| 24 | |
| 25 | template<typename T> |
| 26 | void InterruptNotifier<T>::StopNotifications() { |
| 27 | sensor_->DisableInterrupts(); |
| 28 | } |
| 29 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 30 | template<typename T> |
| 31 | void InterruptNotifier<T>::StaticNotify(uint32_t, void *self_in) { |
brians | 5603268 | 2013-03-02 21:00:17 +0000 | [diff] [blame^] | 32 | if (intContext()) { // if we are in an actual ISR |
| 33 | logMsg(const_cast<char *>("WPILib is calling callbacks" |
| 34 | " in actual ISRs now!!\n"), |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 35 | 0, 0, 0, 0, 0, 0); |
brians | 5603268 | 2013-03-02 21:00:17 +0000 | [diff] [blame^] | 36 | return; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 37 | } |
| 38 | InterruptNotifier<T> *const self = |
| 39 | static_cast<InterruptNotifier<T> *>(self_in); |
brians | 5603268 | 2013-03-02 21:00:17 +0000 | [diff] [blame^] | 40 | self->handler_(self->param_); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | } // namespace crio |
| 44 | } // namespace aos |