1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
43 #include <tdm_client.h>
44 #include <tdm_helper.h>
47 get_time_in_micros(void)
51 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
52 return (int)(tp.tv_sec * 1000000) + (tp.tv_nsec / 1000L);
58 _client_vblank_handler(unsigned int sequence, unsigned int tv_sec,
59 unsigned int tv_usec, void *user_data)
64 client = get_time_in_micros();
65 vblank = tv_sec * 1000000 + tv_usec;
67 if (vblank - prev > 16966 || vblank - prev < 16366) /* +0.3 ~ -0.3 ms */
68 printf("vblank : %d us\n", vblank - prev);
70 if (client - vblank > 2000) /* 2ms */
71 printf("kernel -> tdm-client: %d us\n", client - vblank);
78 main(int argc, char *argv[])
81 tdm_client_error error;
87 printf("Usage: %s\n", argv[0]);
88 printf("\t%s 0 : non-sync\n", argv[0]);
89 printf("\t%s 1 : sync\n", argv[0]);
95 client = tdm_client_create(&error);
96 if (error != TDM_CLIENT_ERROR_NONE) {
97 printf("tdm_client_create failed\n");
101 error = tdm_client_get_fd(client, &fd);
102 if (error != TDM_CLIENT_ERROR_NONE || fd < 0) {
103 printf("tdm_client_get_fd failed\n");
114 error = tdm_client_wait_vblank(client, "unknown-0", 1, 1, sync,
115 _client_vblank_handler, NULL);
116 if (error != TDM_CLIENT_ERROR_NONE) {
117 printf("tdm_client_wait_vblank failed\n");
122 ret = poll(&fds, 1, -1);
124 if (errno == EBUSY) /* normal case */
127 printf("poll failed: %m\n");
132 error = tdm_client_handle_events(client);
133 if (error != TDM_CLIENT_ERROR_NONE)
134 printf("tdm_client_handle_events failed\n");
139 tdm_client_destroy(client);