int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb) { int status; static char data[] = "hello"; int nb; if (optv) { printf ("%s: in io_read\n", progname); } if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK) { if (optv) printf("read failed because of error %d\n", status ); return (status); } // No special xtypes if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) { return(ENOSYS); } nb = strlen(data ); nb = min( nb, msg->i.nbytes ); _IO_SET_READ_NBYTES (ctp, nb); SETIOV( ctp->iov, data, nb ); if (nb > 0) ocb->attr->flags |= IOFUNC_ATTR_ATIME; return (_RESMGR_NPARTS (1)); }
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb) { int nleft; int nbytes; int nparts; int status; if ((status = iofunc_read_verify (ctp, msg, ocb, NULL)) != EOK) return (status); if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) return (ENOSYS); /* * On all reads (first and subsequent), calculate * how many bytes we can return to the client, * based upon the number of bytes available (nleft) * and the client's buffer size */ nleft = ocb->attr->nbytes - ocb->offset; nbytes = min(msg->i.nbytes, nleft); if (nbytes > 0) { /* set up the return data IOV */ SETIOV (ctp->iov, buffer + ocb->offset, nbytes); /* set up the number of bytes (returned by client's read()) */ _IO_SET_READ_NBYTES (ctp, nbytes); /* * advance the offset by the number of bytes * returned to the client. */ ocb->offset += nbytes; nparts = 1; } else { /* * they've asked for zero bytes or they've already previously * read everything */ _IO_SET_READ_NBYTES (ctp, 0); nparts = 0; } /* mark the access time as invalid (we just accessed it) */ if (msg->i.nbytes > 0) ocb->attr->flags |= IOFUNC_ATTR_ATIME; return (_RESMGR_NPARTS (nparts)); }
int _spi_read(resmgr_context_t *ctp, io_read_t *msg, spi_ocb_t *ocb) { uint8_t *buf; int nbytes; int nonblock = 0; int status; SPIDEV *drvhdl = (SPIDEV *)ocb->hdr.attr; spi_dev_t *dev = drvhdl->hdl; if ((status = iofunc_read_verify(ctp, msg, &ocb->hdr, &nonblock)) != EOK) return status; if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) return ENOSYS; /* * Check to see if the device is locked */ if ((status =_spi_lock_check(ctp, ocb->chip, ocb)) != EOK) return status; if (msg->i.nbytes <= 0) { _IO_SET_READ_NBYTES(ctp, 0); return _RESMGR_NPARTS(0); } /* check if message buffer is too short */ nbytes = msg->i.nbytes; if (nbytes > ctp->msg_max_size) { if (dev->buflen < nbytes) { dev->buflen = nbytes; if (dev->buf) free(dev->buf); if (NULL == (dev->buf = malloc(dev->buflen))) { dev->buflen = 0; return ENOMEM; } } buf = dev->buf; } else buf = (uint8_t *)msg; buf = dev->funcs->xfer(drvhdl, _SPI_DEV_READ(ocb->chip), buf, &nbytes); if (nbytes > 0) { _IO_SET_READ_NBYTES(ctp, nbytes); return _RESMGR_PTR(ctp, buf, nbytes); } return EIO; }
static int devi_read(resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb) { int nonblock; devi_attr_t *attr; event_bus_line_t *line; attr = ocb->ocb.attr; line = attr->line; if (iofunc_read_verify(ctp, msg, &ocb->ocb, &nonblock) != EOK) return (errno); pthread_mutex_lock(&line->mutex); /* queue is empty */ if (ocb->read_ptr == line->head) { if (nonblock) { pthread_mutex_unlock(&line->mutex); return (EAGAIN); } else { add_wait_queue(attr, ocb, ctp, msg->i.nbytes); pthread_mutex_unlock(&line->mutex); return (_RESMGR_NOREPLY); } } if (process_read_data(ctp->rcvid, attr, ocb, msg->i.nbytes) < 0) { if (nonblock) { pthread_mutex_unlock(&line->mutex); return (EAGAIN); } else { add_wait_queue(attr, ocb, ctp, msg->i.nbytes); pthread_mutex_unlock(&line->mutex); return (_RESMGR_NOREPLY); } } pthread_mutex_unlock(&line->mutex); return (_RESMGR_NOREPLY); }
int io_read(resmgr_context_t *ctp, io_read_t *msg, iofunc_ocb_t *ocb) { LOCK(resource_mutex); printf("IO read activated\n"); int nonblock, status; if ((status = iofunc_read_verify (ctp, msg, ocb, &nonblock)) != EOK) { RETURN_UNLOCK(status, resource_mutex); } // set data to return if (ocb->offset) { SETIOV(ctp->iov, NULL, 0); _IO_SET_READ_NBYTES(ctp, 0); RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex); } ocb->offset = 1; if (nonblock && !fifo_status(fifoHandler)) { SETIOV(ctp->iov, NULL, 0); _IO_SET_READ_NBYTES(ctp, 0); RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex); } else if(!fifo_status(fifoHandler)) { fifo_add_blocked_id(fifoHandler, ctp->rcvid); RETURN_UNLOCK(_RESMGR_NOREPLY, resource_mutex); } char buffer[WIDTH]; fifo_rem_string(fifoHandler, buffer); SETIOV(ctp->iov, buffer, strlen(buffer)); _IO_SET_READ_NBYTES(ctp, strlen(buffer)); RETURN_UNLOCK(_RESMGR_NPARTS(1), resource_mutex); }
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb) { int status; if (optv) { printf ("%s: in io_read\n", progname); } if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK) return (status); // No special xtypes if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) { return(ENOSYS); } _IO_SET_READ_NBYTES (ctp, 0); if (msg->i.nbytes > 0) ocb->attr->flags |= IOFUNC_ATTR_ATIME; return (_RESMGR_NPARTS (0)); }
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb) { int nleft; int nbytes; int nparts; int status; uint32_t chip; char lbuff[64]; uint32_t cval; if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK) return(status); if ((msg->i.xtype & _IO_XTYPE_NONE) != _IO_XTYPE_NONE) return (ENOSYS); /* * On all reads, calculate how many * bytes we can return to the client * based upon the number of bytes available (nleft) * and the client's buffer size */ nleft = ocb->attr->nbytes - ocb->offset; nbytes = min(msg->i.nbytes, nleft); cval = *(uint32_t *)ics660->regs.control; fprintf(stderr,"io_read - cval %d\n",cval); sprintf(lbuff,"%x",cval); for( chip=1; chip<=4; chip++){ select_chip(ics660->mod_control_reg,chip); printf("MAIN PRINT_REGISTER\n"); print_registers(ics660->dc60m_regs); } select_chip(ics660->mod_control_reg,(uint32_t)0x0); if (nbytes > 0){ /* set up the return data IOV */ //SETIOV( ctp->iov, buffer + ocb->offset, nbytes ); SETIOV( ctp->iov, lbuff + ocb->offset, nbytes ); /* set up the number of bytes (returned by client's read()) */ _IO_SET_READ_NBYTES(ctp, nbytes); /* * advance the offset by the number of bytes * returned to the client. */ ocb->offset += nbytes; nparts = 1; } else { /* * they've asked for zero bytres or they've already * read everything */ _IO_SET_READ_NBYTES(ctp,0); nparts = 0; } /* mark the access time as invalid (we just accessed it) */ if (msg->i.nbytes > 0) ocb->attr->flags |= IOFUNC_ATTR_ATIME; return (_RESMGR_NPARTS(nparts)); }
int io_read(resmgr_context_t *ctp, io_read_t *msg, struct ocb *ocb) { MQDEV *dev = ocb->ocb.attr; MQMSG *mp; static MQMSG dummy; MQWAIT *wp; int nonblock, status, n, rcvid; // Is queue open for read? if((status = iofunc_read_verify(ctp, msg, &ocb->ocb, &nonblock)) != EOK) { return status; } // If an xtype is specified make sure it is a mqueue. if((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE && (msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_MQUEUE) { return ENOSYS; } // Is the msg buffer too small for the queue? if(msg->i.nbytes < dev->mq_attr.mq_msgsize) { return EMSGSIZE; } // Are there waiting msgs. if(dev->mq_attr.mq_curmsgs == 0) { if(nonblock & O_NONBLOCK) { return EAGAIN; } if((wp = MemchunkMalloc(memchunk, sizeof(*wp))) == NULL) { return ENOMEM; } wp->rcvid = ctp->rcvid; wp->scoid = ctp->info.scoid; wp->coid = ctp->info.coid; wp->priority = 0; // Must get real priority from ctp->info wp->xtype = msg->i.xtype; LINK_PRI_CLIENT(&dev->waiting_read, wp); ++dev->mq_attr.mq_recvwait; return _RESMGR_NOREPLY; } // Reply with the data mp = (dev->mq_attr.mq_flags & MQ_SEMAPHORE) ? &dummy : dev->waiting_msg[0]; if(mp->nbytes) { dev->attr.flags |= (IOFUNC_ATTR_ATIME | IOFUNC_ATTR_DIRTY_TIME); } resmgr_endian_context(ctp, _IO_READ, S_IFNAM, msg->i.xtype); _IO_SET_READ_NBYTES(ctp, mp->nbytes); if((msg->i.xtype & _IO_XTYPE_MASK) == _IO_XTYPE_MQUEUE) { uint32_t prio; prio = mp->priority; SETIOV(&ctp->iov[0], &prio, sizeof(prio)); SETIOV(&ctp->iov[1], mp->data, mp->nbytes); if(resmgr_msgreplyv(ctp, ctp->iov, 2) == -1) { return errno; } } else { SETIOV(&ctp->iov[0], mp->data, mp->nbytes); if(resmgr_msgreplyv(ctp, ctp->iov, 1) == -1) { return errno; } } // Remove the msg if(mp != &dummy) { if ((dev->waiting_msg[0] = mp->next) == NULL) dev->waiting_msg[1] = NULL; MemchunkFree(memchunk, mp); } --dev->mq_attr.mq_curmsgs; // Keep stat info up-to-date. We overload st_size to be messages waiting. dev->attr.nbytes = dev->mq_attr.mq_curmsgs; // Since we removed a msg we may need to wake someone waiting for a msg. if(wp = dev->waiting_write) { // Unlink and free wait entry rcvid = wp->rcvid; dev->waiting_write = wp->next; MemchunkFree(memchunk, wp); --dev->mq_attr.mq_sendwait; // Process the message resmgr_msg_again(ctp, rcvid); } if((n = dev->mq_attr.mq_maxmsg - dev->mq_attr.mq_curmsgs) != 0 && IOFUNC_NOTIFY_OUTPUT_CHECK(dev->notify, n)) { iofunc_notify_trigger(dev->notify, n, IOFUNC_NOTIFY_OUTPUT); } return _RESMGR_NOREPLY; }