void usb_class_cdc_acm_init
   (
      /* [IN]  structure with USB pipe information on the interface */
      PIPE_BUNDLE_STRUCT_PTR      pbs_ptr,

      /* [IN] acm call struct pointer2 */
      CLASS_CALL_STRUCT_PTR       ccs_ptr
   )
{ /* Body */
    USB_ACM_CLASS_INTF_STRUCT_PTR acm_anchor = NULL;
    USB_ACM_CLASS_INTF_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle;
    USB_STATUS                    status;
 
    /* Make sure the device is still attached */
    USB_lock();
    status = usb_host_class_intf_init(pbs_ptr, if_ptr, &acm_anchor_abstract);
    if (status == USB_OK) {
        /*
        ** We generate a code_key based on the attached device. This is used to
        ** verify that the device has not been detached and replaced with another.
        */
        ccs_ptr->code_key = 0;
        ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr);
  
        if_ptr->CDC_G.IFNUM = ((INTERFACE_DESCRIPTOR_PTR)if_ptr->CDC_G.G.intf_handle)->bInterfaceNumber;
        if_ptr->interrupt_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_INTERRUPT_PIPE, 0);
  
        if (USB_OK != (status = _usb_event_init(&if_ptr->acm_event))) {
           status = USBERR_INIT_FAILED;
        }
        else {
            /* prepare events to be auto or manual */
            //_lwevent_set_auto_clear(&if_ptr->acm_event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_INT_PIPE_FREE);
            /* pre-set events */
            _usb_event_set(&if_ptr->acm_event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_INT_PIPE_FREE);
        }
    } /* Endif */
 
    /* Signal that an error has occured by setting the "code_key" */
    if (status) {
        ccs_ptr->code_key = 0;
    } /* Endif */
 
    USB_unlock();
    
} /* Endbody */
示例#2
0
void main(void)
#endif
{       
    /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */
    _bsp_platform_init();
#ifdef MCU_MK70F12
    sci2_init();
#else
    sci1_init();
#endif
    TimerInit();
    
   /* Init polling global variable */
   POLL_init();

    /* event for USB callback signaling */
    _usb_event_init(&USB_Event);   
  
    DisableInterrupts; 
    #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
    usb_int_dis();
    #endif	
    ApplicationInit();
	EnableInterrupts;
    #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
    usb_int_en();
    #endif		
    
    fflush(stdout);
	
	/*
     ** Infinite loop, waiting for events requiring action
     */
    for(;;) 
    {
      Poll();
      Main_App_Task();
      __RESET_WATCHDOG(); /* feeds the dog */
    }  
#ifdef __GNUC__
    return 0;
#endif
}
示例#3
0
void main(void) {
  
  extern uint32 __VECTOR_RAM[];           //Get vector table that was copied to RAM
  static USB_STATUS status = USB_OK;
 

  printf("Main OK\n\r");

  /*******************************************/
  /* NVIC Configuration */
    __VECTOR_RAM[89]=(uint_32)USB_ISR;      //replace ISR
    NVICICER2|=(1<<9);                     //Clear any pending interrupts on USB
    NVICISER2|=(1<<9);                     //Enable interrupts from USB module  
  /*******************************************/


    // Disable Watchdog
    //__UNLOCK_WATCHDOG();
    //WDOG_ST_CTRL_H = 0x0;


  
  /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */
  _bsp_platform_init();

  //sci1_init();

  //TimerInit();

  printf("Timer Init OK\n\r");
  
  DisableInterrupts;  
  #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
  usb_int_dis();
  #endif 
  //status = _usb_host_driver_install(0, (pointer2)&_bsp_usb_host_callback_table);


  status = _usb_host_init(HOST_CONTROLLER_NUMBER, /* Use value in header file */
        MAX_FRAME_SIZE,         /* Frame size per USB spec  */
       &host_handle);          /* Returned pointer2 */
  /*
   ** since we are going to act as the host driver, register the driver
   ** information for wanted class/subclass/protocols
   */

  printf("USB HOST Init OK\n\r");
  
  
  status = _usb_host_driver_info_register(host_handle, (void*)DriverInfoTable);
  if(status != USB_OK) {         
      exit(1);
  }
  _usb_event_init(&USB_Event);  
  EnableInterrupts;
  #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
  usb_int_en();
  #endif   
  printf("\nUSB HID Mouse\nWaiting for USB Mouse to be attached...\n");
  ////fflush(stdout);
  
  for(;;) {
    
    Mouse_Task(main_buffer,&main_hid_com);     
    _usb_khci_task();   
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
void usb_class_cdc_data_init
   (
      /* [IN]  structure with USB pipe information on the interface */
      PIPE_BUNDLE_STRUCT_PTR      pbs_ptr,

      /* [IN] acm call struct pointer */
      CLASS_CALL_STRUCT_PTR       ccs_ptr
   )
{ /* Body */
    USB_DATA_CLASS_INTF_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle;
    ENDPOINT_DESCRIPTOR_PTR        in_endpt, out_endpt;
    USB_STATUS                     status;
 
    /* Make sure the device is still attached */
    USB_lock();
    status = usb_host_class_intf_init(pbs_ptr, if_ptr, &data_anchor_abstract);
    if (status == USB_OK) {
        /*
        ** We generate a code_key based on the attached device. This is used to
        ** verify that the device has not been detached and replaced with another.
        */
        ccs_ptr->code_key = 0;
        ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr);
  
        if_ptr->CDC_G.IFNUM = ((INTERFACE_DESCRIPTOR_PTR)if_ptr->CDC_G.G.intf_handle)->bInterfaceNumber;
        if_ptr->in_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_BULK_PIPE, USB_RECV);
        if_ptr->out_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_BULK_PIPE, USB_SEND);

        if ((if_ptr->in_pipe == NULL) && (if_ptr->out_pipe == NULL))
            status = USBERR_OPEN_PIPE_FAILED;
        else if (USB_OK != (status = _usb_event_init(&if_ptr->data_event)))
                status = USBERR_INIT_FAILED;
        else {
            /* prepare events to be auto or manual */
            //_lwevent_set_auto_clear(&if_ptr->data_event, USB_DATA_READ_PIPE_FREE | USB_DATA_SEND_PIPE_FREE);
            /* pre-set events */
            _usb_event_set(&if_ptr->data_event, USB_DATA_READ_PIPE_FREE | USB_DATA_SEND_PIPE_FREE);

            if (if_ptr->out_pipe) {
                /* Don't use host - predefined constant for NAK_COUNT...
                ** NOTE!!!
                ** This hack is not very clean. We need to maximize number of retries to minimize the time of
                ** transaction (minimize task's time while waiting for 1 transaction to be done (with or without data))
                ** The time depends on user expecatation of the read() latency, on the delay between 2 NAKs and on number
                ** of NAKs to be performed.
                ** The workaround is to limit amount of retries for the pipe maximally to 3.
                ** Number 3 is hard-coded here for now.
                */
                if (((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->in_pipe)->NAK_COUNT > 3)
                    ((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->in_pipe)->NAK_COUNT = 3; /* don't use host - predefined constant */
            }
            if (if_ptr->in_pipe) {
                /* The same as for OUT pipe applies here */
                if (((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->out_pipe)->NAK_COUNT > 3)
                    ((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->out_pipe)->NAK_COUNT = 3; /* don't use host - predefined constant */
            
                /* initialize buffer */
                /* size of buffer equals to the size of endpoint data size */
                if_ptr->RX_BUFFER_SIZE = ((PIPE_INIT_PARAM_STRUCT_PTR) (if_ptr->in_pipe))->MAX_PACKET_SIZE;
                if (NULL == (if_ptr->RX_BUFFER = USB_mem_alloc_zero(if_ptr->RX_BUFFER_SIZE))) {
                    status = USBERR_ALLOC;
                }
                else {
                    /* initialize members */
                    if_ptr->RX_BUFFER_APP = if_ptr->RX_BUFFER_DRV = if_ptr->RX_BUFFER;
                }
            }
        }
    } /* Endif */

    /* Signal that an error has occured by setting the "code_key" */
    if (status) {
        ccs_ptr->code_key = 0;
    } /* Endif */
 
    USB_unlock();
       
} /* Endbody */
示例#5
0
void main_usb(void) 
#endif
{
   USB_STATUS           status = USB_OK;
   _usb_host_handle     host_handle;   
   /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */
   _bsp_platform_init();
#if 0 /* << EST */
#ifdef MCU_MK70F12
  sci2_init();
#else
  sci1_init();
#endif
   TimerInit();
#endif
   
   /* Init polling global variable */
   POLL_init(); 

   DisableInterrupts;
   #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
   usb_int_dis();
   #endif	   
   /*
   ** It means that we are going to act like host, so we initialize the
   ** host stack. This call will allow USB system to allocate memory for
   ** data structures, it uses later (e.g pipes etc.).
   */
   status = _usb_host_init (
         HOST_CONTROLLER_NUMBER,   /* Use value in header file */
         MAX_FRAME_SIZE,            /* Frame size per USB spec  */
         &host_handle);             /* Returned pointer */
   if (status != USB_OK) 
   {
#if 0 /* << EST */
      printf("\nUSB Host Initialization failed. STATUS: %%x",(unsigned int) status);
      fflush(stdout);
#endif
      exit(3);
   }
   status = _usb_host_driver_info_register (
                                    host_handle,
                                    (void *)DriverInfoTable
                                    );
   if (status != USB_OK) 
   {
#if 0 /* << EST */
     printf("\nDriver Registration failed. STATUS: %%x", (unsigned int)status);
      fflush(stdout);
#endif
      exit(4);
   }    
  
  EnableInterrupts;
  #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
  usb_int_en();
  #endif	  

#if 0 /* << EST */
  printf("\fInitialization passed. Plug-in CDC device to USB port.\nUse ttyb: as the in/out port for CDC device data.\n");
#endif  
  _usb_event_init(&device_registered);
  uart2usb_num = usb2uart_num = 0; /* reset number of bytes in buffers */

#if 0 /* << EST */
  f_usb = (FILE_CDC_PTR)malloc(sizeof(FILE_CDC));
  memset(f_usb, 0, sizeof(FILE_CDC));
#else
  f_usb = (FILE_CDC_PTR)USB_mem_alloc_zero(sizeof(FILE_CDC));
#endif
    
  f_usb->DEV_PTR = (IO_DEVICE_STRUCT_PTR)USB_mem_alloc_word_aligned(sizeof(IO_DEVICE_STRUCT));
  
  for(;;) 
  {
    Poll(); 
    CDC_Task();
#if 0 /* << EST */
    __RESET_WATCHDOG(); /* feeds the dog */
#endif
  } /* loop forever */
  /* please make sure that you never leave main */
#ifdef __GNUC__
  return 0;
#endif
}
示例#6
0
void main(void) 
#endif
{
   USB_STATUS           status = USB_OK;
   _usb_host_handle     host_handle;
   boolean send = TRUE;
   
   /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */
   _bsp_platform_init();
#ifdef MCU_MK70F12
   sci2_init();
#else
   sci1_init();
#endif
   TimerInit();

   /* Init polling global variable */
   POLL_init(); 
    
#if (defined(_MCF51MM256_H) || (defined _MCF51JE256_H))
   cmt_init();
   Mcu_Init();
   Kbi_Init();
   pwm_init();
#endif

#if (defined(__MCF52259_H__) || (defined (__MCF52221_H__)) ||(defined (_MK_xxx_H_)) )
   	GPIO_Init();
   	pit0_init();
   	pwm_init();
#endif

#if (defined MCU_mcf51jf128)
   	GPIO_Init();
   	mtim_init();
   	pwm_init();
#endif
   DisableInterrupts;
   #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
   usb_int_dis();
   #endif	   
   /*
   ** It means that we are going to act like host, so we initialize the
   ** host stack. This call will allow USB system to allocate memory for
   ** data structures, it uses later (e.g pipes etc.).
   */
   status = _usb_host_init (
         HOST_CONTROLLER_NUMBER,   /* Use value in header file */
         MAX_FRAME_SIZE,            /* Frame size per USB spec  */
         &host_handle);             /* Returned pointer */
   if (status != USB_OK) 
   {
	   printf("\nUSB Host Initialization failed! STATUS: 0x%x", (unsigned int) status);
	   fflush(stdout);
	   exit(3);
   }
   status = _usb_host_driver_info_register (
                                    host_handle,
                                    (pointer)DriverInfoTable
                                    );
	if (status != USB_OK) 
	{
		printf("\nDriver Registration failed! STATUS: 0x%x",(unsigned int) status);
		fflush(stdout);
		exit(4);
   }    
  
  EnableInterrupts;
  #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
  usb_int_en();
  #endif	  

  printf("USB Host Audio Demo\r\nWaitting for USB Audio Device to be attached...\r\n");
 
 _usb_event_init(&USB_Event);
 
	for(;;)
	{
    Poll(); 
    Audio_Task();
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
#ifdef __GNUC__
return 0;
#endif
}