• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __TRANSQ_MSG_H__
16 #define __TRANSQ_MSG_H__
17 
18 #include "hal_transq.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 typedef void (*TRANSQ_MSG_HANDLE_CB_T)(void *param);
25 
26 typedef enum {
27     TRANSQ_MSG_TYPE_TRACE,
28     TRANSQ_MSG_TYPE_AF_OPEN,
29     TRANSQ_MSG_TYPE_AF_CLOSE,
30     TRANSQ_MSG_TYPE_AF_CAPTURE_START,
31     TRANSQ_MSG_TYPE_AF_CAPTURE_STOP,
32     TRANSQ_MSG_TYPE_AF_PLAYBACK_START,
33     TRANSQ_MSG_TYPE_AF_PLAYBACK_STOP,
34     TRANSQ_MSG_TYPE_AF_CAPTURE_IRQ,
35     TRANSQ_MSG_TYPE_AF_PLAYBACK_IRQ,
36     TRANSQ_MSG_TYPE_RECORD_DATA,
37     TRANSQ_MSG_TYPE_USERDATA,
38     TRANSQ_MSG_TYPE_VOIP,
39     TRANSQ_MSG_TYPE_KEY,
40     TRANSQ_MSG_TYPE_CMD,
41     TRANSQ_MSG_TYPE_AUDIO_DUMP,
42     TRANSQ_MSG_TYPE_HEARTBEAT,
43     TRANSQ_MSG_TYPE_CODEC,
44     TRANSQ_MSG_TYPE_MIC_EQ_CFG,
45     TRANSQ_MSG_TYPE_NUM,
46 }TRANSQ_MSG_TYPE_T;
47 
48 struct TRANSQ_MSG_TRACE {
49     unsigned int addr;
50     unsigned int len;
51 };
52 
53 struct TRANSQ_MSG_AF_CONFIG_T {
54     unsigned int bits;
55     unsigned int sample_rate;
56     unsigned int channel_num;
57     unsigned int channel_map;
58     unsigned int device;
59     unsigned int io_path;
60     bool chan_sep_buf;
61     bool i2s_master_clk_wait;
62     unsigned char i2s_sample_cycles;
63     unsigned char *data_ptr;
64     unsigned int data_size;
65 
66     //should define type
67     unsigned char vol;
68 };
69 
70 struct TRANSQ_MSG_AF_BUF {
71     unsigned char *buf;
72     unsigned int len;
73 };
74 
75 union TRANSQ_MSG {
76     struct TRANSQ_MSG_TRACE trace;
77     struct TRANSQ_MSG_AF_CONFIG_T stream_cfg;
78     struct TRANSQ_MSG_AF_BUF stream_buf;
79 };
80 
81 typedef struct {
82     TRANSQ_MSG_TYPE_T type;
83     enum HAL_TRANSQ_PRI_T pri;
84     unsigned int id;
85     union TRANSQ_MSG msg;
86     void *user_data;
87     unsigned int user_data_len;
88     unsigned char sync;
89 } TRANSQ_MSG_T;
90 
91 #ifndef RTOS
92 #define transq_msg_tx_wait_done(p) \
93 do{ \
94     transq_tx_done = 0; \
95     if(transq_msg_tx(p)) { \
96         while (!transq_tx_done) { \
97             hal_sys_timer_delay(MS_TO_TICKS(1)); \
98         } \
99         hal_sys_timer_delay(MS_TO_TICKS(1)); \
100     } \
101 }while(0)
102 #else
103 #define transq_msg_tx_wait_done(p) \
104 do{ \
105     if(transq_msg_tx(p)) { \
106         if (transq_tx_sem != NULL) { \
107             osSemaphoreWait(transq_tx_sem, osWaitForever); \
108         } \
109     } \
110 }while(0)
111 #endif
112 
113 int transq_msg_init();
114 int transq_msg_reinit();
115 int transq_msg_flush();
116 void transq_msg_onoff(int onoff);
117 int transq_msg_tx(TRANSQ_MSG_T *msg);
118 void transq_msg_register(TRANSQ_MSG_TYPE_T type, TRANSQ_MSG_HANDLE_CB_T func, bool tx);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 #endif
124