aboutsummaryrefslogtreecommitdiff
path: root/library/platform/mipi_stp_sim/include/mipi_syst/platform.h
blob: aab1c72a05058a668992677608a4704ec278a840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
Copyright (c) 2018, MIPI Alliance, Inc. 
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in
  the documentation and/or other materials provided with the
  distribution.

* Neither the name of the copyright holder nor the names of its
  contributors may be used to endorse or promote products derived
  from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
 * Contributors:
 * Norbert Schulz (Intel Corporation) - Initial API and implementation
 */

/* Example platform adaptation
 * This "platform" shows how to implement a SyS-T library platform module
 * to simulate MIPI STP data protocol generation for SyS-T messages.
 */
#ifndef MIPI_SYST_PLATFORM_INCLUDED
#define MIPI_SYST_PLATFORM_INCLUDED


/* Uncomment to turn code inlining off.
 *
 * #undef MIPI_SYST_PCFG_ENABLE_INLINE
 */

#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY)
#include <stdlib.h>
#endif

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

	struct MipiStpWriter;

	struct mipi_syst_platform_state {
		void (*write_d32ts)(struct mipi_syst_handle * systh, mipi_syst_u32 v);
		void (*write_d32mts)(struct mipi_syst_handle * systh, mipi_syst_u32 v);
		void (*write_d64mts)(struct mipi_syst_handle * systh, mipi_syst_u64 v);

		void (*write_d8)(struct mipi_syst_handle * systh, mipi_syst_u8 v);
		void (*write_d16)(struct mipi_syst_handle * systh, mipi_syst_u16 v);
		void (*write_d32)(struct mipi_syst_handle * systh, mipi_syst_u32 v);
#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
		void (*write_d64)(struct mipi_syst_handle * systh, mipi_syst_u64 v);
#endif
		void (*write_flag)(struct mipi_syst_handle * systh);

		struct stp_writer_data * stpWriter;
	};

	extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV
		mipi_syst_platform_init(struct mipi_syst_header* , const void *);
	extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV
		mipi_syst_platform_destroy(struct mipi_syst_header* systh);

	struct mipi_syst_platform_handle {
		mipi_syst_u32 master;
		mipi_syst_u32 channel;
	};



#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY)

/**
* Map heap memory allocation to platform malloc() implementation.
*
* This function is used for handle allocations if heap usage
* is supported by the platform.
*
* @param s number of bytes to allocate
* @see MIPI_SYST_HEAP_FREE
*/
#define MIPI_SYST_HEAP_MALLOC(s) mipi_syst_platform_alloc(s)

/**
* Map heap memory free function  to platform free() implementation.
*
* This function is used for handle release if heap usage
* is supported by the platform.
*
* @param p pointer previously returned from MIPI_SYST_HEAP_MALLOC or NULL.
* @see MIPI_SYST_HEAP_MALLOC
*/
#define MIPI_SYST_HEAP_FREE(p)   mipi_syst_platform_free(p)

extern MIPI_SYST_EXPORT void * MIPI_SYST_CALLCONV  mipi_syst_platform_alloc(size_t s);
extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV mipi_syst_platform_free(void *);
#endif

#if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
/* This example uses UNIX epoch time in micro second resolution
 * as own clock.
 */
#define MIPI_SYST_PLATFORM_CLOCK() mipi_syst_get_epoch_us()
#define MIPI_SYST_PLATFORM_FREQ()  1000000

MIPI_SYST_EXPORT mipi_syst_u64  MIPI_SYST_CALLCONV mipi_syst_get_epoch_us();
#endif /* defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) */

/* IO output routine mapping
 * Call the function pointers in the global SyS-T state
 */
#define MIPI_SYST_OUTPUT_D32TS(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d32ts((syst_handle), (data))
#define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d32mts((syst_handle), (data))
#define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d64mts((syst_handle), (data))
#define MIPI_SYST_OUTPUT_D8(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d8((syst_handle), (data))
#define MIPI_SYST_OUTPUT_D16(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d16((syst_handle), (data))
#define MIPI_SYST_OUTPUT_D32(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d32((syst_handle), (data))
#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
#define MIPI_SYST_OUTPUT_D64(syst_handle, data) \
	(syst_handle)->systh_header->systh_platform.write_d64((syst_handle), (data))
#endif
#define MIPI_SYST_OUTPUT_FLAG(syst_handle) \
	(syst_handle)->systh_header->systh_platform.write_flag((syst_handle))

#ifdef __cplusplus
} /* extern C */
#endif

#endif