Specifications

Example: Creating a BSP with Logging
System clock log
JTAG startup log
JTAG interval log, logging twice a second
No write echo
Example 6–6. Creating BSP With Logging and Options
nios2-bsp hal my_bsp ../my_hardware.sopcinfo \
--set hal.log_port uart1 \
--set hal.make.bsp_cflags_user_flags \
-DALT_LOG_FLAGS=2 \
-DALT_LOG_WRITE_ON_FLAG_SETTING=0 \
-DALT_LOG_JTAG_UART_TICKS_DIVISOR=2r
The -DALT_LOG_FLAGS=2 argument adds -DALT_LOG_FLAGS=2 to the ALT_CPP_FLAGS make variable in
public.mk.
Custom Logging Messages
You can add custom messages that are sent to the Altera logging device. To define a custom message,
include the header file alt_log_printf.h in your C source file as follows:
#include "sys/alt_log_printf.h"
Then use the following macro function:
ALT_LOG_PRINTF(const char *format, ...)
This C preprocessor macro is a pared-down version of printf(). The format argument supports most
printf() options. It supports %c, %d %I %o %s %u %x, and %X, as well as some precision and spacing
modifiers, such as %-9.3o. It does not support floating point formats, such as %f or %g. This function is
not compiled if Altera logging is not enabled.
If you want your custom logging message to be controlled by Altera logging preprocessor options, use the
appropriate Altera logging option preprocessor flags from the "ALT_LOG_FLAGS Logging Levels" table
(Table 6-4), or the "Altera Logging Options and Option Modifiers" table (Table 6-3).
Example 6–7. Implementing Logging Options with Custom Logging Messages
/* The following example prints "Level 2 logging message" if
logging is set to level 2 or higher */
#if ( ALT_LOG_FLAGS >= 2 )
ALT_LOG_PRINTF ( "Level 2 logging message" );
#endif
/* The following example prints "Boot logging message" if boot logging
is turned on */
#if ( ALT_LOG_BOOT_ON_FLAG_SETTING == 1)
ALT_LOG_PRINTF ( "Boot logging message" );
#endif
Altera Logging Files
Table 6-5: HAL Implementation Files for Altera Logging
Location File Name
components/altera_hal/HAL/inc/sys/ alt_log_printf.h
6-12
Example: Creating a BSP with Logging
NII5V2
2015.05.14
Altera Corporation
Developing Programs Using the Hardware Abstraction Layer
Send Feedback