|
Fast Research Interface Library
Manual and Documentation
|
00001 // ---------------------- Doxygen info ---------------------- 00050 // ---------------------------------------------------------- 00051 // For a convenient reading of this file's source code, 00052 // please use a tab width of four characters. 00053 // ---------------------------------------------------------- 00054 00055 00056 #include <FastResearchInterface.h> 00057 #include <pthread.h> 00058 #include <errno.h> 00059 #include <OSAbstraction.h> 00060 00061 00062 00063 00064 // **************************************************************** 00065 // WaitForKRCTick() 00066 // 00067 int FastResearchInterface::WaitForKRCTick(const unsigned int &TimeoutValueInMicroSeconds) 00068 { 00069 int ReturnValue = EOK; 00070 00071 #ifdef _NTO_ 00072 00073 struct timespec TimeoutValue 00074 , CurrentTime; 00075 00076 if (TimeoutValueInMicroSeconds > 0) 00077 { 00078 clock_gettime(CLOCK_REALTIME, &CurrentTime); 00079 00080 TimeoutValue.tv_nsec = (CurrentTime.tv_nsec + (TimeoutValueInMicroSeconds * 1000)) % 1000000000; 00081 TimeoutValue.tv_sec = CurrentTime.tv_sec + (TimeoutValueInMicroSeconds % 1000000) 00082 + (CurrentTime.tv_nsec + (TimeoutValueInMicroSeconds * 1000)) / 1000000000; 00083 00084 pthread_mutex_lock(&(this->MutexForControlData)); 00085 while (!this->NewDataFromKRCReceived) 00086 { 00087 00088 ReturnValue = pthread_cond_timedwait( &(this->CondVarForDataReceptionFromKRC) 00089 , &(this->MutexForControlData) 00090 , &TimeoutValue ); 00091 } 00092 this->NewDataFromKRCReceived = false; 00093 pthread_mutex_unlock(&(this->MutexForControlData)); 00094 00095 return(ReturnValue); 00096 } 00097 00098 #endif 00099 00100 pthread_mutex_lock(&(this->MutexForControlData)); 00101 while (!this->NewDataFromKRCReceived) 00102 { 00103 00104 ReturnValue = pthread_cond_wait( &(this->CondVarForDataReceptionFromKRC) 00105 , &(this->MutexForControlData) ); 00106 } 00107 this->NewDataFromKRCReceived = false; 00108 pthread_mutex_unlock(&(this->MutexForControlData)); 00109 00110 00111 return(ReturnValue); 00112 } 00113 00114 00115 00116 // **************************************************************** 00117 // WaitForTimerTick() 00118 // 00119 int FastResearchInterface::WaitForTimerTick(const unsigned int &TimeoutValueInMicroSeconds) 00120 { 00121 int ReturnValue = 0; 00122 00123 #ifdef _NTO_ 00124 00125 struct timespec TimeoutValue 00126 , CurrentTime; 00127 00128 if (TimeoutValueInMicroSeconds > 0) 00129 { 00130 clock_gettime(CLOCK_REALTIME, &CurrentTime); 00131 00132 TimeoutValue.tv_nsec = (CurrentTime.tv_nsec + (TimeoutValueInMicroSeconds * 1000)) % 1000000000; 00133 TimeoutValue.tv_sec = CurrentTime.tv_sec + (TimeoutValueInMicroSeconds % 1000000) 00134 + (CurrentTime.tv_nsec + (TimeoutValueInMicroSeconds * 1000)) / 1000000000; 00135 00136 pthread_mutex_lock(&(this->MutexForCondVarForTimer)); 00137 while (!this->TimerFlag) 00138 { 00139 00140 ReturnValue = pthread_cond_timedwait( &(this->CondVarForTimer) 00141 , &(this->MutexForCondVarForTimer) 00142 , &TimeoutValue ); 00143 } 00144 this->TimerFlag = false; 00145 pthread_mutex_unlock(&(this->MutexForCondVarForTimer)); 00146 00147 return(ReturnValue); 00148 } 00149 00150 #endif 00151 00152 pthread_mutex_lock(&(this->MutexForCondVarForTimer)); 00153 while (!this->TimerFlag) 00154 { 00155 00156 ReturnValue = pthread_cond_wait( &(this->CondVarForTimer) 00157 , &(this->MutexForCondVarForTimer) ); 00158 } 00159 00160 this->TimerFlag = false; 00161 pthread_mutex_unlock(&(this->MutexForCondVarForTimer)); 00162 00163 return(ReturnValue); 00164 }