Skip to content

Commit 75fd9ca

Browse files
committed
Move log_buff() to virtio_log.c and set a proper name for _LOG_TRACE_IO_
1 parent 4be970c commit 75fd9ca

File tree

6 files changed

+115
-40
lines changed

6 files changed

+115
-40
lines changed

cores/arduino/Print.cpp

Lines changed: 6 additions & 28 deletions
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 */
@@ -197,41 +201,15 @@ size_t Print::println(const Printable &x)
197201
}
198202

199203
extern "C" {
200-
#if defined (__LOG_TRACE_IO_)
201-
/**
202-
* By writing OpenAMP trace (log) buffer here, the Linux host can access
203-
* to the content by the following command:
204-
* $ cat /sys/kernel/debug/remoteproc/remoteproc0/trace0
205-
* Ceveats - When the buffer overflows (2kb), the buffer is cleaned by
206-
* a null character. 2kb will be enough for core_debug() logging.
207-
*/
208-
#include "virtio_config.h"
209-
210-
char system_log_buf[SYSTEM_TRACE_BUF_SZ];
211-
212-
void log_buff(uint8_t *data, uint32_t size)
213-
{
214-
static int offset = 0;
215-
216-
for (uint32_t i = 0; i < size; i++) {
217-
system_log_buf[offset++] = *(data + i);
218-
if ((offset + 1) >= SYSTEM_TRACE_BUF_SZ) {
219-
offset = 0;
220-
}
221-
}
222-
system_log_buf[offset] = '\0';
223-
}
224-
#endif
225-
226204
__attribute__((weak))
227205
int _write(int file, char *ptr, int len)
228206
{
229207
switch (file) {
230208
case STDOUT_FILENO:
231209
case STDERR_FILENO:
232210
/* Used for core_debug() */
233-
#if defined (__LOG_TRACE_IO_)
234-
log_buff((uint8_t *)ptr, (uint32_t)len);
211+
#if defined (VIRTIO_LOG)
212+
virtio_log((uint8_t *)ptr, (uint32_t)len);
235213
#elif defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
236214
uart_debug_write((uint8_t *)ptr, (uint32_t)len);
237215
#endif

cores/arduino/stm32/OpenAMP/rsc_table.c

Lines changed: 7 additions & 7 deletions
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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
#define VRING_NUM_BUFFS 16
2424
#define RPMSG_VRING_TOTAL_PAYLOAD_SIZE (RPMSG_VRING_PAYLOAD_SIZE * VRING_NUM_BUFFS)
2525

26-
#if defined (__LOG_TRACE_IO_)
27-
// OpenAMP trace (log) buffer configuration. See rsc_table.c and Print.cpp
28-
#define SYSTEM_TRACE_BUF_SZ 2048
29-
extern char system_log_buf[SYSTEM_TRACE_BUF_SZ]; /*!< buffer for debug traces */
26+
#if defined (VIRTIO_LOG)
27+
/**
28+
* OpenAMP trace (log) buffer configuration.
29+
* Users are free to redefine the size if needed.
30+
*/
31+
#ifndef VIRTIO_LOG_BUFFER_SIZE
32+
#define VIRTIO_LOG_BUFFER_SIZE (2048)
33+
#endif
34+
3035
#endif
3136

3237
#endif // __VIRTIO_CONFIG_H
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* MIT License:
3+
* Copyright (c) 2020 Bumsik kim <k.bumsik@gmail.com>
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
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* MIT License:
3+
* Copyright (c) 2020 Bumsik kim <k.bumsik@gmail.com>
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+
#ifndef __VIRTIO_LOG_H
24+
#define __VIRTIO_LOG_H
25+
26+
#include <stdint.h>
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
/**
33+
* @brief Write data to the OpenAMP trace buffer
34+
* @note By writing OpenAMP trace (log) buffer here, the Linux host can access
35+
* to the content by the following command:
36+
* $ cat /sys/kernel/debug/remoteproc/remoteproc0/trace0
37+
* @note When the buffer overflows (2kb by default, configurable.),
38+
* the buffer is cleaned by a null character. Consider increasing
39+
* VIRTIO_LOG_BUFFER_SIZE if a larger log buffer is needed.
40+
* @param data: Data to send
41+
* @param size: size of data
42+
*/
43+
void virtio_log(uint8_t *data, uint32_t size);
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif // __VIRTIO_LOG_H

platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ build.pid=0
8585
# that the preprocessor cannot detect.
8686

8787
# VirtIO RPMsg Serial Flags
88-
build.virtio_flags=-DVIRTIOCON -DHAL_IPCC_MODULE_ENABLED -DNO_ATOMIC_64_SUPPORT -DMETAL_INTERNAL -DMETAL_MAX_DEVICE_REGIONS=2 -DVIRTIO_SLAVE_ONLY -D__LOG_TRACE_IO_
88+
build.virtio_flags=-DVIRTIOCON -DHAL_IPCC_MODULE_ENABLED -DNO_ATOMIC_64_SUPPORT -DMETAL_INTERNAL -DMETAL_MAX_DEVICE_REGIONS=2 -DVIRTIO_SLAVE_ONLY -DVIRTIO_LOG
8989
build.virtio_extra_include="-I{build.system.path}/Middlewares/OpenAMP" "-I{build.system.path}/Middlewares/OpenAMP/open-amp/lib/include" "-I{build.system.path}/Middlewares/OpenAMP/libmetal/lib/include" "-I{build.system.path}/Middlewares/OpenAMP/virtual_driver"
9090

9191
# Build information's

0 commit comments

Comments
 (0)