usbMsgLen_t usbFunctionSetup(uchar data[8])
{
  usbRequest_t    *rq = (usbRequest_t*)((void *)data);

    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* HID class request */
        if(rq->bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */
            /* since we have only one report type, we can ignore the report-ID */
	    static uchar dataBuffer[1];  /* buffer must stay valid when usbFunctionSetup returns */
	    if (tx_available()) {
	      dataBuffer[0] = tx_read();
	      usbMsgPtr = dataBuffer; /* tell the driver which data to return */
	      return 1; /* tell the driver to send 1 byte */
	    } else {
	      // Drop through to return 0 (which will stall the request?)
	    }
        }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
            /* since we have only one report type, we can ignore the report-ID */

	  // TODO: Check race issues?
	  store_char(rq->wIndex.bytes[0], &rx_buffer);

        }
    }else{
        /* ignore vendor type requests, we don't use any */
    }
    return 0;
}
Beispiel #2
0
void  process_call()
{
    /* variables */
    enum tcp_conn_status  cur_status;	/* current connection state */



    /* get the current connection state */
    cur_status = tcp_connection_status();

    /* if the current connection state has changed, need to reset the */
    /*    the receive buffers, they may have old tone data in them */
    if (cur_status != last_status)
        reset_tx_buffer();

    /* always update the last status */
    last_status = cur_status;


    /* now check the status of the connection */
    switch  (cur_status)  {

        case CALL_RINGING:	/* connection is ringing on the other end */

				/* generate a buffer of ringing tone if */
				/*    there is room for it */
				if (rcv_available())  {
				    /* have a buffer, get and fill it */
				    ring_fill(get_rcv_buffer(), AUDIO_BUFLEN);
				}

				/* if there is a buffer to transmit, need */
                                /*    to discard it */
				if (xmit_available())  {
				    /* have a buffer, dump it */
				    get_xmit_buffer();
				}
				break;

        case CALL_BUSY:		/* connection is busy on the other end */

				/* generate a buffer of busy signal if */
				/*    there is room for it */
				if (rcv_available())  {
				    /* have a buffer, get and fill it */
				    busy_fill(get_rcv_buffer(), AUDIO_BUFLEN);
				}

				/* if there is a buffer to transmit, need */
                                /*    to discard it */
				if (xmit_available())  {
				    /* have a buffer, dump it */
				    get_xmit_buffer();
				}
				break;

        case CALL_CONNECTED:	/* are talking on the connection */

			        /* check if there is a buffer to transmit */
				if (xmit_available())  {
				    /* buffer is available - try sending it */
				    if (tcp_connection_tx(get_xmit_next_ptr(), AUDIO_BUFLEN))
				        /* actually sent it, let buffer functions know */
				        get_xmit_buffer();
				}

				/* check if have room for a received buffer */
				if (rcv_available())  {
				    /* have room - try to get a buffer */
				    if (tcp_connection_rx(get_rcv_next_ptr(), AUDIO_BUFLEN))
				        /* got the buffer, so allocate it */
					get_rcv_buffer();
				}
				break;

	default:		/* some other status, must have aborted call */

				/* if there is a buffer to transmit, need */
                                /*    to discard it */
				if (xmit_available())  {
				    /* have a buffer, dump it */
				    get_xmit_buffer();
				}
				break;
    }


    /* try to play and receive any buffers */

    /* check if a receive buffer is available for recording into */
    if (rx_available())  {

        /* have a receive buffer, see if update is ready */
	if (update_rx(get_rx_next_ptr()))
	    /* it wanted the buffer - actually allocate it */
	    get_rx_buffer();
    }

    /* check if a transmit buffer is available for playing */
    if (tx_available())  {

        /* have a transmit buffer, see if update is ready */
	if (update_tx(get_tx_next_ptr()))
	    /* it wanted the buffer - actually allocate it */
	    get_tx_buffer();
    }


    /* all done processing the call for now - return */
    return;

}