1e41f4b71Sopenharmony_ci# Dying Gasp
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## When to Use<a name="section158501652121514"></a>
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciFor 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.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Available APIs<a name="section1186411122215"></a>
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThe 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:
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```
12e41f4b71Sopenharmony_citypedef VOID (*log_read_write_fn)(UINT32 startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf);
13e41f4b71Sopenharmony_ci...
14e41f4b71Sopenharmony_ciVOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_write_fn hook);
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Parameters<a name="section1083765723015"></a>
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Table  1**  LOS\_ExcInfoRegHook parameter description
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci<a name="table1345253123117"></a>
22e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row19452331143115"><th class="cellrowborder" valign="top" width="42.77%" id="mcps1.2.3.1.1"><p id="p1145253110313"><a name="p1145253110313"></a><a name="p1145253110313"></a>Parameter</p>
23e41f4b71Sopenharmony_ci</th>
24e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="57.230000000000004%" id="mcps1.2.3.1.2"><p id="p9452153114313"><a name="p9452153114313"></a><a name="p9452153114313"></a>Description</p>
25e41f4b71Sopenharmony_ci</th>
26e41f4b71Sopenharmony_ci</tr>
27e41f4b71Sopenharmony_ci</thead>
28e41f4b71Sopenharmony_ci<tbody><tr id="row5452131123110"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p1245233110317"><a name="p1245233110317"></a><a name="p1245233110317"></a>startAddr</p>
29e41f4b71Sopenharmony_ci</td>
30e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p1845203116313"><a name="p1845203116313"></a><a name="p1845203116313"></a>Start address of the physical medium to be got or set</p>
31e41f4b71Sopenharmony_ci</td>
32e41f4b71Sopenharmony_ci</tr>
33e41f4b71Sopenharmony_ci<tr id="row745217316312"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p7452331133118"><a name="p7452331133118"></a><a name="p7452331133118"></a>space</p>
34e41f4b71Sopenharmony_ci</td>
35e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p9452203117312"><a name="p9452203117312"></a><a name="p9452203117312"></a>Size of the space</p>
36e41f4b71Sopenharmony_ci</td>
37e41f4b71Sopenharmony_ci</tr>
38e41f4b71Sopenharmony_ci<tr id="row15578112463216"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p5578202413220"><a name="p5578202413220"></a><a name="p5578202413220"></a>buf</p>
39e41f4b71Sopenharmony_ci</td>
40e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p1057816247322"><a name="p1057816247322"></a><a name="p1057816247322"></a>Memory buffer used to get or set the exception information</p>
41e41f4b71Sopenharmony_ci</td>
42e41f4b71Sopenharmony_ci</tr>
43e41f4b71Sopenharmony_ci<tr id="row0123932163215"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p612320322321"><a name="p612320322321"></a><a name="p612320322321"></a>log_read_write_fn</p>
44e41f4b71Sopenharmony_ci</td>
45e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p17123143218322"><a name="p17123143218322"></a><a name="p17123143218322"></a>Function used to get or set the exception information</p>
46e41f4b71Sopenharmony_ci</td>
47e41f4b71Sopenharmony_ci</tr>
48e41f4b71Sopenharmony_ci</tbody>
49e41f4b71Sopenharmony_ci</table>
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Table  2**  log\_read\_write\_fn parameter description
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci<a name="table1950318463620"></a>
54e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row45034463611"><th class="cellrowborder" valign="top" width="42.77%" id="mcps1.2.3.1.1"><p id="p950316412365"><a name="p950316412365"></a><a name="p950316412365"></a>Parameter</p>
55e41f4b71Sopenharmony_ci</th>
56e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="57.230000000000004%" id="mcps1.2.3.1.2"><p id="p1050304123619"><a name="p1050304123619"></a><a name="p1050304123619"></a>Description</p>
57e41f4b71Sopenharmony_ci</th>
58e41f4b71Sopenharmony_ci</tr>
59e41f4b71Sopenharmony_ci</thead>
60e41f4b71Sopenharmony_ci<tbody><tr id="row1850394153612"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p155039453619"><a name="p155039453619"></a><a name="p155039453619"></a>startAddr</p>
61e41f4b71Sopenharmony_ci</td>
62e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p18503341366"><a name="p18503341366"></a><a name="p18503341366"></a>Start address of the physical medium to be got or set</p>
63e41f4b71Sopenharmony_ci</td>
64e41f4b71Sopenharmony_ci</tr>
65e41f4b71Sopenharmony_ci<tr id="row1450354113617"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p115031642363"><a name="p115031642363"></a><a name="p115031642363"></a>space</p>
66e41f4b71Sopenharmony_ci</td>
67e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p1350354113619"><a name="p1350354113619"></a><a name="p1350354113619"></a>Size of the space</p>
68e41f4b71Sopenharmony_ci</td>
69e41f4b71Sopenharmony_ci</tr>
70e41f4b71Sopenharmony_ci<tr id="row750314413361"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p115031241361"><a name="p115031241361"></a><a name="p115031241361"></a>rwFlag</p>
71e41f4b71Sopenharmony_ci</td>
72e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p8503548362"><a name="p8503548362"></a><a name="p8503548362"></a>Read/Write flag. The value <strong id="b1039910495392"><a name="b1039910495392"></a><a name="b1039910495392"></a>0</strong> indicates write, and the value <strong id="b236735363912"><a name="b236735363912"></a><a name="b236735363912"></a>1</strong> indicates read.</p>
73e41f4b71Sopenharmony_ci</td>
74e41f4b71Sopenharmony_ci</tr>
75e41f4b71Sopenharmony_ci<tr id="row250312420363"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p850314493611"><a name="p850314493611"></a><a name="p850314493611"></a>buf</p>
76e41f4b71Sopenharmony_ci</td>
77e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p85033413613"><a name="p85033413613"></a><a name="p85033413613"></a>Memory buffer used to get or set the exception information</p>
78e41f4b71Sopenharmony_ci</td>
79e41f4b71Sopenharmony_ci</tr>
80e41f4b71Sopenharmony_ci</tbody>
81e41f4b71Sopenharmony_ci</table>
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci## How to Develop<a name="section783435801510"></a>
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciThe 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.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci>![](../public_sys-resources/icon-note.gif) **NOTE:** 
88e41f4b71Sopenharmony_ci>-   The location registered to store the exception information cannot overlap with other storage locations.
89e41f4b71Sopenharmony_ci>-   The registered memory buffer should be greater than or equal to 16 KiB. Otherwise, the exception information stored may be incomplete.
90e41f4b71Sopenharmony_ci>-   The exception information can be accessed successfully only when the driver of the storage medium corresponding to the registered read/write function is normal.
91e41f4b71Sopenharmony_ci
92