Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "i8254.h"
- #include <minix/sysutil.h>
- #define DELAY_US 20000
- #define ESC_Code 0x81
- #define STAT_REG 0x64
- #define KBC_CMD_REG 0x64
- #define Read_Com 0x20
- #define OUT_BUF 0x60
- #define Double 0xe0
- int hook_id;
- int Bit_Order_Teclado = 4;
- unsigned long stat, data, data_save;
- int timer_subscribe_KBC_int(void ) {
- hook_id = Bit_Order_Teclado;
- sys_irqsetpolicy(IRQ_1, IRQ_REENABLE|IRQ_EXCLUSIVE, &hook_id);
- sys_irqenable(&hook_id);
- return BIT(Bit_Order_Teclado);
- }
- int timer_unsubscribe_KBC_int(void) {
- sys_irqdisable(&hook_id);
- sys_irqrmpolicy(&hook_id);
- return 0;
- }
- unsigned long timer_Ler_KBC()
- {
- while( 1 ) {
- sys_inb(STAT_REG, &stat);
- if( stat & OBF ) {
- sys_inb(OUT_BUF, &data);
- if ( (stat &(PAR_ERR | TO_ERR)) == 0 )
- return data;
- else
- return -1;
- }
- delay(DELAY_US);
- }
- }
- void imprime_data (unsigned long data)
- {
- if (data == -1)
- {
- printf("ERROR");
- }
- if(ESC_Code == data)
- {
- return;
- }
- if(data == Double)
- {
- if (BIT(7) & timer_Ler_KBC());
- {
- printf("Break Code: ",Double," ",data);
- }
- else
- {
- printf("Make Code: ",Double," ",data);
- }
- }
- else
- {
- if (BIT(7) & data);
- {
- printf("Break Code: ",data);
- }
- else
- {
- printf("Make Code: ",data);
- }
- }
- return;
- }
- int kbd_test_scan(unsigned short assembly) {
- unsigned long irq_set;
- message msg;
- int ipc_status;
- timer_subscribe_KBC_int();
- while( ) {
- /* Get a request message. */
- if ( ( r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
- printf("driver_receive failed with: %d", r);
- continue;
- }
- if (is_ipc_notify(ipc_status)) { /* received notification */
- switch (_ENDPOINT_P(msg.m_source)) {
- case HARDWARE: /* hardware interrupt notification */
- if (msg.NOTIFY_ARG & irq_set) {
- imprime_data(timer_Ler_KBC());
- }
- break;
- default:
- break; /* no other notifications expected: do nothing */
- }
- } else { /* received a standard message, not a notification */
- /* no standard messages expected: do nothing */
- }
- }
- tickdelay(micros_to_ticks(DELAY_US);
- timer_unsubscribe_KBC_int;
- }
- int kbd_test_poll() {
- /* To be completed */
- }
- int kbd_test_timed_scan(unsigned short n) {
- /* To be completed */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement