亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? hal_usb.c

?? 非常全的nrf2401設計資料
?? C
?? 第 1 頁 / 共 2 頁
字號:
            if( LSB(req->wValue) == 0x00 )
            {
                packetize(g_hal_usb.descs.string_zero,
                    MIN(LSB(req->wLength), sizeof(g_hal_usb.descs.string_zero)),
                        g_hal_usb.descs.dev->bMaxPacketSize0);
                packetizer_isr_ep0_in();
            }
            else
            {
                if( ( LSB(req->wValue) - 1 ) < USB_STRING_DESC_COUNT )
                {
                    packetize((uint8_t*)(g_hal_usb.descs.string->idx[LSB(req->wValue)-1]),
                        MIN(LSB(req->wLength), g_hal_usb.descs.string->idx[LSB(req->wValue)-1][0]),
                        g_hal_usb.descs.dev->bMaxPacketSize0);
                    packetizer_isr_ep0_in();
                }
                else
                {
                    USB_EP0_STALL();
                }
            }
            break;
        case USB_DESC_INTERFACE:
        case USB_DESC_ENDPOINT:
        case USB_DESC_DEVICE_QUAL:
        case USB_DESC_OTHER_SPEED_CONF:
        case USB_DESC_INTERFACE_POWER:
            USB_EP0_STALL();
            break;
        default:
            ret = g_hal_usb.device_req(req, &data_ptr, &data_size);
            usb_process_dev_req_cb_response(ret, req, data_ptr, data_size);
            break;
    }
}

