Skip to content

Commit 3faacd3

Browse files
committed
[VirtIO] Add logging support for core_debug()
1 parent 662d591 commit 3faacd3

File tree

10 files changed

+119
-256
lines changed

10 files changed

+119
-256
lines changed

cores/arduino/Print.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
#include "Print.h"
3030

31+
#if defined (VIRTIO_LOG)
32+
#include "virtio_log.h"
33+
#endif
34+
3135
// Public Methods //////////////////////////////////////////////////////////////
3236

3337
/* default implementation: may be overridden */
@@ -203,10 +207,13 @@ extern "C" {
203207
switch (file) {
204208
case STDOUT_FILENO:
205209
case STDERR_FILENO:
206-
#if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
207210
/* Used for core_debug() */
211+
#if defined (VIRTIO_LOG)
212+
virtio_log((uint8_t *)ptr, (uint32_t)len);
213+
#elif defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
208214
uart_debug_write((uint8_t *)ptr, (uint32_t)len);
209215
#endif
216+
break;
210217
case STDIN_FILENO:
211218
break;
212219
default:

cores/arduino/VirtIOSerial.h

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#if defined (VIRTIOCON)
2828
#include "Stream.h"
2929
#include "openamp.h"
30-
#include "openamp_log.h"
3130
#include "wiring.h"
3231
#include "virtio_buffer.h"
3332

cores/arduino/stm32/OpenAMP/openamp_conf.h

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
extern "C" {
2828
#endif
2929

30-
/* Includes ------------------------------------------------------------------*/
31-
#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_)
32-
#include "openamp_log.h"
33-
#endif
3430
/**
3531
* Note: Do not remove this. Removing this might not trigger compile error but
3632
* the configuration can be significantly different.

cores/arduino/stm32/OpenAMP/openamp_log.c

-104
This file was deleted.

cores/arduino/stm32/OpenAMP/openamp_log.h

-138
This file was deleted.

cores/arduino/stm32/OpenAMP/rsc_table.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
/* VirtIO rpmsg device id */
3232
#define VIRTIO_ID_RPMSG 7
3333

34-
#if defined (__LOG_TRACE_IO_)
35-
extern char system_log_buf[];
34+
#if defined (VIRTIO_LOG)
35+
extern char virtio_log_buffer[];
3636
#endif
3737

3838
const struct shared_resource_table __attribute__((__section__(".resource_table"))) __attribute__((used)) resource_table = {
3939
.version = 1,
40-
#if defined (__LOG_TRACE_IO_)
40+
#if defined (VIRTIO_LOG)
4141
.num = 2,
4242
#else
4343
.num = 1,
@@ -74,13 +74,13 @@ const struct shared_resource_table __attribute__((__section__(".resource_table")
7474
.notifyid = VRING1_ID,
7575
.reserved = 0
7676
},
77-
#if defined (__LOG_TRACE_IO_)
77+
#if defined (VIRTIO_LOG)
7878
.cm_trace = {
7979
.type = RSC_TRACE,
80-
.da = (uint32_t)system_log_buf,
81-
.len = SYSTEM_TRACE_BUF_SZ,
80+
.da = (uint32_t)virtio_log_buffer,
81+
.len = VIRTIO_LOG_BUFFER_SIZE,
8282
.reserved = 0,
83-
.name = "arduino_core_debug",
83+
.name = "arduino_log",
8484
},
8585
#endif
8686
} ;

cores/arduino/stm32/OpenAMP/virtio_config.h

+11
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@
2828
#endif
2929
#define RPMSG_VRING_TOTAL_PAYLOAD_SIZE (RPMSG_VRING_PAYLOAD_SIZE * VRING_NUM_BUFFS)
3030

31+
#if defined (VIRTIO_LOG)
32+
/**
33+
* OpenAMP trace (log) buffer configuration.
34+
* Users are free to redefine the size if needed.
35+
*/
36+
#ifndef VIRTIO_LOG_BUFFER_SIZE
37+
#define VIRTIO_LOG_BUFFER_SIZE (2048)
38+
#endif
39+
40+
#endif
41+
3142
#endif // __OPENAMP_VIRTIO_CONFIG_H
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* MIT License:
3+
* Copyright (c) 2020 Bumsik kim <[email protected]>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
#if defined(VIRTIOCON) && defined(VIRTIO_LOG)
24+
25+
#include "virtio_config.h"
26+
#include "virtio_log.h"
27+
28+
char virtio_log_buffer[VIRTIO_LOG_BUFFER_SIZE];
29+
30+
void virtio_log(uint8_t *data, uint32_t size)
31+
{
32+
static int offset = 0;
33+
34+
for (uint32_t i = 0; i < size; i++) {
35+
virtio_log_buffer[offset++] = *(data + i);
36+
if ((offset + 1) >= VIRTIO_LOG_BUFFER_SIZE) {
37+
offset = 0;
38+
}
39+
}
40+
virtio_log_buffer[offset] = '\0';
41+
}
42+
43+
#endif

0 commit comments

Comments
 (0)