示例#1
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : Main_App_Task
* Returned Value : None
* Comments       :
*     Application function 
*END*--------------------------------------------------------------------*/
void Main_App_Task(void)
{
  // Wait for insertion or removal event
  if(_usb_event_wait_ticks(&USB_Event, USB_EVENT_CTRL | USB_EVENT_DATA, FALSE, 0) == USB_EVENT_SET)
  {
    _usb_event_clear(&USB_Event, USB_EVENT_CTRL);
    ApplicationTask();
  }
}
示例#2
0
USB_STATUS usb_class_cdc_set_acm_ctrl_state
   (
      /* [IN] The communication device data instance structure */
      CLASS_CALL_STRUCT_PTR            ccs_ptr,
      /* [IN] DTR state to set */
      uint_8                           dtr,
      /* [IN] RTS state to set */
      uint_8                           rts
   )
{ /* Body */
    USB_DATA_CLASS_INTF_STRUCT_PTR if_data_ptr;
    USB_ACM_CLASS_INTF_STRUCT_PTR  if_acm_ptr;
    CLASS_CALL_STRUCT_PTR          acm_instance;
    USB_STATUS                     status = USBERR_NO_INTERFACE;
    USB_EVENT_STRUCT_PTR             event;
    CDC_COMMAND                    cmd;

    USB_lock();
    /* Validity checking: for data interface */
    if (usb_host_class_intf_validate(ccs_ptr)) {
        if_data_ptr = (USB_DATA_CLASS_INTF_STRUCT_PTR)ccs_ptr->class_intf_handle;
        acm_instance = if_data_ptr->BOUND_CONTROL_INTERFACE;
  
        if (usb_host_class_intf_validate(acm_instance)) {
            if_acm_ptr = (USB_ACM_CLASS_INTF_STRUCT_PTR) if_data_ptr->BOUND_CONTROL_INTERFACE->class_intf_handle;
   
            if (if_acm_ptr->acm_desc->bmCapabilities & USB_ACM_CAP_LINE_CODING) {
                event = &if_acm_ptr->acm_event;
   
                USB_unlock(); /* we must wait until ctrl pipe is used */
#if !HIGH_SPEED_DEVICE
                while(USB_EVENT_NOT_SET == _usb_event_wait_ticks(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH, FALSE, 0)){
                  _usb_khci_task();
                }
#endif
                _usb_event_clear(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH);
                
                USB_lock();
                if (usb_host_class_intf_validate(acm_instance)) {
                    cmd.CLASS_PTR = ccs_ptr;
                    cmd.CALLBACK_FN = (tr_callback)usb_class_cdc_ctrl_acm_callback;
                    cmd.CALLBACK_PARAM = acm_instance;
                    
                    if_acm_ptr->ctrl_state.bmStates[0]  = (uint_8)(dtr ? USB_ACM_LINE_STATE_DTR : 0);
                    if_acm_ptr->ctrl_state.bmStates[0] |= rts ? USB_ACM_LINE_STATE_RTS : 0;
                    status = usb_class_cdc_cntrl_common(&cmd, if_acm_ptr,
                        REQ_TYPE_OUT | REQ_TYPE_CLASS | REQ_TYPE_INTERFACE,
                        USB_CDC_SET_CTRL_LINE_STATE, * ((uint_16 *) &if_acm_ptr->ctrl_state), 0, NULL);
                }
            }
            else
               status = USBERR_INVALID_BMREQ_TYPE;
        } /* Endif */
    } /* Endif */
    
 
    USB_unlock();
#if !HIGH_SPEED_DEVICE
                while(USB_EVENT_NOT_SET == _usb_event_wait_ticks(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH, FALSE, 0)){
                  _usb_khci_task();
                }
#endif
                _usb_event_clear(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH);
    _usb_event_set(event, USB_ACM_CTRL_PIPE_FREE);
 
    return status;
} /* Endbody */
示例#3
0
USB_STATUS usb_class_cdc_get_acm_line_coding
   (
      /* [IN] The communication device data instance structure */
      CLASS_CALL_STRUCT_PTR            ccs_ptr,
      /* [IN] Where to store coding */
      USB_CDC_UART_CODING_PTR          uart_coding_ptr
   )
{ /* Body */
    USB_DATA_CLASS_INTF_STRUCT_PTR if_data_ptr;
    USB_ACM_CLASS_INTF_STRUCT_PTR  if_acm_ptr;
    CLASS_CALL_STRUCT_PTR          acm_instance;
    USB_STATUS                     status = USBERR_NO_INTERFACE;
    USB_EVENT_STRUCT_PTR             event;
    CDC_COMMAND                    cmd;
 
    USB_lock();
    /* Validity checking: for data interface */
    if (usb_host_class_intf_validate(ccs_ptr)) {
        if_data_ptr = (USB_DATA_CLASS_INTF_STRUCT_PTR)ccs_ptr->class_intf_handle;
        acm_instance = if_data_ptr->BOUND_CONTROL_INTERFACE;
  
        if (usb_host_class_intf_validate(if_data_ptr->BOUND_CONTROL_INTERFACE)) {
            if_acm_ptr = (USB_ACM_CLASS_INTF_STRUCT_PTR) if_data_ptr->BOUND_CONTROL_INTERFACE->class_intf_handle;
         
            if (if_acm_ptr->acm_desc->bmCapabilities & USB_ACM_CAP_LINE_CODING) {
                event = &if_acm_ptr->acm_event;
    
                USB_unlock(); /* we must wait until ctrl pipe is used */
#if !HIGH_SPEED_DEVICE   
                while(USB_EVENT_NOT_SET == _usb_event_wait_ticks(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH, FALSE, 0)){
                  _usb_khci_task();
                }
#endif
                _usb_event_clear(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH);
                
                USB_lock();
                if (usb_host_class_intf_validate(acm_instance)) {
                    cmd.CLASS_PTR = ccs_ptr;
                    cmd.CALLBACK_FN = (tr_callback)usb_class_cdc_ctrl_acm_callback;
                    cmd.CALLBACK_PARAM = acm_instance;
                    status = usb_class_cdc_cntrl_common(&cmd, if_acm_ptr,
                        REQ_TYPE_IN | REQ_TYPE_CLASS | REQ_TYPE_INTERFACE,
                        USB_CDC_GET_LINE_CODING, 0, 7 /* sizeof(USB_CDC_UART_CODING)*/, (uchar_ptr)uart_coding_ptr);
                }
            }
            else
               status = USBERR_INVALID_BMREQ_TYPE;
        } /* Endif */
    } /* Endif */
    
    USB_unlock();
#if !HIGH_SPEED_DEVICE
                while(USB_EVENT_NOT_SET == _usb_event_wait_ticks(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH, FALSE, 0)){
                  _usb_khci_task();
                }
#endif
                _usb_event_clear(event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_DETACH);
    _usb_event_set(event, USB_ACM_CTRL_PIPE_FREE);
 
    return status;
} /* Endbody */
示例#4
0
void Mouse_Task ( uchar *buffer, HID_COMMAND_PTR hid_com  )
{
	USB_STATUS              status = USB_OK;
	static _usb_pipe_handle        pipe;
	static uint_32 check = 0, usb_event_flag = 1;
	static TR_INIT_PARAM_STRUCT    tr;
	uint_32                 result, test_buffer[4]; 
   	
		// Wait for insertion or removal event
        //result = _usb_event_wait_ticks(&USB_Event, USB_EVENT_CTRL, FALSE, 0);
        
        //if (USB_EVENT_NOT_SET == result) return;
      	switch ( hid_device.DEV_STATE ) {
         	case USB_DEVICE_IDLE:
            	break;
         	case USB_DEVICE_ATTACHED:
	            printf("\nMouse device attached");
	            //fflush(stdout);
	            hid_device.DEV_STATE = USB_DEVICE_SET_INTERFACE_STARTED;
	            status = _usb_hostdev_select_interface(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, (pointer2)&hid_device.CLASS_INTF);
	            if (status != USB_OK) {
               		printf("\nError in _usb_hostdev_select_interface: %x", status);
               		//fflush(stdout);
               		exit(1);
            	} /* Endif */
            	break;
         	case USB_DEVICE_SET_INTERFACE_STARTED:
            	break;
         	case USB_DEVICE_INTERFACED:
         		printf("Mouse interfaced, setting protocol...\n");
         		/* now we will set the USB Hid standard boot protocol */
            	hid_device.DEV_STATE = USB_DEVICE_SETTING_PROTOCOL;
            
	            hid_com->CLASS_PTR = (CLASS_CALL_STRUCT_PTR)&hid_device.CLASS_INTF;
	            hid_com->CALLBACK_FN = usb_host_hid_ctrl_callback;
	            hid_com->CALLBACK_PARAM = 0;
         	
	         	status = usb_class_hid_set_protocol(hid_com, USB_PROTOCOL_HID_MOUSE);
         
	         	if (status != USB_STATUS_TRANSFER_QUEUED) {
	                  printf("\nError in usb_class_hid_set_protocol: %x", status);
	                  //fflush(stdout);
	         	}
	            break;
			case USB_DEVICE_INUSE:
			    if(0 == check){
			      check = 1;
            pipe = _usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_INTERRUPT_PIPE, USB_RECV);
         		if(pipe){
         			printf("Mouse device ready, try to move the mouse\n");
			      } 
			    }

   			/******************************************************************
              Initiate a transfer request on the interrupt pipe
              ******************************************************************/
              if (usb_event_flag == 1){
     			      usb_hostdev_tr_init(&tr, usb_host_hid_recv_callback, NULL);
              	tr.RX_BUFFER = buffer;
              	tr.RX_LENGTH = HID_BUFFER_SIZE;	                  	
              	
              	status = _usb_host_recv_data(host_handle, pipe, &tr);
              	
              	if (status != USB_STATUS_TRANSFER_QUEUED) {
                 	printf("\nError in _usb_host_recv_data: %x", status);
                 	//fflush(stdout);
                }
              }
            
              /* Wait untill we get the data from keyboard. */
              if(_usb_event_wait_ticks(&USB_Event,USB_EVENT_CTRL | USB_EVENT_DATA, FALSE, 0) == USB_EVENT_SET){
                usb_event_flag = 1;
                _usb_event_clear(&USB_Event, USB_EVENT_CTRL | USB_EVENT_DATA);
              } else {
                usb_event_flag = 0;
              }
              
              /* if not detached in the meanwhile */
              if((hid_device.DEV_STATE == USB_DEVICE_INUSE) && (usb_event_flag == 1)) {	                         
//              if((hid_device.DEV_STATE == USB_DEVICE_INUSE)) {	                         
                  process_mouse_buffer((uchar *)buffer);  
                  //_usb_event_clear(&USB_Event, USB_EVENT_CTRL | USB_EVENT_DATA);      
                                             	                
              }
              //else {
              //    /* kick the outer loop again to handle the CTRL event */
              //    _usb_event_set(&USB_Event, USB_EVENT_CTRL);
              //    break;
              //}
	         		
    	     	break;
         	case USB_DEVICE_DETACHED:
         	  check = 0;
         		printf("Going to idle state\n");
            	hid_device.DEV_STATE = USB_DEVICE_IDLE;
            	break;
         	case USB_DEVICE_OTHER:
	            break;
    	     default:
        	    printf("Unknown Mouse Device State = %d\n", hid_device.DEV_STATE);
            	//fflush(stdout);
            	break;
      	} /* Endswitch */
   
} /* Endbody */
示例#5
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : CDC_Task
* Returned Value : none
* Comments       :
*     Execution starts here
*
*END*--------------------------------------------------------------------*/
void CDC_Task ()
{ /* Body */
    USB_STATUS           status = USB_OK;
    uint_32              i = 0;    
    static uint_32       char_to_recv = 0;

    /* due to the fact that uart driver blocks task, we will check if char is available and then we read it */
    /* write them to USB */
    if(USB_EVENT_NOT_SET == _usb_event_wait_ticks(&device_registered, 0x01, TRUE, 0))
      return;

    if (0 == check_open)
    {
    	_io_cdc_serial_open(f_usb, device_name, (char *)&usb_open_param);
    	check_open = 1;
    }
    else
    {
#ifdef MCU_mcf51jf128
    	/* todo AI: change this for MCU_mcf51jf128 */
    	char temp;
    	
    	temp = TERMIO_GetChar();
    	if(temp)
    	{
    		buff_index = 1;
    		buff[0] = temp;
    	}
#endif /* MCU_mcf51jf128 */
    	
		/* Read data from UART */
#if 0 /* << EST */    	
		 DisableInterrupts;
		 uart2usb_num = buff_index;
		 for (i = 0; i < buff_index; i++) {
			 uart2usb[i] = buff[i];
                 }
		 buff_index = 0;
		 EnableInterrupts;
#endif
		 
#if 0 /* << EST */
		 /* Write data to USB */
		 if (uart2usb_num) 
		 {
			num_done = _io_cdc_serial_write(f_usb, uart2usb, (int_32)(sizeof(uart2usb[0]) * uart2usb_num));
			if(num_done > 0)
			{
				for (i = (uint_32)num_done; i < uart2usb_num; i++) /* move buffer data, remove the written ones */
					uart2usb[i - num_done] = uart2usb[i];
				uart2usb_num -= num_done; 
				char_to_recv += num_done;
			}
		 }
#endif        
		 /* Read data from USB */    
		 if(char_to_recv > 0)
		 {       
			 num_done = _io_cdc_serial_read(f_usb, usb2uart + usb2uart_num, (int_32)(sizeof(uart2usb) / sizeof(uart2usb[0]) - usb2uart_num));
			 if(num_done > 0)
			 {
				 usb2uart_num += num_done;	
				 if(char_to_recv >= num_done)
				 {
					 char_to_recv -= num_done;	
				 }
				 else
				 {
					 char_to_recv  = 0;
				 }
			 }
			 else
			 {
				 char_to_recv  = 0;
			 }      
		 }
		 
		 /* write them to UART */
		 if (usb2uart_num > 0) 
		 {
#if 0 /* << EST */
			 for (i = 0; i < usb2uart_num; i++) 
			 {
#ifdef MCU_mcf51jf128
				 printf(" --received--> %%c\n\r",usb2uart[i]);
#else
				 sci2_PutChar(usb2uart[i]);
#endif
			 }
#endif
			 usb2uart_num = 0;      
		 }
    } 
} /* Endbody */