static void isr_sudav()
{
    // Parse data in setupbuf
    hal_usb_dev_req_resp_t ret;
    uint8_t *data_ptr;
    uint16_t data_size;

     // Parsing the request into request structure
    req.bmRequestType = i_usb.map->setupbuf[0];
    req.bRequest = i_usb.map->setupbuf[1];
    req.wValue = i_usb.map->setupbuf[2] + (i_usb.map->setupbuf[3] << 8);
    req.wIndex = i_usb.map->setupbuf[4] + (i_usb.map->setupbuf[5] << 8);
    req.wLength = i_usb.map->setupbuf[6] + (i_usb.map->setupbuf[7] << 8);
    req.wLength = req.wLength > 0xff ? 0xff : LSB(req.wLength); // We truncate packets requests longer then 255 bytes

#if 0
    uart0_putstring("\r\n--\r\nbmRequestType: "); hex_out_byte(req.bmRequestType);
    uart0_putstring("\r\nbRequest     : "); hex_out_byte(req.bRequest);
    uart0_putstring("\r\nwValue [H][L]: "); hex_out_byte(MSB(req.wValue)); hex_out_byte(LSB(req.wValue));
    uart0_putstring("\r\nwIndex [H][L]: "); hex_out_byte(MSB(req.wIndex)); hex_out_byte(LSB(req.wIndex));
    uart0_putstring("\r\nwLength[H][L]: "); hex_out_byte(MSB(req.wLength)); hex_out_byte(LSB(req.wLength));
#endif

     // bmRequestType = 0 00 xxxxx : Data transfer direction: Host-to-device Type: Standard
    if( ( req.bmRequestType & 0x60 ) == 0x00 )
    {
        switch(req.bRequest)
        {
           case USB_REQ_GET_DESCRIPTOR:
               usb_process_get_descriptor(&req);
               break;
           case USB_REQ_GET_STATUS:
               usb_process_get_status(&req); 
               break; // case USB_REQ_GET_STATUS --end--
           case USB_REQ_CLEAR_FEATURE: 
              switch(req.bmRequestType)
              {
                  case 0x00: // Device
                      if( LSB(req.wValue) == USB_DEVICE_REMOTE_WAKEUP )
                      {
                          g_hal_usb.bm_state &= ~(USB_BM_STATE_ALLOW_REMOTE_WAKEUP);
                          USB_EP0_HSNAK();
                      }
                      else USB_EP0_STALL();
                      break;
                  case 0x01: // Interface
                      USB_EP0_STALL();
                      break;
                  case 0x02: // Endpoint
                      if( LSB(req.wValue) == USB_ENDPOINT_HALT )
                      {
                          hal_usb_endpoint_stall(LSB(req.wIndex), false);
                          USB_EP0_HSNAK();
                      }
                      else USB_EP0_STALL();
                      break;
                  default:
                      USB_EP0_STALL();
                      break;
              }
              break;
           case USB_REQ_SET_FEATURE: 
               switch(req.bmRequestType)
               {
                   case 0x00: // Device
                       if( LSB(req.wValue) == USB_DEVICE_REMOTE_WAKEUP )
                       {
                           g_hal_usb.bm_state |= USB_BM_STATE_ALLOW_REMOTE_WAKEUP;
                           USB_EP0_HSNAK();
                       }
                       else USB_EP0_STALL();
                       break;
                   case 0x01: // Interface
                       USB_EP0_STALL();
                       break;
                   case 0x02: // Endpoint - TODO: check for valid endpoints here
                       if( LSB(req.wValue) == USB_ENDPOINT_HALT )
                       {
                            hal_usb_endpoint_stall(LSB(req.wIndex), true);
                            USB_EP0_HSNAK();
                       }
                       else
                       {
                            USB_EP0_STALL();
                       }
                       break;
                   default:
                       USB_EP0_STALL();
                       break;
               }
               break;
        case USB_REQ_SET_ADDRESS:
           g_hal_usb.state = ADDRESSED;
           g_hal_usb.current_config = 0x00;
           break;
        case USB_REQ_SET_DESCRIPTOR:
           USB_EP0_STALL();
           break;
        case USB_REQ_GET_CONFIGURATION:
           switch( g_hal_usb.state )
           {
               case ADDRESSED:
                   i_usb.map->in0buf[0] = 0x00;
                   i_usb.map->in0bc = 0x01;
                   break;
               case CONFIGURED:
                   i_usb.map->in0buf[0] = g_hal_usb.current_config;
                   i_usb.map->in0bc = 0x01;
                   break;
               default:
                   USB_EP0_STALL();
                   break;
           }
           break;
        case USB_REQ_SET_CONFIGURATION:
           switch(LSB(req.wValue)) {
               case 0x00:
                   g_hal_usb.state = ADDRESSED;
                   g_hal_usb.current_config = 0x00;
                   USB_EP0_HSNAK();
                   break;
               case 0x01:
                   g_hal_usb.state = CONFIGURED;
                   g_hal_usb.bm_state |= USB_BM_STATE_CONFIGURED;
                   g_hal_usb.current_config = 0x01;
                   USB_EP0_HSNAK();
                   break;
               default:
                   USB_EP0_STALL();
                   break;
           }
           break;
        case USB_REQ_GET_INTERFACE: // GET_INTERFACE
            i_usb.map->in0buf[0] = g_hal_usb.current_alt_interface;
            i_usb.map->in0bc = 0x01;
            break;
        case USB_REQ_SET_INTERFACE: // SET_INTERFACE
        case USB_REQ_SYNCH_FRAME:   // SYNCH_FRAME
           USB_EP0_STALL();  // We do not support any of these
           break;
        default:
           USB_EP0_STALL();
           break;
        };
    } 
    // bmRequestType = 0 01 xxxxx : Data transfer direction: Host-to-device, Type: Class
    else if( ( req.bmRequestType & 0x60 ) == 0x20 )  // Class request
    {
        if( req.wLength != 0 && ((req.bmRequestType & 0x80) == 0x00) )
        {
            // If there is a OUT-transaction associated with the Control-Transfer-Write we call the callback
            // when the OUT-transaction is finished. Note that this function do not handle several out transactions.
            i_usb.map->out0bc = 0xff;
        }
        else
        {
            ret = g_hal_usb.device_req(&req, &data_ptr, &data_size);
            usb_process_dev_req_cb_response(ret, &req, data_ptr, data_size);
        }
        // Call the callback function. Data to be sent back to the host is store by the callback in data_ptr and the size in data_size.
    } 
    else  // Unknown request type
    {
        USB_EP0_STALL();
    }
}

static void isr_sof()
{
}

static void isr_sutok()
{
    i_usb.packetizer.data_ptr = NULL;
    i_usb.packetizer.data_size = 0;
    i_usb.packetizer.pkt_size = 0;
}

static void isr_suspend()
{
    uint8_t allow_remote_wu = 0;

    g_hal_usb.bm_state &= ~(USB_BM_STATE_HOST_WU); // We clear the flag that indicates that the host awoke the MCU via USB here
 
    if( g_hal_usb.state == CONFIGURED )
    {
        if( ( g_hal_usb.bm_state & USB_BM_STATE_ALLOW_REMOTE_WAKEUP ) == USB_BM_STATE_ALLOW_REMOTE_WAKEUP )
        {
            allow_remote_wu = 1;
        }
    }

    g_hal_usb.state = SUSPENDED;

    if( g_hal_usb.suspend != NULL ) 
    {
        g_hal_usb.suspend(allow_remote_wu);
    }
}

