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 /* Minimal platform example (which is acutally is a NOP) 40 * This "platform" shows how to use the SyS-T platform modules 41 * to implement platform specific customizations. 42 */ 43 44 #ifndef MIPI_SYST_PLATFORM_INCLUDED 45 #define MIPI_SYST_PLATFORM_INCLUDED 46 47 /* Uncomment to turn code inlining 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 volatile void * mmio; 73 }; 74 75 extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV 76 mipi_syst_platform_init(struct mipi_syst_header *, const void *); 77 extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV 78 mipi_syst_platform_destroy(struct mipi_syst_header * systh); 79 80 #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) 81 /* this example uses UNIX epoch time in micro-second resolution 82 * as own clock. 83 */ 84 #if defined(MIPI_SYST_UNIT_TEST) 85 #define MIPI_SYST_PLATFORM_CLOCK() 0x12345678aabbccdd 86 #else 87 #define MIPI_SYST_PLATFORM_CLOCK() 0 /* replace with real clock provider */ 88 #endif 89 #define MIPI_SYST_PLATFORM_FREQ() 1000*1000 90 91 #endif /* defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) */ 92 93 /** 94 * Platform specific SyS-T handle state extension 95 * 96 * The contents of this structure can be freely defined to 97 * match platform specific data needs. It can later be 98 * accessed through the syst_handles's systh_platform member. 99 * 100 * @see MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA struct mipi_syst_handle 101 */ 102 struct mipi_syst_platform_handle { 103 volatile void * mmio_addr; 104 }; 105 106 107 #if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) 108 /** 109 * Map heap memory allocation to platfrom malloc() implementation. 110 * 111 * This function is used for handle allocations if heap usage 112 * is supported by the platform. 113 * 114 * @param s number of bytes to allocate 115 * @see MIPI_SYST_HEAP_FREE 116 */ 117 #define MIPI_SYST_HEAP_MALLOC(s) mipi_syst_platform_alloc(s) 118 119 /** 120 * Map heap memory free function to platfrom free() implementation. 121 * 122 * This function is used for handle release if heap usage 123 * is supported by the platform. 124 * 125 * @param p pointer previously returned from MIPI_SYST_HEAP_MALLOC or NULL. 126 * @see MIPI_SYST_HEAP_MALLOC 127 */ 128 #define MIPI_SYST_HEAP_FREE(p) mipi_syst_platform_free(p) 129 130 extern MIPI_SYST_EXPORT void * MIPI_SYST_CALLCONV mipi_syst_platform_alloc(size_t s); 131 extern MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV mipi_syst_platform_free(void *); 132 #endif 133 134 /* IO output routine mapping 135 * Define these to generate SyS-T data protocol output 136 */ 137 #define MIPI_SYST_OUTPUT_D32TS(syst_handle, data) 138 #define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data) 139 #define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data) 140 #define MIPI_SYST_OUTPUT_D8(syst_handle, data) 141 #define MIPI_SYST_OUTPUT_D16(syst_handle, data) 142 #define MIPI_SYST_OUTPUT_D32(syst_handle, data) 143 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) 144 #define MIPI_SYST_OUTPUT_D64(syst_handle, data) 145 #endif 146 #define MIPI_SYST_OUTPUT_FLAG(syst_handle) 147 148 #endif 149 150 151 #ifdef __cplusplus 152 } /* extern C */ 153 #endif 154