Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbd_bulk.c Source File

usbd_bulk.c

Go to the documentation of this file.
00001 /**
00002  * @file    usbd_bulk.c
00003  * @brief   DAPv2 BULK driver
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2019, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include <string.h>
00023 
00024 #include "rl_usb.h"
00025 #include "usb_for_lib.h"
00026 #include "util.h"
00027 #include "DAP_queue.h"
00028 
00029 static U8 *ptrDataIn;
00030 static U16 DataInReceLen;
00031 static DAP_queue DAP_Cmd_queue;
00032 
00033 static volatile uint8_t  USB_ResponseIdle;
00034 
00035 void usbd_bulk_init(void)
00036 {
00037     ptrDataIn     = USBD_Bulk_BulkOutBuf;
00038     DataInReceLen = 0;
00039     DAP_queue_init(&DAP_Cmd_queue);
00040     USB_ResponseIdle = 1;
00041 }
00042 
00043 /*
00044  *  USB Device Bulk In Endpoint Event Callback
00045  *    Parameters:      event: not used (just for compatibility)
00046  *    Return Value:    None
00047  */
00048 
00049 void USBD_BULK_EP_BULKIN_Event(U32 event)
00050 {
00051     uint8_t * sbuf = 0;
00052     int slen;
00053     if(DAP_queue_get_send_buf(&DAP_Cmd_queue, &sbuf, &slen)){
00054         USBD_WriteEP(usbd_bulk_ep_bulkin | 0x80, sbuf, slen);
00055     } else {
00056         USB_ResponseIdle = 1;
00057     }
00058 }
00059 
00060 
00061 /*
00062  *  USB Device Bulk Out Endpoint Event Callback
00063  *    Parameters:      event: not used (just for compatibility)
00064  *    Return Value:    None
00065  */
00066 
00067 void USBD_BULK_EP_BULKOUT_Event(U32 event)
00068 {
00069     U16 bytes_rece;
00070     uint8_t * rbuf;
00071 
00072     bytes_rece      = USBD_ReadEP(usbd_bulk_ep_bulkout, ptrDataIn, USBD_Bulk_BulkBufSize - DataInReceLen);
00073     ptrDataIn      += bytes_rece;
00074     DataInReceLen  += bytes_rece;
00075 
00076     if ((DataInReceLen >= USBD_Bulk_BulkBufSize) ||
00077             (bytes_rece    <  usbd_bulk_maxpacketsize[USBD_HighSpeed])) {
00078         if (DAP_queue_execute_buf(&DAP_Cmd_queue, USBD_Bulk_BulkOutBuf, DataInReceLen, &rbuf)) {
00079             //Trigger the BULKIn for the reply
00080             if (USB_ResponseIdle) {
00081                 USBD_BULK_EP_BULKIN_Event(0);
00082                 USB_ResponseIdle = 0;
00083             }
00084         }
00085         //revert the input pointers
00086         DataInReceLen = 0;
00087         ptrDataIn     = USBD_Bulk_BulkOutBuf;
00088     }
00089 }
00090 
00091 
00092 /*
00093  *  USB Device Bulk In/Out Endpoint Event Callback
00094  *    Parameters:      event: USB Device Event
00095  *                       USBD_EVT_OUT: Output Event
00096  *                       USBD_EVT_IN:  Input Event
00097  *    Return Value:    None
00098  */
00099 
00100 void USBD_BULK_EP_BULK_Event(U32 event)
00101 {
00102     if (event & USBD_EVT_OUT) {
00103         USBD_BULK_EP_BULKOUT_Event(0);
00104     }
00105 
00106     if (event & USBD_EVT_IN) {
00107         USBD_BULK_EP_BULKIN_Event(0);
00108     }
00109 }