static void isr_usbreset()
{
    g_hal_usb.state = DEFAULT;
    g_hal_usb.current_config = 0;
    g_hal_usb.current_alt_interface = 0;
    g_hal_usb.bm_state = 0;
    if( g_hal_usb.reset != NULL ) g_hal_usb.reset();
}

// For now we only support one out-transaction in a Control Transfer Write
static void isr_ep0out()
{
    hal_usb_dev_req_resp_t ret;
    uint8_t* data_ptr;
    uint16_t data_size;
    i_usb.packetizer.data_size = 0;
    req.misc_data = i_usb.map->out0buf;
    ret = g_hal_usb.device_req(&req, &data_ptr, &data_size);
    usb_process_dev_req_cb_response(ret, &req, data_ptr, data_size);
}

//lint --e{528} suppress "usb_wu() not referenced"
void usb_wu(void) interrupt USB_WU // address: 0x005b
{
#define ICH4
#ifdef ICH4
    uint8_t t;
#endif

    // Check if the wakeup source is the pin to the USB controller
    // If it is by the pin to the USB controller we want to start
    // a remote wakeup
    if( ( i_usb.map->usbcs & 0x80 ) == 0x80 )
    {
        // Reset the wakesrc indicator
        i_usb.map->usbcs = 0x80;

        // If we are allowed to perform a remote wakeup do that
        if( ( g_hal_usb.bm_state & USB_BM_STATE_ALLOW_REMOTE_WAKEUP ) == USB_BM_STATE_ALLOW_REMOTE_WAKEUP )
        {
#ifdef ICH4
            // Force the J state on the USB lines
            i_usb.map->usbcs |= 0x02;
    
            // Typical 5.4us delay
            _nop_();
            _nop_();
    
            t = i_usb.map->usbcs;
    
            // Stop J state on the USB lines
            t &= ~0x02;
    
            // Signal remote resume
            t |= 0x01;
    
            // We have to set this register in one operation to avoid
            // idle state is restored between the forced J and resume state
            i_usb.map->usbcs = t;
#else
            i_usb.map->usbcs |= 0x01;  // Turn on the resume signal on the USB bus
#endif
            delay_ms(7); //.1.7.7 Resume: The remote wakeup device must hold the resume signaling for at 
                          // least 1 ms but for no more than 15ms
    
            i_usb.map->usbcs &= ~0x01; // Turn off the resume signal on the USB bus
        }
    }
    else 
    {
        // We are awoken by the bus
        g_hal_usb.bm_state |= USB_BM_STATE_HOST_WU;
    }

    if( ( g_hal_usb.bm_state & USB_BM_STATE_CONFIGURED ) == USB_BM_STATE_CONFIGURED )
    {
        g_hal_usb.state = CONFIGURED;
    }
    else
    {
        g_hal_usb.state = DEFAULT;
    }

    // Call resume callback
    g_hal_usb.resume();
}

// This function processes the response from the EP callback
static void usb_process_ep_response(uint8_t ret, uint8_t* cs_ptr, uint8_t* bc_ptr)
{
    if( ret == 0xff ) // Clear the OUTx busy flag enabling reception of the next OUT from USB-host
    {
        *bc_ptr = 0xff;
    }
    else if( ( ret & 0x80 ) == 0x80 )  // STALL
    {
        *cs_ptr = 0x01;
    }
    else if( ( ret & 0x60 ) == 0x60 ) // NAK
    {
        *cs_ptr = 0x02;
    }
    else if( ret == 0 ) // Zero length data
    {
        *bc_ptr = 0;
    }
    else
    {
        *bc_ptr = ret;
    }
}

