⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbmain.c

📁 在CCS开发环境下的DSP 5509A的固件程序
💻 C
📖 第 1 页 / 共 2 页
字号:
                                0x40, USB_EVENT_EOT,USB_ctl_handler);                              

  // init endpoint 2 objects - bulk mode, endpoint size 64 byte
  // dispatch end of transfer event to endpoint object
  usb_status = USB_initEndptObj(USB0, &usbEpObjOut2, USB_OUT_EP2, USB_BULK,
                                0x40, USB_EVENT_EOT,USB_bulkOutEvHandler);
  // dispatch end of transfer and USB reset events to endpoint object                              
  usb_status = USB_initEndptObj(USB0, &usbEpObjIn2, USB_IN_EP2, USB_BULK, 0x40,
                                USB_EVENT_EOT|USB_EVENT_RESET,USB_bulkInEvHandler);
  
  
  // init endpoint3 object - interrupt mode, endpoint size 64 byte
  // dispatch end of transfer and USB reset events to endpoint object
  usb_status = USB_initEndptObj(USB0, &usbEpObjIn3, USB_IN_EP3, USB_INTR, 0x40,
                                USB_EVENT_EOT|USB_EVENT_RESET,USB_endpt3EvHandler);
                                
  // init endpoint 4 objects - bulk mode (for host dma operation mode)
  // endpoint size 64 byte, no event to dispatch to the endpoint object
  usb_status = USB_initEndptObj(USB0, &usbEpObjOut4, USB_OUT_EP4, USB_HPORT,
                                0x40, USB_EVENT_NONE, USB_EvISR_NONE);
  // no event to dispatch to the endpoint object                              
  usb_status = USB_initEndptObj(USB0, &usbEpObjIn4, USB_IN_EP4, USB_HPORT, 0x40,
                                USB_EVENT_NONE, USB_EvISR_NONE);
  
  
  // init endpoint5 object - iso mode, endpoint size 16 byte
  // dispatch pre-start-of-frame events to endpoint object
  usb_status = USB_initEndptObj(USB0, &usbEpObjIn5, USB_IN_EP5, USB_ISO, 0x10,
                                USB_EVENT_PSOF, USB_isoInEvHandler);                              
                                
                                

  // init USB module - module will assume configuration defined by myUsbConfig[]
  // PSOF interrupt occurs 128 ticks (750kHz clock) prior to SOF.
  usb_status = USB_init(USB0, myUsbConfig, 0x80);
  
    

// enable USB interrupt:
  
  // if using DSP/BIOS, these regs will be initialized by DSP/BIOS
  IVPD  = ((Uint32)RESET_VEC>>8) & 0xFFFF; // init IVPD reg
  IVPH  = ((Uint32)RESET_VEC>>8) & 0xFFFF; // init IVPH reg
  IFR0 |= IFR0_USBMSK;                     // Clear USB intrpt flag
  IER0 |= IER0_USBMSK;                     // Enable USB intrpt mask
  INTR_GLOBAL_ENABLE;                      // enable global interrupt
  

     
// if the USB module configured properly, 
// connect it to up stream port

  if(usb_status) USB_connectDev(USB0);
  
// go to idle loop, since all the USB activities are interrupt driven

  while(1)    /* loop idle */
  {
    for(ii=0; ii<1000; ii++);
  }

}   // end of main



/******************************************************************************/
/*                     Bulk Out Event Handlers                                */
/*                                                                            */
/******************************************************************************/

void USB_bulkOutEvHandler()
{
  // call the bulk out data handler routine.
  
  // if DSP/BIOS used, a SWI can be posted to service the endpoint events.
  // All USB event handler routines must be executed in the order the 
  // actual events arrived - to achieve this, if SWI used, all the USB 
  // event handler routines must be assigned the same priority level.
  
  USB_bulkOutDatHandler(&usbEpObjIn2, &usbEpObjOut2);
}


void USB_bulkOutDatHandler(USB_EpHandle hEpIn, USB_EpHandle hEpOut)
{
   // loop back data received from endpt2 out to endpt2 in
   if(USB_isTransactionDone(hEpOut))  
      USB_postTransaction(hEpIn, Endpt2Buff[0], &Endpt2Buff, USB_IOFLAG_NOSHORT);                      
                             
}

/******************************************************************************/
/*                      Bulk In Event Handlers                                */
/*                                                                            */
/******************************************************************************/

