static int write_output(u8 val, unsigned long hpa) { int wait = 250; while (read_status(hpa) & LASI_STAT_TBNE) { if (!--wait) { return 0; } mdelay(1); } gsc_writeb(val, hpa+LASI_XMTDATA); return 1; }
int CC1101::recv(uint8_t& src, uint8_t& port, void* buf, size_t len, uint32_t ms) { // Check if we need to wait for a message uint8_t size; if (!m_avail) { // Fix: Use wakeup on radio to reduce power during wait uint32_t start = RTC::millis(); if (read_status().mode == IDLE_MODE) { strobe(SFRX); strobe(SRX); } do { while (!m_avail && ((ms == 0) || (RTC::since(start) < ms))) yield(); if (!m_avail) return (-2); spi.begin(this); loop_until_bit_is_clear(PIN, Board::MISO); size = read(RXBYTES); spi.end(); } while ((size & RXBYTES) == 0); } m_avail = false; // Read the payload size and check against buffer length spi.begin(this); loop_until_bit_is_clear(PIN, Board::MISO); size = read(RXFIFO) - 3; if (size > len) { spi.end(); strobe(SIDLE); strobe(SFRX); return (-1); } // Read the frame (dest, src, payload) m_dest = read(RXFIFO); src = read(RXFIFO); port = read(RXFIFO); read(RXFIFO, buf, size); spi.end(); // Read the link quality status spi.begin(this); loop_until_bit_is_clear(PIN, Board::MISO); read(RXFIFO, &m_recv_status, sizeof(m_recv_status)); spi.end(); // Fix: Add possible address checking for robustness return (size); }
long frequency_measure(unsigned BaseAddress) { unsigned secondcount=0; double frequency; long returnval; unsigned long timeout = 655350L; OUTPORTB(BaseAddress + 3, 0x76); // 0111 0110 ctr1 mode3, LSB/MSB OUTPORTB(BaseAddress + 1, 0xFE); // load LSB and MSB values into OUTPORTB(BaseAddress + 1, 0xFF); // ctr1 to make slow input to gate 0 while (read_status(BaseAddress) && timeout--); // out ctr1 = 1 timeout = 655350L; OUTPORTB(BaseAddress + 3, 0x34); // 0011 0100 ctr0 mode 2 L/M OUTPORTB(BaseAddress, 0xFF); OUTPORTB(BaseAddress, 0xFF); // load 65535 into ctr 0 while (!(read_status(BaseAddress)) && timeout--); // ctr1 still 0 timeout = 655350L; while (read_status(BaseAddress) && timeout--); // ctr1 = 1 timeout = 655350L; secondcount = get_count(BaseAddress); // read value of counter frequency = (65535 - secondcount)/0.032767; // convert from counts to f returnval = frequency; // convert from double to int return(returnval); }
static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, int page) { struct denali_nand_info *denali = mtd_to_denali(mtd); uint32_t addr, id; int i; switch (cmd) { case NAND_CMD_PAGEPROG: break; case NAND_CMD_STATUS: read_status(denali); break; case NAND_CMD_READID: case NAND_CMD_PARAM: reset_buf(denali); /*sometimes ManufactureId read from register is not right * e.g. some of Micron MT29F32G08QAA MLC NAND chips * So here we send READID cmd to NAND insteand * */ addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); index_addr(denali, (uint32_t)addr | 0, 0x90); index_addr(denali, (uint32_t)addr | 1, 0); for (i = 0; i < 5; i++) { index_addr_read_data(denali, (uint32_t)addr | 2, &id); write_byte_to_buf(denali, id); } break; case NAND_CMD_READ0: case NAND_CMD_SEQIN: denali->page = page; break; case NAND_CMD_RESET: reset_bank(denali); break; case NAND_CMD_READOOB: /* TODO: Read OOB data */ break; default: printk(KERN_ERR ": unsupported command" " received 0x%x\n", cmd); break; } }
/* Library finalizer function */ static void __attribute__((destructor)) interpose_fini(void) { /* Look for descriptors not explicitly closed */ for(int i=0; i<max_descriptors; i++) { trace_close(i); } read_exe(); read_status(); read_stat(); read_io(); tprintf("stop: %lf\n", get_time()); /* Close trace file */ tclose(); }
/* * wait for any data; whether it's from the controller, * the keyboard, or the aux device. */ static int wait_for_data(struct atkbdc_softc *kbdc) { int retry; int f; /* CPU will stay inside the loop for 200msec at most */ retry = kbdc->retry * 2; while ((f = read_status(kbdc) & KBDS_ANY_BUFFER_FULL) == 0) { DELAY(KBDC_DELAYTIME); if (--retry < 0) return 0; } DELAY(KBDD_DELAYTIME); return f; }
/* discard any data from the keyboard or the aux device */ void empty_both_buffers(KBDC p, int wait) { int t; int f; int waited = 0; #if KBDIO_DEBUG >= 2 int c1 = 0; int c2 = 0; #endif int delta = 2; for (t = wait; t > 0; ) { if ((f = read_status(kbdcp(p))) & KBDS_ANY_BUFFER_FULL) { DELAY(KBDD_DELAYTIME); (void)read_data(kbdcp(p)); #if KBDIO_DEBUG >= 2 if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) ++c1; else ++c2; #endif t = wait; } else { t -= delta; } /* * Some systems (Intel/IBM blades) do not have keyboard devices and * will thus hang in this procedure. Time out after delta seconds to * avoid this hang -- the keyboard attach will fail later on. */ waited += (delta * 1000); if (waited == (delta * 1000000)) return; DELAY(delta*1000); } #if KBDIO_DEBUG >= 2 if ((c1 > 0) || (c2 > 0)) log(LOG_DEBUG, "kbdc: %d:%d char read (empty_both_buffers)\n", c1, c2); #endif emptyq(&kbdcp(p)->kbd); emptyq(&kbdcp(p)->aux); }
int NRF24L01P::send(uint8_t dest, uint8_t port, const iovec_t* vec) { // Sanity check the payload size if (vec == NULL) return (-1); size_t len = 0; for (const iovec_t* vp = vec; vp->buf != NULL; vp++) len += vp->size; if (len > PAYLOAD_MAX) return (-1); // Setting transmit destination set_transmit_mode(dest); // Write source address and payload to the transmit fifo // Fix: Allow larger payload(30*3) with fragmentation spi.begin(this); m_status = spi.transfer(dest ? W_TX_PAYLOAD : W_TX_PAYLOAD_NO_ACK); spi.transfer(m_addr.device); spi.transfer(port); for (const iovec_t* vp = vec; vp->buf != NULL; vp++) spi.write(vp->buf, vp->size); spi.end(); m_trans += 1; // Wait for transmission do { Power::sleep(m_mode); read_status(); } while (!m_status.tx_ds && !m_status.max_rt); bool data_sent = m_status.tx_ds; // Reset status bits and read retransmission counter and update write(STATUS, _BV(MAX_RT) | _BV(TX_DS)); observe_tx_t observe = read_observe_tx(); m_retrans += observe.arc_cnt; // Check that the message was delivered if (data_sent) return (len); // Failed to delivery write(FLUSH_TX); m_drops += 1; return (-2); }
static u8 handle_lasikbd_event(unsigned long hpa) { u8 status_keyb,status_mouse,scancode,id; extern void handle_at_scancode(int); /* in drivers/char/keyb_at.c */ /* Mask to get the base address of the PS/2 controller */ id = gsc_readb(hpa+LASI_ID) & 0x0f; if (id==1) hpa -= LASI_PSAUX_OFFSET; status_keyb = read_status(hpa); status_mouse = read_status(hpa+LASI_PSAUX_OFFSET); while ((status_keyb|status_mouse) & LASI_STAT_RBNE){ while (status_keyb & LASI_STAT_RBNE) { scancode = read_input(hpa); /* XXX don't know if this is a valid fix, but filtering * 0xfa avoids 'unknown scancode' errors on, eg, capslock * on some keyboards. */ if (scancode == AUX_REPLY_ACK) cmd_status=0; else if (scancode == AUX_RESEND) cmd_status=1; else handle_at_scancode(scancode); status_keyb =read_status(hpa); } #ifdef CONFIG_PSMOUSE while (status_mouse & LASI_STAT_RBNE) { scancode = read_input(hpa+LASI_PSAUX_OFFSET); handle_mouse_scancode(scancode); status_mouse = read_status(hpa+LASI_PSAUX_OFFSET); } status_mouse = read_status(hpa+LASI_PSAUX_OFFSET); #endif /* CONFIG_PSMOUSE */ status_keyb = read_status(hpa); } tasklet_schedule(&keyboard_tasklet); return (status_keyb|status_mouse); }
static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, int page) { struct denali_nand_info *denali = mtd_to_denali(mtd); uint32_t addr, id; int i; switch (cmd) { case NAND_CMD_PAGEPROG: break; case NAND_CMD_STATUS: read_status(denali); break; case NAND_CMD_READID: case NAND_CMD_PARAM: reset_buf(denali); addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); index_addr(denali, (uint32_t)addr | 0, 0x90); index_addr(denali, (uint32_t)addr | 1, 0); for (i = 0; i < 5; i++) { index_addr_read_data(denali, (uint32_t)addr | 2, &id); write_byte_to_buf(denali, id); } break; case NAND_CMD_READ0: case NAND_CMD_SEQIN: denali->page = page; break; case NAND_CMD_RESET: reset_bank(denali); break; case NAND_CMD_READOOB: break; default: printk(KERN_ERR ": unsupported command" " received 0x%x\n", cmd); break; } }
void add_post(postrec *pp) { postrec p; int close_file=0; /* open the sub, if necessary */ if (sub_f <= 0) { open_sub(1); close_file=1; } if (sub_f>=0) { /* get updated info */ read_status(); sh_lseek(sub_f, 0L, SEEK_SET); sh_read(sub_f, &p, sizeof(postrec)); /* one more post */ p.owneruser++; nummsgs=p.owneruser; sh_lseek(sub_f, 0L, SEEK_SET); sh_write(sub_f, &p, sizeof(postrec)); /* add the new post */ sh_lseek(sub_f, ((long)nummsgs)*sizeof(postrec), SEEK_SET); sh_write(sub_f, pp, sizeof(postrec)); /* we've modified the sub */ believe_cache=0; subchg=0; sub_dates[curlsub]=pp->qscan; } if (close_file) close_sub(); }
/* wait for data from the aux device */ static int wait_for_aux_data(struct atkbdc_softc *kbdc) { int retry; int f; /* CPU will stay inside the loop for 200msec at most */ retry = kbdc->retry * 2; while ((f = read_status(kbdc) & KBDS_BUFFER_FULL) != KBDS_AUX_BUFFER_FULL) { if (f == KBDS_KBD_BUFFER_FULL) { DELAY(KBDD_DELAYTIME); addq(&kbdc->kbd, read_data(kbdc)); } DELAY(KBDC_DELAYTIME); if (--retry < 0) return 0; } DELAY(KBDD_DELAYTIME); return f; }
/* * device I/O routines */ static int wait_while_controller_busy(struct atkbdc_softc *kbdc) { int retry; int f; /* CPU will stay inside the loop for 100msec at most */ retry = kbdc->retry; while ((f = read_status(kbdc)) & KBDS_INPUT_BUFFER_FULL) { if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) { DELAY(KBDD_DELAYTIME); addq(&kbdc->kbd, read_data(kbdc)); } else if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) { DELAY(KBDD_DELAYTIME); addq(&kbdc->aux, read_data(kbdc)); } DELAY(KBDC_DELAYTIME); if (--retry < 0) return FALSE; } return TRUE; }
/* this might become useful again at some point. not now -prumpf */ int lasi_ps2_test(void *hpa) { u8 control,c; int i, ret = 0; control = read_control(hpa); write_control(control | LASI_CTRL_LPBXR | LASI_CTRL_ENBL, hpa); for (i=0; i<256; i++) { write_output(i, hpa); while (!(read_status(hpa) & LASI_STAT_RBNE)) /* just wait */; c = read_input(hpa); if (c != i) ret--; } write_control(control, hpa); return ret; }
/* discard data from the aux device */ void empty_aux_buffer(KBDC p, int wait) { int t; int b; int f; #if KBDIO_DEBUG >= 2 int c1 = 0; int c2 = 0; #endif int delta = 2; for (t = wait; t > 0; ) { if ((f = read_status(kbdcp(p))) & KBDS_ANY_BUFFER_FULL) { DELAY(KBDD_DELAYTIME); b = read_data(kbdcp(p)); if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) { addq(&kbdcp(p)->kbd, b); #if KBDIO_DEBUG >= 2 ++c1; } else { ++c2; #endif } t = wait; } else { t -= delta; } DELAY(delta*1000); } #if KBDIO_DEBUG >= 2 if ((c1 > 0) || (c2 > 0)) log(LOG_DEBUG, "kbdc: %d:%d char read (empty_aux_buffer)\n", c1, c2); #endif emptyq(&kbdcp(p)->aux); }
static int wait_status (struct parport_internal *port, unsigned char mask, unsigned char val, struct timeval *timeout) { /* Simple-minded polling. TODO: Use David Paschal's method for this. */ #if !(defined __MINGW32__ || defined _MSC_VER) struct timeval deadline, now; gettimeofday (&deadline, NULL); deadline.tv_sec += timeout->tv_sec; deadline.tv_usec += timeout->tv_usec; deadline.tv_sec += deadline.tv_usec / 1000000; deadline.tv_usec %= 1000000; #else struct timeb tb; int deadline, now; ftime (&tb); deadline = tb.time * 1000 + tb.millitm + timeout->tv_sec * 1000 + timeout->tv_usec / 1000; #endif do { if ((debug_display_status ((unsigned char)(read_status (port))) & mask) == val) return E1284_OK; delay (IO_POLL_DELAY); #if !(defined __MINGW32__ || defined _MSC_VER) gettimeofday (&now, NULL); } while (now.tv_sec < deadline.tv_sec || (now.tv_sec == deadline.tv_sec && now.tv_usec < deadline.tv_usec)); #else ftime (&tb); now = tb.time * 1000 + tb.millitm; }
int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc) { unsigned long flags; int ret = -ENODATA; u8 status; spin_lock_irqsave(&kcs_bmc->lock, flags); status = read_status(kcs_bmc); if (status & KCS_STATUS_IBF) { if (!kcs_bmc->running) kcs_force_abort(kcs_bmc); else if (status & KCS_STATUS_CMD_DAT) kcs_bmc_handle_cmd(kcs_bmc); else kcs_bmc_handle_data(kcs_bmc); ret = 0; } spin_unlock_irqrestore(&kcs_bmc->lock, flags); return ret; }
static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, int page) { struct denali_nand_info *denali = mtd_to_denali(mtd); uint32_t addr, id; uint32_t pages_per_block; uint32_t block; int i; switch (cmd) { case NAND_CMD_PAGEPROG: break; case NAND_CMD_STATUS: read_status(denali); break; case NAND_CMD_READID: reset_buf(denali); /* * sometimes ManufactureId read from register is not right * e.g. some of Micron MT29F32G08QAA MLC NAND chips * So here we send READID cmd to NAND insteand */ addr = MODE_11 | BANK(denali->flash_bank); index_addr(denali, addr | 0, 0x90); index_addr(denali, addr | 1, col); for (i = 0; i < 8; i++) { index_addr_read_data(denali, addr | 2, &id); write_byte_to_buf(denali, id); } break; case NAND_CMD_PARAM: reset_buf(denali); /* turn on R/B interrupt */ denali_set_intr_modes(denali, false); denali_irq_mask = DENALI_IRQ_ALL | INTR_STATUS__INT_ACT; clear_interrupts(denali); denali_irq_enable(denali, denali_irq_mask); denali_set_intr_modes(denali, true); addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); index_addr(denali, (uint32_t)addr | 0, cmd); index_addr(denali, (uint32_t)addr | 1, col & 0xFF); /* Wait tR time... */ udelay(25); /* And then wait for R/B interrupt */ wait_for_irq(denali, INTR_STATUS__INT_ACT); /* turn off R/B interrupt now */ denali_irq_mask = DENALI_IRQ_ALL; denali_set_intr_modes(denali, false); denali_irq_enable(denali, denali_irq_mask); denali_set_intr_modes(denali, true); for (i = 0; i < 256; i++) { index_addr_read_data(denali, (uint32_t)addr | 2, &id); write_byte_to_buf(denali, id); } break; case NAND_CMD_READ0: case NAND_CMD_SEQIN: denali->page = page; break; case NAND_CMD_RESET: reset_bank(denali); break; case NAND_CMD_READOOB: /* TODO: Read OOB data */ break; case NAND_CMD_UNLOCK1: pages_per_block = mtd->erasesize / mtd->writesize; block = page / pages_per_block; addr = (uint32_t)MODE_10 | (block * pages_per_block); index_addr(denali, addr, 0x10); break; case NAND_CMD_UNLOCK2: pages_per_block = mtd->erasesize / mtd->writesize; block = (page+pages_per_block-1) / pages_per_block; addr = (uint32_t)MODE_10 | (block * pages_per_block); index_addr(denali, addr, 0x11); break; case NAND_CMD_ERASE1: case NAND_CMD_ERASE2: addr = MODE_10 | BANK(denali->flash_bank) | page; index_addr(denali, addr, 0x1); break; default: pr_err(": unsupported command received 0x%x\n", cmd); break; } }
int top_main(int argc, char **argv) { status_t *statuslist; struct dirent **namelist; int opt, num, interval, lines; #if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS struct winsize win = { 0, 0, 0, 0 }; #endif /* Default update rate is 5 seconds */ interval = 5; /* Default to 25 lines - 5 lines for status */ lines = 25 - 5; /* do normal option parsing */ while ((opt = getopt(argc, argv, "d:")) > 0) { switch (opt) { case 'd': interval = atoi(optarg); break; default: show_usage(); } } #if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS ioctl(fileno(stdout), TIOCGWINSZ, &win); if (win.ws_row > 4) lines = win.ws_row - 5; #endif /* change to proc */ if (chdir("/proc") < 0) { perror_msg_and_die("chdir('/proc')"); } /* read process IDs for all the processes from the procfs */ num = scandir(".", &namelist, filter_pids, num_sort); if (num < 0) { perror_msg_and_die("scandir('/proc')"); } if (lines > num) { lines = num; } /* read command line for each of the processes */ statuslist = read_info(num, namelist); if (!statuslist) { return EXIT_FAILURE; } while (1) { /* read status for each of the processes */ read_status(num, statuslist); /* display status */ display_status(lines, statuslist); sleep(interval); } free(statuslist); return EXIT_SUCCESS; }
static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time) { unsigned char status; unsigned char state; status = read_status(kcs); if (kcs_debug & KCS_DEBUG_STATES) printk(KERN_DEBUG "KCS: State = %d, %x\n", kcs->state, status); if (!check_ibf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; state = GET_STATUS_STATE(status); switch (kcs->state) { case KCS_IDLE: clear_obf(kcs, status); if (GET_STATUS_ATN(status)) return SI_SM_ATTN; else return SI_SM_IDLE; case KCS_START_OP: if (state != KCS_IDLE_STATE) { start_error_recovery(kcs, "State machine not idle at start"); break; } clear_obf(kcs, status); write_cmd(kcs, KCS_WRITE_START); kcs->state = KCS_WAIT_WRITE_START; break; case KCS_WAIT_WRITE_START: if (state != KCS_WRITE_STATE) { start_error_recovery( kcs, "Not in write state at write start"); break; } read_data(kcs); if (kcs->write_count == 1) { write_cmd(kcs, KCS_WRITE_END); kcs->state = KCS_WAIT_WRITE_END; } else { write_next_byte(kcs); kcs->state = KCS_WAIT_WRITE; } break; case KCS_WAIT_WRITE: if (state != KCS_WRITE_STATE) { start_error_recovery(kcs, "Not in write state for write"); break; } clear_obf(kcs, status); if (kcs->write_count == 1) { write_cmd(kcs, KCS_WRITE_END); kcs->state = KCS_WAIT_WRITE_END; } else { write_next_byte(kcs); } break; case KCS_WAIT_WRITE_END: if (state != KCS_WRITE_STATE) { start_error_recovery(kcs, "Not in write state" " for write end"); break; } clear_obf(kcs, status); write_next_byte(kcs); kcs->state = KCS_WAIT_READ; break; case KCS_WAIT_READ: if ((state != KCS_READ_STATE) && (state != KCS_IDLE_STATE)) { start_error_recovery( kcs, "Not in read or idle in read state"); break; } if (state == KCS_READ_STATE) { if (!check_obf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; read_next_byte(kcs); } else { clear_obf(kcs, status); kcs->orig_write_count = 0; kcs->state = KCS_IDLE; return SI_SM_TRANSACTION_COMPLETE; } break; case KCS_ERROR0: clear_obf(kcs, status); status = read_status(kcs); if (GET_STATUS_OBF(status)) if (time_before(jiffies, kcs->error0_timeout)) return SI_SM_CALL_WITH_TICK_DELAY; write_cmd(kcs, KCS_GET_STATUS_ABORT); kcs->state = KCS_ERROR1; break; case KCS_ERROR1: clear_obf(kcs, status); write_data(kcs, 0); kcs->state = KCS_ERROR2; break; case KCS_ERROR2: if (state != KCS_READ_STATE) { start_error_recovery(kcs, "Not in read state for error2"); break; } if (!check_obf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; clear_obf(kcs, status); write_data(kcs, KCS_READ_BYTE); kcs->state = KCS_ERROR3; break; case KCS_ERROR3: if (state != KCS_IDLE_STATE) { start_error_recovery(kcs, "Not in idle state for error3"); break; } if (!check_obf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; clear_obf(kcs, status); if (kcs->orig_write_count) { restart_kcs_transaction(kcs); } else { kcs->state = KCS_IDLE; return SI_SM_TRANSACTION_COMPLETE; } break; case KCS_HOSED: break; } if (kcs->state == KCS_HOSED) { init_kcs_data(kcs, kcs->io); return SI_SM_HOSED; } return SI_SM_CALL_WITHOUT_DELAY; }
/* check if any data is waiting to be processed */ int kbdc_data_ready(KBDC p) { return (availq(&kbdcp(p)->kbd) || availq(&kbdcp(p)->aux) || (read_status(kbdcp(p)) & KBDS_ANY_BUFFER_FULL)); }
void CC1101::await(Mode mode) { while (read_status().mode != mode) Watchdog::delay(24); }
Host::Host(QWidget *ParentMainWin, USB_VCP *usbObj) : QWidget(ParentMainWin) { // Rename obj pointers for convenience mainWin = (MainWindow*)ParentMainWin; ui = (Ui::MainWindow*)mainWin->ui; usb_vcp = (USB_VCP*)usbObj; // Comms connect(ui->pushButton_comms_open, SIGNAL(clicked()), this, SLOT(comms_open())); connect(ui->pushButton_comms_test, SIGNAL(clicked()), this, SLOT(comms_test())); //ui->listWidget_comms_list->hide(); connect(ui->listWidget_comms_list, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(comms_open_selected(QListWidgetItem*))); // PDP connect(ui->pushButton_read_DMA, SIGNAL(clicked()), this, SLOT(read_DMA())); ui->pushButton_read_DMA->setVisible(false); connect(ui->pushButton_read_AC, SIGNAL(clicked()), this, SLOT(read_channelDMA())); ui->pushButton_read_AC->setVisible(false); connect(ui->pushButton_read_AC_filtered, SIGNAL(clicked()), this, SLOT(read_channelDMA_filtered())); connect(ui->pushButton_write_command, SIGNAL(clicked()), this, SLOT(write_command())); connect(ui->pushButton_read_status, SIGNAL(clicked()), this, SLOT(read_status())); connect(ui->pushButton_read_relay, SIGNAL(clicked()), this, SLOT(relay_read())); connect(ui->radioButton_relayOn, SIGNAL(clicked()), this, SLOT(relay_on())); connect(ui->radioButton_relayOff, SIGNAL(clicked()), this, SLOT(relay_off())); QGridLayout *gbox = new QGridLayout(ui->groupBox_relaySelect); int i = 0; for(int x = 0;x < 4; x++) { for(int y = 0;y < 4; y++) { relaySelectButton[i] = new QRadioButton(IntToStr(i)); gbox->addWidget(relaySelectButton[i], y, x); connect(relaySelectButton[i], SIGNAL(clicked()), this, SLOT(relay_selected())); i++; } } ui->groupBox_relaySelect->setLayout(gbox); relayNumberSelected = 0; relaySelectButton[relayNumberSelected]->setChecked(true); // PDP graph init graph_init(); }
bool AGPIO::read() { return read_status(); }
static void read_procs(void) { DIR *proc_dir, *task_dir; struct dirent *pid_dir, *tid_dir; char filename[64]; FILE *file; int proc_num; struct proc_info *proc; pid_t pid, tid; int i; proc_dir = opendir("/proc"); if (!proc_dir) die("Could not open /proc.\n"); new_procs = calloc(INIT_PROCS * (threads ? THREAD_MULT : 1), sizeof(struct proc_info *)); num_new_procs = INIT_PROCS * (threads ? THREAD_MULT : 1); file = fopen("/proc/stat", "r"); if (!file) die("Could not open /proc/stat.\n"); fscanf(file, "cpu %lu %lu %lu %lu %lu %lu %lu", &new_cpu.utime, &new_cpu.ntime, &new_cpu.stime, &new_cpu.itime, &new_cpu.iowtime, &new_cpu.irqtime, &new_cpu.sirqtime); fclose(file); proc_num = 0; while ((pid_dir = readdir(proc_dir))) { if (!isdigit(pid_dir->d_name[0])) continue; pid = atoi(pid_dir->d_name); struct proc_info cur_proc; if (!threads) { proc = alloc_proc(); proc->pid = proc->tid = pid; sprintf(filename, "/proc/%d/stat", pid); read_stat(filename, proc); sprintf(filename, "/proc/%d/cmdline", pid); read_cmdline(filename, proc); sprintf(filename, "/proc/%d/status", pid); read_status(filename, proc); read_policy(pid, proc); proc->num_threads = 0; } else { sprintf(filename, "/proc/%d/cmdline", pid); read_cmdline(filename, &cur_proc); sprintf(filename, "/proc/%d/status", pid); read_status(filename, &cur_proc); proc = NULL; } sprintf(filename, "/proc/%d/task", pid); task_dir = opendir(filename); if (!task_dir) continue; while ((tid_dir = readdir(task_dir))) { if (!isdigit(tid_dir->d_name[0])) continue; if (threads) { tid = atoi(tid_dir->d_name); proc = alloc_proc(); proc->pid = pid; proc->tid = tid; sprintf(filename, "/proc/%d/task/%d/stat", pid, tid); read_stat(filename, proc); read_policy(tid, proc); strcpy(proc->name, cur_proc.name); proc->uid = cur_proc.uid; proc->gid = cur_proc.gid; add_proc(proc_num++, proc); } else { proc->num_threads++; } } closedir(task_dir); if (!threads) add_proc(proc_num++, proc); } for (i = proc_num; i < num_new_procs; i++) new_procs[i] = NULL; closedir(proc_dir); }
/** \fn:bulk_only_transfer \param udi: corresponding device \param cmd: SCSI command to be performed on USB device \param cmdlen: length of SCSI command \param data_sg: io vectors array with data to transfer \param sglist_count: count of entries in io vector array \param transfer_len: overall length of data to be transferred \param dir: direction of data transfer \param ccbio: CCB_SCSIIO struct for original SCSI command \param cb: callback to handle of final stage of command performing (autosense \ request etc.) transfer procedure for bulk-only protocol. Performs SCSI command on USB device [2] */ void bulk_only_transfer(usb_device_info *udi, uint8 *cmd, uint8 cmdlen, //sg_buffer *sgb, iovec *sg_data,int32 sg_count, int32 transfer_len, EDirection dir, CCB_SCSIIO *ccbio, ud_transfer_callback cb) { status_t status = B_OK; status_t command_status = B_OK; int32 residue = transfer_len; usb_mass_CSW csw = {0}; /* initialize and fill in Command Block Wrapper */ usb_mass_CBW cbw = { .signature = CBW_SIGNATURE, .tag = atomic_add(&udi->tag, 1), .data_transfer_len = transfer_len, .flags = (dir == eDirIn) ? CBW_FLAGS_IN : CBW_FLAGS_OUT, .lun = ccbio->cam_ch.cam_target_lun & 0xf, .cdb_len = cmdlen, }; memcpy(cbw.CDB, cmd, cbw.cdb_len); do{ trace_CBW(udi, &cbw); /* send CBW to device */ status = queue_bulk(udi, &cbw, CBW_LENGTH, false); if(status != B_OK || udi->status != B_OK){ PTRACE_ALWAYS(udi, "bulk_only_transfer: queue_bulk failed:" "status:%08x usb status:%08x\n", status, udi->status); (*udi->protocol_m->reset)(udi); command_status = B_CMD_WIRE_FAILED; break; } /* perform data transfer if required */ if(transfer_len != 0x0){ status = process_data_io(udi, sg_data, sg_count, dir); if(status != B_OK && status != B_DEV_STALLED){ command_status = B_CMD_WIRE_FAILED; break; } } /* get status of command */ status = read_status(udi, &csw, transfer_len); if(B_OK != status){ command_status = B_CMD_WIRE_FAILED; break; } residue = csw.data_residue; if(csw.status == CSW_STATUS_FAILED){ command_status = B_CMD_FAILED; }else{ command_status = B_OK; } }while(false); /* finalize transfer */ cb(udi, ccbio, residue, command_status); } protocol_module_info bulk_only_protocol_m = { {0, 0, 0}, /* this is not a real kernel module - just interface */ bulk_only_initialize, bulk_only_reset, bulk_only_transfer, };
int iscan1(int si, int quick) /* * Initializes use of a sub value (subboards[], not usub[]). If quick, then * don't worry about anything detailed, just grab qscan info. */ { postrec p; /* make sure we have cache space */ if (!cache) { cache=malloca(MAX_TO_CACHE*sizeof(postrec)); if (!cache) return(0); } /* forget it if an invalid sub # */ if ((si<0) || (si>=num_subs)) return(0); /* skip this stuff if being called from the WFC cache code */ if (!quick) { /* go to correct net # */ if (xsubs[si].num_nets) set_net_num(xsubs[si].nets[0].net_num); else set_net_num(0); /* see if a sub has changed */ read_status(); /* if already have this one set, nothing more to do */ if (si==currsub) return(1); } currsub=si; /* sub cache no longer valid */ believe_cache=0; /* set sub filename */ sprintf(subdat_fn,"%s%s.SUB",syscfg.datadir,subboards[si].filename); /* open file, and create it if necessary */ if (open_sub(0)<0) { if (open_sub(1)<0) return(0); p.owneruser=0; sh_write(sub_f,(void *) &p,sizeof(postrec)); } /* set sub */ curlsub=si; subchg=0; last_msgnum=0; /* read in first rec, specifying # posts */ sh_lseek(sub_f,0L,SEEK_SET); sh_read(sub_f,&p, sizeof(postrec)); nummsgs=p.owneruser; /* read in sub date, if don't already know it */ if (sub_dates[si]==0) { if (nummsgs) { sh_lseek(sub_f, ((long) nummsgs)*sizeof(postrec), SEEK_SET); sh_read(sub_f, &p, sizeof(postrec)); sub_dates[si]=p.qscan; } else { sub_dates[si]=1; } } /* close file */ close_sub(); /* iscanned correctly */ return(1); }
/* enable one or more DTrace probes for a given JVM */ int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types) { int fd, status = 0; char ch; const char* args[1]; char buf[16]; int probe_type = 0, index; int count = 0; if (jvm == NULL) { set_jvm_error(JVM_ERR_NULL_PARAM); print_debug("jvm_t* is NULL\n"); return -1; } if (num_probe_types == 0 || probe_types == NULL || probe_types[0] == NULL) { set_jvm_error(JVM_ERR_INVALID_PARAM); print_debug("invalid probe type argument(s)\n"); return -1; } for (index = 0; index < num_probe_types; index++) { const char* p = probe_types[index]; if (strcmp(p, JVM_DTPROBE_OBJECT_ALLOC) == 0) { probe_type |= DTRACE_ALLOC_PROBES; count++; } else if (strcmp(p, JVM_DTPROBE_METHOD_ENTRY) == 0 || strcmp(p, JVM_DTPROBE_METHOD_RETURN) == 0) { probe_type |= DTRACE_METHOD_PROBES; count++; } else if (strcmp(p, JVM_DTPROBE_MONITOR_ENTER) == 0 || strcmp(p, JVM_DTPROBE_MONITOR_ENTERED) == 0 || strcmp(p, JVM_DTPROBE_MONITOR_EXIT) == 0 || strcmp(p, JVM_DTPROBE_MONITOR_WAIT) == 0 || strcmp(p, JVM_DTPROBE_MONITOR_WAITED) == 0 || strcmp(p, JVM_DTPROBE_MONITOR_NOTIFY) == 0 || strcmp(p, JVM_DTPROBE_MONITOR_NOTIFYALL) == 0) { probe_type |= DTRACE_MONITOR_PROBES; count++; } else if (strcmp(p, JVM_DTPROBE_ALL) == 0) { probe_type |= DTRACE_ALL_PROBES; count++; } } if (count == 0) { return count; } sprintf(buf, "%d", probe_type); args[0] = buf; fd = enqueue_command(jvm, ENABLE_DPROBES_CMD, 1, args); if (fd < 0) { set_jvm_error(JVM_ERR_DOOR_CMD_SEND); return -1; } status = read_status(fd); // non-zero status is error if (status) { set_jvm_error(JVM_ERR_DOOR_CMD_STATUS); print_debug("%s command failed (status: %d) in target JVM\n", ENABLE_DPROBES_CMD, status); file_close(fd); return -1; } // read from stream until EOF while (file_read(fd, &ch, sizeof(ch)) == sizeof(ch)) { if (libjvm_dtrace_debug) { printf("%c", ch); } } file_close(fd); clear_jvm_error(); return count; }
/* * This implements the state machine defined in the IPMI manual, see * that for details on how this works. Divide that flowchart into * sections delimited by "Wait for IBF" and this will become clear. */ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time) { unsigned char status; unsigned char state; status = read_status(kcs); if (kcs_debug & KCS_DEBUG_STATES) printk(KERN_DEBUG "KCS: State = %d, %x\n", kcs->state, status); /* All states wait for ibf, so just do it here. */ if (!check_ibf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; /* Just about everything looks at the KCS state, so grab that, too. */ state = GET_STATUS_STATE(status); switch (kcs->state) { case KCS_IDLE: /* If there's and interrupt source, turn it off. */ clear_obf(kcs, status); if (GET_STATUS_ATN(status)) return SI_SM_ATTN; else return SI_SM_IDLE; case KCS_START_OP: if (state != KCS_IDLE_STATE) { start_error_recovery(kcs, "State machine not idle at start"); break; } clear_obf(kcs, status); write_cmd(kcs, KCS_WRITE_START); kcs->state = KCS_WAIT_WRITE_START; break; case KCS_WAIT_WRITE_START: if (state != KCS_WRITE_STATE) { start_error_recovery( kcs, "Not in write state at write start"); break; } read_data(kcs); if (kcs->write_count == 1) { write_cmd(kcs, KCS_WRITE_END); kcs->state = KCS_WAIT_WRITE_END; } else { write_next_byte(kcs); kcs->state = KCS_WAIT_WRITE; } break; case KCS_WAIT_WRITE: if (state != KCS_WRITE_STATE) { start_error_recovery(kcs, "Not in write state for write"); break; } clear_obf(kcs, status); if (kcs->write_count == 1) { write_cmd(kcs, KCS_WRITE_END); kcs->state = KCS_WAIT_WRITE_END; } else { write_next_byte(kcs); } break; case KCS_WAIT_WRITE_END: if (state != KCS_WRITE_STATE) { start_error_recovery(kcs, "Not in write state" " for write end"); break; } clear_obf(kcs, status); write_next_byte(kcs); kcs->state = KCS_WAIT_READ; break; case KCS_WAIT_READ: if ((state != KCS_READ_STATE) && (state != KCS_IDLE_STATE)) { start_error_recovery( kcs, "Not in read or idle in read state"); break; } if (state == KCS_READ_STATE) { if (!check_obf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; read_next_byte(kcs); } else { /* * We don't implement this exactly like the state * machine in the spec. Some broken hardware * does not write the final dummy byte to the * read register. Thus obf will never go high * here. We just go straight to idle, and we * handle clearing out obf in idle state if it * happens to come in. */ clear_obf(kcs, status); kcs->orig_write_count = 0; kcs->state = KCS_IDLE; return SI_SM_TRANSACTION_COMPLETE; } break; case KCS_ERROR0: clear_obf(kcs, status); status = read_status(kcs); if (GET_STATUS_OBF(status)) /* controller isn't responding */ if (time_before(jiffies, kcs->error0_timeout)) return SI_SM_CALL_WITH_TICK_DELAY; write_cmd(kcs, KCS_GET_STATUS_ABORT); kcs->state = KCS_ERROR1; break; case KCS_ERROR1: clear_obf(kcs, status); write_data(kcs, 0); kcs->state = KCS_ERROR2; break; case KCS_ERROR2: if (state != KCS_READ_STATE) { start_error_recovery(kcs, "Not in read state for error2"); break; } if (!check_obf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; clear_obf(kcs, status); write_data(kcs, KCS_READ_BYTE); kcs->state = KCS_ERROR3; break; case KCS_ERROR3: if (state != KCS_IDLE_STATE) { start_error_recovery(kcs, "Not in idle state for error3"); break; } if (!check_obf(kcs, status, time)) return SI_SM_CALL_WITH_DELAY; clear_obf(kcs, status); if (kcs->orig_write_count) { restart_kcs_transaction(kcs); } else { kcs->state = KCS_IDLE; return SI_SM_TRANSACTION_COMPLETE; } break; case KCS_HOSED: break; } if (kcs->state == KCS_HOSED) { init_kcs_data(kcs, kcs->io); return SI_SM_HOSED; } return SI_SM_CALL_WITHOUT_DELAY; }
void testrunner_t::run_test(testfn_t *fn) { running_ = fn; nrun_++; int pipefd[2]; if (pipe(pipefd) < 0) { perror("pipe"); return; } dmsg("Forking"); pid_t pid = fork(); if (pid < 0) { perror("fork"); close(pipefd[PIPE_READ]); close(pipefd[PIPE_WRITE]); running_ = 0; return; } if (pid == 0) { /* child process - return and run the test code, dtor will exit. */ dmsg("In child process"); close(pipefd[PIPE_READ]); /* record the write end of the status pipe for _check() */ status_pipe = pipefd[PIPE_WRITE]; /* run the fixtures and test function */ fn->run(); /* send a success message */ char buf[STATUS_LEN]; snprintf(buf, sizeof(buf), "+PASS %s.%s", fn->suite(), fn->name()); retry_write(status_pipe, buf, strlen(buf)); dmsg("Child process exiting normally"); exit(0); } else { /* parent process - read status and wait for the child to finish */ dmsg("In parent process"); close(pipefd[PIPE_WRITE]); /* we expect at most one status line, from either a * _check() failure or a successful test. */ char buf[STATUS_LEN]; if (read_status(buf, sizeof(buf), pipefd[PIPE_READ]) < 0) { running_ = 0; return; } close(pipefd[PIPE_READ]); /* wait the for child process to exit */ int r = wait_for_child(pid); /* diagnose test failure */ if (r < 0 && r != -ESRCH) { running_ = 0; return; } if (r == 0 && buf[0] == '+') { fprintf(stderr, "PASS %s.%s\n", fn->suite(), fn->name()); npass_++; } else if (buf[0] != '\0') { fprintf(stderr, "Test %s.%s failed:\n", fn->suite(), fn->name()); fputs(buf+1, stderr); } } running_ = 0; }