Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include "i8254.h"
  2. #include <minix/sysutil.h>
  3. #define DELAY_US 20000
  4. #define ESC_Code 0x81
  5. #define STAT_REG 0x64
  6. #define KBC_CMD_REG 0x64
  7. #define Read_Com 0x20
  8. #define OUT_BUF 0x60
  9. #define Double 0xe0
  10.  
  11. int hook_id;
  12. int Bit_Order_Teclado = 4;
  13. unsigned long stat, data, data_save;
  14.  
  15. int timer_subscribe_KBC_int(void ) {
  16.  
  17. hook_id = Bit_Order_Teclado;
  18.  
  19. sys_irqsetpolicy(IRQ_1, IRQ_REENABLE|IRQ_EXCLUSIVE, &hook_id);
  20.  
  21. sys_irqenable(&hook_id);
  22.  
  23. return BIT(Bit_Order_Teclado);
  24.  
  25.  
  26.  
  27. }
  28.  
  29. int timer_unsubscribe_KBC_int(void) {
  30.  
  31. sys_irqdisable(&hook_id);
  32.  
  33. sys_irqrmpolicy(&hook_id);
  34.  
  35.  
  36. return 0;
  37. }
  38.  
  39.  
  40.  
  41. unsigned long timer_Ler_KBC()
  42. {
  43.  
  44.  
  45. while( 1 ) {
  46. sys_inb(STAT_REG, &stat);
  47. if( stat & OBF ) {
  48. sys_inb(OUT_BUF, &data);
  49. if ( (stat &(PAR_ERR | TO_ERR)) == 0 )
  50. return data;
  51. else
  52. return -1;
  53. }
  54. delay(DELAY_US);
  55. }
  56. }
  57.  
  58.  
  59.  
  60. void imprime_data (unsigned long data)
  61. {
  62. if (data == -1)
  63. {
  64. printf("ERROR");
  65. }
  66. if(ESC_Code == data)
  67. {
  68.  
  69. return;
  70.  
  71. }
  72. if(data == Double)
  73. {
  74. if (BIT(7) & timer_Ler_KBC());
  75. {
  76. printf("Break Code: ",Double," ",data);
  77.  
  78. }
  79. else
  80. {
  81. printf("Make Code: ",Double," ",data);
  82. }
  83.  
  84. }
  85. else
  86. {
  87. if (BIT(7) & data);
  88. {
  89. printf("Break Code: ",data);
  90.  
  91. }
  92. else
  93. {
  94. printf("Make Code: ",data);
  95. }
  96.  
  97. }
  98. return;
  99. }
  100.  
  101.  
  102.  
  103. int kbd_test_scan(unsigned short assembly) {
  104. unsigned long irq_set;
  105. message msg;
  106. int ipc_status;
  107.  
  108.  
  109. timer_subscribe_KBC_int();
  110.  
  111.  
  112. while( ) {
  113. /* Get a request message. */
  114. if ( ( r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
  115.  
  116. printf("driver_receive failed with: %d", r);
  117.  
  118. continue;
  119. }
  120.  
  121. if (is_ipc_notify(ipc_status)) { /* received notification */
  122.  
  123. switch (_ENDPOINT_P(msg.m_source)) {
  124.  
  125. case HARDWARE: /* hardware interrupt notification */
  126.  
  127. if (msg.NOTIFY_ARG & irq_set) {
  128.  
  129. imprime_data(timer_Ler_KBC());
  130.  
  131.  
  132. }
  133. break;
  134.  
  135. default:
  136.  
  137. break; /* no other notifications expected: do nothing */
  138.  
  139. }
  140.  
  141. } else { /* received a standard message, not a notification */
  142.  
  143. /* no standard messages expected: do nothing */
  144. }
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. tickdelay(micros_to_ticks(DELAY_US);
  153.  
  154.  
  155. timer_unsubscribe_KBC_int;
  156.  
  157.  
  158. }
  159. int kbd_test_poll() {
  160. /* To be completed */
  161. }
  162. int kbd_test_timed_scan(unsigned short n) {
  163. /* To be completed */
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement