int test_scan(void) { int r; unsigned long data = 0, irq_set; irq_set = kbd_subscribe_int(); int ipc_status; message msg; int i = 0; while (data != BREAK_ESC){ 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) { data = kbd_read_out(); if(1 << 7 & data) printf("Break: 0x%X \n", data); else printf("Make: 0x%X \n", data); }break; default: break; } } } kbd_unsubscribe_int(); return 0; }
int kbd_test_scan(unsigned short ass) { int irq_set = kbd_subscribe_int(); int ipc_status; message msg; unsigned char result = 0; if (irq_set == ERROR) { printf("kbd_test_scan()::kernel call didn't return 0\n"); return ERROR; } while (result != KEY_ESC) { if (driver_receive(ANY, &msg, &ipc_status) != OK) { printf("kbd_test_scan()::driver_receive failed\n"); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { if (ass) { result = kbd_int_handler_asm(); } else { result = kbd_int_handler_C(); } if (result == KEY_ESC) { printf( "kbd_test_scan()::esc was pressed, press any key to continue\n"); } } break; } } } kbd_unsubscribe_int(); return 0; }
/*===========================================================================* * main * *===========================================================================*/ int main(int argc, char *argv[]) { message m_out; int r, ipc_status; size_t size; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); for (;;) { /* Wait for request. */ if(driver_receive(ANY, &m_in, &ipc_status) != OK) { panic("driver_receive failed"); } #if DEBUG2 printf("Filter: got request %d from %d\n", m_in.m_type, m_in.m_source); #endif if(m_in.m_source == DS_PROC_NR && is_ipc_notify(ipc_status)) { ds_event(); continue; } who_e = m_in.m_source; req_id = m_in.BDEV_ID; grant_id = m_in.BDEV_GRANT; size = 0; /* Forword the request message to the drivers. */ switch(m_in.m_type) { case BDEV_OPEN: /* open/close is a noop for filter. */ case BDEV_CLOSE: r = OK; break; case BDEV_READ: r = do_rdwt(FLT_READ); break; case BDEV_WRITE: r = do_rdwt(FLT_WRITE); break; case BDEV_GATHER: r = do_vrdwt(FLT_READ); break; case BDEV_SCATTER: r = do_vrdwt(FLT_WRITE); break; case BDEV_IOCTL: r = do_ioctl(&m_in); break; default: printf("Filter: ignoring unknown request %d from %d\n", m_in.m_type, m_in.m_source); continue; } #if DEBUG2 printf("Filter: replying with code %d\n", r); #endif /* Send back reply message. */ m_out.m_type = BDEV_REPLY; m_out.BDEV_ID = req_id; m_out.BDEV_STATUS = r; send(who_e, &m_out); } return 0; }
int timer_test_int(unsigned long time) { if (timer_subscribe_int()) { return 1; } int r, ipc_status; message msg; time_counter = 0; while (time_counter <= time * TIMER_DEFAULT_FREQ) { /* 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 & BIT(TIMER0_HOOK_BIT)) { /////// /* subscribed interrupt */ timer_int_handler(); if(time_counter % TIMER_DEFAULT_FREQ == 0) { printf("Segundos decorridos: %d\n", time_counter / TIMER_DEFAULT_FREQ); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return timer_unsubscribe_int(); }
int kbd_test_scan_C(void) { int r; unsigned long data = 0, irq_set; int ipc_status; message msg; irq_set = kbd_subscribe_int(); while (data != ESC_CODE){ 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 &BIT(irq_set)) { data = kbd_read_buff(); if(BIT(7) & data) printf("Break code: 0x%2X", data); else printf("Make code: 0x%2X", data); printf("\n ----///---- \n"); }break; default: break; } } } kbd_unsubscribe_int(); return 0; }
/*===========================================================================* * dsp_write *===========================================================================*/ PRIVATE void dsp_write(const message *m_ptr) { message mess; int ipc_status; dprint("sb16_dsp.c: dsp_write()\n"); if(m_ptr->COUNT != DspFragmentSize) { reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, EINVAL); return; } if(m_ptr->m_type != DmaMode && DmaBusy >= 0) { reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, EBUSY); return; } reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, SUSPEND); is_processing = TRUE; if(DmaBusy < 0) { /* Dma tranfer not yet started */ DmaMode = DEV_WRITE_S; /* Dma mode is writing */ sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)DmaPtr, (phys_bytes)DspFragmentSize); dsp_dma_setup(DmaPhys, DspFragmentSize * DMA_NR_OF_BUFFERS); dsp_setup(); DmaBusy = 0; /* Dma is busy */ dprint(" filled dma[0]\n"); DmaFillNext = 1; } else if(DmaBusy != DmaFillNext) { /* Dma transfer started, but Dma buffer not yet full */ sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)DmaPtr + DmaFillNext * DspFragmentSize, (phys_bytes)DspFragmentSize); dprint(" filled dma[%d]\n", DmaFillNext); DmaFillNext = (DmaFillNext + 1) % DMA_NR_OF_BUFFERS; } else if(BufReadNext < 0) { /* Dma buffer full, fill first element of second buffer */ sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)Buffer, (phys_bytes)DspFragmentSize); dprint(" filled buf[0]\n"); BufReadNext = 0; BufFillNext = 1; } else { /* Dma buffer is full, filling second buffer */ while(BufReadNext == BufFillNext) { /* Second buffer also full, wait for space to become available */ driver_receive(HARDWARE, &mess, &ipc_status); dsp_hardware_msg(); } sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)Buffer + BufFillNext * DspFragmentSize, (phys_bytes)DspFragmentSize); dprint(" filled buf[%d]\n", BufFillNext); BufFillNext = (BufFillNext + 1) % DSP_NR_OF_BUFFERS; } is_status_msg_expected = TRUE; revivePending = 1; reviveStatus = DspFragmentSize; reviveProcNr = m_ptr->IO_ENDPT; notify(m_ptr->m_source); }
int main(void) { int err; message m; int ipc_status; sef_local_startup(); for(;;) { err = driver_receive(ANY, &m, &ipc_status); if (err != OK) { printf("ACPI: driver_receive failed: %d\n", err); continue; } switch (((struct acpi_request_hdr *)&m)->request) { case ACPI_REQ_GET_IRQ: do_get_irq(&m); break; case ACPI_REQ_MAP_BRIDGE: do_map_bridge(&m); break; default: printf("ACPI: ignoring unsupported request %d " "from %d\n", ((struct acpi_request_hdr *)&m)->request, ((struct acpi_request_hdr *)&m)->m_source); } err = send(m.m_source, &m); if (err != OK) { printf("ACPI: send failed: %d\n", err); } } }
int test_gesture(short length, unsigned short tolerance) { int ipc_status; message msg; int receive; int validation = 1; sumOfX = 0; int irq_set = mouse_subscribe(); unsigned long clean; counter = 0; interrupts = 0; while (validation) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { validation = gesture_handler(length, tolerance); } break; default: break; } } else { } } mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); //Clean the buffer return 0; }
int test_packet(unsigned short cnt) { int i = 0; int ipc_status; message msg; int receive; int irq_set = mouse_subscribe(); unsigned long clean; counter = 0; interrupts = 0; while (i < cnt * 3) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { mouse_handler(); i++; } break; default: break; } } else { } } mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); //Clean the buffer return 0; }
int test_square(unsigned short x, unsigned short y, unsigned short size, unsigned long color) { vg_init(GRAPHIC_MODE); int ipc_status; message msg; int request; int irq_set; irq_set = subscribe_kbd(); while (scanCode != EXIT_MAKE_CODE) { request = driver_receive(ANY, &msg, &ipc_status); if (request != 0) { printf("driver_receive failed with: %d", request); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { kbd_handler(); } vg_draw_rectangle(x,y,size,size,color); break; default: break; } } else { } } unsubscribe_kbd(); vg_exit(); return 0; }
int test_date() { int ipc_status; message msg; unsigned int i=0; unsigned rtc_hook_id; rtc_subscribe_int(&rtc_hook_id); while(1) { if (driver_receive(ANY, &msg, &ipc_status) != 0) { if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & (1 << RTC_HOOK)) { /* subscribed interrupt */ i++; } break; default: break; } } } } rtc_unsubscribe_int(rtc_hook_id); sys_outb(RTC_ADDR_REG, RTC_CTRL_REG_B); /// }
int start() { unsigned short character = 0x00; int ipc_status; message msg; int irq_set_kb = kb_subscribe_int(); int irq_set_timer = timer_subscribe_int(); int irq_set_mouse = mouse_subscribe_int(); int r; unsigned char packet[3]; unsigned short counter = 0; space_invaders_font = font_init("spaceinvader_font_transparent.bmp"); srand(1); options_load(); mouse_init(); init_state(); highscore_load(); vg_init(VBE_VIDEO_MODE); while (1) { //TODO change condition /* 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_kb) { /* keyboard interrupt */ character = kb_int_handler(); if (character != KB_2BYTE_SCODE) kb_event_handler(character); } if (msg.NOTIFY_ARG & irq_set_mouse){ /* mouse interrupt */ mouse_int_handler(counter, packet); if(packet[0] != MOUSE_ACK && (packet[0] & BIT(3))) counter++; if(counter == 3){ counter = 0; mouse_event_handler(packet); } } if (msg.NOTIFY_ARG & irq_set_timer){ /* timer interrupt */ timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return 0; }
int kbd_test_timed_scan(unsigned short n) { int ipc_status, r, exit = 0, max, counter = 0, flag = 0; unsigned long irq1, irq2, data; message msg; irq2 = subscribe_int(TIMER0_IRQ, IRQ_REENABLE, &timer0_id); irq1 = subscribe_int(KB_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &kb_id); if (irq1 == -1 || irq2 == -1) return -1; // check if subscribe_int failed max = n*60; do { r = driver_receive(ANY, &msg, &ipc_status); if (r != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq1) { counter = 0; data = keyboard_handler(0); flag = print_scancodes(data, flag); if (data == ESC) { printf("Done\n"); exit = 1; } } if (msg.NOTIFY_ARG & irq2) { counter++; if (counter >= max) { printf("Done\n"); exit = 1; } } break; default: break; } } } while (exit == 0); unsubscribe_int(&kb_id); unsubscribe_int(&timer0_id); return 0; }
int main_menu() { continue_condition = true; fade_condition = false; function_to_call = NULL; darken = 127; int failure = 0; initialize_main_menu_buttons(); int ipc_status; message msg; int r; char * display_name = (char*)malloc(sizeof(char) * strlen("Player name: ")+MAX_PLAYER_NAME_LENGTH); strcpy(display_name, "Player name: "); display_name = strcat(display_name, get_program_playername()); if(!failure){ do{ /* 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 & get_kbd_irq_set()){ /* subscribed kbd interrupt */ kbd_int_handler(); } if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */ if(rtc_ih()) failure = 1; getDateString(get_date_str_ptr()); } if(msg.NOTIFY_ARG & get_timer_irq_set()){ timer_int_handler(); main_menu_render(); } if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */ mouse_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } if(mouse_is_updated()) { assign_mouse(get_previous_mouse(), get_mouse()); assign_mouse(get_mouse(), get_mouse_state()); main_menu_mouse_event(get_previous_mouse(), get_mouse()); move_cursor(get_cursor(), get_mouse()->coords); } } while(continue_condition); } return failure; }
int test_line(unsigned short xi, unsigned short yi, unsigned short xf, unsigned short yf, unsigned long color) { char* video_mem = NULL; int failure =0; if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL) { printf("test_line(): vg_init() failed"); return 1; } draw_line(video_mem,xi,yi, xf,yf,color); int kbd_irq_set = 0; if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts printf("test_line(): kbd_subscribe_int() failed \n"); failure = 1; } int ipc_status; message msg; int r; if(!failure){ do{ /* 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 & kbd_irq_set) { /* subscribed kbd interrupt */ if(kbd_int_handler()) failure = 1; } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } while(get_scancode() != ESC_BREAK && !failure); } if(kbd_unsubscribe_int()){//unsubscribe interrupts printf("test_square(): kbd_unsubscribe_int() failed\n"); failure = 1; } printf("Done\n"); if(vg_exit()){ printf("test_line(): vg_exit() failed"); return 1; } return failure; }
int main(void) { int r; message m; int ipc_status; /* SEF local startup. */ sef_local_startup(); for(;;) { r= driver_receive(ANY, &m, &ipc_status); if (r < 0) { printf("PCI: driver_receive failed: %d\n", r); break; } if (is_ipc_notify(ipc_status)) { printf("PCI: got notify from %d\n", m.m_source); /* done, get a new message */ continue; } switch(m.m_type) { case BUSC_PCI_INIT: do_init(&m); break; case BUSC_PCI_FIRST_DEV: do_first_dev(&m); break; case BUSC_PCI_NEXT_DEV: do_next_dev(&m); break; case BUSC_PCI_FIND_DEV: do_find_dev(&m); break; case BUSC_PCI_IDS: do_ids(&m); break; case BUSC_PCI_DEV_NAME: do_dev_name(&m); break; case BUSC_PCI_RESERVE: do_reserve(&m); break; case BUSC_PCI_ATTR_R8: do_attr_r8(&m); break; case BUSC_PCI_ATTR_R16: do_attr_r16(&m); break; case BUSC_PCI_ATTR_R32: do_attr_r32(&m); break; case BUSC_PCI_ATTR_W8: do_attr_w8(&m); break; case BUSC_PCI_ATTR_W16: do_attr_w16(&m); break; case BUSC_PCI_ATTR_W32: do_attr_w32(&m); break; case BUSC_PCI_RESCAN: do_rescan_bus(&m); break; case BUSC_PCI_DEV_NAME_S: do_dev_name_s(&m); break; case BUSC_PCI_SLOT_NAME_S: do_slot_name_s(&m); break; case BUSC_PCI_SET_ACL: do_set_acl(&m); break; case BUSC_PCI_DEL_ACL: do_del_acl(&m); break; case BUSC_PCI_GET_BAR: do_get_bar(&m); break; default: printf("PCI: got message from %d, type %d\n", m.m_source, m.m_type); break; } } return 0; }
/*===========================================================================* * main *===========================================================================*/ PUBLIC int main(int argc, char *argv[]) { int r; endpoint_t caller; int proc_nr; message mess; int ipc_status; /* SEF local startup. */ sef_local_startup(); while(TRUE) { /* Wait for an incoming message */ driver_receive(ANY, &mess, &ipc_status); caller = mess.m_source; proc_nr = mess.IO_ENDPT; if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(mess.m_source)) { case HARDWARE: dsp_hardware_msg(); continue; /* don't reply */ default: r = EINVAL; } /* dont with this message */ goto send_reply; } /* Now carry out the work. */ switch(mess.m_type) { case DEV_OPEN: r = dsp_open(); break; case DEV_CLOSE: r = dsp_close(); break; #ifdef DEV_IOCTL case DEV_IOCTL: r = dsp_ioctl(&mess); break; #endif #ifdef DEV_READ case DEV_READ: r = EINVAL; break; /* Not yet implemented */ case DEV_WRITE: dsp_write(&mess); continue; /* don't reply */ #endif case DEV_STATUS: dsp_status(&mess); continue; /* don't reply */ default: r = EINVAL; } send_reply: /* Finally, prepare and send the reply message. */ reply(TASK_REPLY, caller, proc_nr, r); } }
/*===========================================================================* * blockdriver_receive_mq * *===========================================================================*/ PUBLIC int blockdriver_receive_mq(message *m_ptr, int *status_ptr) { /* receive() interface for drivers with message queueing. */ /* Any queued messages? */ if (mq_dequeue(SINGLE_THREAD, m_ptr, status_ptr)) return OK; /* Fall back to standard receive() interface otherwise. */ return driver_receive(ANY, m_ptr, status_ptr); }
//Interrupt receptor void interupt_handler(int time) { int ipc_status; message msg; //int irq_set=timer_subscribe_int(); int error; //ligar RTC unsigned long regB; counter = 0; regB = read_rtc(RTC_REG_B); regB = regB ^ RTC_UIE; write_rtc(RTC_REG_B,regB); while(counter<(time*60) && check_number_of_tries()==0) { /* Get a request message. */ error = driver_receive(ANY, &msg, &ipc_status); if (error != 0 ) { printf("driver_receive failed with: %d",error); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ /*if ((msg.NOTIFY_ARG & BIT(0)) && (counter%60==0)) //subscribed interruptTimer { //timer_int_handler(counter); //same function as in lab3 RTC_handler_date(); counter++; } else*/ if(msg.NOTIFY_ARG & BIT(1)) { keyboard_handler(); //different function from the original } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } counter++; } return; }
int kbd_test_timed_scan(unsigned short n) { int ipc_status; message msg; int validation = 0; int counter = 0; // usado para evitar chamar a função driver_receive várias vezes int receive; //subscribe() já verifica se não há problemas. int irq_set1 = kbd_subscribe(); int irq_set2 = timer_subscribe_int(); //Para quando a tecla ESC é libertada, ou quando passam n segundos sem input while (!validation) { /* Get a request message. */ receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); 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_set1) { /* subscribed interrupt */ validation = kbd_handler_c(); /* process it */ counter = 0; } if (msg.NOTIFY_ARG & irq_set2) { /* subscribed interrupt */ counter++; /* process it */ if (counter == n*60) { printf("\n\tkbd_test_scan() stopped, press ENTER to continue!\n"); validation = 1; } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } // unsubscribe_int() já verifica se não há problemas. kbd_unsubscribe(); timer_unsubscribe_int(); return 0; }
void *test_init(unsigned short mode, unsigned short delay) { void* video_mem = NULL; if((video_mem=vg_init(mode)) == NULL) { printf("test_init(): vg_init() failed"); return NULL; } int failure=0; int timer_irq_set=0; if((timer_irq_set = timer_subscribe_int()) < 0){//subscribe timer 0 interrupts printf("test_move(): timer_subscribe_int() failed \n"); failure = 1; } int ipc_status; message msg; int r; //unsigned long ticks=0; if(!failure){ do{ /* 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 & timer_irq_set){ timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } while(get_ticks() < delay * 60); } if(timer_unsubscribe_int()){//unsubscribe interrupts printf("test_move(): timer_unsubscribe_int() failed\n"); failure = 1; } if(vg_exit()){ printf("test_init(): vg_exit() failed"); return NULL; } printf("Physical Address of VRAM: 0x%X\n", get_vram_phys_addr()); return (void*)get_video_mem(); }
int timer0_sleep(int n){ int r; int irq_set_timer; int ipc_status; message msg; int time = 60 * n; irq_set_timer = timer_subscribe_int(); while( /*get_counter() < time*/1 ) { r = driver_receive(ANY, &msg, &ipc_status); if ( 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 & BIT(irq_set_timer)) { /* subscribed interrupt */ //timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } timer_unsubscribe_int(); //reset_counter(); return 0; }
int test_packet(unsigned short cnt) { unsigned long mouse_byte; int ipc_status, loops = 0,contador = 0; message msg; unsigned char packets[3]; short irq_set = BIT(mouse_subscribe_int()); enable_packets(); while (loops != cnt) { /* Get a request message. */ if (driver_receive(ANY, &msg, &ipc_status) != 0) { printf("driver_receive failed with: %d"); 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) { mouse_byte = mouse_int_handler(); if (contador == 0) { if (!first_byte(mouse_byte)) { contador = 0; continue; } } packets[contador] = mouse_byte; if (contador == 2) { contador = 0; print_packet(packets); loops++; continue; } contador++; } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return mouse_unsubscribe_int(); }
int test_packet(unsigned short cnt) { int conta = 0, ind = 0, r, ipc_status; unsigned long irq_set, data; char cmd; message msg; if ((irq_set = mouse_subscribe()) == -1) { printf("Unable to subscribe mouse!\n"); return 1; } if (sys_outb(STAT_REG, ENABLE_MOUSE) != OK) //rato enable printf("Error\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) //MOUSE printf("Error-MC\n"); if (sys_outb(OUT_BUF, ENABLE_SEND) != OK) //Ativar o envio printf("Error-SEND\n"); while (cnt > conta) { if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { get_packet(); mouse_print(); } break; default: break; } } else { } } printf("Terminou!\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) printf("ERROR-MC"); if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK) printf("ERROR-DISABLE_STREAM"); if (sys_inb(OUT_BUF, &data) != OK) printf("OUT_BUF not full!\n"); if (data != ACK) printf("Not ACK!\n"); if (mouse_unsubscribe() == -1) printf("falhou unsubscribe mouse!\n"); return 0; }
/*===========================================================================* * main *===========================================================================*/ PUBLIC int main(int argc, char *argv[]) { message mess; int ipc_status; int err, caller, proc_nr; /* SEF local startup. */ sef_local_startup(); /* Here is the main loop of the mixer task. It waits for a message, carries * it out, and sends a reply. */ while (TRUE) { driver_receive(ANY, &mess, &ipc_status); caller = mess.m_source; proc_nr = mess.IO_ENDPT; switch (caller) { case HARDWARE: /* Leftover interrupt. */ continue; case VFS_PROC_NR: /* The only legitimate caller. */ break; default: dprint("sb16: got message from %d\n", caller); continue; } /* Now carry out the work. */ switch(mess.m_type) { case DEV_OPEN: err = mixer_open(&mess); break; case DEV_CLOSE: err = mixer_close(&mess); break; #ifdef DEV_IOCTL case DEV_IOCTL: err = mixer_ioctl(&mess); break; #endif default: err = EINVAL; break; } /* Finally, prepare and send the reply message. */ mess.m_type = TASK_REPLY; mess.REP_ENDPT = proc_nr; dprint("%d %d", err, OK); mess.REP_STATUS = err; /* error code */ send(caller, &mess); /* send reply to caller */ } }
int exit_on_ESC() { int ipc_status, r, exit = 0; unsigned long irq_set, data; message msg; irq_set = keyboard_subscribe_int(); if (irq_set == -1) return 1; // check if subscribe_int failed do { r = driver_receive(ANY, &msg, &ipc_status); if (r != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { data = readFromKBC(); if (data == ESC) { exit = 1; if (vg_exit() != 0) { printf("\texit_on_ESC(): vg_exit() failed\n"); return 1; } } } break; default: break; } } } while (exit == 0); keyboard_unsubscribe_int(); return 0; }
/*===========================================================================* * restart_driver * *===========================================================================*/ static void restart_driver(int which, int tell_rs) { /* Restart the given driver. Block until the new instance is up. */ message msg; int ipc_status; int r; if (tell_rs) { /* Tell RS to refresh or restart the driver */ msg.m_type = RS_REFRESH; msg.RS_CMD_ADDR = driver[which].label; msg.RS_CMD_LEN = strlen(driver[which].label); #if DEBUG printf("Filter: asking RS to refresh %s..\n", driver[which].label); #endif r = sendrec(RS_PROC_NR, &msg); if (r != OK || msg.m_type != OK) panic("RS request failed: %d", r); #if DEBUG printf("Filter: RS call succeeded\n"); #endif } /* Wait until the new driver instance is up, and get its endpoint. */ #if DEBUG printf("Filter: endpoint update driver %d; old endpoint %d\n", which, driver[which].endpt); #endif if(driver[which].up_event == UP_EXPECTED) { driver[which].up_event = UP_NONE; } while(driver[which].up_event != UP_PENDING) { r = driver_receive(DS_PROC_NR, &msg, &ipc_status); if(r != OK) panic("driver_receive returned error: %d", r); ds_event(); } }
int timer_test_int(unsigned long time) { int irq_set = timer_subscribe_int(); //subscreve e inicia as interrupções do timer0 timer_set_square(0,60); //coloca a frequencia a 60 int ipc_status; int r; message msg; unsigned i = 0; while( i < time) { // enquando a contagem é menor que o valor passado no parametro /* 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) { /* subscribed interrupt */ timer_int_handler(); if (counter % 60 == 0) //a cada segundo (60 contagens a 60 de frequencia) { i++; printf("%d", i); // imprime o valor do segundo. printf("\n"); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } if (timer_unsubscribe_int() != OK) //termina a subscrição, caso dê erro retorna 1 return 1; return 0; }
int kbd_test_scan(unsigned short ass) { int ipc_status, r, exit = 0, flag = 0; unsigned long irq_set, data; message msg; irq_set = subscribe_int(KB_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &kb_id); if (irq_set == -1) return -1; // check if subscribe_int failed do { r = driver_receive(ANY, &msg, &ipc_status); if (r != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { data = keyboard_handler(ass); flag = print_scancodes(data, flag); if (data == ESC) { printf("Done\n"); exit = 1; } } break; default: break; } } } while (exit == 0); unsubscribe_int(&kb_id); return 0; }
int test_gesture(short length, unsigned short tolerance) { int ipc_status; message msg; int request; unsigned long irq_set; int stop=0; counter = 0; X = 0; Y = 0; LENGTH = length; TOLERANCE = tolerance; irq_set = subscribe_mouse(); while(!stop) { request = driver_receive(ANY, &msg, &ipc_status); if (request != 0 ) { printf("driver_receive failed with: %d", request); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { stop=gesture_handler(); if(abs(Y) > tolerance){ X=0; Y=0; } } break; default: break; } } } mouse_write_byte(DISABLE_DATA_PACKETS); unsubscribe_mouse(); printf("\nExit gesture!\n"); return 0; }