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_NUM, 45 }TRANSQ_MSG_TYPE_T; 46 47 struct TRANSQ_MSG_TRACE { 48 unsigned int addr; 49 unsigned int len; 50 }; 51 52 struct TRANSQ_MSG_AF_CONFIG_T { 53 unsigned int bits; 54 unsigned int sample_rate; 55 unsigned int channel_num; 56 unsigned int channel_map; 57 unsigned int device; 58 unsigned int io_path; 59 bool chan_sep_buf; 60 bool i2s_master_clk_wait; 61 unsigned char i2s_sample_cycles; 62 unsigned char *data_ptr; 63 unsigned int data_size; 64 65 //should define type 66 unsigned char vol; 67 }; 68 69 struct TRANSQ_MSG_AF_BUF { 70 unsigned char *buf; 71 unsigned int len; 72 }; 73 74 union TRANSQ_MSG { 75 struct TRANSQ_MSG_TRACE trace; 76 struct TRANSQ_MSG_AF_CONFIG_T stream_cfg; 77 struct TRANSQ_MSG_AF_BUF stream_buf; 78 }; 79 80 typedef struct { 81 TRANSQ_MSG_TYPE_T type; 82 enum HAL_TRANSQ_PRI_T pri; 83 unsigned int id; 84 union TRANSQ_MSG msg; 85 void *user_data; 86 unsigned int user_data_len; 87 unsigned char sync; 88 } TRANSQ_MSG_T; 89 90 #ifndef RTOS 91 #define transq_msg_tx_wait_done(p) \ 92 do{ \ 93 transq_tx_done = 0; \ 94 if(transq_msg_tx(p)) { \ 95 while (!transq_tx_done) { \ 96 hal_sys_timer_delay(MS_TO_TICKS(1)); \ 97 } \ 98 hal_sys_timer_delay(MS_TO_TICKS(1)); \ 99 } \ 100 }while(0) 101 #else 102 #define transq_msg_tx_wait_done(p) \ 103 do{ \ 104 if(transq_msg_tx(p)) { \ 105 if (transq_tx_sem != NULL) { \ 106 osSemaphoreWait(transq_tx_sem, osWaitForever); \ 107 } \ 108 } \ 109 }while(0) 110 #endif 111 112 int transq_msg_init(); 113 int transq_msg_reinit(); 114 int transq_msg_flush(); 115 void transq_msg_onoff(int onoff); 116 int transq_msg_tx(TRANSQ_MSG_T *msg); 117 void transq_msg_register(TRANSQ_MSG_TYPE_T type, TRANSQ_MSG_HANDLE_CB_T func, bool tx); 118 119 #ifdef __cplusplus 120 } 121 #endif 122 #endif 123