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 /* Example platform specific extensions
40  * This "platform" shows how to implement a SyS-T platform modules.
41  * This platform simple prints its IO actions to stdout.
42  */
43 
44 #ifndef MIPI_SYST_PLATFORM_INCLUDED
45 #define MIPI_SYST_PLATFORM_INCLUDED
46 
47 /* Uncomment to turn  code in-lining off.
48  *
49  * #undef MIPI_SYST_PCFG_ENABLE_INLINE
50  */
51 
52 #if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY)
53 #include <stdlib.h>
54 #endif
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 /**
61 * Platform specific SyS-T global state extension
62 *
63 * The contents of this structure can be freely defined to
64 * match platform specific data needs. It can later be
65 * accessed through the mipi_syst_header systh_platform member.
66 *
67 * This platform example puts low-level output function pointers
68 * here. Real implementations may have them "inlined" for performance
69 * reasons.
70 */
71 struct mipi_syst_platform_state {
72 	void (*write_d32ts)(struct mipi_syst_handle * systh, mipi_syst_u32 v);
73 	void (*write_d32mts)(struct mipi_syst_handle * systh, mipi_syst_u32 v);
74 	void (*write_d64mts)(struct mipi_syst_handle * systh, mipi_syst_u64 v);
75 	void (*write_d8)(struct mipi_syst_handle * systh, mipi_syst_u8 v);
76 	void (*write_d16)(struct mipi_syst_handle * systh, mipi_syst_u16 v);
77 	void (*write_d32)(struct mipi_syst_handle * systh, mipi_syst_u32 v);
78 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
79 	void (*write_d64)(struct mipi_syst_handle * systh, mipi_syst_u64 v);
80 #endif
81 	void (*write_flag)(struct mipi_syst_handle * systh);
82 
83 	void * sph_init_data;
84 };
85 
86 extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV
87 	mipi_syst_platform_init(struct mipi_syst_header *, const void *);
88 extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV
89 	mipi_syst_platform_destroy(struct mipi_syst_header * systh);
90 
91 #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
92 /* This example uses  UNIX epoch time in micro second resolution
93 * as own clock.
94 */
95 #define MIPI_SYST_PLATFORM_CLOCK() mipi_syst_get_epoch_us()
96 #define MIPI_SYST_PLATFORM_FREQ()  1000000
97 
98 MIPI_SYST_EXPORT mipi_syst_u64  MIPI_SYST_CALLCONV mipi_syst_get_epoch_us(void);
99 
100 #endif /* defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) */
101 
102 /**
103 * Platform specific SyS-T handle state extension
104 *
105 * The contents of this structure can be freely defined to
106 * match platform specific data needs. It can later be
107 * accessed through the syst_handles systh_platform member.
108 *
109 * @see MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA struct mipi_syst_handle
110 */
111 struct mipi_syst_platform_handle {
112 	mipi_syst_u32 sph_io_count; /**< cnt io's, used for pretty printing */
113 	mipi_syst_u32 sph_raw_count;  /**< number of raw bytes in sph_raw   */
114 	mipi_syst_u8  sph_raw[2 * 64 * 1024]; /**< buffer for printing      */
115 };
116 
117 
118 #if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY)
119 /**
120 * Map heap memory allocation to platform malloc() implementation.
121 *
122 * This function is used for handle allocations if heap usage
123 * is supported by the platform.
124 *
125 * @param s number of bytes to allocate
126 * @see MIPI_SYST_HEAP_FREE
127 */
128 #define MIPI_SYST_HEAP_MALLOC(s) mipi_syst_platform_alloc(s)
129 
130 /**
131 * Map heap memory free function  to platform free() implementation.
132 *
133 * This function is used for handle release if heap usage
134 * is supported by the platform.
135 *
136 * @param p pointer previously returned from MIPI_SYST_HEAP_MALLOC or NULL.
137 * @see MIPI_SYST_HEAP_MALLOC
138 */
139 #define MIPI_SYST_HEAP_FREE(p)   mipi_syst_platform_free(p)
140 
141 extern MIPI_SYST_EXPORT void * MIPI_SYST_CALLCONV  mipi_syst_platform_alloc(size_t s);
142 extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV mipi_syst_platform_free(void *);
143 #endif
144 
145 /* IO output routine mapping
146 * Call the function pointers in the global state
147 */
148 #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)
149 #define MIPI_SYST_OUTPUT_D32TS(syst_handle, data) \
150 	(syst_handle)->systh_header->systh_platform.write_d32ts((syst_handle), (data))
151 #define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data) \
152 	(syst_handle)->systh_header->systh_platform.write_d32mts((syst_handle), (data))
153 #define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data) \
154 	(syst_handle)->systh_header->systh_platform.write_d64mts((syst_handle), (data))
155 #define MIPI_SYST_OUTPUT_D8(syst_handle, data) \
156 	(syst_handle)->systh_header->systh_platform.write_d8((syst_handle), (data))
157 #define MIPI_SYST_OUTPUT_D16(syst_handle, data) \
158 	(syst_handle)->systh_header->systh_platform.write_d16((syst_handle), (data))
159 #define MIPI_SYST_OUTPUT_D32(syst_handle, data) \
160 	(syst_handle)->systh_header->systh_platform.write_d32((syst_handle), (data))
161 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
162 #define MIPI_SYST_OUTPUT_D64(syst_handle, data) \
163 	(syst_handle)->systh_header->systh_platform.write_d64((syst_handle), (data))
164 #endif
165 #define MIPI_SYST_OUTPUT_FLAG(syst_handle) \
166 	(syst_handle)->systh_header->systh_platform.write_flag((syst_handle))
167 #else
168 #define MIPI_SYST_OUTPUT_D32TS(syst_handle, data)
169 #define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data)
170 #define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data)
171 #define MIPI_SYST_OUTPUT_D8(syst_handle, data)
172 #define MIPI_SYST_OUTPUT_D16(syst_handle, data)
173 #define MIPI_SYST_OUTPUT_D32(syst_handle, data)
174 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
175 #define MIPI_SYST_OUTPUT_D64(syst_handle, data)
176 #endif
177 #define MIPI_SYST_OUTPUT_FLAG(syst_handle)
178 #endif // MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
179 
180 #endif
181 
182 #if defined(MIPI_SYST_UNIT_TEST)
183 #define MIPI_SYST_UNIT_TEST_EXAMPLE
184 #endif
185 
186 #ifdef __cplusplus
187 } /* extern C */
188 #endif
189