static void serial_data_rcv_done(serial_channel *chan, int chars_rcvd) { cbuf_t *cbuf = &chan->in_cbuf; cbuf->put += chars_rcvd; cbuf->nb += chars_rcvd; if (cbuf->put == cbuf->len) cbuf->put = 0; CYG_ASSERT(cbuf->nb <= cbuf->len, "Buffer overflow"); CYG_ASSERT(cbuf->put < cbuf->len, "Invalid put ptr"); CYG_ASSERT(cbuf->get < cbuf->len, "Invalid get ptr"); if (cbuf->waiting) { cbuf->waiting = false; cyg_drv_cond_signal(&cbuf->wait); } #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL // If we've hit the high water mark, tell the other side to stop if ( cbuf->nb >= cbuf->high_water ) { throttle_rx( chan, false ); } #endif #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT // Wake up any pending selectors if we have // put some data into a previously empty buffer. if (chars_rcvd == cbuf->nb) cyg_selwakeup( &cbuf->selinfo ); #endif #ifdef CYGDBG_USE_ASSERTS cbuf->block_mode_xfer_running = false; #endif }
static void kbd_scan(cyg_addrword_t param) { unsigned char ch; unsigned char *ev; diag_printf("Keyboard scan\n"); while (true) { cyg_thread_delay(SCAN_DELAY); if (aaed2000_KeyboardTest()) { ch = aaed2000_KeyboardGetc(); if (num_events < MAX_EVENTS) { num_events++; ev = &_events[_event_put++]; if (_event_put == MAX_EVENTS) { _event_put = 0; } *ev = ch; if (kbd_select_active) { kbd_select_active = false; cyg_selwakeup(&kbd_select_info); } } } } }
// // Note: this routine is called from the Atmel processing DSR // static void ts_handler(atmel_pkt *pkt) { unsigned char *dp = pkt->data; static short lastX, lastY; short x, y; struct _event *ev; #ifdef DEBUG_RAW_EVENTS memcpy(&_ts_buf[_ts_buf_ptr], pkt->data, 8); _ts_buf_ptr += 8; if (_ts_buf_ptr == 512) { diag_printf("TS handler\n"); diag_dump_buf(_ts_buf, 512); _ts_buf_ptr = 0; } #endif // Try and interpret the mouse data if ((dp[0] & 0x0F) == 0) { // This is a pen up event x = lastX; y = lastY; pen_down = false; } else { // Some sort of event with the pen down x = lastX = (dp[1] << 8) | dp[2]; y = lastY = (dp[3] << 8) | dp[4]; pen_down = true; } if (num_events < MAX_EVENTS) { num_events++; ev = &_events[_event_put++]; if (_event_put == MAX_EVENTS) { _event_put = 0; } ev->button_state = pen_down ? 0x04 : 0x00; ev->xPos = x; ev->yPos = y; if (ts_select_active) { ts_select_active = false; cyg_selwakeup(&ts_select_info); } } }
static __inline__ void restart_tx( serial_channel *chan ) { serial_funs *funs = chan->funs; chan->flow_desc.flags &= ~CYG_SERIAL_FLOW_OUT_THROTTLED; #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT // See if there is now enough room to say it is available // for writing { cbuf_t *cbuf = &chan->out_cbuf; int space; space = cbuf->len - cbuf->nb; if (space >= cbuf->low_water) cyg_selwakeup( &cbuf->selinfo ); } #endif if ( chan->out_cbuf.nb > 0 ) (funs->start_xmit)(chan); }
static void serial_data_xmt_done(serial_channel *chan, int chars_sent) { cbuf_t *cbuf = &chan->out_cbuf; serial_funs *funs = chan->funs; int space; cbuf->get += chars_sent; cbuf->nb -= chars_sent; if (cbuf->get == cbuf->len) cbuf->get = 0; CYG_ASSERT(cbuf->nb <= cbuf->len, "Buffer overflow"); CYG_ASSERT(cbuf->nb >= 0, "Buffer underflow"); CYG_ASSERT(cbuf->put < cbuf->len, "Invalid put ptr"); CYG_ASSERT(cbuf->get < cbuf->len, "Invalid get ptr"); if (0 == cbuf->nb) { (funs->stop_xmit)(chan); // Done with transmit cbuf->get = cbuf->put = 0; // reset ptrs if empty } // See if there is now enough room to restart writer space = cbuf->len - cbuf->nb; if (space >= cbuf->low_water) { if (cbuf->waiting) { cbuf->waiting = false; cyg_drv_cond_broadcast(&cbuf->wait); } #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT cyg_selwakeup( &cbuf->selinfo ); #endif } #ifdef CYGDBG_USE_ASSERTS cbuf->block_mode_xfer_running = false; #endif }
static void serial_rcv_char(serial_channel *chan, unsigned char c) { cbuf_t *cbuf = &chan->in_cbuf; #ifdef CYGPKG_NET_BLUEZ_STACK if(chan->receive)//clyu { extern unsigned char bluetooth_buf[]; int len = 0; struct tty_ldisc *ldisc = chan->tty_ldisc; if(ldisc && ldisc->receive_buf && cbuf->nb) { diag_printf("bluetooth\n"); if(cbuf->put < cbuf->get) { memcpy(bluetooth_buf, cbuf->data + cbuf->get, cbuf->len - cbuf->get); len = cbuf->len - cbuf->get; //ldisc->receive_buf(serial_driver, cbuf->data + cbuf->get, (char*)cbuf, cbuf->len - cbuf->get); cbuf->nb -= len; cbuf->get = 0; } memcpy(bluetooth_buf + len, cbuf->data + cbuf->get, cbuf->put); len += cbuf->put; cbuf->get = cbuf->put; cbuf->nb -= len; //ldisc->receive_buf(serial_driver, cbuf->data + cbuf->get, (char*)cbuf, cbuf->nb); ldisc->receive_buf(serial_driver, bluetooth_buf, (char*)cbuf, len); } chan->receive = 0; return; } #endif #if CYGINT_IO_SERIAL_BLOCK_TRANSFER CYG_ASSERT(false == cbuf->block_mode_xfer_running, "Attempting char rcv while block transfer is running"); #endif #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 ); return; // it wasn't a "real" character } else if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XON_CHAR ) { restart_tx( chan ); return; // it wasn't a "real" character } } #endif #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL // If we've hit the high water mark, tell the other side to stop if ( cbuf->nb >= cbuf->high_water ) { throttle_rx( chan, false ); } #endif #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT // Wake up any pending selectors if we are about to // put some data into a previously empty buffer. if( cbuf->nb == 0 ) cyg_selwakeup( &cbuf->selinfo ); #endif // If the flow control is not enabled/sufficient and the buffer is // already full, just throw new characters away. if ( cbuf->nb < cbuf->len ) { cbuf->data[cbuf->put++] = c; if (cbuf->put == cbuf->len) cbuf->put = 0; cbuf->nb++; } // note trailing else #ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS else { // Overrun. Report the error. cyg_serial_line_status_t stat; stat.which = CYGNUM_SERIAL_STATUS_OVERRUNERR; serial_indicate_status(chan, &stat); } #endif if (cbuf->waiting) { #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); enable_diag_uart = 0; HAL_CLOCK_READ(&_time); _stime = (int)cyg_current_time(); diag_printf("Signal reader - time: %x.%x\n", _stime, _time); enable_diag_uart = _enable; #endif // CYGDBG_DIAG_BUF cbuf->waiting = false; cyg_drv_cond_signal(&cbuf->wait); } }
static void serial_xmt_char(serial_channel *chan) { cbuf_t *cbuf = &chan->out_cbuf; serial_funs *funs = chan->funs; unsigned char c; int space; #if CYGINT_IO_SERIAL_BLOCK_TRANSFER CYG_ASSERT(false == cbuf->block_mode_xfer_running, "Attempting char xmt while block transfer is running"); #endif #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE // if we are required to send an XON/XOFF char, send it before // anything else // FIXME: what if XON gets corrupted in transit to the other end? // Should we resend XON even though the other end may not be wanting // to send us stuff at this point? if ( chan->config.flags & CYGNUM_SERIAL_FLOW_XONXOFF_RX ) { if ( chan->flow_desc.xchar ) { if ( (funs->putc)(chan, chan->flow_desc.xchar) ) { chan->flow_desc.xchar = '\0'; } else { // otherwise there's no space and we have to wait return; } } } #endif #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL // if we're meant to be throttled, just stop and leave if ( chan->flow_desc.flags & CYG_SERIAL_FLOW_OUT_THROTTLED ) { (funs->stop_xmit)(chan); // Stop transmitting for now return; } #endif while (cbuf->nb > 0) { c = cbuf->data[cbuf->get]; if ((funs->putc)(chan, c)) { cbuf->get++; if (cbuf->get == cbuf->len) cbuf->get = 0; cbuf->nb--; } else { // See if there is now enough room to restart writer space = cbuf->len - cbuf->nb; if (space >= cbuf->low_water) { if (cbuf->waiting) { cbuf->waiting = false; cyg_drv_cond_broadcast(&cbuf->wait); } #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT cyg_selwakeup( &cbuf->selinfo ); #endif } return; // Need to wait for more space } } (funs->stop_xmit)(chan); // Done with transmit #ifdef CYGPKG_NET_BLUEZ_STACK if(chan->tty_ldisc)//clyu { struct tty_ldisc *ldisc = chan->tty_ldisc; //diag_printf("chan->tty_ldisc != NULL\n"); if(ldisc && ldisc->write_wakeup) ldisc->write_wakeup(serial_driver); } #endif // must signal waiters, and wake up selecters for the case when // this was the last char to be sent and they hadn't been signalled // before (e.g. because of flow control) if (cbuf->waiting) { cbuf->waiting = false; //diag_printf("cyg_drv_cond_broadcast signal\n"); //cyg_drv_cond_signal(&cbuf->wait);//clyu ? cyg_drv_cond_broadcast(&cbuf->wait); } #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT cyg_selwakeup( &cbuf->selinfo ); #endif }
void selwakeup(struct selinfo *info) { cyg_selwakeup( info); }
void poll_wakeup(void) { cyg_selwakeup(&sg_PanelSignal); }
static void ts_scan(cyg_addrword_t param) { short lastX, lastY; short x, y; struct _event *ev; bool pen_down; diag_printf("Touch Screen thread started\n"); // Discard the first sample - it's always 0 x = read_ts(ADS_MEASURE_X); y = read_ts(ADS_MEASURE_Y); lastX = lastY = -1; pen_down = false; while (true) { cyg_thread_delay(SCAN_DELAY); if ((*(volatile cyg_uint32 *)AAEC_PFDR & TS_INT) == 0) { // Pen is down x = read_ts(ADS_MEASURE_X); y = read_ts(ADS_MEASURE_Y); // diag_printf("X = %x, Y = %x\n", x, y); if ((x < X_THRESHOLD) || (y < Y_THRESHOLD)) { // Ignore 'bad' samples continue; } lastX = x; lastY = y; pen_down = true; } else { if (pen_down) { // Capture first 'up' event pen_down = false; x = lastX; y = lastY; } else { continue; // Nothing new to report } } if (num_events < MAX_EVENTS) { num_events++; ev = &_events[_event_put++]; if (_event_put == MAX_EVENTS) { _event_put = 0; } ev->button_state = pen_down ? 0x04 : 0x00; ev->xPos = x; ev->yPos = y; if (ts_select_active) { ts_select_active = false; cyg_selwakeup(&ts_select_info); } } #ifdef DEBUG_RAW_EVENTS memcpy(&_ts_buf[_ts_buf_ptr], pkt->data, 8); _ts_buf_ptr += 8; if (_ts_buf_ptr == 512) { diag_printf("TS handler\n"); diag_dump_buf(_ts_buf, 512); _ts_buf_ptr = 0; } #endif } }