Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /**
Pawel Zarembski 0:01f31e923fe2 2 * @file usbd_bulk.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief DAPv2 BULK driver
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2019, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 7 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 8 *
Pawel Zarembski 0:01f31e923fe2 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 10 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 11 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 12 *
Pawel Zarembski 0:01f31e923fe2 13 * http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 14 *
Pawel Zarembski 0:01f31e923fe2 15 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 18 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 19 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 20 */
Pawel Zarembski 0:01f31e923fe2 21
Pawel Zarembski 0:01f31e923fe2 22 #include <string.h>
Pawel Zarembski 0:01f31e923fe2 23
Pawel Zarembski 0:01f31e923fe2 24 #include "rl_usb.h"
Pawel Zarembski 0:01f31e923fe2 25 #include "usb_for_lib.h"
Pawel Zarembski 0:01f31e923fe2 26 #include "util.h"
Pawel Zarembski 0:01f31e923fe2 27 #include "DAP_queue.h"
Pawel Zarembski 0:01f31e923fe2 28
Pawel Zarembski 0:01f31e923fe2 29 static U8 *ptrDataIn;
Pawel Zarembski 0:01f31e923fe2 30 static U16 DataInReceLen;
Pawel Zarembski 0:01f31e923fe2 31 static DAP_queue DAP_Cmd_queue;
Pawel Zarembski 0:01f31e923fe2 32
Pawel Zarembski 0:01f31e923fe2 33 static volatile uint8_t USB_ResponseIdle;
Pawel Zarembski 0:01f31e923fe2 34
Pawel Zarembski 0:01f31e923fe2 35 void usbd_bulk_init(void)
Pawel Zarembski 0:01f31e923fe2 36 {
Pawel Zarembski 0:01f31e923fe2 37 ptrDataIn = USBD_Bulk_BulkOutBuf;
Pawel Zarembski 0:01f31e923fe2 38 DataInReceLen = 0;
Pawel Zarembski 0:01f31e923fe2 39 DAP_queue_init(&DAP_Cmd_queue);
Pawel Zarembski 0:01f31e923fe2 40 USB_ResponseIdle = 1;
Pawel Zarembski 0:01f31e923fe2 41 }
Pawel Zarembski 0:01f31e923fe2 42
Pawel Zarembski 0:01f31e923fe2 43 /*
Pawel Zarembski 0:01f31e923fe2 44 * USB Device Bulk In Endpoint Event Callback
Pawel Zarembski 0:01f31e923fe2 45 * Parameters: event: not used (just for compatibility)
Pawel Zarembski 0:01f31e923fe2 46 * Return Value: None
Pawel Zarembski 0:01f31e923fe2 47 */
Pawel Zarembski 0:01f31e923fe2 48
Pawel Zarembski 0:01f31e923fe2 49 void USBD_BULK_EP_BULKIN_Event(U32 event)
Pawel Zarembski 0:01f31e923fe2 50 {
Pawel Zarembski 0:01f31e923fe2 51 uint8_t * sbuf = 0;
Pawel Zarembski 0:01f31e923fe2 52 int slen;
Pawel Zarembski 0:01f31e923fe2 53 if(DAP_queue_get_send_buf(&DAP_Cmd_queue, &sbuf, &slen)){
Pawel Zarembski 0:01f31e923fe2 54 USBD_WriteEP(usbd_bulk_ep_bulkin | 0x80, sbuf, slen);
Pawel Zarembski 0:01f31e923fe2 55 } else {
Pawel Zarembski 0:01f31e923fe2 56 USB_ResponseIdle = 1;
Pawel Zarembski 0:01f31e923fe2 57 }
Pawel Zarembski 0:01f31e923fe2 58 }
Pawel Zarembski 0:01f31e923fe2 59
Pawel Zarembski 0:01f31e923fe2 60
Pawel Zarembski 0:01f31e923fe2 61 /*
Pawel Zarembski 0:01f31e923fe2 62 * USB Device Bulk Out Endpoint Event Callback
Pawel Zarembski 0:01f31e923fe2 63 * Parameters: event: not used (just for compatibility)
Pawel Zarembski 0:01f31e923fe2 64 * Return Value: None
Pawel Zarembski 0:01f31e923fe2 65 */
Pawel Zarembski 0:01f31e923fe2 66
Pawel Zarembski 0:01f31e923fe2 67 void USBD_BULK_EP_BULKOUT_Event(U32 event)
Pawel Zarembski 0:01f31e923fe2 68 {
Pawel Zarembski 0:01f31e923fe2 69 U16 bytes_rece;
Pawel Zarembski 0:01f31e923fe2 70 uint8_t * rbuf;
Pawel Zarembski 0:01f31e923fe2 71
Pawel Zarembski 0:01f31e923fe2 72 bytes_rece = USBD_ReadEP(usbd_bulk_ep_bulkout, ptrDataIn, USBD_Bulk_BulkBufSize - DataInReceLen);
Pawel Zarembski 0:01f31e923fe2 73 ptrDataIn += bytes_rece;
Pawel Zarembski 0:01f31e923fe2 74 DataInReceLen += bytes_rece;
Pawel Zarembski 0:01f31e923fe2 75
Pawel Zarembski 0:01f31e923fe2 76 if ((DataInReceLen >= USBD_Bulk_BulkBufSize) ||
Pawel Zarembski 0:01f31e923fe2 77 (bytes_rece < usbd_bulk_maxpacketsize[USBD_HighSpeed])) {
Pawel Zarembski 0:01f31e923fe2 78 if (DAP_queue_execute_buf(&DAP_Cmd_queue, USBD_Bulk_BulkOutBuf, DataInReceLen, &rbuf)) {
Pawel Zarembski 0:01f31e923fe2 79 //Trigger the BULKIn for the reply
Pawel Zarembski 0:01f31e923fe2 80 if (USB_ResponseIdle) {
Pawel Zarembski 0:01f31e923fe2 81 USBD_BULK_EP_BULKIN_Event(0);
Pawel Zarembski 0:01f31e923fe2 82 USB_ResponseIdle = 0;
Pawel Zarembski 0:01f31e923fe2 83 }
Pawel Zarembski 0:01f31e923fe2 84 }
Pawel Zarembski 0:01f31e923fe2 85 //revert the input pointers
Pawel Zarembski 0:01f31e923fe2 86 DataInReceLen = 0;
Pawel Zarembski 0:01f31e923fe2 87 ptrDataIn = USBD_Bulk_BulkOutBuf;
Pawel Zarembski 0:01f31e923fe2 88 }
Pawel Zarembski 0:01f31e923fe2 89 }
Pawel Zarembski 0:01f31e923fe2 90
Pawel Zarembski 0:01f31e923fe2 91
Pawel Zarembski 0:01f31e923fe2 92 /*
Pawel Zarembski 0:01f31e923fe2 93 * USB Device Bulk In/Out Endpoint Event Callback
Pawel Zarembski 0:01f31e923fe2 94 * Parameters: event: USB Device Event
Pawel Zarembski 0:01f31e923fe2 95 * USBD_EVT_OUT: Output Event
Pawel Zarembski 0:01f31e923fe2 96 * USBD_EVT_IN: Input Event
Pawel Zarembski 0:01f31e923fe2 97 * Return Value: None
Pawel Zarembski 0:01f31e923fe2 98 */
Pawel Zarembski 0:01f31e923fe2 99
Pawel Zarembski 0:01f31e923fe2 100 void USBD_BULK_EP_BULK_Event(U32 event)
Pawel Zarembski 0:01f31e923fe2 101 {
Pawel Zarembski 0:01f31e923fe2 102 if (event & USBD_EVT_OUT) {
Pawel Zarembski 0:01f31e923fe2 103 USBD_BULK_EP_BULKOUT_Event(0);
Pawel Zarembski 0:01f31e923fe2 104 }
Pawel Zarembski 0:01f31e923fe2 105
Pawel Zarembski 0:01f31e923fe2 106 if (event & USBD_EVT_IN) {
Pawel Zarembski 0:01f31e923fe2 107 USBD_BULK_EP_BULKIN_Event(0);
Pawel Zarembski 0:01f31e923fe2 108 }
Pawel Zarembski 0:01f31e923fe2 109 }