📄 alt_log_printf.h
字号:
/* alt_log_printf.h
*
* ALT_LOG is designed to provide extra logging/debugging messages from HAL
* through a different port than stdout. It is enabled by the ALT_LOG_ENABLE
* define, which needs to supplied at compile time. When logging is turned off,
* code size is unaffected. Thus, this should be transparent to the user
* when it is not actively turned on, and should not affect projects in any way.
*
* There are macros sprinkled within different components, such as the jtag uart
* and timer, in the HAL code. They are always named ALT_LOG_<name>, and can be
* safely ignored if ALT_LOG is turned off.
*
* To turn on ALT_LOG, ALT_LOG_ENABLE must be defined, and ALT_LOG_PORT_TYPE and
* ALT_LOG_PORT_BASE must be set in system.h. This is done through editing
* <project>.ptf, by editing the alt_log_port_type & alt_log_port_base settings.
* See the documentation html file for examples.
*
* When it is turned on, it will output extra HAL messages to a port specified
* in system.h. This can be a UART or JTAG UART port. By default it will
* output boot messages, detailing every step of the boot process.
*
* Extra logging is designed to be enabled by flags, which are defined in
* alt_log_printf.c. The default value is that all flags are off, so only the
* boot up logging messages show up. ALT_LOG_FLAGS can be set to enable certain
* groupings of flags, and that grouping is done in this file. Each flag can
* also be overridden with a -D at compile time.
*
* This header file includes the necessary prototypes for using the alt_log
* functions. It also contains all the macros that are used to remove the code
* from alt log is turned off. Also, the macros in other HAL files are defined
* here at the bottom. These macros all call some C function that is in
* alt_log_printf.c.
*
* The logging has functions for printing in C (ALT_LOG_PRINTF) and in assembly
* (ALT_LOG_PUTS). This was needed because the assembly printing occurs before
* the device is initialized. The assembly function corrupts register R4-R7,
* which are not used in the normal boot process. For this reason, do not call
* the assembly function in C.
*
* author: gkwan
*/
#ifndef __ALT_LOG_PRINTF_H__
#define __ALT_LOG_PRINTF_H__
#include <system.h>
/* Global switch to turn on logging functions */
#ifdef ALT_LOG_ENABLE
/* ALT_LOG_PORT_TYPE values as defined in system.h. They are defined as
* numbers here first becasue the C preprocessor does not handle string
* comparisons. */
#define ALTERA_AVALON_JTAG_UART 1
#define ALTERA_AVALON_UART 0
/* If this .h file is included by an assembly file, skip over include files
* that won't compile in assembly. */
#ifndef ALT_ASM_SRC
#include <stdarg.h>
#include "sys/alt_alarm.h"
#include "sys/alt_dev.h"
#ifdef __ALTERA_AVALON_JTAG_UART
#include "altera_avalon_jtag_uart.h"
#endif
#endif /* ALT_ASM_SRC */
/* These are included for the port register offsets and masks, needed
* to write to the port. Only include if the port type is set correctly,
* otherwise error. If alt_log is turned on and the port to output to is
* incorrect or does not exist, then should exit. */
#if ALT_LOG_PORT_TYPE == ALTERA_AVALON_JTAG_UART
#ifdef __ALTERA_AVALON_JTAG_UART
#include <altera_avalon_jtag_uart_regs.h>
#else
#error ALT_LOG: JTAG_UART port chosen, but no JTAG_UART in system.
#endif
#elif ALT_LOG_PORT_TYPE == ALTERA_AVALON_UART
#ifdef __ALTERA_AVALON_UART
#include <altera_avalon_uart_regs.h>
#else
#error ALT_LOG: UART Port chosen, but no UART in system.
#endif
#else
#error ALT_LOG: alt_log_port_type declaration invalid!
#endif
/* ALT_LOG_ENABLE turns on the basic printing function */
#define ALT_LOG_PRINTF(...) do {alt_log_printf_proc(__VA_ARGS__);} while (0)
/* Assembly macro for printing in assembly, calls tx_log_str
* which is in altera_nios2/HAL/src/alt_log_macro.S
* If alt_log_boot_on_flag is 0, skips the printing */
#define ALT_LOG_PUTS(str) movhi r4, %hiadj(alt_log_boot_on_flag) ; \
addi r4, r4, %lo(alt_log_boot_on_flag) ; \
ldwio r5, 0(r4) ; \
beq r0, r5, 0f ; \
movhi r4, %hiadj(str) ; \
addi r4, r4, %lo(str) ; \
call tx_log_str ; \
0:
/* These defines are here to faciliate the use of one output function
* (alt_log_txchar) to print to both the JTAG UART or the UART. Depending
* on the port type, the status register, read mask, and output register
* are set to the appropriate value for the port. */
#if ALT_LOG_PORT_TYPE == ALTERA_AVALON_JTAG_UART
#define ALT_LOG_PRINT_REG_RD IORD_ALTERA_AVALON_JTAG_UART_CONTROL
#define ALT_LOG_PRINT_MSK ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK
#define ALT_LOG_PRINT_TXDATA_WR IOWR_ALTERA_AVALON_JTAG_UART_DATA
#define ALT_LOG_PRINT_REG_OFFSET (ALTERA_AVALON_JTAG_UART_CONTROL_REG*0x4)
#define ALT_LOG_PRINT_TXDATA_REG_OFFSET (ALTERA_AVALON_JTAG_UART_DATA_REG*0x4)
#elif ALT_LOG_PORT_TYPE == ALTERA_AVALON_UART
#define ALT_LOG_PRINT_REG_RD IORD_ALTERA_AVALON_UART_STATUS
#define ALT_LOG_PRINT_MSK ALTERA_AVALON_UART_STATUS_TRDY_MSK
#define ALT_LOG_PRINT_TXDATA_WR IOWR_ALTERA_AVALON_UART_TXDATA
#define ALT_LOG_PRINT_REG_OFFSET (ALTERA_AVALON_UART_STATUS_REG*0x4)
#define ALT_LOG_PRINT_TXDATA_REG_OFFSET (ALTERA_AVALON_UART_TXDATA_REG*0x4)
#endif /* ALT_LOG_PORT */
/* Grouping of flags via ALT_LOG_FLAGS. Each specific flag can be set via
* -D at compile time, or else they'll be set to a default value according
* to ALT_LOG_FLAGS. ALT_LOG_FLAGS = 0 or not set is the default, where
* only the boot messages will be printed. As ALT_LOG_FLAGS increase, they
* increase in intrusiveness to the program, and will affect performance.
*
* Flag Level 1 - turns on system clock and JTAG UART startup status
* 2 - turns on write echo and JTAG_UART alarm (periodic report)
* 3 - turns on JTAG UART ISR logging - will slow performance
* significantly.
* -1 - All logging output is off, but if ALT_LOG_ENABLE is
* defined all logging function is built and code size
* remains constant
*
* Flag settings - 1 = on, 0 = off. */
/* This flag turns on "boot" messages for printing. This includes messages
* during crt0.S, then alt_main, and finally alt_exit. */
#ifndef ALT_LOG_BOOT_ON_FLAG_SETTING
#if ALT_LOG_FLAGS == 1
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == 2
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == 3
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == -1 /* silent mode */
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x0
#else /* default setting */
#define ALT_LOG_BOOT_ON_FLAG_SETTING 0x1
#endif
#endif /* ALT_LOG_BOOT_ON_FLAG_SETTING */
#ifndef ALT_LOG_SYS_CLK_ON_FLAG_SETTING
#if ALT_LOG_FLAGS == 1
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == 2
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == 3
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == -1 /* silent mode */
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x0
#else /* default setting */
#define ALT_LOG_SYS_CLK_ON_FLAG_SETTING 0x0
#endif
#endif /* ALT_LOG_SYS_CLK_ON_FLAG_SETTING */
#ifndef ALT_LOG_WRITE_ON_FLAG_SETTING
#if ALT_LOG_FLAGS == 1
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x0
#elif ALT_LOG_FLAGS == 2
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == 3
#define ALT_LOG_WRITE_ON_FLAG_SETTING 0x1
#elif ALT_LOG_FLAGS == -1 /* silent mode */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -