int scull_p_poll (struct inode *inode, struct file *filp, int mode, select_table *table) { Scull_Pipe *dev = filp->private_data; if (mode == SEL_IN) { if (dev->rp != dev->wp) return 1; /* readable */ PDEBUG("Waiting to read\n"); select_wait(&dev->inq, table); /* wait for data */ return 0; } if (mode == SEL_OUT) { /* * the buffer is full if "wp" is right behind "rp", * and the buffer is circular. "left" can't drop * to 0, as this would be taken as empty buffer */ int left = (dev->rp + dev->buffersize - dev->wp) % dev->buffersize; if (left>1) return 1; /* writable */ PDEBUG("Waiting to write\n"); select_wait(&dev->outq, table); /* wait for free space */ return 0; } return 0; /* never exception-able */ }
int scull_p_poll(struct inode *inode, struct file *filp, int mode, select_table *table) { Scull_Pipe *dev = filp->private_data; if (mode == SEL_IN) { if (dev->rp != dev->wp) return 1; /* readable */ PDEBUG("Waiting to read\n"); select_wait(&dev->inq, table); /* wait for data */ return 0; } if (mode == SEL_OUT) { /* * The buffer is circular; it is considered full * if "wp" is right behind "rp". "left" is 0 if the * buffer is empty, and it is "1" if it is completely full. */ int left = (dev->rp + dev->buffersize - dev->wp) % dev->buffersize; if (left != 1) return 1; /* writable */ PDEBUG("Waiting to write\n"); select_wait(&dev->outq, table); /* wait for free space */ return 0; } return 0; /* never exception-able */ }
static int normal_select(struct tty_struct * tty, struct inode * inode, struct file * file, int sel_type, select_table *wait) { switch (sel_type) { case SEL_IN: if (input_available_p(tty)) return 1; /* fall through */ case SEL_EX: if (tty->packet && tty->link->ctrl_status) return 1; if (tty->flags & (1 << TTY_SLAVE_CLOSED)) return 1; if (tty_hung_up_p(file)) return 1; select_wait(&tty->secondary.proc_list, wait); return 0; case SEL_OUT: if (LEFT(&tty->write_q) > WAKEUP_CHARS) return 1; select_wait(&tty->write_q.proc_list, wait); return 0; } return 0; }
static int normal_select(struct tty_struct * tty, struct inode * inode, struct file * file, int sel_type, select_table *wait) { switch (sel_type) { case SEL_IN: if (input_available_p(tty, TIME_CHAR(tty) ? 0 : MIN_CHAR(tty))) return 1; /* fall through */ case SEL_EX: if (tty->packet && tty->link->ctrl_status) return 1; if (tty->flags & (1 << TTY_OTHER_CLOSED)) return 1; if (tty_hung_up_p(file)) return 1; if (!waitqueue_active(&tty->read_wait)) { if (MIN_CHAR(tty) && !TIME_CHAR(tty)) tty->minimum_to_wake = MIN_CHAR(tty); else tty->minimum_to_wake = 1; } select_wait(&tty->read_wait, wait); return 0; case SEL_OUT: if (tty->driver.chars_in_buffer(tty) < WAKEUP_CHARS) return 1; select_wait(&tty->write_wait, wait); return 0; } return 0; }
static int unix_select(struct socket *sock, int sel_type, select_table * wait) { struct unix_proto_data *upd, *peerupd; /* * Handle server sockets specially. */ if (sock->flags & SO_ACCEPTCON) { if (sel_type == SEL_IN) { if (sock->iconn) return 1; select_wait(sock->wait, wait); return (sock->iconn ? 1 : 0); } select_wait(sock->wait, wait); return 0; } if (sel_type == SEL_IN) { upd = UN_DATA(sock); if (UN_BUF_AVAIL(upd)) /* even if disconnected */ return 1; else if (sock->state != SS_CONNECTED) return 1; select_wait(sock->wait, wait); return 0; } if (sel_type == SEL_OUT) { if (sock->state != SS_CONNECTED) return 1; peerupd = UN_DATA(sock->conn); if (UN_BUF_SPACE(peerupd) > 0) return 1; select_wait(sock->wait, wait); return 0; } /* * Exceptions - SEL_EX */ return 0; }
static int unix_proto_select(struct socket *sock, int sel_type, select_table * wait) { struct unix_proto_data *upd, *peerupd; /* * handle server sockets specially */ if (sock->flags & SO_ACCEPTCON) { if (sel_type == SEL_IN) { PRINTK("sock_select: %sconnections pending\n", sock->iconn ? "" : "no "); if (sock->iconn) return 1; select_wait(sock->wait, wait); return sock->iconn ? 1 : 0; } PRINTK("sock_select: nothing else for server socket\n"); select_wait(sock->wait, wait); return 0; } if (sel_type == SEL_IN) { upd = UN_DATA(sock); PRINTK("unix_proto_select: there is%s data available\n", UN_BUF_AVAIL(upd) ? "" : " no"); if (UN_BUF_AVAIL(upd)) /* even if disconnected */ return 1; else if (sock->state != SS_CONNECTED) { PRINTK("unix_proto_select: socket not connected (read EOF)\n"); return 1; } select_wait(sock->wait,wait); return 0; } if (sel_type == SEL_OUT) { if (sock->state != SS_CONNECTED) { PRINTK("unix_proto_select: socket not connected (write EOF)\n"); return 1; } peerupd = UN_DATA(sock->conn); PRINTK("unix_proto_select: there is%s space available\n", UN_BUF_SPACE(peerupd) ? "" : " no"); if (UN_BUF_SPACE(peerupd) > 0) return 1; select_wait(sock->wait,wait); return 0; } /* SEL_EX */ PRINTK("unix_proto_select: there are no exceptions here?!\n"); return 0; }
void test_select_function(chanend c, chanend d) { // Setup the channels to generate events chanend_setup_select(c, EVENT_CHAN_C); chanend_setup_select(d, EVENT_CHAN_D); chanend_enable_trigger(c); chanend_enable_trigger(d); for (int count = 0; count < 10; count++) { event_choice_t choice = select_wait(); switch (choice) { case EVENT_CHAN_C: { // Read value and clear event uint32_t x; chan_in_word(c, &x); debug_printf("Received %d on channel c\n", x); break; } case EVENT_CHAN_D: { // Read value and clear event uint32_t x; chan_in_word(d, &x); debug_printf("Received %d on channel d\n", x); break; } } } chanend_disable_trigger(c); chanend_disable_trigger(d); }
static int capi_select(struct inode *inode, struct file *file, int sel_type, select_table * wait) { unsigned int minor = MINOR(inode->i_rdev); struct capidev *cdev; if (!minor || minor > CAPI_MAXMINOR || !capidevs[minor].is_registered) return -ENODEV; cdev = &capidevs[minor]; switch (sel_type) { case SEL_IN: if (!skb_queue_empty(&cdev->recv_queue)) return 1; /* fall througth */ case SEL_EX: /* error conditions ? */ select_wait(&cdev->recv_wait, wait); return 0; case SEL_OUT: /* if (!queue_full()) return 1; select_wait(&cdev->send_wait, wait); return 0; */ return 1; } return 1; }
static int resizetty(void) { /* * \e7 Save current state (cursor coordinates, attributes, * character sets pointed at by G0, G1). * \e[r Set scrolling region; parameters are top and bottom row. * \e[32766E Move cursor down 32766 (INT16_MAX - 1) rows. * \e[32766C Move cursor right 32766 columns. * \e[6n Report cursor position. * \e8 Restore state most recently saved by \e7. */ static const char *getpos = "\e7\e[r\e[32766E\e[32766C\e[6n\e8"; char retstr[32]; int row, col; size_t pos; ssize_t rc; struct winsize ws; struct termios saved_attributes; int saved_fl; if (!isatty(STDIN_FILENO)) errx(EXIT_FAILURE, _("stdin does not refer to a terminal")); tty_raw(&saved_attributes, &saved_fl); if (write_all(STDIN_FILENO, getpos, strlen(getpos)) < 0) { warn(_("write failed")); tty_restore(&saved_attributes, &saved_fl); return 1; } for (pos = 0; pos < sizeof(retstr) - 1;) { if (0 == select_wait()) break; if ((rc = read(STDIN_FILENO, retstr + pos, sizeof(retstr) - 1 - pos)) < 0) { if (errno == EINTR) continue; warn(_("read failed")); tty_restore(&saved_attributes, &saved_fl); return 1; } pos += rc; if (retstr[pos - 1] == 'R') break; } retstr[pos] = 0; tty_restore(&saved_attributes, &saved_fl); rc = sscanf(retstr, "\033[%d;%dR", &row, &col); if (rc != 2) { warnx(_("invalid cursor position: %s"), retstr); return 1; } memset(&ws, 0, sizeof(struct winsize)); ioctl(STDIN_FILENO, TIOCGWINSZ, &ws); ws.ws_row = row; ws.ws_col = col; ioctl(STDIN_FILENO, TIOCSWINSZ, &ws); return 0; }
static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table *wait) { if (sel_type == SEL_IN) { if (mouse.ready) return 1; select_wait(&mouse.wait, wait); } return 0; }
static int kmsg_select(struct inode *inode, struct file *file, int sel_type, select_table * wait) { if (sel_type != SEL_IN) return 0; if (log_size) return 1; select_wait(&log_wait, wait); return 0; }
static int aux_select(struct inode *inode, struct file *file, int sel_type, select_table * wait) { if (sel_type != SEL_IN) return 0; if (aux_ready) return 1; select_wait(&queue->proc_list, wait); return 0; }
static int lirc_select(struct inode *node, struct file *file, int sel_type, select_table * wait) { if (sel_type != SEL_IN) return 0; if (rbh != rbt) return 1; select_wait(&lirc_wait_in, wait); return 0; }
int tty_select(struct inode *inode, /* how revolting, K&R style defs */ struct file *file, int sel_type) { register struct tty *tty = determine_tty(inode->i_rdev); register char *ret = 0; switch (sel_type) { case SEL_IN: if (chq_peekch(&tty->inq)) return 1; select_wait(&tty->inq.wq); break; case SEL_OUT: ret = (char *)(!chq_full(&tty->outq)); if (!ret) select_wait(&tty->outq.wq); /*@fallthrough@*/ /* case SEL_EX: */ /* break; */ } return (int) ret; }
static int netlink_select(struct inode *inode, struct file *file, int sel_type, select_table * wait) { unsigned int minor = MINOR(inode->i_rdev); switch (sel_type) { case SEL_IN: if (skb_peek(&skb_queue_rd[minor])!=NULL) return 1; select_wait(&read_space_wait[minor], wait); break; case SEL_OUT: return 1; } return 0; }
static int inet_select(register struct socket *sock, int sel_type, select_table * wait) { debug("inet_select\n"); if (sel_type == SEL_IN) { if (sock->avail_data || sock->state != SS_CONNECTED) return 1; else { select_wait(sock->wait); return 0; } } else if (sel_type == SEL_OUT) return 1; return 0; }
static void keypress_wait(CdIo_t *p_cdio) { action("press any key to continue"); while (1 != select_wait(b_cd ? 1 : 5)) { read_subchannel(p_cdio); display_status(true); } (void) getch(); clrtobot(); action(NULL); if (!b_all_tracks) display_cdinfo(p_cdio, i_tracks_global, i_first_track_global); i_last_display_track = CDIO_INVALID_TRACK; }
static int ds_select(struct inode *inode, struct file *file, int sel_type, select_table *wait) { socket_t i = MINOR(inode->i_rdev); socket_info_t *s; user_info_t *user; DEBUG(2, "ds_select(socket %d)\n", i); if ((i >= sockets) || (sockets == 0)) return -ENODEV; s = &socket_table[i]; user = file->private_data; if (CHECK_USER(user)) return -EIO; if (sel_type != SEL_IN) return 0; if (!queue_empty(user)) return 1; select_wait(&s->queue, wait); return 0; } /* ds_select */
int datagram_select(struct sock *sk, int sel_type, select_table *wait) { select_wait(sk->sleep, wait); switch(sel_type) { case SEL_IN: if (sk->type==SOCK_SEQPACKET && sk->state==TCP_CLOSE) { /* Connection closed: Wake up */ return(1); } if (sk->rqueue != NULL || sk->err != 0) { /* This appears to be consistent with other stacks */ return(1); } return(0); case SEL_OUT: if (sk->prot && sk->prot->wspace(sk) >= MIN_WRITE_SPACE) { return(1); } if (sk->prot==NULL && sk->sndbuf-sk->wmem_alloc >= MIN_WRITE_SPACE) { return(1); } return(0); case SEL_EX: if (sk->err) return(1); /* Socket has gone into error state (eg icmp error) */ return(0); } return(0); }
/* Display an error message.. */ static void xperror(const char *psz_msg) { char line[80]; if (!b_interactive) { if (b_verbose) { fprintf(stderr, "error: "); perror(psz_msg); } return; } if (b_verbose) { snprintf(line, sizeof(line), "%s: %s", psz_msg, strerror(errno)); attron(A_STANDOUT); mvprintw(LINE_ACTION, 0, (char *) "error : %s", line); attroff(A_STANDOUT); clrtoeol(); refresh(); select_wait(3); action(""); } }
int main(int argc, char *argv[]) { int c, nostop=0; char *h; int i_rc = 0; cd_operation_t cd_op = NO_OP; /* operation to do in non-interactive mode */ psz_program = strrchr(argv[0],'/'); psz_program = psz_program ? psz_program+1 : argv[0]; memset(&cddb_opts, 0, sizeof(cddb_opts)); cdio_loglevel_default = CDIO_LOG_WARN; /* parse options */ while ( 1 ) { if (-1 == (c = getopt(argc, argv, "acCdehkplL:sSt:vx"))) break; switch (c) { case 'v': b_verbose = true; if (cdio_loglevel_default > CDIO_LOG_INFO) cdio_loglevel_default = CDIO_LOG_INFO; break; case 'd': debug = 1; if (cdio_loglevel_default > CDIO_LOG_DEBUG) cdio_loglevel_default = CDIO_LOG_DEBUG; break; case 'a': auto_mode = 1; break; case 'L': i_volume_level = atoi(optarg); cd_op = SET_VOLUME; b_interactive = false; break; case 't': if (NULL != (h = strchr(optarg,'-'))) { *h = 0; start_track = atoi(optarg); stop_track = atoi(h+1)+1; if (0 == start_track) start_track = 1; if (1 == stop_track) stop_track = CDIO_CDROM_LEADOUT_TRACK; } else { start_track = atoi(optarg); stop_track = start_track+1; one_track = 1; } b_interactive = false; cd_op = PLAY_TRACK; break; case 'p': b_interactive = false; cd_op = PLAY_CD; break; case 'l': b_interactive = false; cd_op = LIST_TRACKS; break; case 'C': b_interactive = false; cd_op = CLOSE_CD; break; case 'c': b_interactive = false; cd_op = PS_LIST_TRACKS; break; case 's': b_interactive = false; cd_op = STOP_PLAYING; break; case 'S': b_interactive = false; cd_op = LIST_SUBCHANNEL; break; case 'e': b_interactive = false; cd_op = EJECT_CD; break; case 'k': print_keys(); exit(1); case 'h': usage(psz_program); exit(1); default: usage(psz_program); exit(1); } } if (argc > optind) { psz_device = strdup(argv[optind]); } else { char **ppsz_cdda_drives=NULL; char **ppsz_all_cd_drives = cdio_get_devices_ret(&driver_id); if (!ppsz_all_cd_drives) { fprintf(stderr, "Can't find a CD-ROM drive\n"); exit(2); } ppsz_cdda_drives = cdio_get_devices_with_cap(ppsz_all_cd_drives, CDIO_FS_AUDIO, false); if (!ppsz_cdda_drives || !ppsz_cdda_drives[0]) { fprintf(stderr, "Can't find a CD-ROM drive with a CD-DA in it\n"); exit(3); } psz_device = strdup(ppsz_cdda_drives[0]); cdio_free_device_list(ppsz_all_cd_drives); cdio_free_device_list(ppsz_cdda_drives); } if (!b_interactive) { b_sig = true; nostop=1; } tty_raw(); signal(SIGINT,ctrlc); signal(SIGQUIT,ctrlc); signal(SIGTERM,ctrlc); signal(SIGHUP,ctrlc); signal(SIGWINCH, sigwinch); if (CLOSE_CD != cd_op) { /* open device */ if (b_verbose) fprintf(stderr, "open %s... ", psz_device); p_cdio = cdio_open (psz_device, driver_id); if (!p_cdio && cd_op != EJECT_CD) { cd_close(psz_device); p_cdio = cdio_open (psz_device, driver_id); } if (p_cdio && b_verbose) fprintf(stderr,"ok\n"); } if (b_interactive) { #ifdef HAVE_CDDB cddb_log_set_handler (cddb_log_handler); #else ; #endif } else { b_sig = true; nostop=1; if (EJECT_CD == cd_op) { i_rc = cd_eject() ? 0 : 1; } else { switch (cd_op) { case PS_LIST_TRACKS: case LIST_TRACKS: case PLAY_TRACK: read_toc(p_cdio); default: break; } if (p_cdio) switch (cd_op) { case STOP_PLAYING: b_cd = true; i_rc = cd_stop(p_cdio) ? 0 : 1; break; case EJECT_CD: /* Should have been handled above. */ cd_eject(); break; case LIST_TRACKS: list_tracks(); break; case PS_LIST_TRACKS: ps_list_tracks(); break; case PLAY_TRACK: /* play just this one track */ if (b_record) { printf("%s / %s\n", artist, title); if (one_track) printf("%s\n", cd_info[start_track].title); } i_rc = play_track(start_track, stop_track) ? 0 : 1; break; case PLAY_CD: if (b_record) printf("%s / %s\n", artist, title); play_track(1,CDIO_CDROM_LEADOUT_TRACK); break; case SET_VOLUME: i_rc = set_volume_level(p_cdio, i_volume_level); break; case LIST_SUBCHANNEL: if (read_subchannel(p_cdio)) { if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED || sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) { { printf("track %2d - %02x:%02x (%02x:%02x abs) ", sub.track, sub.rel_addr.m, sub.rel_addr.s, sub.abs_addr.m, sub.abs_addr.s); } } printf("drive state: %s\n", mmc_audio_state2str(sub.audio_status)); } else { i_rc = 1; } break; case CLOSE_CD: /* Handled below */ case LIST_KEYS: case TOGGLE_PAUSE: case EXIT_PROGRAM: case NO_OP: break; } else if (CLOSE_CD == cd_op) { i_rc = (DRIVER_OP_SUCCESS == cdio_close_tray(psz_device, NULL)) ? 0 : 1; } else { fprintf(stderr,"no CD in drive (%s)\n", psz_device); } } } /* Play all tracks *unless* we have a play or paused status already. */ read_subchannel(p_cdio); if (sub.audio_status != CDIO_MMC_READ_SUB_ST_PAUSED && sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY) play_track(1, CDIO_CDROM_LEADOUT_TRACK); while ( !b_sig ) { int key; if (!b_cd) read_toc(p_cdio); read_subchannel(p_cdio); display_status(false); if (1 == select_wait(b_cd ? 1 : 5)) { switch (key = getch()) { case '-': decrease_volume_level(p_cdio); break; case '+': increase_volume_level(p_cdio); break; case 'A': case 'a': auto_mode = !auto_mode; break; case 'X': case 'x': nostop=1; /* fall through */ case 'Q': case 'q': b_sig = true; break; case 'E': case 'e': cd_eject(); break; case 's': cd_stop(p_cdio); break; case 'C': case 'c': cd_close(psz_device); break; case 'L': case 'l': b_all_tracks = !b_all_tracks; if (b_all_tracks) display_tracks(); else { i_last_display_track = CDIO_INVALID_TRACK; display_cdinfo(p_cdio, i_tracks, i_first_track); } break; case 'K': case 'k': case 'h': case 'H': case '?': list_keys(); break; case ' ': case 'P': case 'p': toggle_pause(); break; case KEY_RIGHT: if (b_cd && (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED || sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY)) play_track(sub.track+1, CDIO_CDROM_LEADOUT_TRACK); else play_track(1,CDIO_CDROM_LEADOUT_TRACK); break; case KEY_LEFT: if (b_cd && (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED || sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY)) play_track(sub.track-1,CDIO_CDROM_LEADOUT_TRACK); break; case KEY_UP: if (b_cd && sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) skip(10); break; case KEY_DOWN: if (b_cd && sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) skip(-10); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': play_track(key - '0', CDIO_CDROM_LEADOUT_TRACK); break; case '0': play_track(10, CDIO_CDROM_LEADOUT_TRACK); break; case KEY_F(1): case KEY_F(2): case KEY_F(3): case KEY_F(4): case KEY_F(5): case KEY_F(6): case KEY_F(7): case KEY_F(8): case KEY_F(9): case KEY_F(10): case KEY_F(11): case KEY_F(12): case KEY_F(13): case KEY_F(14): case KEY_F(15): case KEY_F(16): case KEY_F(17): case KEY_F(18): case KEY_F(19): case KEY_F(20): play_track(key - KEY_F(1) + 11, CDIO_CDROM_LEADOUT_TRACK); break; } } } if (!nostop) cd_stop(p_cdio); tty_restore(); finish("bye", i_rc); return 0; /* keep compiler happy */ }
int can_select( __LDDK_SELECT_PARAM ) #endif { unsigned int minor = __LDDK_MINOR; msg_fifo_t *RxFifo = &Rx_Buf[minor]; DBGin("can_select"); DBGprint(DBG_DATA,("minor = %d", minor)); #if 0 DBGprint(DBG_DATA,("file = %p", file)); ; DBGprint(DBG_DATA,("s(CanWait[]) = %2d", sizeof(CanWait[0]))); ; /* DBGprint(DBG_DATA,("s(CanWait) = %2d", sizeof(CanWait))); */ ; DBGprint(DBG_DATA,("&CanWait[] = %p", &CanWait[0])); DBGprint(DBG_DATA,("CanWait[minor].task_list.n = %p", CanWait[minor].task_list.next)); DBGprint(DBG_DATA,("CanWait[minor].task_list.p = %p", CanWait[minor].task_list.prev)); DBGprint(DBG_DATA,("&CanWait[minor]->task_list.p = %p", (&CanWait[minor])->task_list.prev)); DBGprint(DBG_DATA,("wait = %p", wait)); if(wait) { DBGprint(DBG_DATA,("wait->error = %d", wait->error)); DBGprint(DBG_DATA,("wait->table = %p", wait->table)); } else { DBGprint(DBG_DATA,("can not dereference wait components")); } #endif #ifdef DEBUG CAN_ShowStat(minor); #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0) DBGprint(DBG_BRANCH,("POLL: fifo empty,poll waiting...\n")); /* every event queue that could wake up the process * and change the status of the poll operation * can be added to the poll_table structure by * calling the function poll_wait: */ /* _select para, wait queue, _select para */ /* X */ poll_wait(file, &CanWait[minor] , wait); DBGprint(DBG_BRANCH,("POLL: wait returned \n")); if( RxFifo->head != RxFifo->tail ) { /* fifo has some telegrams */ /* Return a bit mask * describing operations that could be immediately performed * without blocking. */ DBGout(); /* * POLLIN This bit must be set * if the device can be read without blocking. * POLLRDNORM This bit must be set * if "normal'' data is available for reading. * A readable device returns (POLLIN | POLLRDNORM) * * * */ return POLLIN | POLLRDNORM; } DBGout();return 0; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,3) DBGprint(DBG_BRANCH,("POLL: fifo empty,poll waiting...\n")); poll_wait(file, &CanWait[minor] , wait); DBGprint(DBG_BRANCH,("POLL: wait returned \n")); if( RxFifo->head != RxFifo->tail ) { /* fifo has some telegrams */ DBGout(); return POLLIN | POLLRDNORM; } DBGout();return 0; #else switch (sel_type) { case SEL_IN: DBGprint(DBG_BRANCH,("sel_in \n")); if( RxFifo->head == RxFifo->tail ) { DBGprint(DBG_BRANCH,("fifo empty \n")); select_wait(&CanWait[minor],wait); DBGout();return 0; } break; case SEL_OUT: DBGprint(DBG_BRANCH,("sel_out \n")); /* ready for write ? */ select_wait(&CanWait[minor],wait); DBGout();return 0; } DBGout();return 1; #endif DBGout(); return 0; }
/* * Test selecting off a port. Uses a timer to change the value on an output port * which is looped back to an input port. The input port is set up to event * whenever the value changes. */ void port_example() { static const int period = 5000; select_disable_trigger_all(); port p; port_alloc(&p, port_1A); port q; port_alloc(&q, port_1B); hwtimer_t t; hwtimer_alloc(&t); uint32_t time; hwtimer_get_time(t, &time); time += period; int q_value = 0; port_out(q, q_value); // Setup the resources for eventing hwtimer_setup_select(t, time, EVENT_TIMER); hwtimer_enable_trigger(t); port_setup_select(p, EVENT_PORT_P); port_set_trigger_in_equal(p, 0x1); port_enable_trigger(p); for (int count = 0; count < 10; count++) { port_event_result_t choice = select_wait(); switch (choice) { case EVENT_TIMER: { // Read the timer to clear the event uint32_t dummy; hwtimer_get_time(t, &dummy); // Set up the next timer event time += period; hwtimer_change_trigger_time(t, time); // Toggle the port value q_value = !q_value; port_out(q, q_value); debug_printf("Timer event, drive %d\n", q_value); break; } case EVENT_PORT_P: { // Read the port to clear the event uint32_t x; port_in(p, &x); port_set_trigger_in_not_equal(p, x); debug_printf("Port event got %d\n", x); break; } } } // Release the resources hwtimer_free(&t); port_free(&q); port_free(&p); }