diff options
Diffstat (limited to 'library/platform')
-rw-r--r-- | library/platform/example/include/mipi_syst/platform.h | 188 | ||||
-rw-r--r-- | library/platform/example/src/mipi_syst_platform.c | 404 | ||||
-rw-r--r-- | library/platform/mipi_stp_sim/include/mipi_syst/platform.h | 156 | ||||
-rw-r--r-- | library/platform/mipi_stp_sim/src/mipi_syst_platform.c | 561 | ||||
-rw-r--r-- | library/platform/nop/include/mipi_syst/platform.h | 153 | ||||
-rw-r--r-- | library/platform/nop/src/mipi_syst_platform.c | 146 |
6 files changed, 1608 insertions, 0 deletions
diff --git a/library/platform/example/include/mipi_syst/platform.h b/library/platform/example/include/mipi_syst/platform.h new file mode 100644 index 0000000..701f3a2 --- /dev/null +++ b/library/platform/example/include/mipi_syst/platform.h @@ -0,0 +1,188 @@ +/* +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 specific extensions + * This "platform" shows how to implement a SyS-T platform modules. + * This platform simple prints its IO actions to stdout. + */ + +#ifndef MIPI_SYST_PLATFORM_INCLUDED +#define MIPI_SYST_PLATFORM_INCLUDED + +/* Uncomment to turn code in-lining off. + * + * #undef MIPI_SYST_PCFG_ENABLE_INLINE + */ + +#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) +#include <stdlib.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Platform specific SyS-T global state extension +* +* The contents of this structure can be freely defined to +* match platform specific data needs. It can later be +* accessed through the mipi_syst_header systh_platform member. +* +* This platform example puts low-level output function pointers +* here. Real implementations may have them "inlined" for performance +* reasons. +*/ +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); + + void * sph_init_data; +}; + +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); + +#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(void); + +#endif /* defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) */ + +/** +* Platform specific SyS-T handle state extension +* +* The contents of this structure can be freely defined to +* match platform specific data needs. It can later be +* accessed through the syst_handles systh_platform member. +* +* @see MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA struct mipi_syst_handle +*/ +struct mipi_syst_platform_handle { + mipi_syst_u32 sph_io_count; /**< cnt io's, used for pretty printing */ + mipi_syst_u32 sph_raw_count; /**< number of raw bytes in sph_raw */ + mipi_syst_u8 sph_raw[2 * 64 * 1024]; /**< buffer for printing */ +}; + + +#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 + +/* IO output routine mapping +* Call the function pointers in the global state +*/ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA) +#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)) +#else +#define MIPI_SYST_OUTPUT_D32TS(syst_handle, data) +#define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data) +#define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data) +#define MIPI_SYST_OUTPUT_D8(syst_handle, data) +#define MIPI_SYST_OUTPUT_D16(syst_handle, data) +#define MIPI_SYST_OUTPUT_D32(syst_handle, data) +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) +#define MIPI_SYST_OUTPUT_D64(syst_handle, data) +#endif +#define MIPI_SYST_OUTPUT_FLAG(syst_handle) +#endif // MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA + +#endif + +#if defined(MIPI_SYST_UNIT_TEST) +#define MIPI_SYST_UNIT_TEST_EXAMPLE +#endif + +#ifdef __cplusplus +} /* extern C */ +#endif diff --git a/library/platform/example/src/mipi_syst_platform.c b/library/platform/example/src/mipi_syst_platform.c new file mode 100644 index 0000000..223dbdd --- /dev/null +++ b/library/platform/example/src/mipi_syst_platform.c @@ -0,0 +1,404 @@ +/* +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 + */ + +#include <stdio.h> +#if defined(_WIN32) +#include <windows.h> +#else +#include <sys/time.h> +#endif + +#include "mipi_syst.h" + +/* "driver" data output routines */ +static void write_d32mts(struct mipi_syst_handle* systh, mipi_syst_u32 v); +static void write_d64mts(struct mipi_syst_handle* systh, mipi_syst_u64 v); +static void write_d32ts(struct mipi_syst_handle* systh, mipi_syst_u32 v); +static void write_d8(struct mipi_syst_handle* systh, mipi_syst_u8 v); +static void write_d16(struct mipi_syst_handle* systh, mipi_syst_u16 v); +static void write_d32(struct mipi_syst_handle* systh, mipi_syst_u32 v); +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) +static void write_d64(struct mipi_syst_handle* systh, mipi_syst_u64 vp); +#endif +static void write_flag(struct mipi_syst_handle* systh); + +/** + * Platform specific SyS-T handle initialization hook function + * + * @param systh pointer to the new SyS-T handle structure + */ +static void platform_handle_init(struct mipi_syst_handle* systh) +{ +#if !defined(MIPI_SYST_UNIT_TEST) + printf( + " in SyS-T platform handle init hook: systh = %p\n\n", + systh + ); +#endif + + /* Initialize platform specific data in global state + * This example just stores the platform_data, a real implementation + * would put data into the handle structure that enables the output + * routines to execute efficiently (pointer for MMIO for example). + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + +#endif +} + +/** + * Platform specific SyS-T handle initialization hook function + * + * @param systh pointer to the new SyS-T handle structure + */ +static void platform_handle_release(struct mipi_syst_handle* systh) +{ +#if !defined(MIPI_SYST_UNIT_TEST) && defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + printf( + " in SyS-T platform handle release hook:systh = %p\n", + systh + ); +#endif + + /* Release any handle specific data or resources here.*/ +} + +/** + * Platform specific global state initialization hook function + * + * @param systh pointer to the new SyS-T handle structure + * @param platform_data user defined data for the init function. + */ +MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV +mipi_syst_platform_init(struct mipi_syst_header* systh, const void * platform_data) +{ +#if !defined(MIPI_SYST_UNIT_TEST) + printf( + " in SyS-T platform init hook: \"mipi_syst_platform_state_init()\"\n" + " systh = %p, platform_data = %p\n", + systh, + platform_data + ); +#endif + + /* Set handle init hook that performs per SyS-T handle initialization + * and destruction + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + systh->systh_inith = platform_handle_init; + systh->systh_releaseh = platform_handle_release; +#endif + + /* Initialize platform specific data in global state + * This platform example puts its low level output function + * pointers here. A real implementation may have these "inlined" + * for performance reasons. + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA) + systh->systh_platform.write_d32ts = write_d32ts; + systh->systh_platform.write_d32mts = write_d32mts; + systh->systh_platform.write_d64mts = write_d64mts; + systh->systh_platform.write_d8 = write_d8; + systh->systh_platform.write_d16 = write_d16; + systh->systh_platform.write_d32 = write_d32; +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) + systh->systh_platform.write_d64 = write_d64; +#endif + systh->systh_platform.write_flag = write_flag; +#endif +} + +MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV +mipi_syst_platform_destroy(struct mipi_syst_header* systh) +{ + (void)systh; +} + +#if !defined(MIPI_SYST_STATIC) +/** + * This example platform uses SyS-T as a shared library inside an + * application. The platform init hook is called during a shared library + * constructor call. + */ +static MIPI_SYST_SHAREDLIB_CONSTRUCTOR void shared_library_init() +{ + /* Initialize SyS-T infrastructure + * This must be done once at platform startup. + * The parameters are the platform specific initialization function and + * the data that gets passed to it. + */ + printf("calling MIPI_SYST_INIT() from platform code \n"); + MIPI_SYST_INIT(mipi_syst_platform_init, (void*)42); +} + +/** + * This example platform uses SyS-T as a shared library inside an + * application. The platform destroy hook is called during a shared library + * destructor call. + */ +static MIPI_SYST_SHAREDLIB_DESTRUCTOR void shared_library_exit() +{ + /* run platform shutdown code */ + MIPI_SYST_SHUTDOWN(mipi_syst_platform_destroy); + printf("\nexecuted MIPI_SYST_SHUTDOWN() from platform code \n"); +} + +#if defined(_WIN32) +/** + * Windows DLL main routine, needed to run the global initialization and + * destruction handlers. + */ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) +{ + (void)lpReserved; + (void)hinstDLL; + + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + shared_library_init(); + break; + case DLL_PROCESS_DETACH: + shared_library_exit(); + break; + } + return TRUE; +} +#endif +#endif /* !defined(MIPI_SYST_STATIC) */ + +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + +/* Save a message bytes for printing the raw message when completed. + */ +static void append_raw( + struct mipi_syst_handle* systh, + const void * p, + int n) +{ + int i; + +#if defined(MIPI_SYST_BIG_ENDIAN) + for (i = n-1; i >= 0; --i) { +#else + for (i = 0; i < n; ++i) { +#endif + mipi_syst_u32 index = systh->systh_platform.sph_raw_count++; + if (index < sizeof(systh->systh_platform.sph_raw)) { + systh->systh_platform.sph_raw[index] = + ((const mipi_syst_u8*)p)[i]; + } + else { + fprintf(stderr, "Internal Error: Record buffer overflow\n"); + break; + } + } +} +#endif + +/* dump contents for raw message bytes + */ +static void write_rawdata(struct mipi_syst_handle* systh) +{ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + static char valToHex[] = "0123456789ABCDEF"; + const mipi_syst_u8 *p; + + printf("SYS-T RAW DATA: "); + for (p = systh->systh_platform.sph_raw; + systh->systh_platform.sph_raw_count; + ++p, --systh->systh_platform.sph_raw_count) + { + putc(valToHex[(*p) >> 0x4], stdout); + putc(valToHex[(*p) & 0xF], stdout); + } +#endif +} + +/* Dummy driver output routines that just print their operation. + */ +static void write_d32mts(struct mipi_syst_handle* systh, mipi_syst_u32 v) +{ + /* d32mts == Short SyS-T header, reset io count + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + systh->systh_platform.sph_io_count = 0; + systh->systh_platform.sph_raw_count = 0; + + + printf("STP Protocol Output:\n"); + + printf(" %2d <D32MTS> %08x\n", + systh->systh_platform.sph_io_count++, v); + + append_raw(systh, &v, sizeof(v)); + write_rawdata(systh); + printf("\n\n"); +#endif +} +static void write_d64mts(struct mipi_syst_handle* systh, mipi_syst_u64 v) +{ + /* d64mts == 64-Bit Short SyS-T header, reset io count + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + systh->systh_platform.sph_io_count = 0; + + printf("STP Protocol Output:\n"); + + printf(" %2d <D64MTS> %08llx\n", + systh->systh_platform.sph_io_count++, v); + + append_raw(systh, &v, sizeof(v)); + write_rawdata(systh); + printf("\n\n"); + +#endif +} + +static void write_d32ts(struct mipi_syst_handle* systh, mipi_syst_u32 v) +{ + /* d32ts == SyS-T header, reset io count + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + systh->systh_platform.sph_io_count = 0; + + printf("STP Protocol Output:\n"); + + printf(" %2d <D32TS> %08x\n", + systh->systh_platform.sph_io_count++, v); + + append_raw(systh, &v, sizeof(v)); +#endif +} +static void write_d8(struct mipi_syst_handle* systh, mipi_syst_u8 v) +{ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + printf(" %2d <D8> %02x\n", + systh->systh_platform.sph_io_count++, v); + + append_raw(systh, &v, sizeof(v)); +#endif +} + +static void write_d16(struct mipi_syst_handle* systh, mipi_syst_u16 v) +{ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + printf(" %2d <D16> %04x\n", + systh->systh_platform.sph_io_count++, v); + + append_raw(systh, &v, sizeof(v)); +#endif +} + +static void write_d32(struct mipi_syst_handle* systh, mipi_syst_u32 v) +{ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + printf(" %2d <D32> %08x\n", + systh->systh_platform.sph_io_count++, v); + + append_raw(systh, &v, sizeof(v)); +#endif +} + +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) +static void write_d64(struct mipi_syst_handle* systh, mipi_syst_u64 v) +{ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + printf(" %2d <D64> %08x%08x\n", + systh->systh_platform.sph_io_count++, +#if defined(MIPI_SYST_BIG_ENDIAN) + (mipi_syst_u32)v, (mipi_syst_u32)(v >> 32); +#else + (mipi_syst_u32)(v >> 32), (mipi_syst_u32)v); +#endif +#endif + append_raw(systh, &v, sizeof(v)); +} +#endif + +static void write_flag(struct mipi_syst_handle* systh) +{ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + printf(" %2d <FLAG>\n", systh->systh_platform.sph_io_count++); + + write_rawdata(systh); + printf("\n\n"); + +#endif +} + +MIPI_SYST_EXPORT +mipi_syst_u64 MIPI_SYST_CALLCONV mipi_syst_get_epoch_us() +{ + mipi_syst_u64 epoch; +#if defined(MIPI_SYST_UNIT_TEST) + epoch = 0x12345678aabbccddull; +#elif defined(_WIN32) + // Windows does not offer epoch time API directly. + // Search for the 116444... constant below on + // MSDN for an explanation of the computation: + // + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + epoch = ft.dwHighDateTime; + epoch = ((epoch << 32) | ft.dwLowDateTime) / 10 - 11644473600000000ULL; + +#else + struct timeval tv; + + gettimeofday(&tv, NULL); + epoch = tv.tv_sec; + epoch *= 1000000; + epoch += tv.tv_usec; +#endif + return epoch; +} + +#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) +MIPI_SYST_EXPORT +void * MIPI_SYST_CALLCONV mipi_syst_platform_alloc(size_t s) +{ + return malloc(s); +} + +MIPI_SYST_EXPORT +void MIPI_SYST_CALLCONV mipi_syst_platform_free(void * p) +{ + free(p); +} + +#endif /* defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) */
\ No newline at end of file diff --git a/library/platform/mipi_stp_sim/include/mipi_syst/platform.h b/library/platform/mipi_stp_sim/include/mipi_syst/platform.h new file mode 100644 index 0000000..aab1c72 --- /dev/null +++ b/library/platform/mipi_stp_sim/include/mipi_syst/platform.h @@ -0,0 +1,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 diff --git a/library/platform/mipi_stp_sim/src/mipi_syst_platform.c b/library/platform/mipi_stp_sim/src/mipi_syst_platform.c new file mode 100644 index 0000000..187205b --- /dev/null +++ b/library/platform/mipi_stp_sim/src/mipi_syst_platform.c @@ -0,0 +1,561 @@ +/* +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. + */ +#if defined(_WIN32) +#include <windows.h> +#else +#include <sys/time.h> +#endif +#include <stdio.h> +#include <string.h> + +#include "mipi_syst.h" + +#if defined(_WIN32) +static CRITICAL_SECTION lockPlat; +#define LOCKING_INIT() InitializeCriticalSection(&lockPlat) +#define LOCKING_DESTROY() DeleteCriticalSection(&lockPlat) +#define LOCK() EnterCriticalSection(&lockPlat) +#define UNLOCK() LeaveCriticalSection(&lockPlat) + +#else + +#include <pthread.h> +static pthread_mutex_t lockPlat; + +#define LOCKING_INIT() pthread_mutex_init(&lockPlat, NULL) +#define LOCKING_DESTROY() pthread_mutex_destroy(&lockPlat) +#define LOCK() pthread_mutex_lock(&lockPlat) +#define UNLOCK() pthread_mutex_unlock(&lockPlat) + +#endif + +MIPI_SYST_EXPORT mipi_syst_u64 MIPI_SYST_CALLCONV mipi_syst_get_epoch_us() +{ + mipi_syst_u64 epoch; +#if defined(MIPI_SYST_UNIT_TEST) + epoch = 0x12345678aabbccddull; +#elif defined(_WIN32) + // windows does not offer epoch time API directly. + // Search for the 116444... constant below on + // msdn for an explanation of this computation: + // + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + epoch = ft.dwHighDateTime; + epoch = ((epoch<<32) | ft.dwLowDateTime) / 10 - 11644473600000000ULL; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + epoch = tv.tv_sec; + epoch *= 1000000; + epoch += tv.tv_usec; +#endif + return epoch; +} + +#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) +MIPI_SYST_EXPORT +void * MIPI_SYST_CALLCONV mipi_syst_platform_alloc(size_t s) +{ + return malloc(s); +} + +MIPI_SYST_EXPORT +void MIPI_SYST_CALLCONV mipi_syst_platform_free(void * p) +{ + free(p); +} + +#endif /* defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) */ + +/* helper class for generating STP protocol data +*/ +struct stp_writer_data { + FILE * fp; /* output */ + mipi_syst_u8 byteDone; /* true = byte complete */ + mipi_syst_u8 current; /* current byte value */ + mipi_syst_u16 master; /* current master */ + mipi_syst_u16 channel; /* current channel */ + mipi_syst_u64 recordCount; /* count stp packets */ + + mipi_syst_u64 timestamp; /* first timestamp */ +}; + + +static struct stp_writer_data writer_state; + +void stp_write_putNibble(struct stp_writer_data* p, mipi_syst_u8 n) +{ + p->current |= (n<<4); + p->byteDone = ! p->byteDone; + + if (p->byteDone) { /* push it out .. */ + fputc(p->current, p->fp); + p->current = 0; + } else { /* first nibble, shift it down to b0..3 */ + p->current >>= 4; + } +} + +void stp_write_flush(struct stp_writer_data* p) { + if (!p->byteDone) { + stp_write_putNibble(p, 0); + } + + fflush(p->fp); +} +void stp_write_d4(struct stp_writer_data* p, mipi_syst_u8 v) { + stp_write_putNibble(p, v); +} + +void stp_write_payload8(struct stp_writer_data* p, mipi_syst_u8 v) { + stp_write_d4(p, v); + stp_write_d4(p, v>>4); +} + +void stp_write_payload16(struct stp_writer_data* p, mipi_syst_u16 v) { + stp_write_payload8(p, (mipi_syst_u8)v); + stp_write_payload8(p, (mipi_syst_u8)(v>>8)); +} + +void stp_write_payload32(struct stp_writer_data* p, mipi_syst_u32 v) { + stp_write_payload16(p, (mipi_syst_u16)v); + stp_write_payload16(p, (mipi_syst_u16)(v>>16)); +} + +void stp_write_payload64(struct stp_writer_data* p, mipi_syst_u64 v) { + stp_write_payload32(p, (mipi_syst_u32)v); + stp_write_payload32(p, (mipi_syst_u32)(v>>32)); +} + +mipi_syst_u64 deltaTime(struct stp_writer_data* p) +{ + mipi_syst_u64 delta; + + delta = mipi_syst_get_epoch_us() - p->timestamp; + return delta * 60; /* simluate 60Mhz clock */ +} +void stp_write_d32mts(struct stp_writer_data* p, mipi_syst_u32 v) { + stp_write_d4(p, 0xA); + stp_write_payload32(p, v); + + stp_write_d4(p, 0xE); + stp_write_payload64(p, deltaTime(p)); +} + +void stp_write_d64mts(struct stp_writer_data* p, mipi_syst_u64 v) { + stp_write_d4(p, 0xB); + stp_write_payload64(p, v); + + stp_write_d4(p, 0xE); + stp_write_payload64(p, deltaTime(p)); +} +void stp_write_d32ts(struct stp_writer_data* p, mipi_syst_u32 v) { + stp_write_d4(p, 0xF); + stp_write_d4(p, 0x6); + + stp_write_payload32(p, v); + + stp_write_d4(p, 0xE); + stp_write_payload64(p, deltaTime(p)); +} + +void stp_write_d8(struct stp_writer_data* p, mipi_syst_u8 v) { + stp_write_d4(p, 0x4); + stp_write_payload8(p, v); +} + +void stp_write_d16(struct stp_writer_data* p, mipi_syst_u16 v) { + stp_write_d4(p, 0x5); + stp_write_payload16(p, v); +} + + +void stp_write_d32(struct stp_writer_data* p, mipi_syst_u32 v) { + stp_write_d4(p, 0x6); + stp_write_payload32(p, v); +} + + +void stp_write_d64(struct stp_writer_data* p, mipi_syst_u64 v) +{ + stp_write_d4(p, 0x7); + stp_write_payload64(p, v); +} + +void stp_write_flag(struct stp_writer_data* p) +{ + stp_write_d4(p, 0xF); + stp_write_d4(p, 0xE); +} + +void stp_write_async(struct stp_writer_data* p) +{ + int i; + for(i=0; i < 21; ++i) { + stp_write_d4(p, 0xF); + } + stp_write_d4(p, 0x0); +} + +void stp_write_version(struct stp_writer_data* p) +{ + stp_write_d4(p, 0xF); + stp_write_d4(p, 0x0); + stp_write_d4(p, 0x0); + + stp_write_d4(p, 0x3); /* STPv2NAT */ + + p->master = p->channel = 0; +} + +void stp_write_freq(struct stp_writer_data* p) +{ + stp_write_d4(p, 0xF); + stp_write_d4(p, 0x0); + stp_write_d4(p, 0x8); + stp_write_payload32(p, 60 * 1000 * 1000 ); // 60 Mhz +} + +void stp_write_setMC(struct stp_writer_data* p, + mipi_syst_u16 master, + mipi_syst_u16 channel) +{ + /* re-send async after 20 packets */ + if (!(p->recordCount++ % 20) ) { + stp_write_async(p); + stp_write_version(p); + stp_write_freq(p); + } + + if (p->master != master ) { + stp_write_d4(p, 0xF); + stp_write_d4(p, 0x1); + stp_write_payload16(p, master); + + p->master = master; + p->channel = 0; + } + + if (p->channel != channel) { + stp_write_d4(p, 0xF); + stp_write_d4(p, 0x3); + stp_write_payload16(p, channel); + + p->channel = channel; + } +} + + + +/* output stream for STP data +*/ +static FILE * fp; +static mipi_syst_u16 master = 128; /* Default MIPI STP master:channel */ +static mipi_syst_u16 channel = 1; + + +/* low level "driver" output routines */ +static void sth_write_d32ts(struct mipi_syst_handle* systh, mipi_syst_u32 v); +static void sth_write_d32mts(struct mipi_syst_handle* systh, mipi_syst_u32 v); +static void sth_write_d64mts(struct mipi_syst_handle* systh, mipi_syst_u64 v); +static void sth_write_d8(struct mipi_syst_handle* systh, mipi_syst_u8 v); +static void sth_write_d16(struct mipi_syst_handle* systh, mipi_syst_u16 v); +static void sth_write_d32(struct mipi_syst_handle* systh, mipi_syst_u32 v); +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) +static void sth_write_d64(struct mipi_syst_handle* systh, mipi_syst_u64 vp); +#endif +static void sth_write_user8ts(struct mipi_syst_handle* systh, mipi_syst_u8 v); +static void sth_write_flag(struct mipi_syst_handle* systh); + +/* +* Platform specific SyS-T handle initialization hook function +* +* @param systh pointer to the new SyS-T handle structure +*/ +static void platform_handle_init(struct mipi_syst_handle* systh) +{ + LOCK(); + + /* Simply increment channels on each handle request and advance + * to next master if all consumed. + */ + if (channel > 127) { + ++master; + channel = 1; + } + + systh->systh_platform.channel = channel++; + systh->systh_platform.master = master; + + UNLOCK(); +} + +/** +* Platform specific SyS-T handle initialization hook function +* +* @param systh pointer to the new SyS-T handle structure +*/ +static void platform_handle_release(struct mipi_syst_handle* systh) +{ + LOCK(); + + /* add any race protected cleanup code here + */ + + UNLOCK(); +} + +MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV + mipi_syst_platform_init(struct mipi_syst_header* systh, const void * platform_data) +{ + const char * filename; + + LOCKING_INIT(); + + /* Platform data is expected to be UTF-8 string with the STP output + * file name. + */ + filename = (const char *)platform_data; + + if (filename == NULL ||!strcmp(filename, "-")) + { + fp = stdout; + } else { + fp = fopen((char*)platform_data, "wb"); + + if (fp == NULL) { + fprintf(stderr, "Unable to open file '%s'.\n", (char*)platform_data); + exit(-1); + } + } + + /* create the STP output writer + */ + writer_state.byteDone = 0; + writer_state.fp = fp; + writer_state.current = 0; + writer_state.master = 0; + writer_state.channel = 0; + writer_state.recordCount=0; + writer_state.timestamp = mipi_syst_get_epoch_us(); + + systh->systh_platform.stpWriter = & writer_state; + + /* Set handle init hook that performs per SyS-T handle initialization + * and destruction + */ + systh->systh_inith = platform_handle_init; + systh->systh_releaseh = platform_handle_release; + + /* Initialize platform specific data in global SyS-T state + * This platform example puts its low level output function + * pointers here. A real implementation may have these "inlined" + * for performance reasons. + */ + systh->systh_platform.write_d32ts = sth_write_d32ts; + systh->systh_platform.write_d32mts = sth_write_d32mts; + systh->systh_platform.write_d64mts = sth_write_d64mts; + systh->systh_platform.write_d8 = sth_write_d8; + systh->systh_platform.write_d16 = sth_write_d16; + systh->systh_platform.write_d32 = sth_write_d32; +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) + systh->systh_platform.write_d64 = sth_write_d64; +#endif + systh->systh_platform.write_flag = sth_write_flag; +} + +MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV + mipi_syst_platform_destroy(struct mipi_syst_header* systh) +{ + if (systh->systh_platform.stpWriter != NULL && + systh->systh_platform.stpWriter->fp != NULL) + { + fflush(systh->systh_platform.stpWriter->fp); + + if (systh->systh_platform.stpWriter->fp != stdout) + { + fclose(systh->systh_platform.stpWriter->fp); + systh->systh_platform.stpWriter->fp = NULL; + } + } + + LOCKING_DESTROY(); +} + +#if !defined(MIPI_SYST_STATIC) + +/* +* This example platform uses SyS-T as a shared library inside an +* application. The platform init hook is called during a shared library +* constructor call. +*/ +static MIPI_SYST_SHAREDLIB_CONSTRUCTOR + void shared_library_init() +{ + const char * filename; + + filename = getenv("SYSTCAT_OUTPUT"); + if (filename == NULL) { + filename = "syst_stp_data.bin"; + } + + MIPI_SYST_INIT(mipi_syst_platform_init, filename); + + if (filename[0] != '-' && filename[1] != 0 ) { + printf("writing STP data into '%s' ...\n", filename); + } +} + +/* +* This example platform uses SyS-T as a shared library inside an +* application. The platform destroy hook is called during a shared library +* destructor call. +*/ +static MIPI_SYST_SHAREDLIB_DESTRUCTOR void shared_library_exit() +{ + MIPI_SYST_SHUTDOWN(mipi_syst_platform_destroy); +} + +#if defined(_WIN32) +/* +* Windows DLL main routine, needed to run the global initialization and +* destruction handlers. +*/ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved ) +{ + switch(fdwReason) { + case DLL_PROCESS_ATTACH: + shared_library_init(); + break; + case DLL_PROCESS_DETACH: + shared_library_exit(); + break; + } + return TRUE; +} +#endif + +#endif /* #if !defined(MIPI_SYST_STATIC) */ + + +/* C code low level driver output routine wrappers for SyS-T +*/ +static void sth_write_d32ts(struct mipi_syst_handle* systh, mipi_syst_u32 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + + /* Each message starts with d32ts. We use this as an */ + /* indicator to lock the output writer until we wrote the */ + /* end of record flag pattern. */ + LOCK(); + + + stp_write_setMC(writer, + systh->systh_platform.master, systh->systh_platform.channel ); + stp_write_d32ts(writer, v); +} + +/* short single 32 bit payload message */ +static void sth_write_d32mts(struct mipi_syst_handle* systh, mipi_syst_u32 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + + LOCK(); + + stp_write_setMC(writer, + systh->systh_platform.master,systh->systh_platform.channel ); + stp_write_d32mts(writer, v); + + UNLOCK(); +} +/* short single 64 bit payload message */ +static void sth_write_d64mts(struct mipi_syst_handle* systh, mipi_syst_u64 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + + LOCK(); + + stp_write_setMC(writer, + systh->systh_platform.master,systh->systh_platform.channel ); + stp_write_d64mts(writer, v); + + UNLOCK(); +} +static void sth_write_d8(struct mipi_syst_handle* systh, mipi_syst_u8 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + stp_write_d8(writer, v); +} + +static void sth_write_d16(struct mipi_syst_handle* systh, mipi_syst_u16 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + stp_write_d16(writer, v); +} + +static void sth_write_d32(struct mipi_syst_handle* systh, mipi_syst_u32 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + stp_write_d32(writer, v); +} + +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) +static void sth_write_d64(struct mipi_syst_handle* systh, mipi_syst_u64 v) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + stp_write_d64(writer, v); +} +#endif + +static void sth_write_flag(struct mipi_syst_handle* systh) +{ + struct stp_writer_data * writer = systh->systh_header->systh_platform.stpWriter; + + stp_write_flag(writer); + stp_write_flush(writer); + + /* atomic record write done - matching lock was in sth_write_d32ts() */ + UNLOCK(); +}
\ No newline at end of file diff --git a/library/platform/nop/include/mipi_syst/platform.h b/library/platform/nop/include/mipi_syst/platform.h new file mode 100644 index 0000000..d8c2eb7 --- /dev/null +++ b/library/platform/nop/include/mipi_syst/platform.h @@ -0,0 +1,153 @@ +/* +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 + */ + +/* Minimal platform example (which is acutally is a NOP) +* This "platform" shows how to use the SyS-T platform modules +* to implement platform specific customizations. +*/ + +#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 + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Platform specific SyS-T global state extension +* +* The contents of this structure can be freely defined to +* match platform specific data needs. It can later be +* accessed through the mipi_syst_header systh_platform member. +* +* This platform example puts low-level output function pointers +* here. Real implementations may have them "inlined" for performance +* reasons. +*/ +struct mipi_syst_platform_state { + volatile void * mmio; +}; + +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); + +#if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) +/* this example uses UNIX epoch time in micro-second resolution +* as own clock. +*/ +#if defined(MIPI_SYST_UNIT_TEST) +#define MIPI_SYST_PLATFORM_CLOCK() 0x12345678aabbccdd +#else +#define MIPI_SYST_PLATFORM_CLOCK() 0 /* replace with real clock provider */ +#endif +#define MIPI_SYST_PLATFORM_FREQ() 1000*1000 + +#endif /* defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP) */ + +/** +* Platform specific SyS-T handle state extension +* +* The contents of this structure can be freely defined to +* match platform specific data needs. It can later be +* accessed through the syst_handles's systh_platform member. +* +* @see MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA struct mipi_syst_handle +*/ +struct mipi_syst_platform_handle { + volatile void * mmio_addr; +}; + + +#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) +/** +* Map heap memory allocation to platfrom 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 platfrom 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 + +/* IO output routine mapping + * Define these to generate SyS-T data protocol output + */ +#define MIPI_SYST_OUTPUT_D32TS(syst_handle, data) +#define MIPI_SYST_OUTPUT_D32MTS(syst_handle, data) +#define MIPI_SYST_OUTPUT_D64MTS(syst_handle, data) +#define MIPI_SYST_OUTPUT_D8(syst_handle, data) +#define MIPI_SYST_OUTPUT_D16(syst_handle, data) +#define MIPI_SYST_OUTPUT_D32(syst_handle, data) +#if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO) +#define MIPI_SYST_OUTPUT_D64(syst_handle, data) +#endif +#define MIPI_SYST_OUTPUT_FLAG(syst_handle) + +#endif + + +#ifdef __cplusplus +} /* extern C */ +#endif diff --git a/library/platform/nop/src/mipi_syst_platform.c b/library/platform/nop/src/mipi_syst_platform.c new file mode 100644 index 0000000..3175f33 --- /dev/null +++ b/library/platform/nop/src/mipi_syst_platform.c @@ -0,0 +1,146 @@ +/* +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 + */ + +#include <stdio.h> +#if defined(_WIN32) +#include <windows.h> +#endif +#include "mipi_syst.h" + + +/** + * Platform specific SyS-T handle initialization hook function + * + * @param systh pointer to the new SyS-T handle structure + */ +static void platform_handle_init(struct mipi_syst_handle* systh) +{ +} + +/** + * Platform specific SyS-T handle initialization hook function + * + * @param systh pointer to the new SyS-T handle structure + */ +static void platform_handle_release(struct mipi_syst_handle* systh) +{ +} + +/** + * Platform specific global state initialization hook function + * + * @param systh pointer to the new SyS-T handle structure + * @param platform_data user defined data for the init function. + */ +MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV +mipi_syst_platform_init(struct mipi_syst_header* systh, const void * platform_data) +{ + /* Set handle init hook that performs per SyS-T handle initialization + * and destruction + */ +#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA) + systh->systh_inith = platform_handle_init; + systh->systh_releaseh = platform_handle_release; +#endif +} + +MIPI_SYST_EXPORT void MIPI_SYST_CALLCONV +mipi_syst_platform_destroy(struct mipi_syst_header* systh) +{ +} + + +#if defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) +MIPI_SYST_EXPORT +void * MIPI_SYST_CALLCONV mipi_syst_platform_alloc(size_t s) +{ + return malloc(s); +} + +MIPI_SYST_EXPORT +void MIPI_SYST_CALLCONV mipi_syst_platform_free(void * p) +{ + free(p); +} + + +#if !defined(MIPI_SYST_STATIC) +/** +* This example platform uses SyS-T as a shared library inside an +* application. The platform init hook is called during a shared library +* constructor call. +*/ +static MIPI_SYST_SHAREDLIB_CONSTRUCTOR void shared_library_init() +{ + MIPI_SYST_INIT(mipi_syst_platform_init, (void*)42); +} + +/** +* This example platform uses SyS-T as a shared library inside an +* application. The platform destroy hook is called during a shared library +* destructor call. +*/ +static MIPI_SYST_SHAREDLIB_DESTRUCTOR void shared_library_exit() +{ + /* run platform shutdown code */ + MIPI_SYST_SHUTDOWN(mipi_syst_platform_destroy); +} + +#if defined(_WIN32) +/** +* Windows DLL main routine, needed to run the global initialization and +* destruction handlers. +*/ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) +{ + (void)lpReserved; + (void)hinstDLL; + + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + shared_library_init(); + break; + case DLL_PROCESS_DETACH: + shared_library_exit(); + break; + } + return TRUE; +} +#endif +#endif /* !defined(MIPI_SYST_STATIC) */ +#endif /* defined(MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY) */
\ No newline at end of file |