1 /*
2  * Percepio DFM v2.0.0
3  * Copyright 2023 Percepio AB
4  * www.percepio.com
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 /**
10  * @file
11  *
12  * @brief DFM Storage API
13  */
14 
15 #ifndef DFM_STORAGE_H
16 #define DFM_STORAGE_H
17 
18 #include <stdint.h>
19 #include <dfmStoragePort.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #if ((DFM_CFG_ENABLED) >= 1)
26 
27 /**
28  * @defgroup dfm_storage_apis DFM Storage API
29  * @ingroup dfm_apis
30  * @{
31  */
32 
33 /**
34  * @brief Storage data
35  */
36 typedef struct DfmStorageData
37 {
38 	uint32_t ulInitialized;
39 
40 	DfmStoragePortData_t xStoragePortData;
41 } DfmStorageData_t;
42 
43 /**
44  * @internal Initialize Storage system.
45  *
46  * @param[in] pxBuffer Pointer to memory that will be used by the storage system.
47  *
48  * @retval DFM_FAIL Failure
49  * @retval DFM_SUCCESS Success
50  */
51 DfmResult_t xDfmStorageInitialize(DfmStorageData_t *pxBuffer);
52 
53 /**
54  * @brief Store Session data
55  *
56  * @param[in] pvSession Session data.
57  * @param[in] ulSessionSize Data size.
58  *
59  * @retval DFM_FAIL Failure
60  * @retval DFM_SUCCESS Success
61  */
62 DfmResult_t xDfmStorageStoreSession(void* pvSession, uint32_t ulSessionSize);
63 
64 /**
65 * @brief Retrieve Session data
66 *
67 * @param[in] pvBuffer Pointer to buffer.
68 * @param[in] ulBufferSize Buffer size.
69 *
70 * @retval DFM_FAIL Failure
71 * @retval DFM_SUCCESS Success
72 */
73 DfmResult_t xDfmStorageGetSession(void* pvBuffer, uint32_t ulBufferSize);
74 
75 /**
76 * @brief Store Alert
77 *
78 * @param[in] xEntryHandle The Entry containing an Alert.
79 *
80 * @retval DFM_FAIL Failure
81 * @retval DFM_SUCCESS Success
82 */
83 DfmResult_t xDfmStorageStoreAlert(DfmEntryHandle_t xEntryHandle);
84 
85 /**
86 * @brief Retrieve Alert
87 *
88 * @param[in] pvBuffer Pointer to buffer.
89 * @param[in] ulBufferSize Buffer size.
90 *
91 * @retval DFM_FAIL Failure
92 * @retval DFM_SUCCESS Success
93 */
94 DfmResult_t xDfmStorageGetAlert(void* pvBuffer, uint32_t ulBufferSize);
95 
96 /**
97 * @brief Store Payload chunk
98 *
99 * @param[in] xEntryHandle The Entry containing a Payload chunk.
100 *
101 * @retval DFM_FAIL Failure
102 * @retval DFM_SUCCESS Success
103 */
104 DfmResult_t xDfmStorageStorePayloadChunk(DfmEntryHandle_t xEntryHandle);
105 
106 /**
107 * @brief Retrieve Payload chunk
108 *
109 * @param[in] pvBuffer Pointer to buffer.
110 * @param[in] ulBufferSize Buffer size.
111 *
112 * @retval DFM_FAIL Failure
113 * @retval DFM_SUCCESS Success
114 */
115 DfmResult_t xDfmStorageGetPayloadChunk(char* szSessionId, uint32_t ulAlertId, void* pvBuffer, uint32_t ulBufferSize);
116 
117 /** @} */
118 
119 #else
120 
121 /* Dummy defines */
122 #define xDfmStorageStoreSession(pvSession, ulSessionSize) (DFM_FAIL)
123 #define xDfmStorageGetSession(pvBuffer, ulBufferSize) (DFM_FAIL)
124 #define xDfmStorageStoreAlert(xEntryHandle) (DFM_FAIL)
125 #define xDfmStorageGetAlert(pvBuffer, ulBufferSize) (DFM_FAIL)
126 #define xDfmStorageStorePayloadChunk(xEntryHandle) (DFM_FAIL)
127 #define xDfmStorageGetPayloadChunk(szSessionId, ulAlertId, pvBuffer, ulBufferSize) (DFM_FAIL)
128 
129 #endif
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif
136