Now you can download a copy of these docs so you can use them offline! Download now
Watchdog.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 "Watchdog.h" 00008 00009 const double Watchdog::kDefaultWatchdogExpiration; 00010 00014 Watchdog::Watchdog() 00015 : m_fpgaWatchDog(NULL) 00016 { 00017 tRioStatusCode localStatus = NiFpga_Status_Success; 00018 m_fpgaWatchDog = tWatchdog::create(&localStatus); 00019 wpi_setError(localStatus); 00020 SetExpiration(kDefaultWatchdogExpiration); 00021 SetEnabled(true); 00022 } 00023 00027 Watchdog::~Watchdog() 00028 { 00029 SetEnabled(false); 00030 delete m_fpgaWatchDog; 00031 m_fpgaWatchDog = NULL; 00032 } 00033 00046 bool Watchdog::Feed() 00047 { 00048 bool previous = GetEnabled(); 00049 tRioStatusCode localStatus = NiFpga_Status_Success; 00050 m_fpgaWatchDog->strobeFeed(&localStatus); 00051 wpi_setError(localStatus); 00052 return previous; 00053 } 00054 00061 void Watchdog::Kill() 00062 { 00063 tRioStatusCode localStatus = NiFpga_Status_Success; 00064 m_fpgaWatchDog->strobeKill(&localStatus); 00065 wpi_setError(localStatus); 00066 } 00067 00073 double Watchdog::GetTimer() 00074 { 00075 tRioStatusCode localStatus = NiFpga_Status_Success; 00076 UINT32 timer = m_fpgaWatchDog->readTimer(&localStatus); 00077 wpi_setError(localStatus); 00078 return timer / (kSystemClockTicksPerMicrosecond * 1e6); 00079 } 00080 00086 double Watchdog::GetExpiration() 00087 { 00088 tRioStatusCode localStatus = NiFpga_Status_Success; 00089 UINT32 expiration = m_fpgaWatchDog->readExpiration(&localStatus); 00090 wpi_setError(localStatus); 00091 return expiration / (kSystemClockTicksPerMicrosecond * 1e6); 00092 } 00093 00099 void Watchdog::SetExpiration(double expiration) 00100 { 00101 tRioStatusCode localStatus = NiFpga_Status_Success; 00102 m_fpgaWatchDog->writeExpiration((UINT32)(expiration * (kSystemClockTicksPerMicrosecond * 1e6)), &localStatus); 00103 wpi_setError(localStatus); 00104 } 00105 00111 bool Watchdog::GetEnabled() 00112 { 00113 tRioStatusCode localStatus = NiFpga_Status_Success; 00114 bool enabled = !m_fpgaWatchDog->readImmortal(&localStatus); 00115 wpi_setError(localStatus); 00116 return enabled; 00117 } 00118 00131 void Watchdog::SetEnabled(bool enabled) 00132 { 00133 tRioStatusCode localStatus = NiFpga_Status_Success; 00134 m_fpgaWatchDog->writeImmortal(!enabled, &localStatus); 00135 wpi_setError(localStatus); 00136 } 00137 00150 bool Watchdog::IsAlive() 00151 { 00152 tRioStatusCode localStatus = NiFpga_Status_Success; 00153 bool alive = m_fpgaWatchDog->readStatus_Alive(&localStatus); 00154 wpi_setError(localStatus); 00155 return alive; 00156 } 00157 00163 bool Watchdog::IsSystemActive() 00164 { 00165 tRioStatusCode localStatus = NiFpga_Status_Success; 00166 bool alive = m_fpgaWatchDog->readStatus_SystemActive(&localStatus); 00167 wpi_setError(localStatus); 00168 return alive; 00169 } 00170
Generated on Thu Jan 12 2012 22:35:25 for WPILibC++ by
1.7.1