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.

140 lines
8.6 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "isr.h"
  2. #include <dpmi.h>
  3. #include <go32.h>
  4. #include <conio.h>
  5. static unsigned char IRQ2ISR[16]={0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77};
  6. static CIsr * ___CISR_HANDLER_OBJECT_ARRAY[_CISR_MAX_IRQ_SLOTS]={ NULL };
  7. static volatile uint8_t ___CISR_HANDLER_REGISTERED_IRQS[_CISR_MAX_IRQ_SLOTS]={ 0 };
  8. static volatile uint8_t ___CISR_CURRENTLY_USED_SLOTS = 0;
  9. //outportb( ICR_REGISTER, END_OF_INTERRUPT );
  10. /*
  11. void __CISR_IsrWraper_0( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[0] ){ ___CISR_HANDLER_OBJECT_ARRAY[0]->EOI();___CISR_HANDLER_OBJECT_ARRAY[0]->OnISR(); }; };
  12. void __CISR_IsrWraper_1( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[1] ){ ___CISR_HANDLER_OBJECT_ARRAY[1]->EOI();___CISR_HANDLER_OBJECT_ARRAY[1]->OnISR(); }; };
  13. void __CISR_IsrWraper_2( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[2] ){ ___CISR_HANDLER_OBJECT_ARRAY[2]->EOI();___CISR_HANDLER_OBJECT_ARRAY[2]->OnISR(); }; };
  14. void __CISR_IsrWraper_3( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[3] ){ ___CISR_HANDLER_OBJECT_ARRAY[3]->EOI();___CISR_HANDLER_OBJECT_ARRAY[3]->OnISR(); }; };
  15. void __CISR_IsrWraper_4( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[4] ){ ___CISR_HANDLER_OBJECT_ARRAY[4]->EOI();___CISR_HANDLER_OBJECT_ARRAY[4]->OnISR(); }; };
  16. void __CISR_IsrWraper_5( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[5] ){ ___CISR_HANDLER_OBJECT_ARRAY[5]->EOI();___CISR_HANDLER_OBJECT_ARRAY[5]->OnISR(); }; };
  17. void __CISR_IsrWraper_6( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[6] ){ ___CISR_HANDLER_OBJECT_ARRAY[6]->EOI();___CISR_HANDLER_OBJECT_ARRAY[6]->OnISR(); }; };
  18. void __CISR_IsrWraper_7( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[7] ){ ___CISR_HANDLER_OBJECT_ARRAY[7]->EOI();___CISR_HANDLER_OBJECT_ARRAY[7]->OnISR(); }; };
  19. void __CISR_IsrWraper_8( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[8] ){ ___CISR_HANDLER_OBJECT_ARRAY[8]->EOI();___CISR_HANDLER_OBJECT_ARRAY[8]->OnISR(); }; };
  20. void __CISR_IsrWraper_9( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[9] ){ ___CISR_HANDLER_OBJECT_ARRAY[9]->EOI();___CISR_HANDLER_OBJECT_ARRAY[9]->OnISR(); }; };
  21. void __CISR_IsrWraper_10( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[10] ){ ___CISR_HANDLER_OBJECT_ARRAY[10]->EOI();___CISR_HANDLER_OBJECT_ARRAY[10]->OnISR(); }; };
  22. void __CISR_IsrWraper_11( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[11] ){ ___CISR_HANDLER_OBJECT_ARRAY[11]->EOI();___CISR_HANDLER_OBJECT_ARRAY[11]->OnISR(); }; };
  23. */
  24. void __CISR_IsrWraper_0( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[0] ){ ___CISR_HANDLER_OBJECT_ARRAY[0]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[0]->EOI(); }; };
  25. void __CISR_IsrWraper_1( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[1] ){ ___CISR_HANDLER_OBJECT_ARRAY[1]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[1]->EOI(); }; };
  26. void __CISR_IsrWraper_2( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[2] ){ ___CISR_HANDLER_OBJECT_ARRAY[2]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[2]->EOI(); }; };
  27. void __CISR_IsrWraper_3( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[3] ){ ___CISR_HANDLER_OBJECT_ARRAY[3]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[3]->EOI(); }; };
  28. void __CISR_IsrWraper_4( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[4] ){ ___CISR_HANDLER_OBJECT_ARRAY[4]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[4]->EOI(); }; };
  29. void __CISR_IsrWraper_5( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[5] ){ ___CISR_HANDLER_OBJECT_ARRAY[5]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[5]->EOI(); }; };
  30. void __CISR_IsrWraper_6( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[6] ){ ___CISR_HANDLER_OBJECT_ARRAY[6]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[6]->EOI(); }; };
  31. void __CISR_IsrWraper_7( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[7] ){ ___CISR_HANDLER_OBJECT_ARRAY[7]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[7]->EOI(); }; };
  32. void __CISR_IsrWraper_8( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[8] ){ ___CISR_HANDLER_OBJECT_ARRAY[8]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[8]->EOI(); }; };
  33. void __CISR_IsrWraper_9( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[9] ){ ___CISR_HANDLER_OBJECT_ARRAY[9]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[9]->EOI(); }; };
  34. void __CISR_IsrWraper_10( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[10] ){ ___CISR_HANDLER_OBJECT_ARRAY[10]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[10]->EOI(); }; };
  35. void __CISR_IsrWraper_11( void ){ if( ___CISR_HANDLER_OBJECT_ARRAY[11] ){ ___CISR_HANDLER_OBJECT_ARRAY[11]->OnISR();___CISR_HANDLER_OBJECT_ARRAY[11]->EOI(); }; };
  36. CIsr::CIsr(){
  37. m_bISR = false;
  38. m_iIRQ = -1;
  39. memset( &m_OldIsrProc, 0, sizeof( _go32_dpmi_seginfo ) );//__dpmi_paddr ) );
  40. memset( &m_CurrentIsrProc, 0, sizeof( _go32_dpmi_seginfo) );//__dpmi_paddr ) );
  41. };
  42. CIsr::~CIsr(){
  43. resignISR();
  44. };
  45. bool CIsr::resignISR( void ){
  46. if( m_bISR ) {
  47. _disable();
  48. if( m_iIRQ < 8 ) {
  49. // Disable THIS Interupt
  50. outportb( MASTER_PIC_DATA, inportb(MASTER_PIC_DATA) | ( ( 1 << m_iIRQ ) & 0xFF ) );
  51. } else {
  52. // On Second IMR controller
  53. outportb( SLAVE_PIC_DATA, inportb( SLAVE_PIC_DATA ) | ( (1 << ( m_iIRQ& 0x07 ) ) & 0xFF ) );
  54. if( ( inportb( SLAVE_PIC_DATA ) & 0xFF ) == 0xFF ) {
  55. // If no SLAVE IRQ enabled then Disable SLAVE PIC in MASTER PIC
  56. outportb( MASTER_PIC_DATA, inportb(MASTER_PIC_DATA) | ( (1 << SLAVE_PIC_IRQ ) & 0xFF ) );
  57. };
  58. };
  59. _go32_dpmi_set_protected_mode_interrupt_vector( m_iIRQ, &m_OldIsrProc );
  60. _enable();
  61. for( uint8_t cSlotID = 0; cSlotID < _CISR_MAX_IRQ_SLOTS; cSlotID ++ ) {
  62. if( ___CISR_HANDLER_OBJECT_ARRAY[cSlotID] == this ) {
  63. ___CISR_HANDLER_OBJECT_ARRAY[cSlotID] = NULL;
  64. ___CISR_HANDLER_REGISTERED_IRQS[cSlotID] = 0;
  65. };
  66. };
  67. m_bISR = false;
  68. };
  69. return true;
  70. };
  71. void CIsr::EOI( void ){
  72. if( m_iIRQ >= 8 ) outportb( SLAVE_PIC_CMD, END_OF_INTERRUPT );
  73. outportb( MASTER_PIC_CMD, END_OF_INTERRUPT );
  74. };
  75. bool CIsr::initISR( int IRQ ){
  76. #ifdef DEBUG
  77. printf("Init ISR for IRQ[0x%02X]\n", IRQ );
  78. #endif
  79. if( m_bISR ) return true; // Already On
  80. if( ___CISR_CURRENTLY_USED_SLOTS >= _CISR_MAX_IRQ_SLOTS ) return false; // No Slots
  81. for( uint8_t cSlotID = 0; cSlotID < _CISR_MAX_IRQ_SLOTS; cSlotID ++ ) {
  82. if( ___CISR_HANDLER_OBJECT_ARRAY[cSlotID] == NULL ) {
  83. #ifdef DEBUG
  84. printf("Using ISR Slot [%02d]\n", cSlotID );
  85. #endif
  86. m_iIRQ = IRQ;
  87. ___CISR_HANDLER_REGISTERED_IRQS[cSlotID] = m_iIRQ;
  88. ___CISR_HANDLER_OBJECT_ARRAY[cSlotID] = this;
  89. _go32_dpmi_get_protected_mode_interrupt_vector( IRQ2ISR[m_iIRQ], &m_OldIsrProc );
  90. m_CurrentIsrProc.pm_selector = _my_cs();
  91. switch( cSlotID ) {
  92. case 0: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_0; break;
  93. case 1: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_1; break;
  94. case 2: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_2; break;
  95. case 3: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_3; break;
  96. case 4: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_4; break;
  97. case 5: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_5; break;
  98. case 6: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_6; break;
  99. case 7: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_7; break;
  100. case 8: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_8; break;
  101. case 9: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_9; break;
  102. case 10: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_10; break;
  103. case 11: m_CurrentIsrProc.pm_offset = (uint32_t)&__CISR_IsrWraper_11; break;
  104. };
  105. //printf("New PROC[%d] [0x%8x:0x%8x]\n", cSlotID, m_CurrentIsrProc.selector, m_CurrentIsrProc.offset32 );
  106. // _go32_dpmi_chain_protected_mode_interrupt_vector(
  107. _go32_dpmi_allocate_iret_wrapper( &m_CurrentIsrProc );
  108. _disable();
  109. //Enable THIS Interrupt
  110. if( m_iIRQ < 8 ) {
  111. outportb( MASTER_PIC_DATA, inportb(MASTER_PIC_DATA) & ((~( 1 << m_iIRQ )) & 0xFF ) );
  112. } else {
  113. // On Second
  114. outportb( SLAVE_PIC_DATA, inportb(SLAVE_PIC_DATA) & (~(1 << ( m_iIRQ& 0x07 ) ) & 0xFF ) );
  115. outportb( MASTER_PIC_DATA, inportb(MASTER_PIC_DATA) & (~(1 << SLAVE_PIC_IRQ ) & 0xFF ) );
  116. };
  117. _go32_dpmi_set_protected_mode_interrupt_vector( IRQ2ISR[m_iIRQ], &m_CurrentIsrProc );
  118. _enable();
  119. ___CISR_CURRENTLY_USED_SLOTS++;
  120. m_bISR = true;
  121. break;
  122. };
  123. };
  124. #ifdef DEBUG
  125. if( m_bISR ) {
  126. printf("ISR Setup Sucessfully!\n" );
  127. } else {
  128. printf("No Empty Slots for ISR Routine!\n" );
  129. };
  130. #endif
  131. return m_bISR;
  132. };