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