/*===========================================================================* * do_dev_event * *===========================================================================*/ static void *do_dev_event(void *arg) { /* Device notifies us of an event. */ struct job my_job; my_job = *((struct job *) arg); fp = my_job.j_fp; dev_status(job_m_in.m_source); thread_cleanup(fp); return(NULL); }
/*===========================================================================* * do_control_msgs * *===========================================================================*/ static void *do_control_msgs(void *arg) { struct job my_job; my_job = *((struct job *) arg); fp = my_job.j_fp; /* Check for special control messages. */ if (job_m_in.m_source == CLOCK) { /* Alarm timer expired. Used only for select(). Check it. */ expire_timers(job_m_in.NOTIFY_TIMESTAMP); } else { /* Device notifies us of an event. */ dev_status(job_m_in.m_source); } thread_cleanup(NULL); return(NULL); }
/** * Main function. Initializes the USB-device, parses commandline-parameters and * calls the functions that communicate with the device. * \param argc Number of arguments. * \param argv Arguments. * \return Error code. */ int main(int argc, char **argv) { usb_dev_handle *handle = NULL; if (argc < 2) { usage(argv[0]); exit(1); } usb_init(); if (usbOpenDevice (&handle, USBDEV_SHARED_VENDOR, "www.schatenseite.de", USBDEV_SHARED_PRODUCT, "USB-LED-Fader") != 0) { fprintf(stderr, "Could not find USB device \"USB-LED-Fader\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); exit(1); } /* We have searched all devices on all busses for our USB device above. Now * try to open it and perform the vendor specific control operations for the * function requested by the user. */ if (strcmp(argv[1], "test") == 0) { dev_test(handle, argc, argv); } else if (strcmp(argv[1], "set") == 0) { dev_set(handle, argc, argv); } else if (strcmp(argv[1], "clear") == 0) { dev_clear(handle, argc, argv); } else if (strcmp(argv[1], "status") == 0) { dev_status(handle, argc, argv); } else if (strcmp(argv[1], "reset") == 0) { dev_reset(handle, argc, argv); } else if (strcmp(argv[1], "show") == 0) { dev_show(handle, argc, argv); } else { usage(argv[0]); exit(1); } usb_close(handle); return 0; }
/*===========================================================================* * main * *===========================================================================*/ PUBLIC int main(void) { /* This is the main program of the file system. The main loop consists of * three major activities: getting new work, processing the work, and sending * the reply. This loop never terminates as long as the file system runs. */ int error; /* SEF local startup. */ sef_local_startup(); /* This is the main loop that gets work, processes it, and sends replies. */ while (TRUE) { SANITYCHECK; get_work(); /* sets who and call_nr */ if (call_nr == DEV_REVIVE) { endpoint_t endpt; endpt = m_in.REP_ENDPT; if(endpt == VFS_PROC_NR) { endpt = suspended_ep(m_in.m_source, m_in.REP_IO_GRANT); if(endpt == NONE) { printf("FS: proc with " "grant %d from %d not found (revive)\n", m_in.REP_IO_GRANT, m_in.m_source); continue; } } revive(endpt, m_in.REP_STATUS); continue; } if (call_nr == DEV_REOPEN_REPL) { reopen_reply(); continue; } if (call_nr == DEV_CLOSE_REPL) { close_reply(); continue; } if (call_nr == DEV_SEL_REPL1) { select_reply1(); continue; } if (call_nr == DEV_SEL_REPL2) { select_reply2(); continue; } /* Check for special control messages first. */ if (is_notify(call_nr)) { if (who_e == CLOCK) { /* Alarm timer expired. Used only for select(). * Check it. */ expire_timers(m_in.NOTIFY_TIMESTAMP); } else if(who_e == DS_PROC_NR) { /* DS notifies us of an event. */ ds_event(); } else { /* Device notifies us of an event. */ dev_status(&m_in); } SANITYCHECK; continue; } /* We only expect notify()s from tasks. */ if(who_p < 0) { printf("FS: ignoring message from %d (%d)\n", who_e, m_in.m_type); continue; } /* Now it's safe to set and check fp. */ fp = &fproc[who_p]; /* pointer to proc table struct */ super_user = (fp->fp_effuid == SU_UID ? TRUE : FALSE); /* su? */ #if DO_SANITYCHECKS if(fp_is_blocked(fp)) { printf("VFS: requester %d call %d: suspended\n", who_e, call_nr); panic("requester suspended"); } #endif /* Calls from PM. */ if (who_e == PM_PROC_NR) { service_pm(); continue; } SANITYCHECK; /* Other calls. */ switch(call_nr) { case MAPDRIVER: error= do_mapdriver(); if (error != SUSPEND) reply(who_e, error); break; default: /* Call the internal function that does the work. */ if (call_nr < 0 || call_nr >= NCALLS) { error = SUSPEND; /* Not supposed to happen. */ printf("VFS: illegal %d system call by %d\n", call_nr, who_e); } else if (fp->fp_pid == PID_FREE) { error = ENOSYS; printf( "FS, bad process, who = %d, call_nr = %d, endpt1 = %d\n", who_e, call_nr, m_in.endpt1); } else { #if ENABLE_SYSCALL_STATS calls_stats[call_nr]++; #endif SANITYCHECK; error = (*call_vec[call_nr])(); SANITYCHECK; } /* Copy the results back to the user and send reply. */ if (error != SUSPEND) { reply(who_e, error); } } SANITYCHECK; } return(OK); /* shouldn't come here */ }