2 Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
5 Changyeon Lee <cyeon.lee@samsung.com>,
6 JunKyeong Kim <jk0430.kim@samsung.com>,
7 Boram Park <boram1288.park@samsung.com>,
8 SooChan Lim <sc1.lim@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the "Software"),
12 to deal in the Software without restriction, including without limitation
13 the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 and/or sell copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice (including the next
18 paragraph) shall be included in all copies or substantial portions of the
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
37 #include <tdm_client.h>
38 #include <tdm_helper.h>
41 get_time_in_micros(void)
45 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
46 return (int)(tp.tv_sec * 1000000) + (tp.tv_nsec / 1000L);
52 _client_vblank_handler(unsigned int sequence, unsigned int tv_sec,
53 unsigned int tv_usec, void *user_data)
58 client = get_time_in_micros();
59 vblank = tv_sec * 1000000 + tv_usec;
61 if (vblank - prev > 16966 || vblank - prev < 16366) /* +0.3 ~ -0.3 ms */
62 printf("vblank : %d us\n", vblank - prev);
64 if (client - vblank > 2000) /* 2ms */
65 printf("kernel -> tdm-client: %d us\n", client - vblank);
72 main(int argc, char *argv[])
75 tdm_client_error error;
79 client = tdm_client_create(&error);
80 if (error != TDM_CLIENT_ERROR_NONE) {
81 printf("tdm_client_create failed\n");
85 error = tdm_client_get_fd(client, &fd);
86 if (error != TDM_CLIENT_ERROR_NONE || fd < 0) {
87 printf("tdm_client_get_fd failed\n");
98 error = tdm_client_wait_vblank(client, "unknown-0", 1, 0,
99 _client_vblank_handler, NULL);
100 if (error != TDM_CLIENT_ERROR_NONE) {
101 printf("tdm_client_wait_vblank failed\n");
105 ret = poll(&fds, 1, -1);
107 if (errno == EBUSY) /* normal case */
110 printf("poll failed: %m\n");
115 error = tdm_client_handle_events(client);
116 if (error != TDM_CLIENT_ERROR_NONE)
117 printf("tdm_client_handle_events failed\n");
121 tdm_client_destroy(client);