1 /*
2 Copyright (c) 2018, MIPI Alliance, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17 * Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * Contributors:
36 * Norbert Schulz (Intel Corporation) - Initial API and implementation
37 */
38
39 #include <stdio.h>
40 #if defined(_WIN32)
41 #include <windows.h>
42 #endif
43 #include "mipi_syst.h"
44
45
46 /**
47 * Platform specific SyS-T handle initialization hook function
48 *
49 * @param systh pointer to the new SyS-T handle structure
50 */
platform_handle_init(struct mipi_syst_handle * systh)51 static void platform_handle_init(struct mipi_syst_handle* systh)
52 {
53 }
54
55 /**
56 * Platform specific SyS-T handle initialization hook function
57 *
58 * @param systh pointer to the new SyS-T handle structure
59 */
platform_handle_release(struct mipi_syst_handle * systh)60 static void platform_handle_release(struct mipi_syst_handle* systh)
61 {
62 }
63
64 /**
65 * Platform specific global state initialization hook function
66 *
67 * @param systh pointer to the new SyS-T handle structure
68 * @param platform_data user defined data for the init function.
69 */
70 MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV
mipi_syst_platform_init(struct mipi_syst_header * systh,const void * platform_data)71 mipi_syst_platform_init(struct mipi_syst_header* systh, const void * platform_data)
72 {
73 /* Set handle init hook that performs per SyS-T handle initialization
74 * and destruction
75 */
76 #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)
77 systh->systh_inith = platform_handle_init;
78 systh->systh_releaseh = platform_handle_release;
79 #endif
80 }
81
82 MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV
mipi_syst_platform_destroy(struct mipi_syst_header * systh)83 mipi_syst_platform_destroy(struct mipi_syst_header* systh)
84 {
85 }
86
87
88 #if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY)
89 MIPI_SYST_EXPORT
mipi_syst_platform_alloc(size_t s)90 void * MIPI_SYST_CALLCONV mipi_syst_platform_alloc(size_t s)
91 {
92 return malloc(s);
93 }
94
95 MIPI_SYST_EXPORT
mipi_syst_platform_free(void * p)96 void MIPI_SYST_CALLCONV mipi_syst_platform_free(void * p)
97 {
98 free(p);
99 }
100
101
102 #if !defined(MIPI_SYST_STATIC)
103 /**
104 * This example platform uses SyS-T as a shared library inside an
105 * application. The platform init hook is called during a shared library
106 * constructor call.
107 */
shared_library_init()108 static MIPI_SYST_SHAREDLIB_CONSTRUCTOR void shared_library_init()
109 {
110 MIPI_SYST_INIT(mipi_syst_platform_init, (void*)42);
111 }
112
113 /**
114 * This example platform uses SyS-T as a shared library inside an
115 * application. The platform destroy hook is called during a shared library
116 * destructor call.
117 */
shared_library_exit()118 static MIPI_SYST_SHAREDLIB_DESTRUCTOR void shared_library_exit()
119 {
120 /* run platform shutdown code */
121 MIPI_SYST_SHUTDOWN(mipi_syst_platform_destroy);
122 }
123
124 #if defined(_WIN32)
125 /**
126 * Windows DLL main routine, needed to run the global initialization and
127 * destruction handlers.
128 */
DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved)129 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
130 {
131 (void)lpReserved;
132 (void)hinstDLL;
133
134 switch (fdwReason) {
135 case DLL_PROCESS_ATTACH:
136 shared_library_init();
137 break;
138 case DLL_PROCESS_DETACH:
139 shared_library_exit();
140 break;
141 }
142 return TRUE;
143 }
144 #endif
145 #endif /* !defined(MIPI_SYST_STATIC) */
146 #endif /* defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) */