//lint --e{528} suppress "usb_irq(void) not referenced"
void usb_irq(void) interrupt USB_IRQ // address: 0x0063
{
    uint8_t ep;
    uint8_t ret;
    xdata uint8_t *cs_ptr;
    xdata uint8_t *buf_ptr;
    xdata uint8_t *bc_ptr;

     switch(i_usb.map->ivec)
     {
     case INT_SUDAV:
        i_usb.map->usbirq = 0x01;
        isr_sudav();
        break;
     case INT_SOF:
        i_usb.map->usbirq = 0x02;
        isr_sof();
        break;
     case INT_SUTOK:
        i_usb.map->usbirq = 0x04;
        isr_sutok();
      break;
     case INT_SUSPEND:
        i_usb.map->usbirq = 0x08;
        isr_suspend();
        break;
     case INT_USBRESET:
        i_usb.map->usbirq = 0x10;
        isr_usbreset();
        break;
     case INT_EP0IN:
        i_usb.map->in_irq = 0x01;
        packetizer_isr_ep0_in();
        break;
     case INT_EP0OUT:
        i_usb.map->out_irq = 0x01;
        isr_ep0out();
        break;
     case INT_EP1IN:
     case INT_EP2IN:
     case INT_EP3IN:
     case INT_EP4IN:
     case INT_EP5IN:
        // Calculate IN endpoint number
        ep = ( (i_usb.map->ivec) - INT_EP0IN ) / (INT_EP2IN - INT_EP1IN);

        // Clear interrupt 
        i_usb.map->in_irq = ( 1 << ep );

        cs_ptr = CALCULATE_CS_IN_PTR(ep);
        buf_ptr = CALCULATE_BUF_IN_PTR(ep);
        bc_ptr = CALCULATE_BC_IN_PTR(ep);
    
        // Call registered callback
        ret = i_usb.endpoint_in_isr[ep - 1](buf_ptr, bc_ptr);
        usb_process_ep_response(ret, cs_ptr, bc_ptr);
        break;
     case INT_EP1OUT:
     case INT_EP2OUT:
     case INT_EP3OUT:
     case INT_EP4OUT:
     case INT_EP5OUT:
        // Calculate OUT endpoint number
        ep = ( (i_usb.map->ivec) - INT_EP0OUT) / (INT_EP2OUT - INT_EP1OUT); 

        // Clear interrupt
        i_usb.map->out_irq = ( 1 << ep );
        
        cs_ptr = CALCULATE_CS_OUT_PTR(ep);
        buf_ptr = CALCULATE_BUF_OUT_PTR(ep);
        bc_ptr = CALCULATE_BC_OUT_PTR(ep);

        // Call registered callback
        ret = (i_usb.endpoint_out_isr[ep - 1])(buf_ptr, bc_ptr);
        usb_process_ep_response(ret, cs_ptr, bc_ptr);
        break;
     default:
        break;
     };
}

