Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Cyg_ErrNo serial_read(cyg_io_handle_t handle, void *_buf, cyg_uint32 *len)
- {
- cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
- serial_channel *chan = (serial_channel *)t->priv;
- serial_funs *funs = chan->funs;
- cyg_uint8 *buf = (cyg_uint8 *)_buf;
- cyg_int32 size = 0;
- cbuf_t *cbuf = &chan->in_cbuf;
- Cyg_ErrNo res = ENOERR;
- // *len = 1;
- #ifdef XX_CYGDBG_DIAG_BUF
- extern int enable_diag_uart;
- int _enable = enable_diag_uart;
- int _time, _stime;
- externC cyg_tick_count_t cyg_current_time(void);
- #endif // CYGDBG_DIAG_BUF
- cyg_drv_mutex_lock(&cbuf->lock);
- cbuf->abort = false;
- printf("under serial_read\r\n");
- if (cbuf->len == 0) {
- // Non interrupt driven (i.e. polled) operation
- printf("Before While size %d len %d\r\n",size,*len);
- while (size++ < *len) {
- printf("size %d len %d\r\n",size,*len);
- cyg_uint8 c = (funs->getc)(chan);
- printf("polling base %d %c\r\n",size,c);
- #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE
- // for software flow control, if the driver returns one of the
- // characters we act on it and then drop it (the app must not
- // see it)
- if ( chan->config.flags & CYGNUM_SERIAL_FLOW_XONXOFF_TX ) {
- if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XOFF_CHAR ) {
- throttle_tx( chan );
- } else if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XON_CHAR ) {
- restart_tx( chan );
- }
- else
- *buf++ = c;
- }
- else
- *buf++ = c;
- #else
- *buf++ = c;
- #endif
- }
- } else {
- printf("interrupt driver \r\n");
- cyg_drv_dsr_lock(); // Avoid races
- while (size < *len) {
- if (cbuf->nb > 0) {
- #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL
- if ( (cbuf->nb <= cbuf->low_water) &&
- (chan->flow_desc.flags & CYG_SERIAL_FLOW_IN_THROTTLED) )
- restart_rx( chan, false );
- #endif
- *buf++ = cbuf->data[cbuf->get];
- if (++cbuf->get == cbuf->len) cbuf->get = 0;
- cbuf->nb--;
- size++;
- } else {
- #ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
- if (!cbuf->blocking) {
- *len = size; // characters actually read
- res = size == 0 ? -EAGAIN : ENOERR;
- break;
- }
- #endif // CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
- cbuf->waiting = true;
- #ifdef XX_CYGDBG_DIAG_BUF
- enable_diag_uart = 0;
- HAL_CLOCK_READ(&_time);
- _stime = (int)cyg_current_time();
- diag_printf("READ wait - get: %d, put: %d, time: %x.%x\n", cbuf->get, cbuf->put, _stime, _time);
- enable_diag_uart = _enable;
- #endif // CYGDBG_DIAG_BUF
- if( !cyg_drv_cond_wait(&cbuf->wait) )
- cbuf->abort = true;
- #ifdef XX_CYGDBG_DIAG_BUF
- enable_diag_uart = 0;
- HAL_CLOCK_READ(&_time);
- _stime = (int)cyg_current_time();
- diag_printf("READ continue - get: %d, put: %d, time: %x.%x\n", cbuf->get, cbuf->put, _stime, _time);
- enable_diag_uart = _enable;
- #endif // CYGDBG_DIAG_BUF
- if (cbuf->abort) {
- // Give up!
- *len = size; // characters actually read
- cbuf->abort = false;
- cbuf->waiting = false;
- res = -EINTR;
- break;
- }
- }
- }
- cyg_drv_dsr_unlock();
- }
- #ifdef XX_CYGDBG_DIAG_BUF
- cyg_drv_isr_lock();
- enable_diag_uart = 0;
- HAL_CLOCK_READ(&_time);
- _stime = (int)cyg_current_time();
- diag_printf("READ done - size: %d, len: %d, time: %x.%x\n", size, *len, _stime, _time);
- enable_diag_uart = _enable;
- cyg_drv_isr_unlock();
- #endif // CYGDBG_DIAG_BUF
- cyg_drv_mutex_unlock(&cbuf->lock);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement