Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/daplink/daplink_debug.h@0:01f31e923fe2, 2020-04-07 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file daplink_debug.h |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief optional trace messages useful in development |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2009-2016, 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 | #ifndef DAPLINK_DEBUG_H |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #define DAPLINK_DEBUG_H |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include <stdarg.h> |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #include <stdio.h> |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #include <string.h> |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #include <stdint.h> |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #include "cmsis_os2.h" |
Pawel Zarembski |
0:01f31e923fe2 | 30 | #include "rl_usb.h" |
Pawel Zarembski |
0:01f31e923fe2 | 31 | #include "util.h" |
Pawel Zarembski |
0:01f31e923fe2 | 32 | |
Pawel Zarembski |
0:01f31e923fe2 | 33 | #ifdef __cplusplus |
Pawel Zarembski |
0:01f31e923fe2 | 34 | extern "C" { |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | #ifndef MSC_DEBUG |
Pawel Zarembski |
0:01f31e923fe2 | 38 | //#define MSC_DEBUG |
Pawel Zarembski |
0:01f31e923fe2 | 39 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 40 | |
Pawel Zarembski |
0:01f31e923fe2 | 41 | #if defined (MSC_DEBUG) |
Pawel Zarembski |
0:01f31e923fe2 | 42 | |
Pawel Zarembski |
0:01f31e923fe2 | 43 | static const char error_msg[] = "\r\n<OVERFLOW>\r\n"; |
Pawel Zarembski |
0:01f31e923fe2 | 44 | |
Pawel Zarembski |
0:01f31e923fe2 | 45 | static inline uint32_t daplink_debug(uint8_t *buf, uint32_t size) |
Pawel Zarembski |
0:01f31e923fe2 | 46 | { |
Pawel Zarembski |
0:01f31e923fe2 | 47 | uint32_t total_free; |
Pawel Zarembski |
0:01f31e923fe2 | 48 | uint32_t write_free; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | uint32_t error_len = strlen(error_msg); |
Pawel Zarembski |
0:01f31e923fe2 | 50 | total_free = USBD_CDC_ACM_DataFree(); |
Pawel Zarembski |
0:01f31e923fe2 | 51 | |
Pawel Zarembski |
0:01f31e923fe2 | 52 | if (total_free < error_len) { |
Pawel Zarembski |
0:01f31e923fe2 | 53 | // No space |
Pawel Zarembski |
0:01f31e923fe2 | 54 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 55 | } |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | // Size available for writing |
Pawel Zarembski |
0:01f31e923fe2 | 58 | write_free = total_free - error_len; |
Pawel Zarembski |
0:01f31e923fe2 | 59 | size = MIN(write_free, size); |
Pawel Zarembski |
0:01f31e923fe2 | 60 | USBD_CDC_ACM_DataSend(buf, size); |
Pawel Zarembski |
0:01f31e923fe2 | 61 | |
Pawel Zarembski |
0:01f31e923fe2 | 62 | if (write_free == size) { |
Pawel Zarembski |
0:01f31e923fe2 | 63 | USBD_CDC_ACM_DataSend((uint8_t *)error_msg, error_len); |
Pawel Zarembski |
0:01f31e923fe2 | 64 | } |
Pawel Zarembski |
0:01f31e923fe2 | 65 | |
Pawel Zarembski |
0:01f31e923fe2 | 66 | return size; |
Pawel Zarembski |
0:01f31e923fe2 | 67 | } |
Pawel Zarembski |
0:01f31e923fe2 | 68 | |
Pawel Zarembski |
0:01f31e923fe2 | 69 | static char daplink_debug_buf[128] = {0}; |
Pawel Zarembski |
0:01f31e923fe2 | 70 | static inline uint32_t daplink_debug_print(const char *format, ...) |
Pawel Zarembski |
0:01f31e923fe2 | 71 | { |
Pawel Zarembski |
0:01f31e923fe2 | 72 | uint32_t ret; |
Pawel Zarembski |
0:01f31e923fe2 | 73 | int32_t r = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 74 | va_list arg; |
Pawel Zarembski |
0:01f31e923fe2 | 75 | ret = 1; |
Pawel Zarembski |
0:01f31e923fe2 | 76 | va_start(arg, format); |
Pawel Zarembski |
0:01f31e923fe2 | 77 | r = vsnprintf(daplink_debug_buf, sizeof(daplink_debug_buf), format, arg); |
Pawel Zarembski |
0:01f31e923fe2 | 78 | |
Pawel Zarembski |
0:01f31e923fe2 | 79 | if (r >= sizeof(daplink_debug_buf)) { |
Pawel Zarembski |
0:01f31e923fe2 | 80 | r = snprintf(daplink_debug_buf, sizeof(daplink_debug_buf), "<Error - string length %i exceeds print buffer>\r\n", r); |
Pawel Zarembski |
0:01f31e923fe2 | 81 | ret = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 82 | } |
Pawel Zarembski |
0:01f31e923fe2 | 83 | |
Pawel Zarembski |
0:01f31e923fe2 | 84 | va_end(arg); |
Pawel Zarembski |
0:01f31e923fe2 | 85 | daplink_debug((uint8_t *)daplink_debug_buf, r); |
Pawel Zarembski |
0:01f31e923fe2 | 86 | return ret; |
Pawel Zarembski |
0:01f31e923fe2 | 87 | } |
Pawel Zarembski |
0:01f31e923fe2 | 88 | |
Pawel Zarembski |
0:01f31e923fe2 | 89 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 90 | |
Pawel Zarembski |
0:01f31e923fe2 | 91 | static inline uint32_t daplink_debug_print(const char *format, ...) |
Pawel Zarembski |
0:01f31e923fe2 | 92 | { |
Pawel Zarembski |
0:01f31e923fe2 | 93 | return 1; |
Pawel Zarembski |
0:01f31e923fe2 | 94 | } |
Pawel Zarembski |
0:01f31e923fe2 | 95 | |
Pawel Zarembski |
0:01f31e923fe2 | 96 | static inline uint32_t daplink_debug(uint8_t *data, uint32_t size) |
Pawel Zarembski |
0:01f31e923fe2 | 97 | { |
Pawel Zarembski |
0:01f31e923fe2 | 98 | return 1; |
Pawel Zarembski |
0:01f31e923fe2 | 99 | } |
Pawel Zarembski |
0:01f31e923fe2 | 100 | |
Pawel Zarembski |
0:01f31e923fe2 | 101 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | #define debug_msg(fmt, args...) daplink_debug_print(fmt, ## args); |
Pawel Zarembski |
0:01f31e923fe2 | 104 | #define debug_data(buf, size) daplink_debug(buf, size); |
Pawel Zarembski |
0:01f31e923fe2 | 105 | |
Pawel Zarembski |
0:01f31e923fe2 | 106 | #ifdef __cplusplus |
Pawel Zarembski |
0:01f31e923fe2 | 107 | } |
Pawel Zarembski |
0:01f31e923fe2 | 108 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 109 | |
Pawel Zarembski |
0:01f31e923fe2 | 110 | #endif |