LPC11U14做的USB键盘在mac电脑下无法关机

2019-03-25 20:25发布

如题:
   我使用LPC11U14做一个USB键盘,在windows系统下都能正常,一旦我把键盘插到MAC电脑上面,就会导致MAC电脑一直无法关机,会一直停在小菊花那边,但是,如果我这时拔掉键盘,就能马上关机了,我使用其他的键盘插在MAC电脑上,是能正常关机的,这样,就确定是我键盘firmware程序有问题了,但是,我把所有的代码全部屏蔽掉,只剩下USB初始化,让主机能识别到USB键盘,这个时候仍然是不能关机,现象是,我关机的时候,键盘还没有断电,我猜测是不是没有断电导致键盘还一直在运行,所有导致MAC无法关机呢?另外,我怀疑是不是我USB的代码有问题,所以详细看了下代码,代码是我在网上找的,其中,关于USB端点初始化有部分不理解,代码如下:

#define USB_EPLIST_ADDR 0x20004000
#define USB_EPDATA_ADDR (USB_EPLIST_ADDR + 0x100)
#define USB_EPDATA_PAGE (USB_EPDATA_ADDR&0xFFC00000)/* Bit 22~31 is the page */


/*
*  USB EP List Initialize Function
*    Called by the USB_Init to initialize USB EPList memory
*    The example below is the simpliest case, every location is pre-configured
*    with fixed length for each EP. See USB chapter, Endpoint Command/Status
*    List for more details.
*
*    Parameters:      None
*    Return Value:    None
*/
void NDrv_USB_EPInit(void)
{
U32 *addr, data_ptr,i, j = 0;
addr = (U32 *)USB_EPLIST_ADDR;
LPC_USB->EPLISTSTART = USB_EPLIST_ADDR;
data_ptr = USB_EPDATA_ADDR;
LPC_USB->DATABUFSTART = USB_EPDATA_PAGE;
/* CTRL, BULK or Interrupt IN/OUT EPs, max EP size is 64 */
/* For EP0, double buffer doesn't apply to CTRL EPs, but, EP0OUTBuf0 is
for EP0OUT, EP0OUTBuf1 is for SETUP, EP0INBuf0 is for EP0IN, EP0INTBuf1 is
reserved. Also note: ACTIVE bit doesn't apply to SETUP and Reserved EP buffer. */
*addr++ = (USB_MAX_PACKET0 << 16)|((U16)(data_ptr >> 6));
g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_PACKET0;
data_ptr += USB_MAX_PACKET0;
*addr++ = ((U16)(data_ptr >> 6));/* No length field for SETUP */
g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
g_USBHW_Setting.EPList[j++].buf_length = USB_SETUP_PACKET_SIZE;
/* For easier alignment, the data field is aligned to 64 bytes for all EPs. */
data_ptr += USB_MAX_PACKET0;
*addr++ = (USB_MAX_PACKET0 << 16)|((U16)(data_ptr >> 6));
g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_PACKET0;
data_ptr += USB_MAX_PACKET0;
#if 0
/* EP0 IN second buffer(buffer1) is reserved. */
*addr++ = (USB_MAX_PACKET0<<16)|((uint16_t)(data_ptr>>6));
#else
addr++;
#endif
g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_PACKET0;
data_ptr += USB_MAX_PACKET0;
for(i = 2; i < USB_EP_NUM; i++)
{
  /* Buffer 0 */
#if USB_ISO_COMMUNICATION
  *addr++ = EP_DISABLED|EP_ISO_TYPE|(USB_MAX_ISO_SIZE << 16)|((U16)(data_ptr >> 6));
  g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
  g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_ISO_SIZE;
  data_ptr += USB_MAX_ISO_SIZE;
#else
  *addr++ = EP_DISABLED|(USB_MAX_NON_ISO_SIZE << 16)|((U16)(data_ptr >> 6));
  g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
  g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_NON_ISO_SIZE;
  data_ptr += USB_MAX_NON_ISO_SIZE;
#endif
  /* Buffer 1 */
#if USB_ISO_COMMUNICATION
  *addr++ = EP_DISABLED|EP_ISO_TYPE|(USB_MAX_ISO_SIZE << 16)|((U16)(data_ptr >> 6));
  g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
  g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_ISO_SIZE;
  data_ptr += USB_MAX_ISO_SIZE;
#else
  *addr++ = EP_DISABLED|(USB_MAX_NON_ISO_SIZE << 16)|((U16)(data_ptr >> 6));
  g_USBHW_Setting.EPList[j].buf_ptr = data_ptr;
  g_USBHW_Setting.EPList[j++].buf_length = USB_MAX_NON_ISO_SIZE;
  data_ptr += USB_MAX_NON_ISO_SIZE;
#endif
}
}
这里面的addr主要是用来做什么的呢?它一直在++,但是没有用到这个地址啊,另外, *addr++ = EP_DISABLED|EP_ISO_TYPE|(USB_MAX_ISO_SIZE << 16)|((U16)(data_ptr >> 6));
是什么意思?为什么要右移6位?为什么包大小要左移16位?
我知道LPC11U14的USBRAM是在地址0X20004000处,在程序中 LPC_USB->DATABUFSTART = USB_EPDATA_PAGE又是什么意思?为什么 USB_EPDATA_PAGE要在0X20004000地址基础上加0X100?
求大神指导,急啊!!!!! 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。