For DOS Protected Mode version of sensor core software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.2 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "clock.h"
  2. bool int8clock;
  3. SystemTimer *SystemTimer::_instance = NULL;
  4. SystemTimer *SystemTimer::getInstance(){
  5. if( _instance == NULL ) {
  6. _instance = new SystemTimer();
  7. }
  8. return _instance;
  9. };
  10. SystemTimer::~SystemTimer(){
  11. resignISR();
  12. };
  13. SystemTimer::SystemTimer(): CIsr(){
  14. uint16_t tVal;
  15. outportb( 0x43, 0x00 );
  16. uint8_t lp = inportb( 0x40 );
  17. uint8_t hp = inportb( 0x40 );
  18. outportb( 0x43, 0x00 );
  19. uint8_t lc = inportb( 0x40 );
  20. uint8_t hc = inportb( 0x40 );
  21. if( lp == lc ) {
  22. tVal = ( hp << 8 ) || lp;
  23. } else {
  24. tVal = ( hc << 8 ) || lc;
  25. };
  26. uint16_t DTT = _farpeekw( _dos_ds, 0x046C );
  27. m_nInteruptTimerValue = ( DTT << 8 ) + ( (0xFFFFU - tVal ) >> 8 );
  28. m_nSystemTimerValue = 0;
  29. m_bValid = initISR( 8 );
  30. };
  31. uint32_t SystemTimer::getValue( void ){
  32. if( m_bValid ) {
  33. uint16_t tVal;
  34. outportb( 0x43, 0x00 );
  35. uint8_t lp = inportb( 0x40 );
  36. uint8_t hp = inportb( 0x40 );
  37. outportb( 0x43, 0x00 );
  38. uint8_t lc = inportb( 0x40 );
  39. uint8_t hc = inportb( 0x40 );
  40. if( lp == lc ) {
  41. tVal = ( hp << 8 ) || lp;
  42. } else {
  43. tVal = ( hc << 8 ) || lc;
  44. };
  45. uint16_t DTT = _farpeekw( _dos_ds, 0x046C );
  46. m_nSystemTimerValue = ( DTT << 8 ) + ( (0xFFFFU - tVal ) >> 8 );
  47. if( m_nInteruptTimerValue > m_nSystemTimerValue ){
  48. m_nInteruptTimerValue = m_nInteruptTimerValue - m_nSystemTimerValue;
  49. };
  50. return m_nSystemTimerValue - m_nInteruptTimerValue;
  51. } else return -1;
  52. };
  53. void SystemTimer::OnISR( void ){
  54. m_nInteruptTimerValue++;
  55. };
  56. /*
  57. #ifdef __LGS__DOS__STD__AFX__INCLUDED__
  58. static DWORD Interupt8TimerValue;
  59. static DWORD SystemTimerValue;
  60. static DWORD OldInterupt8Value;
  61. static uint16_t Old8TimerValue;
  62. #ifndef __DJGPP__
  63. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  64. #endif
  65. void interrupt (*OldInterupt8Handler )( __CPPARGS );
  66. void interrupt MyInterupt8Handler( __CPPARGS ){
  67. Interupt8TimerValue++;
  68. outportb(0xA0,0x20); // acknowledge interrupt to PIC2
  69. outportb(0x20,0x20); // acknowlegde interrupt to PIC1
  70. };
  71. unsigned char prevPIC2;
  72. #endif
  73. bool init_sys_clock( void ){
  74. / *
  75. #ifdef __LGS__DOS__STD__AFX__INCLUDED__
  76. _disable();
  77. prevPIC2 = inportb( 0xA1 );
  78. outportb( 0xA1, prevPIC2 & 0xFE );
  79. OldInterupt8Handler = _dos_getvect( IRQ8_INTERRUPT_TIMER );
  80. _dos_setvect( IRQ8_INTERRUPT_TIMER, MyInterupt8Handler );
  81. _enable();
  82. int8clock = true;
  83. #else
  84. int8clock = false;
  85. #endif
  86. * /
  87. #ifdef __DJGPP__
  88. uint16_t tVal;
  89. _disable();
  90. outportb( 0x43, 0x00 );
  91. uint8_t lp = inportb( 0x40 );
  92. uint8_t hp = inportb( 0x40 );
  93. _enable();
  94. tVal = ( hp << 8 ) || lp;
  95. uint16_t DTT = _farpeekw( _dos_ds, 0x046C );
  96. Interupt8TimerValue = ( DTT << 8 ) + ( (0xFFFFU - tVal ) >> 8 );
  97. #else
  98. uint16_t tVal;
  99. asm {
  100. pushf // save current inetrrupt status
  101. cli // no ints while we read the 8254
  102. mov al,0 // command to latch counter for counter 0
  103. out 0x43,al // tell the 8254 to latch the count
  104. db 0x24, 0xf0 // jmp $+2, this slow I/O on fast processors
  105. in al,0x40 // read LSB of 8254's count
  106. mov ah,al // temp save
  107. db 0x24, 0xf0 // jmp $+2
  108. in al,0x40 // read MSB of count
  109. xchg al,ah // get right order of MSB/LSB
  110. popf // return saved interrupt status
  111. }
  112. tVal = _AX;
  113. Interupt8TimerValue = ( ( * g_Timer ) << 8 ) + ( (0xFFFFU - tVal ) >> 8 );
  114. #endif
  115. OldInterupt8Value = 0;
  116. SystemTimerValue = 0;
  117. return int8clock;
  118. };
  119. DWORD get_sys_clock( void ){
  120. #ifdef __DJGPP__
  121. uint16_t tVal;
  122. _disable();
  123. outportb( 0x43, 0x00 );
  124. uint8_t lp = inportb( 0x40 );
  125. uint8_t hp = inportb( 0x40 );
  126. _enable();
  127. tVal = ( hp << 8 ) || lp;
  128. uint16_t DTT = _farpeekw( _dos_ds, 0x046C );
  129. SystemTimerValue = ( DTT << 8 ) + ( (0xFFFFU - tVal ) >> 8 );
  130. #else
  131. uint16_t tVal;
  132. asm {
  133. pushf // save current inetrrupt status
  134. cli // no ints while we read the 8254
  135. mov al,0 // command to latch counter for counter 0
  136. out 0x43,al // tell the 8254 to latch the count
  137. db 0x24, 0xf0 // jmp $+2, this slow I/O on fast processors
  138. in al,0x40 // read LSB of 8254's count
  139. mov ah,al // temp save
  140. db 0x24, 0xf0 // jmp $+2
  141. in al,0x40 // read MSB of count
  142. xchg al,ah // get right order of MSB/LSB
  143. popf // return saved interrupt status
  144. }
  145. tVal = _AX;
  146. SystemTimerValue = ( ( * g_Timer ) << 8 ) + ( (0xFFFFU - tVal ) >> 8 );
  147. #endif
  148. / * Interupt8TimerValue += ( 0x0000FFFFUL + tVal - Old8TimerValue ) & 0xFFFF ;
  149. Old8TimerValue = tVal;
  150. printf( " dodus %ul\n", Interupt8TimerValue );
  151. if( Interupt8TimerValue < OldInterupt8Value ){
  152. SystemTimerValue = ( 0xFFFFFFFFUL >> 20 ) + ( Interupt8TimerValue >> 20 );
  153. } else {
  154. SystemTimerValue = ( OldInterupt8Value >> 20 ) + ( Interupt8TimerValue >> 20 );
  155. };
  156. OldInterupt8Value = Interupt8TimerValue;
  157. * /
  158. if( Interupt8TimerValue > SystemTimerValue ){
  159. Interupt8TimerValue = 0;
  160. SystemTimerValue - Interupt8TimerValue;
  161. };
  162. return SystemTimerValue - Interupt8TimerValue;
  163. };
  164. void stop_sys_clock( void ){
  165. / *
  166. #ifdef __LGS__DOS__STD__AFX__INCLUDED__
  167. _disable();
  168. _dos_setvect( IRQ8_INTERRUPT_TIMER, OldInterupt8Handler );
  169. outportb( 0xA1, prevPIC2 );
  170. _enable();
  171. #else
  172. #endif
  173. int8clock = false;
  174. * /
  175. };
  176. */