void USB_bulkInEvHandler()
{
  // call the bulk in data handler routine.
  
  // if DSP/BIOS used, a SWI can be posted to service the endpoint events.
  // All USB event handler routines must be executed in the order the 
  // actual events arrived - to achieve this, if SWI used, all the USB 
  // event handler routines must be assigned the same priority level.
  
  USB_bulkInDatHandler(&usbEpObjIn2, &usbEpObjOut2);
}


void USB_bulkInDatHandler(USB_EpHandle hEpIn, USB_EpHandle hEpOut)
{
   // initiate packet read from endpt2 out - up to 64 bytes
   if(USB_isTransactionDone(hEpIn))  
      USB_postTransaction(hEpOut, 64, &Endpt2Buff, USB_IOFLAG_NOSHORT);                      
                             
}


/******************************************************************************/
/*                 Endpt3 IN Event Handlers - Interrupt mode                  */
/*                                                                            */
/******************************************************************************/

void USB_endpt3EvHandler()
{
  // call the endpt3 IN data handler routine.
  
  // if DSP/BIOS used a SWI can be posted to service the endpoint events.
  // All USB event, handler routines must be executed in the order the 
  // actual events arrived - to achieve this, if SWI used, all the USB 
  // event handler routines must be assigned the same priority level.
  
  USB_endpt3DatHandler(&usbEpObjIn3);
}


void USB_endpt3DatHandler(USB_EpHandle hEpIn)
{
   static Uint16 bytes_to_send = 1;
   
   // initiate next transfer - number of bytes to transfer varies from 1 to 16
   // transfer 1 byte when the 1st IN token received
   // transfer 2 bytes when the next IN token received and so on
   if(USB_isTransactionDone(hEpIn))
   {  
      if(bytes_to_send > 16)  // roll over to 1 if number of bytes_to_send > 16
         bytes_to_send = 1;
         
      USB_postTransaction(hEpIn, bytes_to_send, &Endpt3Buff, USB_IOFLAG_SWAP);
      
      bytes_to_send += 1;     // send one byte more next time
   }                  
                             
}

/******************************************************************************/
/*                 Endpt5 IN Event Handlers - Iso mode                        */
/*                                                                            */
/******************************************************************************/
void USB_isoInEvHandler()
{
  // call the endpt5 IN data handler routine.
  
  // if DSP/BIOS used a SWI can be posted to service the endpoint events.
  // All USB event, handler routines must be executed in the order the 
  // actual events arrived - to achieve this, if SWI used, all the USB 
  // event handler routines must be assigned the same priority level.
  
  USB_isoInDatHandler(&usbEpObjIn5);
}


void USB_isoInDatHandler(USB_EpHandle hEpIn)
{  // prepare a transfer to send the current USB frame number to the host.
   // In iso mode dma waits for the next SOF to move the data to enpoint
   // buffer, finally iso data moves out in the following frame. Hence the 
   // the frame number received by the host will be #(frame - 2)
   
   Endpt5Buff[1] =  USB_getFrameNo(USB0);      // 2 data bytes    
   USB_postTransaction(hEpIn, 2, &Endpt5Buff, USB_IOFLAG_NONE);                
                             
}

/******************************************************************************/
/*                         USB Interrupt Handler                              */
/*                                                                            */
/******************************************************************************/

interrupt void USB_ISR(void)
{
   USB_evDispatch();   // call USB event dispather to handle all USB events

}



/******************************************************************************/
/* dspclk_init() -  Initialize DSP clock frequency                            */
/*                                                                            */
/* if pllmult > 1                                                             */
/*		outclk = (pllmult / (plldiv + 1)) * inclk                             */
/*                                                                            */
/* if pllmult < 1                                                             */
/*		outclk = (1 / (plldiv + 1)) * inclk                                   */
/*                                                                            */
/******************************************************************************/

void dspclk_init(Uint16 inclk, Uint16 outclk, Uint16 plldiv)
{
  Uint16 pllmult = (outclk * (plldiv+1)) / inclk;

  plldiv &= 0x3u;

  CLKMD = 0;                    // force into BYPASS mode (b4=0)
  while (CLKMD & (1<<LOCK));    // wait for BYPASS mode to be active

	CLKMD = ((1<<IOB)|(pllmult<<PLL_MULT)|(plldiv<<PLL_DIV)|
	         (plldiv<<BYPASS_DIV)|(1<<PLL_ENABLE));

    
	if (pllmult > 1)                  // if pllmult > 1
	{
		while (!(CLKMD & (1<<LOCK))); // wait for PLL mode to be active
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -