1 /*
2  * Copyright (c) 2019 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef MIPI_SYST_PLATFORM_INCLUDED
8 #define MIPI_SYST_PLATFORM_INCLUDED
9 
10 #include <logging/log_output.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #if defined(CONFIG_MIPI_SYST_STP)
17 /*
18  * Structure generating STP protocol data
19  */
20 struct stp_writer_data {
21 	mipi_syst_u8   byteDone;
22 	mipi_syst_u8   current;
23 	mipi_syst_u16  master;
24 	mipi_syst_u16  channel;
25 	mipi_syst_u64  recordCount;
26 	mipi_syst_u64  timestamp;
27 };
28 #endif
29 
30 #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)
31 /*
32  * Platform specific SyS-T global state extension
33  */
34 struct mipi_syst_platform_state {
35 #if defined(CONFIG_MIPI_SYST_STP)
36 	struct stp_writer_data *stpWriter;
37 #endif
38 
39 	void (*write_d8)(struct mipi_syst_handle *systh, mipi_syst_u8 v);
40 	void (*write_d16)(struct mipi_syst_handle *systh, mipi_syst_u16 v);
41 	void (*write_d32)(struct mipi_syst_handle *systh, mipi_syst_u32 v);
42 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
43 	void (*write_d64)(struct mipi_syst_handle *systh, mipi_syst_u64 v);
44 #endif
45 	void (*write_d32ts)(struct mipi_syst_handle *systh, mipi_syst_u32 v);
46 	void (*write_d32mts)(struct mipi_syst_handle *systh, mipi_syst_u32 v);
47 	void (*write_d64mts)(struct mipi_syst_handle *systh, mipi_syst_u64 v);
48 	void (*write_flag)(struct mipi_syst_handle *systh);
49 };
50 
51 /*
52  * Platform specific SyS-T handle state extension
53  */
54 struct mipi_syst_platform_handle {
55 	mipi_syst_u32 flag;
56 #if defined(CONFIG_MIPI_SYST_STP)
57 	mipi_syst_u32 master;
58 	mipi_syst_u32 channel;
59 #endif
60 	struct log_output *log_output;
61 };
62 
63 /*
64  * IO output routine mapping
65  * Call the function pointers in the global state
66  */
67 #define MIPI_SYST_OUTPUT_D8(syst_handle, data) \
68 	((syst_handle)->systh_header-> \
69 		systh_platform.write_d8((syst_handle), (data)))
70 #define MIPI_SYST_OUTPUT_D16(syst_handle, data) \
71 	((syst_handle)->systh_header-> \
72 		systh_platform.write_d16((syst_handle), (data)))
73 #define MIPI_SYST_OUTPUT_D32(syst_handle, data) \
74 	((syst_handle)->systh_header-> \
75 		systh_platform.write_d32((syst_handle), (data)))
76 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
77 #define MIPI_SYST_OUTPUT_D64(syst_handle, data) \
78 	((syst_handle)->systh_header-> \
79 		systh_platform.write_d64((syst_handle), (data)))
80 #endif
81 #define MIPI_SYST_OUTPUT_D32TS(syst_handle, data) \
82 	((syst_handle)->systh_header-> \
83 		systh_platform.write_d32ts((syst_handle), (data)))
84 #define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data) \
85 	((syst_handle)->systh_header-> \
86 		systh_platform.write_d32mts((syst_handle), (data)))
87 #define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data) \
88 	((syst_handle)->systh_header-> \
89 		systh_platform.write_d64mts((syst_handle), (data)))
90 #define MIPI_SYST_OUTPUT_FLAG(syst_handle) \
91 	((syst_handle)->systh_header-> \
92 		systh_platform.write_flag((syst_handle)))
93 
94 #else
95 
96 #define MIPI_SYST_OUTPUT_D8(syst_handle, data)
97 #define MIPI_SYST_OUTPUT_D16(syst_handle, data)
98 #define MIPI_SYST_OUTPUT_D32(syst_handle, data)
99 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
100 #define MIPI_SYST_OUTPUT_D64(syst_handle, data)
101 #endif
102 #define MIPI_SYST_OUTPUT_D32TS(syst_handle, data)
103 #define MIPI_SYST_OUTPUT_FLAG(syst_handle)
104 
105 #endif
106 
107 #if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY)
108 #define MIPI_SYST_HEAP_MALLOC(s)
109 #define MIPI_SYST_HEAP_FREE(p)
110 #endif
111 
112 #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
113 #define MIPI_SYST_PLATFORM_CLOCK() mipi_syst_get_epoch()
114 #define MIPI_SYST_PLATFORM_FREQ()  CONFIG_SYS_CLOCK_TICKS_PER_SEC
115 
116 mipi_syst_u64 mipi_syst_get_epoch(void);
117 #endif
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif
124