Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/daplink/cmsis-dap/SWO.c@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 | * Copyright (c) 2013-2017 ARM Limited. All rights reserved. |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * ---------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * |
Pawel Zarembski |
0:01f31e923fe2 | 20 | * $Date: 1. December 2017 |
Pawel Zarembski |
0:01f31e923fe2 | 21 | * $Revision: V2.0.0 |
Pawel Zarembski |
0:01f31e923fe2 | 22 | * |
Pawel Zarembski |
0:01f31e923fe2 | 23 | * Project: CMSIS-DAP Source |
Pawel Zarembski |
0:01f31e923fe2 | 24 | * Title: SWO.c CMSIS-DAP SWO I/O |
Pawel Zarembski |
0:01f31e923fe2 | 25 | * |
Pawel Zarembski |
0:01f31e923fe2 | 26 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 27 | |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #include "DAP_config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #include "DAP.h" |
Pawel Zarembski |
0:01f31e923fe2 | 30 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 31 | #include "Driver_USART.h" |
Pawel Zarembski |
0:01f31e923fe2 | 32 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 33 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 34 | #include "cmsis_os2.h" |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 38 | #ifdef DAP_FW_V1 |
Pawel Zarembski |
0:01f31e923fe2 | 39 | #error "SWO Streaming Trace not supported in DAP V1!" |
Pawel Zarembski |
0:01f31e923fe2 | 40 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 41 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 42 | |
Pawel Zarembski |
0:01f31e923fe2 | 43 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 44 | |
Pawel Zarembski |
0:01f31e923fe2 | 45 | #ifndef SWO_USART_PORT |
Pawel Zarembski |
0:01f31e923fe2 | 46 | #define SWO_USART_PORT 0 /* USART Port Number */ |
Pawel Zarembski |
0:01f31e923fe2 | 47 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 48 | |
Pawel Zarembski |
0:01f31e923fe2 | 49 | // USART Driver |
Pawel Zarembski |
0:01f31e923fe2 | 50 | #define _USART_Driver_(n) Driver_USART##n |
Pawel Zarembski |
0:01f31e923fe2 | 51 | #define USART_Driver_(n) _USART_Driver_(n) |
Pawel Zarembski |
0:01f31e923fe2 | 52 | extern ARM_DRIVER_USART USART_Driver_(SWO_USART_PORT); |
Pawel Zarembski |
0:01f31e923fe2 | 53 | #define pUSART (&USART_Driver_(SWO_USART_PORT)) |
Pawel Zarembski |
0:01f31e923fe2 | 54 | |
Pawel Zarembski |
0:01f31e923fe2 | 55 | static uint8_t USART_Ready = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | #endif /* (SWO_UART != 0) */ |
Pawel Zarembski |
0:01f31e923fe2 | 58 | |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | #if ((SWO_UART != 0) || (SWO_MANCHESTER != 0)) |
Pawel Zarembski |
0:01f31e923fe2 | 61 | |
Pawel Zarembski |
0:01f31e923fe2 | 62 | |
Pawel Zarembski |
0:01f31e923fe2 | 63 | #define SWO_STREAM_TIMEOUT 50U /* Stream timeout in ms */ |
Pawel Zarembski |
0:01f31e923fe2 | 64 | |
Pawel Zarembski |
0:01f31e923fe2 | 65 | #define USB_BLOCK_SIZE 512U /* USB Block Size */ |
Pawel Zarembski |
0:01f31e923fe2 | 66 | #define TRACE_BLOCK_SIZE 64U /* Trace Block Size (2^n: 32...512) */ |
Pawel Zarembski |
0:01f31e923fe2 | 67 | |
Pawel Zarembski |
0:01f31e923fe2 | 68 | // Trace State |
Pawel Zarembski |
0:01f31e923fe2 | 69 | static uint8_t TraceTransport = 0U; /* Trace Transport */ |
Pawel Zarembski |
0:01f31e923fe2 | 70 | static uint8_t TraceMode = 0U; /* Trace Mode */ |
Pawel Zarembski |
0:01f31e923fe2 | 71 | static uint8_t TraceStatus = 0U; /* Trace Status without Errors */ |
Pawel Zarembski |
0:01f31e923fe2 | 72 | static uint8_t TraceError[2] = {0U, 0U}; /* Trace Error flags (banked) */ |
Pawel Zarembski |
0:01f31e923fe2 | 73 | static uint8_t TraceError_n = 0U; /* Active Trace Error bank */ |
Pawel Zarembski |
0:01f31e923fe2 | 74 | |
Pawel Zarembski |
0:01f31e923fe2 | 75 | // Trace Buffer |
Pawel Zarembski |
0:01f31e923fe2 | 76 | static uint8_t TraceBuf[SWO_BUFFER_SIZE]; /* Trace Buffer (must be 2^n) */ |
Pawel Zarembski |
0:01f31e923fe2 | 77 | static volatile uint32_t TraceIndexI = 0U; /* Incoming Trace Index */ |
Pawel Zarembski |
0:01f31e923fe2 | 78 | static volatile uint32_t TraceIndexO = 0U; /* Outgoing Trace Index */ |
Pawel Zarembski |
0:01f31e923fe2 | 79 | static volatile uint8_t TraceUpdate; /* Trace Update Flag */ |
Pawel Zarembski |
0:01f31e923fe2 | 80 | static uint32_t TraceBlockSize; /* Current Trace Block Size */ |
Pawel Zarembski |
0:01f31e923fe2 | 81 | |
Pawel Zarembski |
0:01f31e923fe2 | 82 | #if (TIMESTAMP_CLOCK != 0U) |
Pawel Zarembski |
0:01f31e923fe2 | 83 | // Trace Timestamp |
Pawel Zarembski |
0:01f31e923fe2 | 84 | static volatile struct { |
Pawel Zarembski |
0:01f31e923fe2 | 85 | uint32_t index; |
Pawel Zarembski |
0:01f31e923fe2 | 86 | uint32_t tick; |
Pawel Zarembski |
0:01f31e923fe2 | 87 | } TraceTimestamp; |
Pawel Zarembski |
0:01f31e923fe2 | 88 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 89 | |
Pawel Zarembski |
0:01f31e923fe2 | 90 | // Trace Helper functions |
Pawel Zarembski |
0:01f31e923fe2 | 91 | static void ClearTrace (void); |
Pawel Zarembski |
0:01f31e923fe2 | 92 | static void ResumeTrace (void); |
Pawel Zarembski |
0:01f31e923fe2 | 93 | static uint32_t GetTraceCount (void); |
Pawel Zarembski |
0:01f31e923fe2 | 94 | static uint8_t GetTraceStatus (void); |
Pawel Zarembski |
0:01f31e923fe2 | 95 | static void SetTraceError (uint8_t flag); |
Pawel Zarembski |
0:01f31e923fe2 | 96 | |
Pawel Zarembski |
0:01f31e923fe2 | 97 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 98 | extern osThreadId_t SWO_ThreadId; |
Pawel Zarembski |
0:01f31e923fe2 | 99 | static volatile uint8_t TransferBusy = 0U; /* Transfer Busy Flag */ |
Pawel Zarembski |
0:01f31e923fe2 | 100 | static uint32_t TransferSize; /* Current Transfer Size */ |
Pawel Zarembski |
0:01f31e923fe2 | 101 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | |
Pawel Zarembski |
0:01f31e923fe2 | 104 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 105 | |
Pawel Zarembski |
0:01f31e923fe2 | 106 | // USART Driver Callback function |
Pawel Zarembski |
0:01f31e923fe2 | 107 | // event: event mask |
Pawel Zarembski |
0:01f31e923fe2 | 108 | static void USART_Callback (uint32_t event) { |
Pawel Zarembski |
0:01f31e923fe2 | 109 | uint32_t index_i; |
Pawel Zarembski |
0:01f31e923fe2 | 110 | uint32_t index_o; |
Pawel Zarembski |
0:01f31e923fe2 | 111 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 112 | uint32_t num; |
Pawel Zarembski |
0:01f31e923fe2 | 113 | |
Pawel Zarembski |
0:01f31e923fe2 | 114 | if (event & ARM_USART_EVENT_RECEIVE_COMPLETE) { |
Pawel Zarembski |
0:01f31e923fe2 | 115 | #if (TIMESTAMP_CLOCK != 0U) |
Pawel Zarembski |
0:01f31e923fe2 | 116 | TraceTimestamp.tick = TIMESTAMP_GET(); |
Pawel Zarembski |
0:01f31e923fe2 | 117 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 118 | index_o = TraceIndexO; |
Pawel Zarembski |
0:01f31e923fe2 | 119 | index_i = TraceIndexI; |
Pawel Zarembski |
0:01f31e923fe2 | 120 | index_i += TraceBlockSize; |
Pawel Zarembski |
0:01f31e923fe2 | 121 | TraceIndexI = index_i; |
Pawel Zarembski |
0:01f31e923fe2 | 122 | #if (TIMESTAMP_CLOCK != 0U) |
Pawel Zarembski |
0:01f31e923fe2 | 123 | TraceTimestamp.index = index_i; |
Pawel Zarembski |
0:01f31e923fe2 | 124 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 125 | num = TRACE_BLOCK_SIZE - (index_i & (TRACE_BLOCK_SIZE - 1U)); |
Pawel Zarembski |
0:01f31e923fe2 | 126 | count = index_i - index_o; |
Pawel Zarembski |
0:01f31e923fe2 | 127 | if (count <= (SWO_BUFFER_SIZE - num)) { |
Pawel Zarembski |
0:01f31e923fe2 | 128 | index_i &= SWO_BUFFER_SIZE - 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 129 | TraceBlockSize = num; |
Pawel Zarembski |
0:01f31e923fe2 | 130 | pUSART->Receive(&TraceBuf[index_i], num); |
Pawel Zarembski |
0:01f31e923fe2 | 131 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 132 | TraceStatus = DAP_SWO_CAPTURE_ACTIVE | DAP_SWO_CAPTURE_PAUSED; |
Pawel Zarembski |
0:01f31e923fe2 | 133 | } |
Pawel Zarembski |
0:01f31e923fe2 | 134 | TraceUpdate = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 135 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 136 | if (TraceTransport == 2U) { |
Pawel Zarembski |
0:01f31e923fe2 | 137 | if (count >= (USB_BLOCK_SIZE - (index_o & (USB_BLOCK_SIZE - 1U)))) { |
Pawel Zarembski |
0:01f31e923fe2 | 138 | osThreadFlagsSet(SWO_ThreadId, 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 139 | } |
Pawel Zarembski |
0:01f31e923fe2 | 140 | } |
Pawel Zarembski |
0:01f31e923fe2 | 141 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 142 | } |
Pawel Zarembski |
0:01f31e923fe2 | 143 | if (event & ARM_USART_EVENT_RX_OVERFLOW) { |
Pawel Zarembski |
0:01f31e923fe2 | 144 | SetTraceError(DAP_SWO_BUFFER_OVERRUN); |
Pawel Zarembski |
0:01f31e923fe2 | 145 | } |
Pawel Zarembski |
0:01f31e923fe2 | 146 | if (event & (ARM_USART_EVENT_RX_BREAK | |
Pawel Zarembski |
0:01f31e923fe2 | 147 | ARM_USART_EVENT_RX_FRAMING_ERROR | |
Pawel Zarembski |
0:01f31e923fe2 | 148 | ARM_USART_EVENT_RX_PARITY_ERROR)) { |
Pawel Zarembski |
0:01f31e923fe2 | 149 | SetTraceError(DAP_SWO_STREAM_ERROR); |
Pawel Zarembski |
0:01f31e923fe2 | 150 | } |
Pawel Zarembski |
0:01f31e923fe2 | 151 | } |
Pawel Zarembski |
0:01f31e923fe2 | 152 | |
Pawel Zarembski |
0:01f31e923fe2 | 153 | // Enable or disable UART SWO Mode |
Pawel Zarembski |
0:01f31e923fe2 | 154 | // enable: enable flag |
Pawel Zarembski |
0:01f31e923fe2 | 155 | // return: 1 - Success, 0 - Error |
Pawel Zarembski |
0:01f31e923fe2 | 156 | __WEAK uint32_t UART_SWO_Mode (uint32_t enable) { |
Pawel Zarembski |
0:01f31e923fe2 | 157 | int32_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 158 | |
Pawel Zarembski |
0:01f31e923fe2 | 159 | USART_Ready = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 160 | |
Pawel Zarembski |
0:01f31e923fe2 | 161 | if (enable != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 162 | status = pUSART->Initialize(USART_Callback); |
Pawel Zarembski |
0:01f31e923fe2 | 163 | if (status != ARM_DRIVER_OK) { |
Pawel Zarembski |
0:01f31e923fe2 | 164 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 165 | } |
Pawel Zarembski |
0:01f31e923fe2 | 166 | status = pUSART->PowerControl(ARM_POWER_FULL); |
Pawel Zarembski |
0:01f31e923fe2 | 167 | if (status != ARM_DRIVER_OK) { |
Pawel Zarembski |
0:01f31e923fe2 | 168 | pUSART->Uninitialize(); |
Pawel Zarembski |
0:01f31e923fe2 | 169 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 170 | } |
Pawel Zarembski |
0:01f31e923fe2 | 171 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 172 | pUSART->Control(ARM_USART_CONTROL_RX, 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 173 | pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 174 | pUSART->PowerControl(ARM_POWER_OFF); |
Pawel Zarembski |
0:01f31e923fe2 | 175 | pUSART->Uninitialize(); |
Pawel Zarembski |
0:01f31e923fe2 | 176 | } |
Pawel Zarembski |
0:01f31e923fe2 | 177 | return (1U); |
Pawel Zarembski |
0:01f31e923fe2 | 178 | } |
Pawel Zarembski |
0:01f31e923fe2 | 179 | |
Pawel Zarembski |
0:01f31e923fe2 | 180 | // Configure UART SWO Baudrate |
Pawel Zarembski |
0:01f31e923fe2 | 181 | // baudrate: requested baudrate |
Pawel Zarembski |
0:01f31e923fe2 | 182 | // return: actual baudrate or 0 when not configured |
Pawel Zarembski |
0:01f31e923fe2 | 183 | __WEAK uint32_t UART_SWO_Baudrate (uint32_t baudrate) { |
Pawel Zarembski |
0:01f31e923fe2 | 184 | int32_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 185 | uint32_t index; |
Pawel Zarembski |
0:01f31e923fe2 | 186 | uint32_t num; |
Pawel Zarembski |
0:01f31e923fe2 | 187 | |
Pawel Zarembski |
0:01f31e923fe2 | 188 | if (baudrate > SWO_UART_MAX_BAUDRATE) { |
Pawel Zarembski |
0:01f31e923fe2 | 189 | baudrate = SWO_UART_MAX_BAUDRATE; |
Pawel Zarembski |
0:01f31e923fe2 | 190 | } |
Pawel Zarembski |
0:01f31e923fe2 | 191 | |
Pawel Zarembski |
0:01f31e923fe2 | 192 | if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE) { |
Pawel Zarembski |
0:01f31e923fe2 | 193 | pUSART->Control(ARM_USART_CONTROL_RX, 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 194 | if (pUSART->GetStatus().rx_busy) { |
Pawel Zarembski |
0:01f31e923fe2 | 195 | TraceIndexI += pUSART->GetRxCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 196 | pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 197 | } |
Pawel Zarembski |
0:01f31e923fe2 | 198 | } |
Pawel Zarembski |
0:01f31e923fe2 | 199 | |
Pawel Zarembski |
0:01f31e923fe2 | 200 | status = pUSART->Control(ARM_USART_MODE_ASYNCHRONOUS | |
Pawel Zarembski |
0:01f31e923fe2 | 201 | ARM_USART_DATA_BITS_8 | |
Pawel Zarembski |
0:01f31e923fe2 | 202 | ARM_USART_PARITY_NONE | |
Pawel Zarembski |
0:01f31e923fe2 | 203 | ARM_USART_STOP_BITS_1, |
Pawel Zarembski |
0:01f31e923fe2 | 204 | baudrate); |
Pawel Zarembski |
0:01f31e923fe2 | 205 | |
Pawel Zarembski |
0:01f31e923fe2 | 206 | if (status == ARM_DRIVER_OK) { |
Pawel Zarembski |
0:01f31e923fe2 | 207 | USART_Ready = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 208 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 209 | USART_Ready = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 210 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 211 | } |
Pawel Zarembski |
0:01f31e923fe2 | 212 | |
Pawel Zarembski |
0:01f31e923fe2 | 213 | if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE) { |
Pawel Zarembski |
0:01f31e923fe2 | 214 | if ((TraceStatus & DAP_SWO_CAPTURE_PAUSED) == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 215 | index = TraceIndexI & (SWO_BUFFER_SIZE - 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 216 | num = TRACE_BLOCK_SIZE - (index & (TRACE_BLOCK_SIZE - 1U)); |
Pawel Zarembski |
0:01f31e923fe2 | 217 | TraceBlockSize = num; |
Pawel Zarembski |
0:01f31e923fe2 | 218 | pUSART->Receive(&TraceBuf[index], num); |
Pawel Zarembski |
0:01f31e923fe2 | 219 | } |
Pawel Zarembski |
0:01f31e923fe2 | 220 | pUSART->Control(ARM_USART_CONTROL_RX, 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 221 | } |
Pawel Zarembski |
0:01f31e923fe2 | 222 | |
Pawel Zarembski |
0:01f31e923fe2 | 223 | return (baudrate); |
Pawel Zarembski |
0:01f31e923fe2 | 224 | } |
Pawel Zarembski |
0:01f31e923fe2 | 225 | |
Pawel Zarembski |
0:01f31e923fe2 | 226 | // Control UART SWO Capture |
Pawel Zarembski |
0:01f31e923fe2 | 227 | // active: active flag |
Pawel Zarembski |
0:01f31e923fe2 | 228 | // return: 1 - Success, 0 - Error |
Pawel Zarembski |
0:01f31e923fe2 | 229 | __WEAK uint32_t UART_SWO_Control (uint32_t active) { |
Pawel Zarembski |
0:01f31e923fe2 | 230 | int32_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 231 | |
Pawel Zarembski |
0:01f31e923fe2 | 232 | if (active) { |
Pawel Zarembski |
0:01f31e923fe2 | 233 | if (!USART_Ready) { |
Pawel Zarembski |
0:01f31e923fe2 | 234 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 235 | } |
Pawel Zarembski |
0:01f31e923fe2 | 236 | TraceBlockSize = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 237 | status = pUSART->Receive(&TraceBuf[0], 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 238 | if (status != ARM_DRIVER_OK) { |
Pawel Zarembski |
0:01f31e923fe2 | 239 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 240 | } |
Pawel Zarembski |
0:01f31e923fe2 | 241 | status = pUSART->Control(ARM_USART_CONTROL_RX, 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 242 | if (status != ARM_DRIVER_OK) { |
Pawel Zarembski |
0:01f31e923fe2 | 243 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 244 | } |
Pawel Zarembski |
0:01f31e923fe2 | 245 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 246 | pUSART->Control(ARM_USART_CONTROL_RX, 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 247 | if (pUSART->GetStatus().rx_busy) { |
Pawel Zarembski |
0:01f31e923fe2 | 248 | TraceIndexI += pUSART->GetRxCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 249 | pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 250 | } |
Pawel Zarembski |
0:01f31e923fe2 | 251 | } |
Pawel Zarembski |
0:01f31e923fe2 | 252 | return (1U); |
Pawel Zarembski |
0:01f31e923fe2 | 253 | } |
Pawel Zarembski |
0:01f31e923fe2 | 254 | |
Pawel Zarembski |
0:01f31e923fe2 | 255 | // Start UART SWO Capture |
Pawel Zarembski |
0:01f31e923fe2 | 256 | // buf: pointer to buffer for capturing |
Pawel Zarembski |
0:01f31e923fe2 | 257 | // num: number of bytes to capture |
Pawel Zarembski |
0:01f31e923fe2 | 258 | __WEAK void UART_SWO_Capture (uint8_t *buf, uint32_t num) { |
Pawel Zarembski |
0:01f31e923fe2 | 259 | TraceBlockSize = num; |
Pawel Zarembski |
0:01f31e923fe2 | 260 | pUSART->Receive(buf, num); |
Pawel Zarembski |
0:01f31e923fe2 | 261 | } |
Pawel Zarembski |
0:01f31e923fe2 | 262 | |
Pawel Zarembski |
0:01f31e923fe2 | 263 | // Get UART SWO Pending Trace Count |
Pawel Zarembski |
0:01f31e923fe2 | 264 | // return: number of pending trace data bytes |
Pawel Zarembski |
0:01f31e923fe2 | 265 | __WEAK uint32_t UART_SWO_GetCount (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 266 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 267 | |
Pawel Zarembski |
0:01f31e923fe2 | 268 | if (pUSART->GetStatus().rx_busy) { |
Pawel Zarembski |
0:01f31e923fe2 | 269 | count = pUSART->GetRxCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 270 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 271 | count = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 272 | } |
Pawel Zarembski |
0:01f31e923fe2 | 273 | return (count); |
Pawel Zarembski |
0:01f31e923fe2 | 274 | } |
Pawel Zarembski |
0:01f31e923fe2 | 275 | |
Pawel Zarembski |
0:01f31e923fe2 | 276 | #endif /* (SWO_UART != 0) */ |
Pawel Zarembski |
0:01f31e923fe2 | 277 | |
Pawel Zarembski |
0:01f31e923fe2 | 278 | |
Pawel Zarembski |
0:01f31e923fe2 | 279 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 280 | |
Pawel Zarembski |
0:01f31e923fe2 | 281 | // Enable or disable Manchester SWO Mode |
Pawel Zarembski |
0:01f31e923fe2 | 282 | // enable: enable flag |
Pawel Zarembski |
0:01f31e923fe2 | 283 | // return: 1 - Success, 0 - Error |
Pawel Zarembski |
0:01f31e923fe2 | 284 | __WEAK uint32_t Manchester_SWO_Mode (uint32_t enable) { |
Pawel Zarembski |
0:01f31e923fe2 | 285 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 286 | } |
Pawel Zarembski |
0:01f31e923fe2 | 287 | |
Pawel Zarembski |
0:01f31e923fe2 | 288 | // Configure Manchester SWO Baudrate |
Pawel Zarembski |
0:01f31e923fe2 | 289 | // baudrate: requested baudrate |
Pawel Zarembski |
0:01f31e923fe2 | 290 | // return: actual baudrate or 0 when not configured |
Pawel Zarembski |
0:01f31e923fe2 | 291 | __WEAK uint32_t Manchester_SWO_Baudrate (uint32_t baudrate) { |
Pawel Zarembski |
0:01f31e923fe2 | 292 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 293 | } |
Pawel Zarembski |
0:01f31e923fe2 | 294 | |
Pawel Zarembski |
0:01f31e923fe2 | 295 | // Control Manchester SWO Capture |
Pawel Zarembski |
0:01f31e923fe2 | 296 | // active: active flag |
Pawel Zarembski |
0:01f31e923fe2 | 297 | // return: 1 - Success, 0 - Error |
Pawel Zarembski |
0:01f31e923fe2 | 298 | __WEAK uint32_t Manchester_SWO_Control (uint32_t active) { |
Pawel Zarembski |
0:01f31e923fe2 | 299 | return (0U); |
Pawel Zarembski |
0:01f31e923fe2 | 300 | } |
Pawel Zarembski |
0:01f31e923fe2 | 301 | |
Pawel Zarembski |
0:01f31e923fe2 | 302 | // Start Manchester SWO Capture |
Pawel Zarembski |
0:01f31e923fe2 | 303 | // buf: pointer to buffer for capturing |
Pawel Zarembski |
0:01f31e923fe2 | 304 | // num: number of bytes to capture |
Pawel Zarembski |
0:01f31e923fe2 | 305 | __WEAK void Manchester_SWO_Capture (uint8_t *buf, uint32_t num) { |
Pawel Zarembski |
0:01f31e923fe2 | 306 | } |
Pawel Zarembski |
0:01f31e923fe2 | 307 | |
Pawel Zarembski |
0:01f31e923fe2 | 308 | // Get Manchester SWO Pending Trace Count |
Pawel Zarembski |
0:01f31e923fe2 | 309 | // return: number of pending trace data bytes |
Pawel Zarembski |
0:01f31e923fe2 | 310 | __WEAK uint32_t Manchester_SWO_GetCount (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 311 | } |
Pawel Zarembski |
0:01f31e923fe2 | 312 | |
Pawel Zarembski |
0:01f31e923fe2 | 313 | #endif /* (SWO_MANCHESTER != 0) */ |
Pawel Zarembski |
0:01f31e923fe2 | 314 | |
Pawel Zarembski |
0:01f31e923fe2 | 315 | |
Pawel Zarembski |
0:01f31e923fe2 | 316 | // Clear Trace Errors and Data |
Pawel Zarembski |
0:01f31e923fe2 | 317 | static void ClearTrace (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 318 | |
Pawel Zarembski |
0:01f31e923fe2 | 319 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 320 | if (TraceTransport == 2U) { |
Pawel Zarembski |
0:01f31e923fe2 | 321 | if (TransferBusy != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 322 | SWO_AbortTransfer(); |
Pawel Zarembski |
0:01f31e923fe2 | 323 | TransferBusy = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 324 | } |
Pawel Zarembski |
0:01f31e923fe2 | 325 | } |
Pawel Zarembski |
0:01f31e923fe2 | 326 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 327 | |
Pawel Zarembski |
0:01f31e923fe2 | 328 | TraceError[0] = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 329 | TraceError[1] = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 330 | TraceError_n = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 331 | TraceIndexI = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 332 | TraceIndexO = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 333 | |
Pawel Zarembski |
0:01f31e923fe2 | 334 | #if (TIMESTAMP_CLOCK != 0U) |
Pawel Zarembski |
0:01f31e923fe2 | 335 | TraceTimestamp.index = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 336 | TraceTimestamp.tick = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 337 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 338 | } |
Pawel Zarembski |
0:01f31e923fe2 | 339 | |
Pawel Zarembski |
0:01f31e923fe2 | 340 | // Resume Trace Capture |
Pawel Zarembski |
0:01f31e923fe2 | 341 | static void ResumeTrace (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 342 | uint32_t index_i; |
Pawel Zarembski |
0:01f31e923fe2 | 343 | uint32_t index_o; |
Pawel Zarembski |
0:01f31e923fe2 | 344 | |
Pawel Zarembski |
0:01f31e923fe2 | 345 | if (TraceStatus == (DAP_SWO_CAPTURE_ACTIVE | DAP_SWO_CAPTURE_PAUSED)) { |
Pawel Zarembski |
0:01f31e923fe2 | 346 | index_i = TraceIndexI; |
Pawel Zarembski |
0:01f31e923fe2 | 347 | index_o = TraceIndexO; |
Pawel Zarembski |
0:01f31e923fe2 | 348 | if ((index_i - index_o) < SWO_BUFFER_SIZE) { |
Pawel Zarembski |
0:01f31e923fe2 | 349 | index_i &= SWO_BUFFER_SIZE - 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 350 | switch (TraceMode) { |
Pawel Zarembski |
0:01f31e923fe2 | 351 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 352 | case DAP_SWO_UART: |
Pawel Zarembski |
0:01f31e923fe2 | 353 | TraceStatus = DAP_SWO_CAPTURE_ACTIVE; |
Pawel Zarembski |
0:01f31e923fe2 | 354 | UART_SWO_Capture(&TraceBuf[index_i], 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 355 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 356 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 357 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 358 | case DAP_SWO_MANCHESTER: |
Pawel Zarembski |
0:01f31e923fe2 | 359 | TraceStatus = DAP_SWO_CAPTURE_ACTIVE; |
Pawel Zarembski |
0:01f31e923fe2 | 360 | Manchester_SWO_Capture(&TraceBuf[index_i], 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 361 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 362 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 363 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 364 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 365 | } |
Pawel Zarembski |
0:01f31e923fe2 | 366 | } |
Pawel Zarembski |
0:01f31e923fe2 | 367 | } |
Pawel Zarembski |
0:01f31e923fe2 | 368 | } |
Pawel Zarembski |
0:01f31e923fe2 | 369 | |
Pawel Zarembski |
0:01f31e923fe2 | 370 | // Get Trace Count |
Pawel Zarembski |
0:01f31e923fe2 | 371 | // return: number of available data bytes in trace buffer |
Pawel Zarembski |
0:01f31e923fe2 | 372 | static uint32_t GetTraceCount (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 373 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 374 | |
Pawel Zarembski |
0:01f31e923fe2 | 375 | if (TraceStatus == DAP_SWO_CAPTURE_ACTIVE) { |
Pawel Zarembski |
0:01f31e923fe2 | 376 | do { |
Pawel Zarembski |
0:01f31e923fe2 | 377 | TraceUpdate = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 378 | count = TraceIndexI - TraceIndexO; |
Pawel Zarembski |
0:01f31e923fe2 | 379 | switch (TraceMode) { |
Pawel Zarembski |
0:01f31e923fe2 | 380 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 381 | case DAP_SWO_UART: |
Pawel Zarembski |
0:01f31e923fe2 | 382 | count += UART_SWO_GetCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 383 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 384 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 385 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 386 | case DAP_SWO_MANCHESTER: |
Pawel Zarembski |
0:01f31e923fe2 | 387 | count += Manchester_SWO_GetCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 388 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 389 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 390 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 391 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 392 | } |
Pawel Zarembski |
0:01f31e923fe2 | 393 | } while (TraceUpdate != 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 394 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 395 | count = TraceIndexI - TraceIndexO; |
Pawel Zarembski |
0:01f31e923fe2 | 396 | } |
Pawel Zarembski |
0:01f31e923fe2 | 397 | |
Pawel Zarembski |
0:01f31e923fe2 | 398 | return (count); |
Pawel Zarembski |
0:01f31e923fe2 | 399 | } |
Pawel Zarembski |
0:01f31e923fe2 | 400 | |
Pawel Zarembski |
0:01f31e923fe2 | 401 | // Get Trace Status (clear Error flags) |
Pawel Zarembski |
0:01f31e923fe2 | 402 | // return: Trace Status (Active flag and Error flags) |
Pawel Zarembski |
0:01f31e923fe2 | 403 | static uint8_t GetTraceStatus (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 404 | uint8_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 405 | uint32_t n; |
Pawel Zarembski |
0:01f31e923fe2 | 406 | |
Pawel Zarembski |
0:01f31e923fe2 | 407 | n = TraceError_n; |
Pawel Zarembski |
0:01f31e923fe2 | 408 | TraceError_n ^= 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 409 | status = TraceStatus | TraceError[n]; |
Pawel Zarembski |
0:01f31e923fe2 | 410 | TraceError[n] = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 411 | |
Pawel Zarembski |
0:01f31e923fe2 | 412 | return (status); |
Pawel Zarembski |
0:01f31e923fe2 | 413 | } |
Pawel Zarembski |
0:01f31e923fe2 | 414 | |
Pawel Zarembski |
0:01f31e923fe2 | 415 | // Set Trace Error flag(s) |
Pawel Zarembski |
0:01f31e923fe2 | 416 | // flag: error flag(s) to set |
Pawel Zarembski |
0:01f31e923fe2 | 417 | static void SetTraceError (uint8_t flag) { |
Pawel Zarembski |
0:01f31e923fe2 | 418 | TraceError[TraceError_n] |= flag; |
Pawel Zarembski |
0:01f31e923fe2 | 419 | } |
Pawel Zarembski |
0:01f31e923fe2 | 420 | |
Pawel Zarembski |
0:01f31e923fe2 | 421 | |
Pawel Zarembski |
0:01f31e923fe2 | 422 | // Process SWO Transport command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 423 | // request: pointer to request data |
Pawel Zarembski |
0:01f31e923fe2 | 424 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 425 | // return: number of bytes in response (lower 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 426 | // number of bytes in request (upper 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 427 | uint32_t SWO_Transport (const uint8_t *request, uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 428 | uint8_t transport; |
Pawel Zarembski |
0:01f31e923fe2 | 429 | uint32_t result; |
Pawel Zarembski |
0:01f31e923fe2 | 430 | |
Pawel Zarembski |
0:01f31e923fe2 | 431 | if ((TraceStatus & DAP_SWO_CAPTURE_ACTIVE) == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 432 | transport = *request; |
Pawel Zarembski |
0:01f31e923fe2 | 433 | switch (transport) { |
Pawel Zarembski |
0:01f31e923fe2 | 434 | case 0U: |
Pawel Zarembski |
0:01f31e923fe2 | 435 | case 1U: |
Pawel Zarembski |
0:01f31e923fe2 | 436 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 437 | case 2U: |
Pawel Zarembski |
0:01f31e923fe2 | 438 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 439 | TraceTransport = transport; |
Pawel Zarembski |
0:01f31e923fe2 | 440 | result = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 441 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 442 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 443 | result = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 444 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 445 | } |
Pawel Zarembski |
0:01f31e923fe2 | 446 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 447 | result = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 448 | } |
Pawel Zarembski |
0:01f31e923fe2 | 449 | |
Pawel Zarembski |
0:01f31e923fe2 | 450 | if (result != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 451 | *response = DAP_OK; |
Pawel Zarembski |
0:01f31e923fe2 | 452 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 453 | *response = DAP_ERROR; |
Pawel Zarembski |
0:01f31e923fe2 | 454 | } |
Pawel Zarembski |
0:01f31e923fe2 | 455 | |
Pawel Zarembski |
0:01f31e923fe2 | 456 | return ((1U << 16) | 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 457 | } |
Pawel Zarembski |
0:01f31e923fe2 | 458 | |
Pawel Zarembski |
0:01f31e923fe2 | 459 | |
Pawel Zarembski |
0:01f31e923fe2 | 460 | // Process SWO Mode command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 461 | // request: pointer to request data |
Pawel Zarembski |
0:01f31e923fe2 | 462 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 463 | // return: number of bytes in response (lower 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 464 | // number of bytes in request (upper 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 465 | uint32_t SWO_Mode (const uint8_t *request, uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 466 | uint8_t mode; |
Pawel Zarembski |
0:01f31e923fe2 | 467 | uint32_t result; |
Pawel Zarembski |
0:01f31e923fe2 | 468 | |
Pawel Zarembski |
0:01f31e923fe2 | 469 | mode = *request; |
Pawel Zarembski |
0:01f31e923fe2 | 470 | |
Pawel Zarembski |
0:01f31e923fe2 | 471 | switch (TraceMode) { |
Pawel Zarembski |
0:01f31e923fe2 | 472 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 473 | case DAP_SWO_UART: |
Pawel Zarembski |
0:01f31e923fe2 | 474 | UART_SWO_Mode(0U); |
Pawel Zarembski |
0:01f31e923fe2 | 475 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 476 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 477 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 478 | case DAP_SWO_MANCHESTER: |
Pawel Zarembski |
0:01f31e923fe2 | 479 | Manchester_SWO_Mode(0U); |
Pawel Zarembski |
0:01f31e923fe2 | 480 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 481 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 482 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 483 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 484 | } |
Pawel Zarembski |
0:01f31e923fe2 | 485 | |
Pawel Zarembski |
0:01f31e923fe2 | 486 | switch (mode) { |
Pawel Zarembski |
0:01f31e923fe2 | 487 | case DAP_SWO_OFF: |
Pawel Zarembski |
0:01f31e923fe2 | 488 | result = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 489 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 490 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 491 | case DAP_SWO_UART: |
Pawel Zarembski |
0:01f31e923fe2 | 492 | result = UART_SWO_Mode(1U); |
Pawel Zarembski |
0:01f31e923fe2 | 493 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 494 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 495 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 496 | case DAP_SWO_MANCHESTER: |
Pawel Zarembski |
0:01f31e923fe2 | 497 | result = Manchester_SWO_Mode(1U); |
Pawel Zarembski |
0:01f31e923fe2 | 498 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 499 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 500 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 501 | result = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 502 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 503 | } |
Pawel Zarembski |
0:01f31e923fe2 | 504 | if (result != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 505 | TraceMode = mode; |
Pawel Zarembski |
0:01f31e923fe2 | 506 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 507 | TraceMode = DAP_SWO_OFF; |
Pawel Zarembski |
0:01f31e923fe2 | 508 | } |
Pawel Zarembski |
0:01f31e923fe2 | 509 | |
Pawel Zarembski |
0:01f31e923fe2 | 510 | TraceStatus = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 511 | |
Pawel Zarembski |
0:01f31e923fe2 | 512 | if (result != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 513 | *response = DAP_OK; |
Pawel Zarembski |
0:01f31e923fe2 | 514 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 515 | *response = DAP_ERROR; |
Pawel Zarembski |
0:01f31e923fe2 | 516 | } |
Pawel Zarembski |
0:01f31e923fe2 | 517 | |
Pawel Zarembski |
0:01f31e923fe2 | 518 | return ((1U << 16) | 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 519 | } |
Pawel Zarembski |
0:01f31e923fe2 | 520 | |
Pawel Zarembski |
0:01f31e923fe2 | 521 | |
Pawel Zarembski |
0:01f31e923fe2 | 522 | // Process SWO Baudrate command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 523 | // request: pointer to request data |
Pawel Zarembski |
0:01f31e923fe2 | 524 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 525 | // return: number of bytes in response (lower 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 526 | // number of bytes in request (upper 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 527 | uint32_t SWO_Baudrate (const uint8_t *request, uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 528 | uint32_t baudrate; |
Pawel Zarembski |
0:01f31e923fe2 | 529 | |
Pawel Zarembski |
0:01f31e923fe2 | 530 | baudrate = (uint32_t)(*(request+0) << 0) | |
Pawel Zarembski |
0:01f31e923fe2 | 531 | (uint32_t)(*(request+1) << 8) | |
Pawel Zarembski |
0:01f31e923fe2 | 532 | (uint32_t)(*(request+2) << 16) | |
Pawel Zarembski |
0:01f31e923fe2 | 533 | (uint32_t)(*(request+3) << 24); |
Pawel Zarembski |
0:01f31e923fe2 | 534 | |
Pawel Zarembski |
0:01f31e923fe2 | 535 | switch (TraceMode) { |
Pawel Zarembski |
0:01f31e923fe2 | 536 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 537 | case DAP_SWO_UART: |
Pawel Zarembski |
0:01f31e923fe2 | 538 | baudrate = UART_SWO_Baudrate(baudrate); |
Pawel Zarembski |
0:01f31e923fe2 | 539 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 540 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 541 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 542 | case DAP_SWO_MANCHESTER: |
Pawel Zarembski |
0:01f31e923fe2 | 543 | baudrate = Manchester_SWO_Baudrate(baudrate); |
Pawel Zarembski |
0:01f31e923fe2 | 544 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 545 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 546 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 547 | baudrate = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 548 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 549 | } |
Pawel Zarembski |
0:01f31e923fe2 | 550 | |
Pawel Zarembski |
0:01f31e923fe2 | 551 | if (baudrate == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 552 | TraceStatus = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 553 | } |
Pawel Zarembski |
0:01f31e923fe2 | 554 | |
Pawel Zarembski |
0:01f31e923fe2 | 555 | *response++ = (uint8_t)(baudrate >> 0); |
Pawel Zarembski |
0:01f31e923fe2 | 556 | *response++ = (uint8_t)(baudrate >> 8); |
Pawel Zarembski |
0:01f31e923fe2 | 557 | *response++ = (uint8_t)(baudrate >> 16); |
Pawel Zarembski |
0:01f31e923fe2 | 558 | *response = (uint8_t)(baudrate >> 24); |
Pawel Zarembski |
0:01f31e923fe2 | 559 | |
Pawel Zarembski |
0:01f31e923fe2 | 560 | return ((4U << 16) | 4U); |
Pawel Zarembski |
0:01f31e923fe2 | 561 | } |
Pawel Zarembski |
0:01f31e923fe2 | 562 | |
Pawel Zarembski |
0:01f31e923fe2 | 563 | |
Pawel Zarembski |
0:01f31e923fe2 | 564 | // Process SWO Control command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 565 | // request: pointer to request data |
Pawel Zarembski |
0:01f31e923fe2 | 566 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 567 | // return: number of bytes in response (lower 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 568 | // number of bytes in request (upper 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 569 | uint32_t SWO_Control (const uint8_t *request, uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 570 | uint8_t active; |
Pawel Zarembski |
0:01f31e923fe2 | 571 | uint32_t result; |
Pawel Zarembski |
0:01f31e923fe2 | 572 | |
Pawel Zarembski |
0:01f31e923fe2 | 573 | active = *request & DAP_SWO_CAPTURE_ACTIVE; |
Pawel Zarembski |
0:01f31e923fe2 | 574 | |
Pawel Zarembski |
0:01f31e923fe2 | 575 | if (active != (TraceStatus & DAP_SWO_CAPTURE_ACTIVE)) { |
Pawel Zarembski |
0:01f31e923fe2 | 576 | if (active) { |
Pawel Zarembski |
0:01f31e923fe2 | 577 | ClearTrace(); |
Pawel Zarembski |
0:01f31e923fe2 | 578 | } |
Pawel Zarembski |
0:01f31e923fe2 | 579 | switch (TraceMode) { |
Pawel Zarembski |
0:01f31e923fe2 | 580 | #if (SWO_UART != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 581 | case DAP_SWO_UART: |
Pawel Zarembski |
0:01f31e923fe2 | 582 | result = UART_SWO_Control(active); |
Pawel Zarembski |
0:01f31e923fe2 | 583 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 584 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 585 | #if (SWO_MANCHESTER != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 586 | case DAP_SWO_MANCHESTER: |
Pawel Zarembski |
0:01f31e923fe2 | 587 | result = Manchester_SWO_Control(active); |
Pawel Zarembski |
0:01f31e923fe2 | 588 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 589 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 590 | default: |
Pawel Zarembski |
0:01f31e923fe2 | 591 | result = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 592 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 593 | } |
Pawel Zarembski |
0:01f31e923fe2 | 594 | if (result != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 595 | TraceStatus = active; |
Pawel Zarembski |
0:01f31e923fe2 | 596 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 597 | if (TraceTransport == 2U) { |
Pawel Zarembski |
0:01f31e923fe2 | 598 | osThreadFlagsSet(SWO_ThreadId, 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 599 | } |
Pawel Zarembski |
0:01f31e923fe2 | 600 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 601 | } |
Pawel Zarembski |
0:01f31e923fe2 | 602 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 603 | result = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 604 | } |
Pawel Zarembski |
0:01f31e923fe2 | 605 | |
Pawel Zarembski |
0:01f31e923fe2 | 606 | if (result != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 607 | *response = DAP_OK; |
Pawel Zarembski |
0:01f31e923fe2 | 608 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 609 | *response = DAP_ERROR; |
Pawel Zarembski |
0:01f31e923fe2 | 610 | } |
Pawel Zarembski |
0:01f31e923fe2 | 611 | |
Pawel Zarembski |
0:01f31e923fe2 | 612 | return ((1U << 16) | 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 613 | } |
Pawel Zarembski |
0:01f31e923fe2 | 614 | |
Pawel Zarembski |
0:01f31e923fe2 | 615 | |
Pawel Zarembski |
0:01f31e923fe2 | 616 | // Process SWO Status command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 617 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 618 | // return: number of bytes in response |
Pawel Zarembski |
0:01f31e923fe2 | 619 | uint32_t SWO_Status (uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 620 | uint8_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 621 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 622 | |
Pawel Zarembski |
0:01f31e923fe2 | 623 | status = GetTraceStatus(); |
Pawel Zarembski |
0:01f31e923fe2 | 624 | count = GetTraceCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 625 | |
Pawel Zarembski |
0:01f31e923fe2 | 626 | *response++ = status; |
Pawel Zarembski |
0:01f31e923fe2 | 627 | *response++ = (uint8_t)(count >> 0); |
Pawel Zarembski |
0:01f31e923fe2 | 628 | *response++ = (uint8_t)(count >> 8); |
Pawel Zarembski |
0:01f31e923fe2 | 629 | *response++ = (uint8_t)(count >> 16); |
Pawel Zarembski |
0:01f31e923fe2 | 630 | *response = (uint8_t)(count >> 24); |
Pawel Zarembski |
0:01f31e923fe2 | 631 | |
Pawel Zarembski |
0:01f31e923fe2 | 632 | return (5U); |
Pawel Zarembski |
0:01f31e923fe2 | 633 | } |
Pawel Zarembski |
0:01f31e923fe2 | 634 | |
Pawel Zarembski |
0:01f31e923fe2 | 635 | |
Pawel Zarembski |
0:01f31e923fe2 | 636 | // Process SWO Extended Status command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 637 | // request: pointer to request data |
Pawel Zarembski |
0:01f31e923fe2 | 638 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 639 | // return: number of bytes in response (lower 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 640 | // number of bytes in request (upper 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 641 | uint32_t SWO_ExtendedStatus (const uint8_t *request, uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 642 | uint8_t cmd; |
Pawel Zarembski |
0:01f31e923fe2 | 643 | uint8_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 644 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 645 | #if (TIMESTAMP_CLOCK != 0U) |
Pawel Zarembski |
0:01f31e923fe2 | 646 | uint32_t index; |
Pawel Zarembski |
0:01f31e923fe2 | 647 | uint32_t tick; |
Pawel Zarembski |
0:01f31e923fe2 | 648 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 649 | uint32_t num; |
Pawel Zarembski |
0:01f31e923fe2 | 650 | |
Pawel Zarembski |
0:01f31e923fe2 | 651 | num = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 652 | cmd = *request; |
Pawel Zarembski |
0:01f31e923fe2 | 653 | |
Pawel Zarembski |
0:01f31e923fe2 | 654 | if (cmd & 0x01U) { |
Pawel Zarembski |
0:01f31e923fe2 | 655 | status = GetTraceStatus(); |
Pawel Zarembski |
0:01f31e923fe2 | 656 | *response++ = status; |
Pawel Zarembski |
0:01f31e923fe2 | 657 | num += 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 658 | } |
Pawel Zarembski |
0:01f31e923fe2 | 659 | |
Pawel Zarembski |
0:01f31e923fe2 | 660 | if (cmd & 0x02U) { |
Pawel Zarembski |
0:01f31e923fe2 | 661 | count = GetTraceCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 662 | *response++ = (uint8_t)(count >> 0); |
Pawel Zarembski |
0:01f31e923fe2 | 663 | *response++ = (uint8_t)(count >> 8); |
Pawel Zarembski |
0:01f31e923fe2 | 664 | *response++ = (uint8_t)(count >> 16); |
Pawel Zarembski |
0:01f31e923fe2 | 665 | *response++ = (uint8_t)(count >> 24); |
Pawel Zarembski |
0:01f31e923fe2 | 666 | num += 4U; |
Pawel Zarembski |
0:01f31e923fe2 | 667 | } |
Pawel Zarembski |
0:01f31e923fe2 | 668 | |
Pawel Zarembski |
0:01f31e923fe2 | 669 | #if (TIMESTAMP_CLOCK != 0U) |
Pawel Zarembski |
0:01f31e923fe2 | 670 | if (cmd & 0x04U) { |
Pawel Zarembski |
0:01f31e923fe2 | 671 | do { |
Pawel Zarembski |
0:01f31e923fe2 | 672 | TraceUpdate = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 673 | index = TraceTimestamp.index; |
Pawel Zarembski |
0:01f31e923fe2 | 674 | tick = TraceTimestamp.tick; |
Pawel Zarembski |
0:01f31e923fe2 | 675 | } while (TraceUpdate != 0U); |
Pawel Zarembski |
0:01f31e923fe2 | 676 | *response++ = (uint8_t)(index >> 0); |
Pawel Zarembski |
0:01f31e923fe2 | 677 | *response++ = (uint8_t)(index >> 8); |
Pawel Zarembski |
0:01f31e923fe2 | 678 | *response++ = (uint8_t)(index >> 16); |
Pawel Zarembski |
0:01f31e923fe2 | 679 | *response++ = (uint8_t)(index >> 24); |
Pawel Zarembski |
0:01f31e923fe2 | 680 | *response++ = (uint8_t)(tick >> 0); |
Pawel Zarembski |
0:01f31e923fe2 | 681 | *response++ = (uint8_t)(tick >> 8); |
Pawel Zarembski |
0:01f31e923fe2 | 682 | *response++ = (uint8_t)(tick >> 16); |
Pawel Zarembski |
0:01f31e923fe2 | 683 | *response++ = (uint8_t)(tick >> 24); |
Pawel Zarembski |
0:01f31e923fe2 | 684 | num += 4U; |
Pawel Zarembski |
0:01f31e923fe2 | 685 | } |
Pawel Zarembski |
0:01f31e923fe2 | 686 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 687 | |
Pawel Zarembski |
0:01f31e923fe2 | 688 | return ((1U << 16) | num); |
Pawel Zarembski |
0:01f31e923fe2 | 689 | } |
Pawel Zarembski |
0:01f31e923fe2 | 690 | |
Pawel Zarembski |
0:01f31e923fe2 | 691 | |
Pawel Zarembski |
0:01f31e923fe2 | 692 | // Process SWO Data command and prepare response |
Pawel Zarembski |
0:01f31e923fe2 | 693 | // request: pointer to request data |
Pawel Zarembski |
0:01f31e923fe2 | 694 | // response: pointer to response data |
Pawel Zarembski |
0:01f31e923fe2 | 695 | // return: number of bytes in response (lower 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 696 | // number of bytes in request (upper 16 bits) |
Pawel Zarembski |
0:01f31e923fe2 | 697 | uint32_t SWO_Data (const uint8_t *request, uint8_t *response) { |
Pawel Zarembski |
0:01f31e923fe2 | 698 | uint8_t status; |
Pawel Zarembski |
0:01f31e923fe2 | 699 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 700 | uint32_t index; |
Pawel Zarembski |
0:01f31e923fe2 | 701 | uint32_t n, i; |
Pawel Zarembski |
0:01f31e923fe2 | 702 | |
Pawel Zarembski |
0:01f31e923fe2 | 703 | status = GetTraceStatus(); |
Pawel Zarembski |
0:01f31e923fe2 | 704 | count = GetTraceCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 705 | |
Pawel Zarembski |
0:01f31e923fe2 | 706 | if (TraceTransport == 1U) { |
Pawel Zarembski |
0:01f31e923fe2 | 707 | n = (uint32_t)(*(request+0) << 0) | |
Pawel Zarembski |
0:01f31e923fe2 | 708 | (uint32_t)(*(request+1) << 8); |
Pawel Zarembski |
0:01f31e923fe2 | 709 | if (n > (DAP_PACKET_SIZE - 4U)) { |
Pawel Zarembski |
0:01f31e923fe2 | 710 | n = DAP_PACKET_SIZE - 4U; |
Pawel Zarembski |
0:01f31e923fe2 | 711 | } |
Pawel Zarembski |
0:01f31e923fe2 | 712 | if (count > n) { |
Pawel Zarembski |
0:01f31e923fe2 | 713 | count = n; |
Pawel Zarembski |
0:01f31e923fe2 | 714 | } |
Pawel Zarembski |
0:01f31e923fe2 | 715 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 716 | count = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 717 | } |
Pawel Zarembski |
0:01f31e923fe2 | 718 | |
Pawel Zarembski |
0:01f31e923fe2 | 719 | *response++ = status; |
Pawel Zarembski |
0:01f31e923fe2 | 720 | *response++ = (uint8_t)(count >> 0); |
Pawel Zarembski |
0:01f31e923fe2 | 721 | *response++ = (uint8_t)(count >> 8); |
Pawel Zarembski |
0:01f31e923fe2 | 722 | |
Pawel Zarembski |
0:01f31e923fe2 | 723 | if (TraceTransport == 1U) { |
Pawel Zarembski |
0:01f31e923fe2 | 724 | index = TraceIndexO; |
Pawel Zarembski |
0:01f31e923fe2 | 725 | for (i = index, n = count; n; n--) { |
Pawel Zarembski |
0:01f31e923fe2 | 726 | i &= SWO_BUFFER_SIZE - 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 727 | *response++ = TraceBuf[i++]; |
Pawel Zarembski |
0:01f31e923fe2 | 728 | } |
Pawel Zarembski |
0:01f31e923fe2 | 729 | TraceIndexO = index + count; |
Pawel Zarembski |
0:01f31e923fe2 | 730 | ResumeTrace(); |
Pawel Zarembski |
0:01f31e923fe2 | 731 | } |
Pawel Zarembski |
0:01f31e923fe2 | 732 | |
Pawel Zarembski |
0:01f31e923fe2 | 733 | return ((2U << 16) | (3U + count)); |
Pawel Zarembski |
0:01f31e923fe2 | 734 | } |
Pawel Zarembski |
0:01f31e923fe2 | 735 | |
Pawel Zarembski |
0:01f31e923fe2 | 736 | |
Pawel Zarembski |
0:01f31e923fe2 | 737 | #if (SWO_STREAM != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 738 | |
Pawel Zarembski |
0:01f31e923fe2 | 739 | // SWO Data Transfer complete callback |
Pawel Zarembski |
0:01f31e923fe2 | 740 | void SWO_TransferComplete (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 741 | TraceIndexO += TransferSize; |
Pawel Zarembski |
0:01f31e923fe2 | 742 | TransferBusy = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 743 | ResumeTrace(); |
Pawel Zarembski |
0:01f31e923fe2 | 744 | osThreadFlagsSet(SWO_ThreadId, 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 745 | } |
Pawel Zarembski |
0:01f31e923fe2 | 746 | |
Pawel Zarembski |
0:01f31e923fe2 | 747 | // SWO Thread |
Pawel Zarembski |
0:01f31e923fe2 | 748 | __NO_RETURN void SWO_Thread (void *argument) { |
Pawel Zarembski |
0:01f31e923fe2 | 749 | uint32_t timeout; |
Pawel Zarembski |
0:01f31e923fe2 | 750 | uint32_t flags; |
Pawel Zarembski |
0:01f31e923fe2 | 751 | uint32_t count; |
Pawel Zarembski |
0:01f31e923fe2 | 752 | uint32_t index; |
Pawel Zarembski |
0:01f31e923fe2 | 753 | uint32_t i, n; |
Pawel Zarembski |
0:01f31e923fe2 | 754 | (void) argument; |
Pawel Zarembski |
0:01f31e923fe2 | 755 | |
Pawel Zarembski |
0:01f31e923fe2 | 756 | timeout = osWaitForever; |
Pawel Zarembski |
0:01f31e923fe2 | 757 | |
Pawel Zarembski |
0:01f31e923fe2 | 758 | for (;;) { |
Pawel Zarembski |
0:01f31e923fe2 | 759 | flags = osThreadFlagsWait(1U, osFlagsWaitAny, timeout); |
Pawel Zarembski |
0:01f31e923fe2 | 760 | if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE) { |
Pawel Zarembski |
0:01f31e923fe2 | 761 | timeout = SWO_STREAM_TIMEOUT; |
Pawel Zarembski |
0:01f31e923fe2 | 762 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 763 | timeout = osWaitForever; |
Pawel Zarembski |
0:01f31e923fe2 | 764 | flags = osFlagsErrorTimeout; |
Pawel Zarembski |
0:01f31e923fe2 | 765 | } |
Pawel Zarembski |
0:01f31e923fe2 | 766 | if (TransferBusy == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 767 | count = GetTraceCount(); |
Pawel Zarembski |
0:01f31e923fe2 | 768 | if (count != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 769 | index = TraceIndexO & (SWO_BUFFER_SIZE - 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 770 | n = SWO_BUFFER_SIZE - index; |
Pawel Zarembski |
0:01f31e923fe2 | 771 | if (count > n) { |
Pawel Zarembski |
0:01f31e923fe2 | 772 | count = n; |
Pawel Zarembski |
0:01f31e923fe2 | 773 | } |
Pawel Zarembski |
0:01f31e923fe2 | 774 | if (flags != osFlagsErrorTimeout) { |
Pawel Zarembski |
0:01f31e923fe2 | 775 | i = index & (USB_BLOCK_SIZE - 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 776 | if (i == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 777 | count &= ~(USB_BLOCK_SIZE - 1U); |
Pawel Zarembski |
0:01f31e923fe2 | 778 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 779 | n = USB_BLOCK_SIZE - i; |
Pawel Zarembski |
0:01f31e923fe2 | 780 | if (count >= n) { |
Pawel Zarembski |
0:01f31e923fe2 | 781 | count = n; |
Pawel Zarembski |
0:01f31e923fe2 | 782 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 783 | count = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 784 | } |
Pawel Zarembski |
0:01f31e923fe2 | 785 | } |
Pawel Zarembski |
0:01f31e923fe2 | 786 | } |
Pawel Zarembski |
0:01f31e923fe2 | 787 | if (count != 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 788 | TransferSize = count; |
Pawel Zarembski |
0:01f31e923fe2 | 789 | TransferBusy = 1U; |
Pawel Zarembski |
0:01f31e923fe2 | 790 | SWO_QueueTransfer(&TraceBuf[index], count); |
Pawel Zarembski |
0:01f31e923fe2 | 791 | } |
Pawel Zarembski |
0:01f31e923fe2 | 792 | } |
Pawel Zarembski |
0:01f31e923fe2 | 793 | } |
Pawel Zarembski |
0:01f31e923fe2 | 794 | } |
Pawel Zarembski |
0:01f31e923fe2 | 795 | } |
Pawel Zarembski |
0:01f31e923fe2 | 796 | |
Pawel Zarembski |
0:01f31e923fe2 | 797 | #endif /* (SWO_STREAM != 0) */ |
Pawel Zarembski |
0:01f31e923fe2 | 798 | |
Pawel Zarembski |
0:01f31e923fe2 | 799 | |
Pawel Zarembski |
0:01f31e923fe2 | 800 | #endif /* ((SWO_UART != 0) || (SWO_MANCHESTER != 0)) */ |