1 /* Copyright 2019 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #ifndef CRAS_BT_LOG_H_
7 #define CRAS_BT_LOG_H_
8
9 #include <stdint.h>
10
11 #include "cras_types.h"
12
13 #define CRAS_BT_LOGGING 1
14
15 #if (CRAS_BT_LOGGING)
16 #define BTLOG(log, event, data1, data2) \
17 cras_bt_event_log_data(log, event, data1, data2);
18 #else
19 #define BTLOG(log, event, data1, data2)
20 #endif
21
22 extern struct cras_bt_event_log *btlog;
23
cras_bt_event_log_init()24 static inline struct cras_bt_event_log *cras_bt_event_log_init()
25 {
26 struct cras_bt_event_log *log;
27 log = (struct cras_bt_event_log *)calloc(
28 1, sizeof(struct cras_bt_event_log));
29 log->len = CRAS_BT_EVENT_LOG_SIZE;
30
31 return log;
32 }
33
cras_bt_event_log_deinit(struct cras_bt_event_log * log)34 static inline void cras_bt_event_log_deinit(struct cras_bt_event_log *log)
35 {
36 free(log);
37 }
38
cras_bt_event_log_data(struct cras_bt_event_log * log,enum CRAS_BT_LOG_EVENTS event,uint32_t data1,uint32_t data2)39 static inline void cras_bt_event_log_data(struct cras_bt_event_log *log,
40 enum CRAS_BT_LOG_EVENTS event,
41 uint32_t data1, uint32_t data2)
42 {
43 struct timespec now;
44
45 clock_gettime(CLOCK_MONOTONIC_RAW, &now);
46 log->log[log->write_pos].tag_sec =
47 (event << 24) | (now.tv_sec & 0x00ffffff);
48 log->log[log->write_pos].nsec = now.tv_nsec;
49 log->log[log->write_pos].data1 = data1;
50 log->log[log->write_pos].data2 = data2;
51
52 log->write_pos++;
53 log->write_pos %= CRAS_BT_EVENT_LOG_SIZE;
54 }
55
56 #endif /* CRAS_BT_LOG_H_ */