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 DAP_queue.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief DAP processing queue
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 #include "DAP_queue.h"
Pawel Zarembski 0:01f31e923fe2 24 void DAP_queue_init(DAP_queue * queue)
Pawel Zarembski 0:01f31e923fe2 25 {
Pawel Zarembski 0:01f31e923fe2 26 queue->recv_idx = 0;
Pawel Zarembski 0:01f31e923fe2 27 queue->send_idx = 0;
Pawel Zarembski 0:01f31e923fe2 28 queue->free_count = FREE_COUNT_INIT;
Pawel Zarembski 0:01f31e923fe2 29 queue->send_count = SEND_COUNT_INIT;
Pawel Zarembski 0:01f31e923fe2 30 }
Pawel Zarembski 0:01f31e923fe2 31
Pawel Zarembski 0:01f31e923fe2 32 /*
Pawel Zarembski 0:01f31e923fe2 33 * Get the a buffer from the DAP_queue where the response to the request is stored
Pawel Zarembski 0:01f31e923fe2 34 * Parameters: queue - DAP queue, buf = return the buffer location, len = return the len of the response
Pawel Zarembski 0:01f31e923fe2 35 * Return Value: TRUE - Success, FALSE - Error
Pawel Zarembski 0:01f31e923fe2 36 */
Pawel Zarembski 0:01f31e923fe2 37
Pawel Zarembski 0:01f31e923fe2 38 BOOL DAP_queue_get_send_buf(DAP_queue * queue, uint8_t ** buf, int * len)
Pawel Zarembski 0:01f31e923fe2 39 {
Pawel Zarembski 0:01f31e923fe2 40 if (queue->send_count) {
Pawel Zarembski 0:01f31e923fe2 41 queue->send_count--;
Pawel Zarembski 0:01f31e923fe2 42 *buf = queue->USB_Request[queue->send_idx];
Pawel Zarembski 0:01f31e923fe2 43 *len = queue->resp_size[queue->send_idx];
Pawel Zarembski 0:01f31e923fe2 44 queue->send_idx = (queue->send_idx + 1) % DAP_PACKET_COUNT;
Pawel Zarembski 0:01f31e923fe2 45 queue->free_count++;
Pawel Zarembski 0:01f31e923fe2 46 return (__TRUE);
Pawel Zarembski 0:01f31e923fe2 47 }
Pawel Zarembski 0:01f31e923fe2 48 return (__FALSE);
Pawel Zarembski 0:01f31e923fe2 49 }
Pawel Zarembski 0:01f31e923fe2 50
Pawel Zarembski 0:01f31e923fe2 51 /*
Pawel Zarembski 0:01f31e923fe2 52 * Execute a request and store result to the DAP_queue
Pawel Zarembski 0:01f31e923fe2 53 * Parameters: queue - DAP queue, reqbuf = buffer with DAP request, len = of the request buffer, retbuf = buffer to peek on the result of the DAP operation
Pawel Zarembski 0:01f31e923fe2 54 * Return Value: TRUE - Success, FALSE - Error
Pawel Zarembski 0:01f31e923fe2 55 */
Pawel Zarembski 0:01f31e923fe2 56
Pawel Zarembski 0:01f31e923fe2 57
Pawel Zarembski 0:01f31e923fe2 58 BOOL DAP_queue_execute_buf(DAP_queue * queue, const uint8_t *reqbuf, int len, uint8_t ** retbuf)
Pawel Zarembski 0:01f31e923fe2 59 {
Pawel Zarembski 0:01f31e923fe2 60 uint32_t rsize;
Pawel Zarembski 0:01f31e923fe2 61 if (queue->free_count > 0) {
Pawel Zarembski 0:01f31e923fe2 62 if (len > DAP_PACKET_SIZE) {
Pawel Zarembski 0:01f31e923fe2 63 len = DAP_PACKET_SIZE;
Pawel Zarembski 0:01f31e923fe2 64 }
Pawel Zarembski 0:01f31e923fe2 65 queue->free_count--;
Pawel Zarembski 0:01f31e923fe2 66 memcpy(queue->USB_Request[queue->recv_idx], reqbuf, len);
Pawel Zarembski 0:01f31e923fe2 67 rsize = DAP_ExecuteCommand(reqbuf, queue->USB_Request[queue->recv_idx]);
Pawel Zarembski 0:01f31e923fe2 68 queue->resp_size[queue->recv_idx] = rsize & 0xFFFF; //get the response size
Pawel Zarembski 0:01f31e923fe2 69 *retbuf = queue->USB_Request[queue->recv_idx];
Pawel Zarembski 0:01f31e923fe2 70 queue->recv_idx = (queue->recv_idx + 1) % DAP_PACKET_COUNT;
Pawel Zarembski 0:01f31e923fe2 71 queue->send_count++;
Pawel Zarembski 0:01f31e923fe2 72 return (__TRUE);
Pawel Zarembski 0:01f31e923fe2 73 }
Pawel Zarembski 0:01f31e923fe2 74 return (__FALSE);
Pawel Zarembski 0:01f31e923fe2 75 }