1 /*
2  * Percepio DFM v2.1.0
3  * Copyright 2023 Percepio AB
4  * www.percepio.com
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  * DFM
9  */
10 
11 #include <dfm.h>
12 
13 #if ((DFM_CFG_ENABLED) >= 1)
14 
15 #if (!defined(DFM_VERSION) || (DFM_VERSION < DFM_VERSION_INITIAL) || (DFM_VERSION > DFM_VERSION_2_0))
16 #error "Invalid DFM_VERSION!"
17 #endif
18 
19 #include <assert.h>
20 #include <string.h>
21 #include <stdint.h>
22 
23 static DfmData_t xDfmData;
24 static DfmData_t* pxDfmData = &xDfmData;
25 
26 DfmUserCallback_t xDfmUserGetUniqueSessionID;
27 DfmUserCallback_t xDfmUserGetDeviceName;
28 
xDfmInitialize(DfmUserCallback_t xGetUniqueSessionID,DfmUserCallback_t xGetDeviceName)29 DfmResult_t xDfmInitialize(DfmUserCallback_t xGetUniqueSessionID, DfmUserCallback_t xGetDeviceName)
30 {
31 	if (pxDfmData == (void*)0)
32 	{
33 		return DFM_FAIL;
34 	}
35 
36 	if (xGetUniqueSessionID == 0)
37 	{
38 		return DFM_FAIL;
39 	}
40 
41 	if (xGetDeviceName == 0)
42 	{
43 		return DFM_FAIL;
44 	}
45 
46 	(void)memset(pxDfmData, 0, sizeof(DfmData_t));
47 
48 	xDfmUserGetUniqueSessionID = xGetUniqueSessionID;
49 	xDfmUserGetDeviceName = xGetDeviceName;
50 
51 	if (xDfmSessionInitialize(&pxDfmData->xSessionData) == DFM_FAIL)
52 	{
53 		return DFM_FAIL;
54 	}
55 
56 	if (xDfmKernelPortInitialize(&pxDfmData->xKernelPortData) == DFM_FAIL)
57 	{
58 		return DFM_FAIL;
59 	}
60 
61 	if (xDfmAlertInitialize(&pxDfmData->xAlertData) == DFM_FAIL)
62 	{
63 		return DFM_FAIL;
64 	}
65 
66 	if (xDfmEntryInitialize(&pxDfmData->xEntryData) == DFM_FAIL)
67 	{
68 		return DFM_FAIL;
69 	}
70 
71 	if (xDfmCloudInitialize(&pxDfmData->xCloudData) == DFM_FAIL)
72 	{
73 		return DFM_FAIL;
74 	}
75 
76 	if (xDfmStorageInitialize(&pxDfmData->xStorageData) == DFM_FAIL)
77 	{
78 		return DFM_FAIL;
79 	}
80 
81 #if (defined(DFM_CFG_RETAINED_MEMORY) && (DFM_CFG_RETAINED_MEMORY >= 1))
82 	if (xDfmRetainedMemoryInitialize(&pxDfmData->xRetainedMemoryData) == DFM_FAIL)
83 	{
84 		return DFM_FAIL;
85 	}
86 #endif
87 
88 	pxDfmData->ulDfmInitialized = 1;
89 
90 	(void)xDfmSessionEnable(0); /* Try to enable, but don't override if disabled */
91 
92 	return DFM_SUCCESS;
93 }
94 
ulDfmIsInitialized(void)95 uint32_t ulDfmIsInitialized(void)
96 {
97 	return xDfmData.ulDfmInitialized;
98 }
99 
100 #endif
101