Now you can download a copy of these docs so you can use them offline! Download now
InterruptableSensorBase.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "InterruptableSensorBase.h" 00008 #include "Utility.h" 00009 00010 InterruptableSensorBase::InterruptableSensorBase() 00011 { 00012 m_manager = NULL; 00013 m_interrupt = NULL; 00014 } 00015 00016 InterruptableSensorBase::~InterruptableSensorBase() 00017 { 00018 00019 } 00020 00021 void InterruptableSensorBase::AllocateInterrupts(bool watcher) 00022 { 00023 wpi_assert(m_interrupt == NULL); 00024 wpi_assert(m_manager == NULL); 00025 // Expects the calling leaf class to allocate an interrupt index. 00026 tRioStatusCode localStatus = NiFpga_Status_Success; 00027 m_interrupt = tInterrupt::create(m_interruptIndex, &localStatus); 00028 m_interrupt->writeConfig_WaitForAck(false, &localStatus); 00029 m_manager = new tInterruptManager(1 << m_interruptIndex, watcher, &localStatus); 00030 wpi_setError(localStatus); 00031 } 00032 00037 void InterruptableSensorBase::CancelInterrupts() 00038 { 00039 wpi_assert(m_manager != NULL); 00040 wpi_assert(m_interrupt != NULL); 00041 delete m_interrupt; 00042 delete m_manager; 00043 m_interrupt = NULL; 00044 m_manager = NULL; 00045 } 00046 00051 void InterruptableSensorBase::WaitForInterrupt(float timeout) 00052 { 00053 wpi_assert(m_manager != NULL); 00054 wpi_assert(m_interrupt != NULL); 00055 tRioStatusCode localStatus = NiFpga_Status_Success; 00056 m_manager->watch((INT32)(timeout * 1e3), &localStatus); 00057 wpi_setError(localStatus); 00058 } 00059 00065 void InterruptableSensorBase::EnableInterrupts() 00066 { 00067 wpi_assert(m_manager != NULL); 00068 wpi_assert(m_interrupt != NULL); 00069 tRioStatusCode localStatus = NiFpga_Status_Success; 00070 m_manager->enable(&localStatus); 00071 wpi_setError(localStatus); 00072 } 00073 00077 void InterruptableSensorBase::DisableInterrupts() 00078 { 00079 wpi_assert(m_manager != NULL); 00080 wpi_assert(m_interrupt != NULL); 00081 tRioStatusCode localStatus = NiFpga_Status_Success; 00082 m_manager->disable(&localStatus); 00083 wpi_setError(localStatus); 00084 } 00085 00091 double InterruptableSensorBase::ReadInterruptTimestamp() 00092 { 00093 wpi_assert(m_interrupt != NULL); 00094 tRioStatusCode localStatus = NiFpga_Status_Success; 00095 UINT32 timestamp = m_interrupt->readTimeStamp(&localStatus); 00096 wpi_setError(localStatus); 00097 return timestamp * 1e-6; 00098 }
Generated on Thu Jan 12 2012 22:35:20 for WPILibC++ by
1.7.1