static void delay_ms(uint8_t ms)
{
    uint16_t i, j;
    
    for(i = 0; i < ms; i++ )
    {
        for( j = 0; j < 1403; j++) // 196
        {
            _nop_();
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国模无码大尺度一区二区三区| 国产一区二区三区蝌蚪| 久久综合成人精品亚洲另类欧美 | 日韩精品电影在线观看| 欧美精品一区二区三区一线天视频| av在线播放不卡| 久久精品国产999大香线蕉| 亚洲欧美日韩国产一区二区三区| 欧美一区二区三区在线观看视频| 91色|porny| 国产精品白丝jk白祙喷水网站| 日韩激情一二三区| 亚洲人成精品久久久久| 国产日韩欧美综合在线| 日韩欧美中文字幕公布| 欧美性色aⅴ视频一区日韩精品| 国产精品一二三四五| 免费国产亚洲视频| 性感美女久久精品| 亚洲一区二区在线视频| 亚洲天天做日日做天天谢日日欢| 艳妇臀荡乳欲伦亚洲一区| 欧美国产一区视频在线观看| 欧美一区二区精品久久911| 日本韩国一区二区三区视频| 成人h动漫精品| 国产成人自拍在线| 国产成人av资源| 国产专区欧美精品| 九九**精品视频免费播放| 人妖欧美一区二区| 日韩成人一区二区| 男人的天堂亚洲一区| 日韩电影在线观看电影| 日韩电影一区二区三区四区| 日韩高清一区二区| 日本不卡的三区四区五区| 午夜久久久久久电影| 亚洲午夜激情网页| 图片区小说区国产精品视频| 亚洲一区二区三区美女| 亚洲成人第一页| 石原莉奈在线亚洲二区| 日韩av一级片| 另类欧美日韩国产在线| 激情综合网av| 懂色一区二区三区免费观看 | 久久国产乱子精品免费女| 日韩av成人高清| 麻豆精品视频在线观看视频| 蜜桃视频一区二区| 麻豆国产精品777777在线| 日韩电影一区二区三区| 日韩高清不卡一区二区三区| 免费在线观看视频一区| 久久国产精品99精品国产| 国产精品香蕉一区二区三区| 国产精品一二三区| 91视频一区二区三区| 色一情一伦一子一伦一区| 欧美日韩一区二区不卡| 91精品国产一区二区三区香蕉| 日韩欧美国产不卡| 欧美国产日韩一二三区| 综合久久一区二区三区| 五月天一区二区三区| 蜜桃免费网站一区二区三区| 国产成人精品免费一区二区| 色诱视频网站一区| 8v天堂国产在线一区二区| 久久综合九色综合欧美亚洲| 国产精品国产三级国产a| 亚洲国产日产av| 久久se这里有精品| 99久久久国产精品免费蜜臀| 欧美年轻男男videosbes| 亚洲欧美区自拍先锋| 爽好多水快深点欧美视频| 久久91精品久久久久久秒播| 99久久国产综合精品女不卡| 欧美人狂配大交3d怪物一区| 国产亚洲一二三区| 一区二区欧美视频| 久久99久久久欧美国产| 91亚洲精品乱码久久久久久蜜桃| 欧美一区二区三区在线观看| 国产精品乱码久久久久久| 日韩av在线免费观看不卡| 成人免费观看视频| 日韩欧美一级片| 樱桃视频在线观看一区| 国产在线播精品第三| 欧美最新大片在线看| 久久久久久久久久美女| 亚洲成av人综合在线观看| 成人精品视频一区二区三区| 欧美一级黄色片| 亚洲色图欧美偷拍| 国产美女在线观看一区| 欧美性生活一区| 中文字幕一区视频| 国产一区二区在线影院| 欧美日韩aaaaa| 亚洲精品国产第一综合99久久 | 欧美四级电影网| 国产精品久久毛片av大全日韩| 午夜日韩在线观看| 色视频成人在线观看免| 国产日韩v精品一区二区| 首页综合国产亚洲丝袜| 91成人在线免费观看| 国产精品午夜久久| 国产久卡久卡久卡久卡视频精品| 欧美日韩在线播| 亚洲激情中文1区| 国产成人精品亚洲午夜麻豆| 欧美xxxxxxxxx| 美女一区二区久久| 欧美日韩激情一区二区| 亚洲激情av在线| 色综合天天综合网国产成人综合天 | 亚洲成a人v欧美综合天堂下载| 91在线视频18| 国产精品美女久久久久aⅴ国产馆| 国内不卡的二区三区中文字幕| 在线播放欧美女士性生活| 亚洲午夜羞羞片| 欧美在线看片a免费观看| 亚洲欧美二区三区| 91丨porny丨户外露出| 日韩精品免费视频人成| 欧美日韩国产精选| 亚洲成人福利片| 欧美色网一区二区| 亚洲一区视频在线| 欧美日本国产视频| 午夜久久久久久久久| 欧美片在线播放| 天天影视色香欲综合网老头| 欧美日韩国产区一| 日本不卡一区二区三区高清视频| 欧美视频三区在线播放| 婷婷开心激情综合| 7777精品伊人久久久大香线蕉完整版| 午夜av一区二区| 欧美一区二区三区四区五区| 无码av免费一区二区三区试看| 欧美乱妇20p| 国内精品视频666| 国产色产综合产在线视频| 99久久精品免费精品国产| 亚洲欧美日韩国产综合在线| 欧美图区在线视频| 日本在线不卡一区| 久久久久久久综合色一本| 丰满岳乱妇一区二区三区| 一色桃子久久精品亚洲| 91伊人久久大香线蕉| 亚洲国产精品自拍| 日韩欧美一区中文| 国产jizzjizz一区二区| 亚洲欧美一区二区久久| 欧美日韩高清影院| 国产乱子轮精品视频| 国产精品欧美一级免费| 欧美在线视频日韩| 久国产精品韩国三级视频| 中文字幕不卡在线| 欧美探花视频资源| 狠狠色综合色综合网络| 最新日韩av在线| 欧美精品一二三| 国产aⅴ综合色| 亚洲国产三级在线| 久久久久久**毛片大全| 色婷婷一区二区三区四区| 久久99精品国产麻豆婷婷 | 亚洲欧洲av另类| 欧美日韩dvd在线观看| 国产成人在线色| 成人国产精品免费| 亚洲国产精品久久不卡毛片| 久久免费电影网| 欧美在线制服丝袜| 国产一区二区毛片| 午夜婷婷国产麻豆精品| 久久精品一区蜜桃臀影院| 在线视频一区二区三区| 国产一区美女在线| 亚洲图片有声小说| 中文字幕高清不卡| 日韩欧美亚洲国产精品字幕久久久 | 欧美成人video| 色8久久精品久久久久久蜜| 精品一区二区免费在线观看| 日韩理论片在线| 国产午夜亚洲精品羞羞网站| 3d动漫精品啪啪一区二区竹菊| 北条麻妃一区二区三区| 国内精品写真在线观看|