static void hscx_empty_fifo(struct HscxState *hsp, int count) { u_char *ptr; struct IsdnCardState *sp = hsp->sp; long flags; if ((sp->debug & L1_DEB_HSCX) && !(sp->debug & L1_DEB_HSCX_FIFO)) debugl1(sp, "hscx_empty_fifo"); if (hsp->rcvidx + count > HSCX_BUFMAX) { if (sp->debug & L1_DEB_WARN) debugl1(sp, "hscx_empty_fifo: incoming packet too large"); writehscxCMDR(sp->hscx[hsp->hscx], 0x80); hsp->rcvidx = 0; return; } ptr = hsp->rcvbuf + hsp->rcvidx; hsp->rcvidx += count; save_flags(flags); cli(); read_fifo(sp->hscx[hsp->hscx], ptr, count); writehscxCMDR(sp->hscx[hsp->hscx], 0x80); restore_flags(flags); if (sp->debug & L1_DEB_HSCX_FIFO) { char tmp[128]; char *t = tmp; t += sprintf(t, "hscx_empty_fifo %c cnt %d", hsp->hscx ? 'B' : 'A', count); QuickHex(t, ptr, count); debugl1(sp, tmp); } }
static void s3c_out_epn(struct s3c_udc *dev, u32 ep_idx) { struct s3c_ep *ep = &dev->ep[ep_idx]; struct s3c_request *req; if (unlikely(!(ep->desc))) { /* Throw packet away.. */ printk("%s: No descriptor?!?\n", __FUNCTION__); return; } if (list_empty(&ep->queue)) req = 0; else req = list_entry(ep->queue.next, struct s3c_request, queue); if (unlikely(!req)) { DEBUG_OUT_EP("%s: NULL REQ on OUT EP-%d\n", __FUNCTION__, ep_idx); return; } else { read_fifo(ep, req); } }
void EXTI0_IRQHandler(void) { if(EXTI_GetITStatus(DIO0_IRQ) != RESET) { EXTI_ClearITPendingBit(DIO0_IRQ); hal_DIOx_ITConfig(all,DISABLE); if(g_fsk.states == RF_STATE_TX_RUNNING) { SX1276FskSetOpMode( RF_OPMODE_STANDBY ); g_fsk.states = RF_STATE_TX_DONE; process_post(&hal_RF_process, PROCESS_EVENT_MSG, (void *)(&g_fsk.states)); } if(g_fsk.states == RF_STATE_RX_SYNC) { SX1276FskSetOpMode( RF_OPMODE_STANDBY ); read_fifo(true); etimer_stop(&timer_rf); g_fsk.states = RF_STATE_RX_DONE; process_post(&hal_RF_process, PROCESS_EVENT_MSG, (void *)(&g_fsk.states)); } } }
static void musb_peri_rx_ep(unsigned int ep) { u16 peri_rxcount = readw(&musbr->ep[ep].epN.rxcount); if (peri_rxcount) { struct usb_endpoint_instance *endpoint; u32 length; u8 *data; endpoint = GET_ENDPOINT(udc_device, ep); if (endpoint && endpoint->rcv_urb) { struct urb *urb = endpoint->rcv_urb; unsigned int remaining_space = urb->buffer_length - urb->actual_length; if (remaining_space) { int urb_bad = 0; /* urb is good */ if (peri_rxcount > remaining_space) length = remaining_space; else length = peri_rxcount; data = (u8 *) urb->buffer_data; data += urb->actual_length; /* The common musb fifo reader */ read_fifo(ep, length, data); musb_peri_rx_ack(ep); /* * urb's actual_length is updated in * usbd_rcv_complete */ usbd_rcv_complete(endpoint, length, urb_bad); } else { if (debug_level > 0) serial_printf("ERROR : %s %d no space " "in rcv buffer\n", __PRETTY_FUNCTION__, ep); } } else { if (debug_level > 0) serial_printf("ERROR : %s %d problem with " "endpoint\n", __PRETTY_FUNCTION__, ep); } } else { if (debug_level > 0) serial_printf("ERROR : %s %d with nothing to do\n", __PRETTY_FUNCTION__, ep); } }
int main(int argc, char *argv[]) { args list; int fd; pid_t pid; int size = 0; int i = 1; int nodes_num = 0; char sz[25]; char pipe_path[30]; if(process_c_args(argc, argv, &list)) { return -1; } size = strtol(list.file_name, NULL, 10); snprintf(sz, 25, "%d", size); if(mkfifo ("/tmp/1_p",0666) == -1) { perror("Error creating named pipe"); } pid = fork(); if(pid == 0) //child { //SM node arguments: lower bound, upper bound, sorting attribute, file name, node number, current depth, max depth execl("smnode", "smnode", "0", sz, list.attrib, list.file_name, "1", "0", list.depth, (char *)0); fflush(stdout); perror("Can't execute smnode\n"); } else if (pid < 0) //fork failed { perror("Fork error!\n"); } else //parent { fd = open("/tmp/1_p", O_RDONLY); read_fifo(fd,size); close(fd); } printf("\n\n ======================= Sorting Statistics ======================= \n\n"); read_stat(); printf("\n\n ================================================================== \n\n"); //remove the pipes when finished nodes_num = (int)(pow(2,atoi(list.depth)+1)) - 1; for(i = 1; i <= nodes_num; i++) { snprintf(pipe_path, 30, "/tmp/%d_p", i); unlink(pipe_path); } return 0; }
std::vector<uint32_t>& get_next_pulse(uint32_t n_pts) { adc_data.resize(n_pts); if (n_pts == 0) return adc_data; wait_for(1); uint32_t data = read_fifo(); // Wait for the beginning of a pulse while ((data & (1 << 15)) != (1 << 15)) { wait_for(1); data = read_fifo(); } adc_data[0] = data; wait_for(n_pts -1); for (unsigned int i=1; i < n_pts; i++) adc_data[i] = read_fifo(); return adc_data; }
int main(int argc, char **argv) { pid_t pid; int i = 1; int top, floor; make_fifo(); if (argc < 2) { fprintf(stderr, "usage: %s 44 100...\n", argv[0]); exit(1); } for(; argv[i] != '\0'; i++) { pid = fork(); if (pid < 0) { exit(1); } else if (pid == 0) { if(i == 1) { floor = 2; } else floor = atoi(argv[i-1]) + 1; top = atoi(argv[i]); printf("child %i: bottom=%i, top=%i\n", getpid(), floor, top); sieve(floor, top); exit(0x47); } else { int status = 0; read_fifo(); wait(&status); if(status == 18176) printf("child %i exited cleanly\n", pid); else printf("unknown exit %i (0x%x)\n", status, status); } } return 0; }
static void ReadHSCXfifo(struct IsdnCardState *cs, int hscx, u_char * data, int size) { switch (cs->subtyp) { case R647: case R685: read_fifo(cs->hw.gazel.hscxfifo[hscx], data, size); break; case R753: case R742: read_fifo_ipac(cs->hw.gazel.ipac, hscx * 0x40, data, size); break; } }
static void ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size) { switch (cs->subtyp) { case R647: case R685: read_fifo(cs->hw.gazel.isacfifo, data, size); break; case R753: case R742: read_fifo_ipac(cs->hw.gazel.ipac, 0x80, data, size); break; } }
/* gets a byte from MIDI-In, returns !=0 if byte received, byte in *b. */ int mididrv_in(BYTE *b) { if (!handle_in) { log_error(mididrv_log, "Attempt to read from closed MIDI-In port!"); return -1; } if (read_fifo(b)) { #ifdef DEBUG log_message(mididrv_log, "in got %02x", *b); #endif return 1; } return 0; }
static ssize_t lis331_read(struct file *filp, char *buffer, size_t buflen) { /* if the buffer is large enough, and data are available, return success */ if (buflen >= 12) { if (read_fifo((uint16_t *)buffer)) return 12; /* no data */ return 0; } /* buffer too small */ errno = ENOSPC; return ERROR; }
static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr) { struct lh7a40x_ep *ep = &dev->ep[ep_idx]; struct lh7a40x_request *req; DEBUG("%s: %d\n", __func__, ep_idx); usb_set_index(ep_idx); if (ep->desc) { u32 csr; csr = usb_read(ep->csr1); while ((csr = usb_read(ep-> csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY | USB_OUT_CSR1_SENT_STALL)) { DEBUG("%s: %x\n", __func__, csr); if (csr & USB_OUT_CSR1_SENT_STALL) { DEBUG("%s: stall sent, flush fifo\n", __func__); /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */ flush(ep); } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) { if (list_empty(&ep->queue)) req = 0; else req = list_entry(ep->queue.next, struct lh7a40x_request, queue); if (!req) { printk(KERN_WARNING "%s: NULL REQ %d\n", __func__, ep_idx); flush(ep); break; } else { read_fifo(ep, req); } } } } else {
void EXTI1_IRQHandler(void) { if(EXTI_GetITStatus(DIO1_IRQ) != RESET) { EXTI_ClearITPendingBit(DIO1_IRQ); if(g_fsk.states == RF_STATE_TX_RUNNING) { fill_fifo(); } if(g_fsk.states == RF_STATE_RX_SYNC) { read_fifo(false); } } }
/* * This function handles the control transfer in data phase */ static int ctrlreq_in_data_phase(struct usb_device *dev, u32 len, void *buffer) { u16 csr; u32 rxlen = 0; u32 nextlen = 0; u8 maxpktsize = (1 << dev->maxpacketsize) * 8; u8 *rxbuff = (u8 *)buffer; u8 rxedlength; int result; while (rxlen < len) { /* Determine the next read length */ nextlen = ((len-rxlen) > maxpktsize) ? maxpktsize : (len-rxlen); /* Set the ReqPkt bit */ csr = readw(&musbr->txcsr); writew(csr | MUSB_CSR0_H_REQPKT, &musbr->txcsr); result = wait_until_ep0_ready(dev, MUSB_CSR0_RXPKTRDY); if (result < 0) return result; /* Actual number of bytes received by usb */ rxedlength = readb(&musbr->rxcount); /* Read the data from the RxFIFO */ read_fifo(MUSB_CONTROL_EP, rxedlength, &rxbuff[rxlen]); /* Clear the RxPktRdy Bit */ csr = readw(&musbr->txcsr); csr &= ~MUSB_CSR0_RXPKTRDY; writew(csr, &musbr->txcsr); /* short packet? */ if (rxedlength != nextlen) { dev->act_len += rxedlength; break; } rxlen += nextlen; dev->act_len = rxlen; } return 0; }
static int handle_ep(struct imx_ep_struct *imx_ep) { struct imx_request *req; int completed = 0; do { if (!list_empty(&imx_ep->queue)) req = list_entry(imx_ep->queue.next, struct imx_request, queue); else { D_REQ(imx_ep->imx_usb->dev, "<%s> no request on %s\n", __func__, imx_ep->ep.name); return 0; } if (EP_DIR(imx_ep)) /* */ completed = write_fifo(imx_ep, req); else /* */ completed = read_fifo(imx_ep, req); dump_ep_stat(__func__, imx_ep); } while (completed);
static void elfin_out_epn(struct elfin_udc *dev, u32 ep_idx) { struct elfin_ep *ep = &dev->ep[ep_idx]; struct elfin_request *req; DPRINTK("%s: %d\n", __FUNCTION__, ep_idx); if (ep->desc) { u32 csr; csr = usb_read(ep->csr1, ep_index(ep)); while ((csr = usb_read(ep->csr1, ep_index(ep))) & (S3C2410_UDC_OCSR1_PKTRDY | S3C2410_UDC_OCSR1_SENTSTL)) { DPRINTK("%s: %x\n", __FUNCTION__, csr); if (csr & S3C2410_UDC_OCSR1_SENTSTL) { DPRINTK("%s: stall sent, flush fifo\n", __FUNCTION__); /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1, ep_index(ep)); */ } else if (csr & S3C2410_UDC_OCSR1_PKTRDY) { if (list_empty(&ep->queue)) req = 0; else req = list_entry(ep->queue.next, struct elfin_request, queue); if (!req) { //printk("%s: NULL REQ %d\n", // __FUNCTION__, ep_idx); break; } else { read_fifo(ep, req); } } } } else {
static void isac_empty_fifo(struct IsdnCardState *sp, int count) { u_char *ptr; long flags; if ((sp->debug & L1_DEB_ISAC) && !(sp->debug & L1_DEB_ISAC_FIFO)) if (sp->debug & L1_DEB_ISAC) debugl1(sp, "isac_empty_fifo"); if ((sp->rcvidx + count) >= MAX_DFRAME_LEN) { if (sp->debug & L1_DEB_WARN) { char tmp[40]; sprintf(tmp, "isac_empty_fifo overrun %d", sp->rcvidx + count); debugl1(sp, tmp); } writereg(sp->isac, ISAC_CMDR, 0x80); sp->rcvidx = 0; return; } ptr = sp->rcvbuf + sp->rcvidx; sp->rcvidx += count; save_flags(flags); cli(); read_fifo(sp->isac, ptr, count); writereg(sp->isac, ISAC_CMDR, 0x80); restore_flags(flags); if (sp->debug & L1_DEB_ISAC_FIFO) { char tmp[128]; char *t = tmp; t += sprintf(t, "isac_empty_fifo cnt %d", count); QuickHex(t, ptr, count); debugl1(sp, tmp); } }
static void musb_peri_ep0_rx(void) { /* * This is the completion of the data OUT / RX * * Host is sending data to ep0 that is not * part of setup. This comes from the cdc_recv_setup * op that is device specific. * * Pass the data back to driver ep0_recv_setup which * should give the cdc_recv_setup the chance to handle * the rx */ u16 csr0; u16 count0; if (debug_level > 3) { if (0 != ep0_urb->actual_length) { serial_printf("%s finished ? %d of %d\n", __PRETTY_FUNCTION__, ep0_urb->actual_length, ep0_urb->device_request.wLength); } } if (ep0_urb->device_request.wLength == ep0_urb->actual_length) { musb_peri_ep0_last(); SET_EP0_STATE(IDLE); ep0_recv_setup(ep0_urb); return; } csr0 = readw(&musbr->ep[0].ep0.csr0); if (!(MUSB_CSR0_RXPKTRDY & csr0)) return; count0 = readw(&musbr->ep[0].ep0.count0); if (count0) { struct usb_endpoint_instance *endpoint; u32 length; u8 *data; endpoint = ep0_endpoint; if (endpoint && endpoint->rcv_urb) { struct urb *urb = endpoint->rcv_urb; unsigned int remaining_space = urb->buffer_length - urb->actual_length; if (remaining_space) { int urb_bad = 0; /* urb is good */ if (count0 > remaining_space) length = remaining_space; else length = count0; data = (u8 *) urb->buffer_data; data += urb->actual_length; /* The common musb fifo reader */ read_fifo(0, length, data); musb_peri_ep0_ack_req(); /* * urb's actual_length is updated in * usbd_rcv_complete */ usbd_rcv_complete(endpoint, length, urb_bad); } else { if (debug_level > 0) serial_printf("ERROR : %s no space in " "rcv buffer\n", __PRETTY_FUNCTION__); } } else { if (debug_level > 0) serial_printf("ERROR : %s problem with " "endpoint\n", __PRETTY_FUNCTION__); } } else { if (debug_level > 0) serial_printf("ERROR : %s with nothing to do\n", __PRETTY_FUNCTION__); } }
int GrabImage(char* str) { char VH,VL; uint8_t temp; uint8_t buf[256]; static int k = 0; int i,j = 0; int nmemb = 1; printf("GrabImage.\n"); //Open the new file fp = fopen(str,"w+"); if (fp == NULL) { printf("open file failed\n"); return 0; } //Switch to FIFO Mode write_reg(ARDUCHIP_TIM, MODE_MASK); //Flush the FIFO flush_fifo(); //Start capture capture(); printf("Start Capture\n"); //Polling the capture done flag while(!(read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)); printf("Capture Done!\n"); k = 0; //Write the BMP header for( i = 0; i < BMPIMAGEOFFSET; i++) { char ch = pgm_read_byte(&bmp_header[i]); buf[k++] = ch; } fwrite(buf,k,nmemb,fp); //Read first dummy byte //myCAM.read_fifo(); k = 0; //Read 320x240x2 byte from FIFO //Save as RGB565 bmp format for(i = 0; i < 240; i++) for(j = 0; j < 320; j++) { VH = read_fifo(); VL = read_fifo(); buf[k++] = VL; buf[k++] = VH; //Write image data to bufer if not full if(k >= 256) { //Write 256 bytes image data to file from buffer fwrite(buf,256,nmemb,fp); k = 0; } } //Close the file fclose(fp); //Clear the capture done flag clear_fifo_flag(); //Switch to LCD Mode write_reg(ARDUCHIP_TIM, 0); return 1; }
static void hscx_read_fifo(struct IsdnCardState *cs, int hscx, u8 *data, int size) { read_fifo(cs->hw.teles3.hscxfifo[hscx], data, size); }
static void isac_read_fifo(struct IsdnCardState *cs, u8 * data, int size) { read_fifo(cs->hw.teles3.isacfifo, data, size); }
static void ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size) { read_fifo(cs->hw.teles3.isacfifo, data, size); }
int main() { FILE* fp[3]; int cnt; char buf[180]; char res[80]; #if defined(__WINSCW__) || defined(__WINS__) char* exe_names[] = { "z:\\sys\\bin\\get_connection_1.exe", "z:\\sys\\bin\\get_connection_2.exe", "z:\\sys\\bin\\get_connection_3.exe" }; #else char* exe_names[] = { "c:\\sys\\bin\\get_connection_1.exe", "c:\\sys\\bin\\get_connection_2.exe", "c:\\sys\\bin\\get_connection_3.exe" }; #endif char* fifopath[3] = { "C:\\mkfifo001.file", "C:\\mkfifo002.file", "C:\\mkfifo003.file"}; for(cnt=0; cnt<3; cnt++) { if(make_fifo(fifopath[cnt])) { std_log(LOG_FILENAME_LINE,"Failed to open FIFO for %d count", cnt); create_xml(1); return 1; } } for(cnt=0; cnt<3; cnt++) { fp[cnt] = popen(exe_names[cnt], "r"); if(!fp[cnt]) { std_log(LOG_FILENAME_LINE,"Failed to open %d th EXE", cnt); create_xml(1); return 1; } } for(cnt=0; cnt<3; cnt++) { if(read_fifo(fifopath[cnt], res)) { std_log(LOG_FILENAME_LINE,"Failed to read FIFO for %d exe and %s", cnt, res); create_xml(1); return 1; } } std_log(LOG_FILENAME_LINE,"Test Successful"); create_xml(0); return 0; }
static void musb_peri_ep0_idle(void) { u16 count0; int err; u16 csr0; /* * Verify addresses * A lot of confusion can be caused if the address * in software, udc layer, does not agree with the * hardware. Since the setting of the hardware address * must be set after the set address request, the * usb state machine is out of sync for a few frame. * It is a good idea to run this check when changes * are made to the state machine. */ if ((debug_level > 0) && (ep0_state != SET_ADDRESS)) { u8 faddr; faddr = readb(&musbr->faddr); if (udc_device->address != faddr) { serial_printf("ERROR : %s addresses do not" "match sw %d vs hw %d\n", __PRETTY_FUNCTION__, udc_device->address, faddr); udelay(1000 * 1000); hang(); } } csr0 = readw(&musbr->ep[0].ep0.csr0); if (!(MUSB_CSR0_RXPKTRDY & csr0)) goto end; count0 = readw(&musbr->ep[0].ep0.count0); if (count0 == 0) goto end; if (count0 != 8) { if ((debug_setup) && (debug_level > 1)) serial_printf("WARN : %s SETUP incorrect size %d\n", __PRETTY_FUNCTION__, count0); musb_peri_ep0_stall(); goto end; } read_fifo(0, count0, &ep0_urb->device_request); if (debug_level > 2) print_usb_device_request(&ep0_urb->device_request); if (ep0_urb->device_request.wLength == 0) { err = ep0_recv_setup(ep0_urb); /* Zero data request */ musb_peri_ep0_zero_data_request(err); } else { /* Is data coming or going ? */ u8 reqType = ep0_urb->device_request.bmRequestType; if (USB_REQ_DEVICE2HOST == (reqType & USB_REQ_DIRECTION_MASK)) { err = ep0_recv_setup(ep0_urb); /* Device to host */ musb_peri_ep0_tx_data_request(err); } else { /* * Host to device * * The RX routine will call ep0_recv_setup * when the data packet has arrived. */ musb_peri_ep0_rx_data_request(); } } end: return; }