RISCV LOG SAVING FUNCTION USER GUIDE

1. OVERVIEW

RISCV RTOS terminal supports two input and output modes:

  • Input and output terminal information through uart communication
  • Relocate RTOS terminal input and output to Linux terminal through the shared memory

Currently, RTOS terminal uses uart communication as input and output by default. This article mainly introduces how to enable the second input and output method described above.

2. RTOS USAGE INTRODUCTION

2.1. CONFIG Configuration

Modify the CONFIG_CONSOLE_OUTPUT_MODE configuration in the mak/options_chipname_riscv_isw.mak config file to BUFFER_MODE:

# Feature_Name = [SYS] Select defaule console output mode
# Description = Select default console output mode
# Option_Selection = DIRECT_MODE, BUFFER_MODE
CONFIG_CONSOLE_OUTPUT_MODE = BUFFER_MODE

When CONFIG_CONSOLE_OUTPUT_MODE is configured as DIRECT_MODE, the terminal log will be directly output to uart; when configured as BUFFER_MODE, the terminal log will be output to the ring buffer inside the RTOS system. You can choose to output to the terminal software through uart or to the Linux terminal by configuring the SYS file.

2.2. SYS Configuration

Modify the mode_u8 attribute of the console node in the sc/driver/sysdriver/sysdesc/hal/pcupid/pub/pcupid-default.sys file to 1:

<console>
    [mode_u8] 0;
    [poll_size_u16] 1024;
    [poll_timeout_u16] 1000;
    [status_u8] 1;
Attribute Description Setting value Remark
mode_u8 When mode_u8 is configured to 0, the terminal log will be output to the terminal software through uart; when configured to 1, the terminal log will be saved in the ring buffer The default value is 0 Can be modified as needed
poll_size_u16 Set the bufsize of log storage. When the size is reached, it will trigger the notification arm to save the log. The default value is 1024 bytes Can be modified as needed
poll_timeout_u16 Set the Log timeout. If the timeout is reached but the Log size does not reach the poll size, arm is triggered to save the log. The unit is ms, the default is 1 second Can be modified as needed
status_u8 Choose whether to enable 1:enable,0:disable Can be modified as needed

3. USAGE METHOD

3.1. Command Line Testing

After the configuration is correct, you can see that RISCV uart has no output. At this time, you can control RISCV RTOS through procfs under Linux and output RTOS commands to the RTOS terminal:

/ # echo cli version > /proc/dualos/rtos

Get the RTOS terminal command execution log:

/ # cat /proc/dualos/log
cli - 'version'

Build on 14:54:18 Jun 26 2024
FreeRTOS V10.4.4+
g22cf99b[rtk][master_riscv]

The version command in the example can be replaced with any command supported by RTOS.

3.2. Use Demo Program to Test

3.2.1 Compile Demo Program

Enter the sdk/verify/sample_code directory and execute the following command to compile the demo:

cd sdk/verify/sample_code
make clean && make source/pcupid/riscv/riscv_log_save_demo

The compiled executable file is located in the following path:

sample_code/out/arm64/app/prog_riscv_riscv_log_save_demo

3.2.2 Run Demo Program

Put the compiled executable file prog_riscv_riscv_log_save_demo on the board, and add executable permissions to the prog_riscv_riscv_log_save_demo file. Execute the following command to start capturing logs:

chmod +x prog_riscv_riscv_log_save_demo
./prog_riscv_riscv_log_save_demo riscv.log

riscv.log is the specified log output file. Enter the test command:

echo cli version > /proc/dualos/rtos echo cli version > /proc/dualos/rtos ...

The above commands need to be executed multiple times. When the number of logs output by RISCV RTOS reaches a certain number, the demo will capture the output logs and output similar to the following in the Linux terminal:

./prog_riscv_riscv_log_save_demo riscv.log
write 0 bytes log data to log file
write 1035 bytes log data to log file

At this point, you can execute CTRL + C to stop the program and end capturing logs. Open riscv.log and you can see logs output by RISCV RTOS:

/ # cat riscv.log
cli - 'version'

Build on 14:54:18 Jun 26 2024
FreeRTOS V10.4.4+
g22cf99b[rtk][master_riscv]

cli - 'version'

Build on 14:54:18 Jun 26 2024
FreeRTOS V10.4.4+
g22cf99b[rtk][master_riscv]