# Dying Gasp ## When to Use For a device without a serial port, the dying gasp saves the exception information to a non-volatile storage medium to facilitate fault location during system running. ## Available APIs The system provides a mechanism to save printed exception information to a non-volatile storage medium. You can register the hook function of the information printed when the read and write operations are abnormal. In this way, fault information can be saved on different storage media, facilitating fault locating for devices without serial ports. The API is **LOS\_ExcInfoRegHook**. This function is declared in **los\_config.h**. The function prototype is as follows: ``` typedef VOID (*log_read_write_fn)(UINT32 startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf); ... VOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_write_fn hook); ``` ## Parameters **Table 1** LOS\_ExcInfoRegHook parameter description

Parameter

Description

startAddr

Start address of the physical medium to be got or set

space

Size of the space

buf

Memory buffer used to get or set the exception information

log_read_write_fn

Function used to get or set the exception information

**Table 2** log\_read\_write\_fn parameter description

Parameter

Description

startAddr

Start address of the physical medium to be got or set

space

Size of the space

rwFlag

Read/Write flag. The value 0 indicates write, and the value 1 indicates read.

buf

Memory buffer used to get or set the exception information

## How to Develop The dying gasp function depends on the macro **LOSCFG\_SAVE\_EXCINFO**. Before using this function, choose **Debug**-\> **Enable Saving Exception Information** in the configuration items to enable this macro. If this macro is disabled, this function cannot be used. Then, call **LOS\_ExcInfoRegHook** in **SystemInit** to register the position, size, memory buffer, and access function for accessing the exception information. When an exception occurs in the system, the system saves the exception information in the memory buffer passed in the registration, and then calls the registered access function to write the exception information to the physical storage medium. >![](../public_sys-resources/icon-note.gif) **NOTE:** >- The location registered to store the exception information cannot overlap with other storage locations. >- The registered memory buffer should be greater than or equal to 16 KiB. Otherwise, the exception information stored may be incomplete. >- The exception information can be accessed successfully only when the driver of the storage medium corresponding to the registered read/write function is normal.