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

« Back to documentation index

Show/hide line numbers DAP_queue.c Source File

DAP_queue.c

Go to the documentation of this file.
00001 /**
00002  * @file    DAP_queue.c
00003  * @brief   DAP processing queue
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 #include "DAP_queue.h"
00024 void DAP_queue_init(DAP_queue * queue)
00025 {
00026     queue->recv_idx = 0;
00027     queue->send_idx = 0;
00028     queue->free_count = FREE_COUNT_INIT;
00029     queue->send_count = SEND_COUNT_INIT;
00030 }
00031 
00032 /*
00033  *  Get the a buffer from the DAP_queue where the response to the request is stored
00034  *    Parameters:      queue - DAP queue, buf = return the buffer location, len = return the len of the response
00035  *    Return Value:    TRUE - Success, FALSE - Error
00036  */
00037 
00038 BOOL DAP_queue_get_send_buf(DAP_queue * queue, uint8_t ** buf, int * len)
00039 {
00040     if (queue->send_count) {
00041         queue->send_count--;
00042         *buf = queue->USB_Request[queue->send_idx];
00043         *len = queue->resp_size[queue->send_idx];
00044         queue->send_idx = (queue->send_idx + 1) % DAP_PACKET_COUNT;
00045         queue->free_count++;
00046         return (__TRUE);
00047     }
00048     return (__FALSE);
00049 }
00050 
00051 /*
00052  *  Execute a request and store result to the DAP_queue
00053  *    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
00054  *    Return Value:    TRUE - Success, FALSE - Error
00055  */
00056 
00057 
00058 BOOL DAP_queue_execute_buf(DAP_queue * queue, const uint8_t *reqbuf, int len, uint8_t ** retbuf)
00059 {
00060     uint32_t rsize;
00061     if (queue->free_count > 0) {
00062         if (len > DAP_PACKET_SIZE) {
00063             len = DAP_PACKET_SIZE;
00064         }
00065         queue->free_count--;
00066         memcpy(queue->USB_Request[queue->recv_idx], reqbuf, len);
00067         rsize = DAP_ExecuteCommand(reqbuf, queue->USB_Request[queue->recv_idx]);
00068         queue->resp_size[queue->recv_idx] = rsize & 0xFFFF; //get the response size
00069         *retbuf = queue->USB_Request[queue->recv_idx];
00070         queue->recv_idx = (queue->recv_idx + 1) % DAP_PACKET_COUNT;
00071         queue->send_count++;
00072         return (__TRUE);
00073     }
00074     return (__FALSE);
00075 }