hpifunc.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  1. #include "hpi_internal.h"
  2. #include "hpimsginit.h"
  3. #include "hpidebug.h"
  4. struct hpi_handle {
  5. unsigned int obj_index:12;
  6. unsigned int obj_type:4;
  7. unsigned int adapter_index:14;
  8. unsigned int spare:1;
  9. unsigned int read_only:1;
  10. };
  11. union handle_word {
  12. struct hpi_handle h;
  13. u32 w;
  14. };
  15. u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
  16. const u16 object_index)
  17. {
  18. union handle_word handle;
  19. handle.h.adapter_index = adapter_index;
  20. handle.h.spare = 0;
  21. handle.h.read_only = 0;
  22. handle.h.obj_type = c_object;
  23. handle.h.obj_index = object_index;
  24. return handle.w;
  25. }
  26. static u16 hpi_handle_indexes(const u32 h, u16 *p1, u16 *p2)
  27. {
  28. union handle_word uhandle;
  29. if (!h)
  30. return HPI_ERROR_INVALID_HANDLE;
  31. uhandle.w = h;
  32. *p1 = (u16)uhandle.h.adapter_index;
  33. if (p2)
  34. *p2 = (u16)uhandle.h.obj_index;
  35. return 0;
  36. }
  37. void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
  38. u16 *pw_object_index)
  39. {
  40. hpi_handle_indexes(handle, pw_adapter_index, pw_object_index);
  41. }
  42. char hpi_handle_object(const u32 handle)
  43. {
  44. union handle_word uhandle;
  45. uhandle.w = handle;
  46. return (char)uhandle.h.obj_type;
  47. }
  48. void hpi_format_to_msg(struct hpi_msg_format *pMF,
  49. const struct hpi_format *pF)
  50. {
  51. pMF->sample_rate = pF->sample_rate;
  52. pMF->bit_rate = pF->bit_rate;
  53. pMF->attributes = pF->attributes;
  54. pMF->channels = pF->channels;
  55. pMF->format = pF->format;
  56. }
  57. static void hpi_msg_to_format(struct hpi_format *pF,
  58. struct hpi_msg_format *pMF)
  59. {
  60. pF->sample_rate = pMF->sample_rate;
  61. pF->bit_rate = pMF->bit_rate;
  62. pF->attributes = pMF->attributes;
  63. pF->channels = pMF->channels;
  64. pF->format = pMF->format;
  65. pF->mode_legacy = 0;
  66. pF->unused = 0;
  67. }
  68. void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
  69. {
  70. pSR->u.legacy_stream_info.auxiliary_data_available =
  71. pSR->u.stream_info.auxiliary_data_available;
  72. pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
  73. }
  74. static inline void hpi_send_recvV1(struct hpi_message_header *m,
  75. struct hpi_response_header *r)
  76. {
  77. hpi_send_recv((struct hpi_message *)m, (struct hpi_response *)r);
  78. }
  79. u16 hpi_subsys_get_version_ex(u32 *pversion_ex)
  80. {
  81. struct hpi_message hm;
  82. struct hpi_response hr;
  83. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  84. HPI_SUBSYS_GET_VERSION);
  85. hpi_send_recv(&hm, &hr);
  86. *pversion_ex = hr.u.s.data;
  87. return hr.error;
  88. }
  89. u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)
  90. {
  91. struct hpi_message hm;
  92. struct hpi_response hr;
  93. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  94. HPI_SUBSYS_GET_NUM_ADAPTERS);
  95. hpi_send_recv(&hm, &hr);
  96. *pn_num_adapters = (int)hr.u.s.num_adapters;
  97. return hr.error;
  98. }
  99. u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index,
  100. u16 *pw_adapter_type)
  101. {
  102. struct hpi_message hm;
  103. struct hpi_response hr;
  104. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  105. HPI_SUBSYS_GET_ADAPTER);
  106. hm.obj_index = (u16)iterator;
  107. hpi_send_recv(&hm, &hr);
  108. *padapter_index = (int)hr.u.s.adapter_index;
  109. *pw_adapter_type = hr.u.s.adapter_type;
  110. return hr.error;
  111. }
  112. u16 hpi_adapter_open(u16 adapter_index)
  113. {
  114. struct hpi_message hm;
  115. struct hpi_response hr;
  116. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  117. HPI_ADAPTER_OPEN);
  118. hm.adapter_index = adapter_index;
  119. hpi_send_recv(&hm, &hr);
  120. return hr.error;
  121. }
  122. u16 hpi_adapter_close(u16 adapter_index)
  123. {
  124. struct hpi_message hm;
  125. struct hpi_response hr;
  126. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  127. HPI_ADAPTER_CLOSE);
  128. hm.adapter_index = adapter_index;
  129. hpi_send_recv(&hm, &hr);
  130. return hr.error;
  131. }
  132. u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)
  133. {
  134. return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,
  135. HPI_ADAPTER_MODE_SET);
  136. }
  137. u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode,
  138. u16 query_or_set)
  139. {
  140. struct hpi_message hm;
  141. struct hpi_response hr;
  142. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  143. HPI_ADAPTER_SET_MODE);
  144. hm.adapter_index = adapter_index;
  145. hm.u.ax.mode.adapter_mode = adapter_mode;
  146. hm.u.ax.mode.query_or_set = query_or_set;
  147. hpi_send_recv(&hm, &hr);
  148. return hr.error;
  149. }
  150. u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)
  151. {
  152. struct hpi_message hm;
  153. struct hpi_response hr;
  154. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  155. HPI_ADAPTER_GET_MODE);
  156. hm.adapter_index = adapter_index;
  157. hpi_send_recv(&hm, &hr);
  158. if (padapter_mode)
  159. *padapter_mode = hr.u.ax.mode.adapter_mode;
  160. return hr.error;
  161. }
  162. u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams,
  163. u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number,
  164. u16 *pw_adapter_type)
  165. {
  166. struct hpi_message hm;
  167. struct hpi_response hr;
  168. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  169. HPI_ADAPTER_GET_INFO);
  170. hm.adapter_index = adapter_index;
  171. hpi_send_recv(&hm, &hr);
  172. *pw_adapter_type = hr.u.ax.info.adapter_type;
  173. *pw_num_outstreams = hr.u.ax.info.num_outstreams;
  174. *pw_num_instreams = hr.u.ax.info.num_instreams;
  175. *pw_version = hr.u.ax.info.version;
  176. *pserial_number = hr.u.ax.info.serial_number;
  177. return hr.error;
  178. }
  179. u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index,
  180. u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version,
  181. u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)
  182. {
  183. struct hpi_message hm;
  184. struct hpi_response hr;
  185. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  186. HPI_ADAPTER_MODULE_INFO);
  187. hm.adapter_index = adapter_index;
  188. hm.u.ax.module_info.index = module_index;
  189. hpi_send_recv(&hm, &hr);
  190. *pw_module_type = hr.u.ax.info.adapter_type;
  191. *pw_num_outputs = hr.u.ax.info.num_outstreams;
  192. *pw_num_inputs = hr.u.ax.info.num_instreams;
  193. *pw_version = hr.u.ax.info.version;
  194. *pserial_number = hr.u.ax.info.serial_number;
  195. *ph_module = 0;
  196. return hr.error;
  197. }
  198. u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1,
  199. u16 parameter2)
  200. {
  201. struct hpi_message hm;
  202. struct hpi_response hr;
  203. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  204. HPI_ADAPTER_SET_PROPERTY);
  205. hm.adapter_index = adapter_index;
  206. hm.u.ax.property_set.property = property;
  207. hm.u.ax.property_set.parameter1 = parameter1;
  208. hm.u.ax.property_set.parameter2 = parameter2;
  209. hpi_send_recv(&hm, &hr);
  210. return hr.error;
  211. }
  212. u16 hpi_adapter_get_property(u16 adapter_index, u16 property,
  213. u16 *pw_parameter1, u16 *pw_parameter2)
  214. {
  215. struct hpi_message hm;
  216. struct hpi_response hr;
  217. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  218. HPI_ADAPTER_GET_PROPERTY);
  219. hm.adapter_index = adapter_index;
  220. hm.u.ax.property_set.property = property;
  221. hpi_send_recv(&hm, &hr);
  222. if (!hr.error) {
  223. if (pw_parameter1)
  224. *pw_parameter1 = hr.u.ax.property_get.parameter1;
  225. if (pw_parameter2)
  226. *pw_parameter2 = hr.u.ax.property_get.parameter2;
  227. }
  228. return hr.error;
  229. }
  230. u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index,
  231. u16 what_to_enumerate, u16 property_index, u32 *psetting)
  232. {
  233. return 0;
  234. }
  235. u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
  236. u32 sample_rate, u32 bit_rate, u32 attributes)
  237. {
  238. u16 err = 0;
  239. struct hpi_msg_format fmt;
  240. switch (channels) {
  241. case 1:
  242. case 2:
  243. case 4:
  244. case 6:
  245. case 8:
  246. case 16:
  247. break;
  248. default:
  249. err = HPI_ERROR_INVALID_CHANNELS;
  250. return err;
  251. }
  252. fmt.channels = channels;
  253. switch (format) {
  254. case HPI_FORMAT_PCM16_SIGNED:
  255. case HPI_FORMAT_PCM24_SIGNED:
  256. case HPI_FORMAT_PCM32_SIGNED:
  257. case HPI_FORMAT_PCM32_FLOAT:
  258. case HPI_FORMAT_PCM16_BIGENDIAN:
  259. case HPI_FORMAT_PCM8_UNSIGNED:
  260. case HPI_FORMAT_MPEG_L1:
  261. case HPI_FORMAT_MPEG_L2:
  262. case HPI_FORMAT_MPEG_L3:
  263. case HPI_FORMAT_DOLBY_AC2:
  264. case HPI_FORMAT_AA_TAGIT1_HITS:
  265. case HPI_FORMAT_AA_TAGIT1_INSERTS:
  266. case HPI_FORMAT_RAW_BITSTREAM:
  267. case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
  268. case HPI_FORMAT_OEM1:
  269. case HPI_FORMAT_OEM2:
  270. break;
  271. default:
  272. err = HPI_ERROR_INVALID_FORMAT;
  273. return err;
  274. }
  275. fmt.format = format;
  276. if (sample_rate < 8000L) {
  277. err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  278. sample_rate = 8000L;
  279. }
  280. if (sample_rate > 200000L) {
  281. err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  282. sample_rate = 200000L;
  283. }
  284. fmt.sample_rate = sample_rate;
  285. switch (format) {
  286. case HPI_FORMAT_MPEG_L1:
  287. case HPI_FORMAT_MPEG_L2:
  288. case HPI_FORMAT_MPEG_L3:
  289. fmt.bit_rate = bit_rate;
  290. break;
  291. case HPI_FORMAT_PCM16_SIGNED:
  292. case HPI_FORMAT_PCM16_BIGENDIAN:
  293. fmt.bit_rate = channels * sample_rate * 2;
  294. break;
  295. case HPI_FORMAT_PCM32_SIGNED:
  296. case HPI_FORMAT_PCM32_FLOAT:
  297. fmt.bit_rate = channels * sample_rate * 4;
  298. break;
  299. case HPI_FORMAT_PCM8_UNSIGNED:
  300. fmt.bit_rate = channels * sample_rate;
  301. break;
  302. default:
  303. fmt.bit_rate = 0;
  304. }
  305. switch (format) {
  306. case HPI_FORMAT_MPEG_L2:
  307. if ((channels == 1)
  308. && (attributes != HPI_MPEG_MODE_DEFAULT)) {
  309. attributes = HPI_MPEG_MODE_DEFAULT;
  310. err = HPI_ERROR_INVALID_FORMAT;
  311. } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
  312. attributes = HPI_MPEG_MODE_DEFAULT;
  313. err = HPI_ERROR_INVALID_FORMAT;
  314. }
  315. fmt.attributes = attributes;
  316. break;
  317. default:
  318. fmt.attributes = attributes;
  319. }
  320. hpi_msg_to_format(p_format, &fmt);
  321. return err;
  322. }
  323. u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
  324. u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
  325. {
  326. u32 bytes_per_second;
  327. u32 size;
  328. u16 channels;
  329. struct hpi_format *pF = p_format;
  330. channels = pF->channels;
  331. switch (pF->format) {
  332. case HPI_FORMAT_PCM16_BIGENDIAN:
  333. case HPI_FORMAT_PCM16_SIGNED:
  334. bytes_per_second = pF->sample_rate * 2L * channels;
  335. break;
  336. case HPI_FORMAT_PCM24_SIGNED:
  337. bytes_per_second = pF->sample_rate * 3L * channels;
  338. break;
  339. case HPI_FORMAT_PCM32_SIGNED:
  340. case HPI_FORMAT_PCM32_FLOAT:
  341. bytes_per_second = pF->sample_rate * 4L * channels;
  342. break;
  343. case HPI_FORMAT_PCM8_UNSIGNED:
  344. bytes_per_second = pF->sample_rate * 1L * channels;
  345. break;
  346. case HPI_FORMAT_MPEG_L1:
  347. case HPI_FORMAT_MPEG_L2:
  348. case HPI_FORMAT_MPEG_L3:
  349. bytes_per_second = pF->bit_rate / 8L;
  350. break;
  351. case HPI_FORMAT_DOLBY_AC2:
  352. bytes_per_second = 256000L / 8L;
  353. break;
  354. default:
  355. return HPI_ERROR_INVALID_FORMAT;
  356. }
  357. size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
  358. 1000L;
  359. *recommended_buffer_size =
  360. roundup_pow_of_two(((size + 4095L) & ~4095L));
  361. return 0;
  362. }
  363. u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index,
  364. u32 *ph_outstream)
  365. {
  366. struct hpi_message hm;
  367. struct hpi_response hr;
  368. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  369. HPI_OSTREAM_OPEN);
  370. hm.adapter_index = adapter_index;
  371. hm.obj_index = outstream_index;
  372. hpi_send_recv(&hm, &hr);
  373. if (hr.error == 0)
  374. *ph_outstream =
  375. hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
  376. outstream_index);
  377. else
  378. *ph_outstream = 0;
  379. return hr.error;
  380. }
  381. u16 hpi_outstream_close(u32 h_outstream)
  382. {
  383. struct hpi_message hm;
  384. struct hpi_response hr;
  385. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  386. HPI_OSTREAM_HOSTBUFFER_FREE);
  387. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  388. return HPI_ERROR_INVALID_HANDLE;
  389. hpi_send_recv(&hm, &hr);
  390. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  391. HPI_OSTREAM_GROUP_RESET);
  392. hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
  393. hpi_send_recv(&hm, &hr);
  394. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  395. HPI_OSTREAM_CLOSE);
  396. hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
  397. hpi_send_recv(&hm, &hr);
  398. return hr.error;
  399. }
  400. u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state,
  401. u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played,
  402. u32 *pauxiliary_data_to_play)
  403. {
  404. struct hpi_message hm;
  405. struct hpi_response hr;
  406. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  407. HPI_OSTREAM_GET_INFO);
  408. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  409. return HPI_ERROR_INVALID_HANDLE;
  410. hpi_send_recv(&hm, &hr);
  411. if (pw_state)
  412. *pw_state = hr.u.d.u.stream_info.state;
  413. if (pbuffer_size)
  414. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  415. if (pdata_to_play)
  416. *pdata_to_play = hr.u.d.u.stream_info.data_available;
  417. if (psamples_played)
  418. *psamples_played = hr.u.d.u.stream_info.samples_transferred;
  419. if (pauxiliary_data_to_play)
  420. *pauxiliary_data_to_play =
  421. hr.u.d.u.stream_info.auxiliary_data_available;
  422. return hr.error;
  423. }
  424. u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data,
  425. u32 bytes_to_write, const struct hpi_format *p_format)
  426. {
  427. struct hpi_message hm;
  428. struct hpi_response hr;
  429. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  430. HPI_OSTREAM_WRITE);
  431. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  432. return HPI_ERROR_INVALID_HANDLE;
  433. hm.u.d.u.data.pb_data = (u8 *)pb_data;
  434. hm.u.d.u.data.data_size = bytes_to_write;
  435. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  436. hpi_send_recv(&hm, &hr);
  437. return hr.error;
  438. }
  439. u16 hpi_outstream_start(u32 h_outstream)
  440. {
  441. struct hpi_message hm;
  442. struct hpi_response hr;
  443. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  444. HPI_OSTREAM_START);
  445. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  446. return HPI_ERROR_INVALID_HANDLE;
  447. hpi_send_recv(&hm, &hr);
  448. return hr.error;
  449. }
  450. u16 hpi_outstream_wait_start(u32 h_outstream)
  451. {
  452. struct hpi_message hm;
  453. struct hpi_response hr;
  454. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  455. HPI_OSTREAM_WAIT_START);
  456. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  457. return HPI_ERROR_INVALID_HANDLE;
  458. hpi_send_recv(&hm, &hr);
  459. return hr.error;
  460. }
  461. u16 hpi_outstream_stop(u32 h_outstream)
  462. {
  463. struct hpi_message hm;
  464. struct hpi_response hr;
  465. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  466. HPI_OSTREAM_STOP);
  467. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  468. return HPI_ERROR_INVALID_HANDLE;
  469. hpi_send_recv(&hm, &hr);
  470. return hr.error;
  471. }
  472. u16 hpi_outstream_sinegen(u32 h_outstream)
  473. {
  474. struct hpi_message hm;
  475. struct hpi_response hr;
  476. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  477. HPI_OSTREAM_SINEGEN);
  478. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  479. return HPI_ERROR_INVALID_HANDLE;
  480. hpi_send_recv(&hm, &hr);
  481. return hr.error;
  482. }
  483. u16 hpi_outstream_reset(u32 h_outstream)
  484. {
  485. struct hpi_message hm;
  486. struct hpi_response hr;
  487. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  488. HPI_OSTREAM_RESET);
  489. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  490. return HPI_ERROR_INVALID_HANDLE;
  491. hpi_send_recv(&hm, &hr);
  492. return hr.error;
  493. }
  494. u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)
  495. {
  496. struct hpi_message hm;
  497. struct hpi_response hr;
  498. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  499. HPI_OSTREAM_QUERY_FORMAT);
  500. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  501. return HPI_ERROR_INVALID_HANDLE;
  502. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  503. hpi_send_recv(&hm, &hr);
  504. return hr.error;
  505. }
  506. u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)
  507. {
  508. struct hpi_message hm;
  509. struct hpi_response hr;
  510. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  511. HPI_OSTREAM_SET_FORMAT);
  512. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  513. return HPI_ERROR_INVALID_HANDLE;
  514. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  515. hpi_send_recv(&hm, &hr);
  516. return hr.error;
  517. }
  518. u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)
  519. {
  520. struct hpi_message hm;
  521. struct hpi_response hr;
  522. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  523. HPI_OSTREAM_SET_VELOCITY);
  524. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  525. return HPI_ERROR_INVALID_HANDLE;
  526. hm.u.d.u.velocity = velocity;
  527. hpi_send_recv(&hm, &hr);
  528. return hr.error;
  529. }
  530. u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample,
  531. u32 punch_out_sample)
  532. {
  533. struct hpi_message hm;
  534. struct hpi_response hr;
  535. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  536. HPI_OSTREAM_SET_PUNCHINOUT);
  537. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  538. return HPI_ERROR_INVALID_HANDLE;
  539. hm.u.d.u.pio.punch_in_sample = punch_in_sample;
  540. hm.u.d.u.pio.punch_out_sample = punch_out_sample;
  541. hpi_send_recv(&hm, &hr);
  542. return hr.error;
  543. }
  544. u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)
  545. {
  546. struct hpi_message hm;
  547. struct hpi_response hr;
  548. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  549. HPI_OSTREAM_ANC_RESET);
  550. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  551. return HPI_ERROR_INVALID_HANDLE;
  552. hm.u.d.u.data.format.channels = mode;
  553. hpi_send_recv(&hm, &hr);
  554. return hr.error;
  555. }
  556. u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)
  557. {
  558. struct hpi_message hm;
  559. struct hpi_response hr;
  560. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  561. HPI_OSTREAM_ANC_GET_INFO);
  562. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  563. return HPI_ERROR_INVALID_HANDLE;
  564. hpi_send_recv(&hm, &hr);
  565. if (hr.error == 0) {
  566. if (pframes_available)
  567. *pframes_available =
  568. hr.u.d.u.stream_info.data_available /
  569. sizeof(struct hpi_anc_frame);
  570. }
  571. return hr.error;
  572. }
  573. u16 hpi_outstream_ancillary_read(u32 h_outstream,
  574. struct hpi_anc_frame *p_anc_frame_buffer,
  575. u32 anc_frame_buffer_size_in_bytes,
  576. u32 number_of_ancillary_frames_to_read)
  577. {
  578. struct hpi_message hm;
  579. struct hpi_response hr;
  580. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  581. HPI_OSTREAM_ANC_READ);
  582. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  583. return HPI_ERROR_INVALID_HANDLE;
  584. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  585. hm.u.d.u.data.data_size =
  586. number_of_ancillary_frames_to_read *
  587. sizeof(struct hpi_anc_frame);
  588. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  589. hpi_send_recv(&hm, &hr);
  590. else
  591. hr.error = HPI_ERROR_INVALID_DATASIZE;
  592. return hr.error;
  593. }
  594. u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)
  595. {
  596. struct hpi_message hm;
  597. struct hpi_response hr;
  598. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  599. HPI_OSTREAM_SET_TIMESCALE);
  600. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  601. return HPI_ERROR_INVALID_HANDLE;
  602. hm.u.d.u.time_scale = time_scale;
  603. hpi_send_recv(&hm, &hr);
  604. return hr.error;
  605. }
  606. u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)
  607. {
  608. struct hpi_message hm;
  609. struct hpi_response hr;
  610. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  611. HPI_OSTREAM_HOSTBUFFER_ALLOC);
  612. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  613. return HPI_ERROR_INVALID_HANDLE;
  614. hm.u.d.u.data.data_size = size_in_bytes;
  615. hpi_send_recv(&hm, &hr);
  616. return hr.error;
  617. }
  618. u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
  619. struct hpi_hostbuffer_status **pp_status)
  620. {
  621. struct hpi_message hm;
  622. struct hpi_response hr;
  623. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  624. HPI_OSTREAM_HOSTBUFFER_GET_INFO);
  625. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  626. return HPI_ERROR_INVALID_HANDLE;
  627. hpi_send_recv(&hm, &hr);
  628. if (hr.error == 0) {
  629. if (pp_buffer)
  630. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  631. if (pp_status)
  632. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  633. }
  634. return hr.error;
  635. }
  636. u16 hpi_outstream_host_buffer_free(u32 h_outstream)
  637. {
  638. struct hpi_message hm;
  639. struct hpi_response hr;
  640. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  641. HPI_OSTREAM_HOSTBUFFER_FREE);
  642. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  643. return HPI_ERROR_INVALID_HANDLE;
  644. hpi_send_recv(&hm, &hr);
  645. return hr.error;
  646. }
  647. u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)
  648. {
  649. struct hpi_message hm;
  650. struct hpi_response hr;
  651. u16 adapter;
  652. char c_obj_type;
  653. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  654. HPI_OSTREAM_GROUP_ADD);
  655. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  656. return HPI_ERROR_INVALID_HANDLE;
  657. if (hpi_handle_indexes(h_stream, &adapter,
  658. &hm.u.d.u.stream.stream_index))
  659. return HPI_ERROR_INVALID_HANDLE;
  660. c_obj_type = hpi_handle_object(h_stream);
  661. switch (c_obj_type) {
  662. case HPI_OBJ_OSTREAM:
  663. case HPI_OBJ_ISTREAM:
  664. hm.u.d.u.stream.object_type = c_obj_type;
  665. break;
  666. default:
  667. return HPI_ERROR_INVALID_OBJ;
  668. }
  669. if (adapter != hm.adapter_index)
  670. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  671. hpi_send_recv(&hm, &hr);
  672. return hr.error;
  673. }
  674. u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map,
  675. u32 *pinstream_map)
  676. {
  677. struct hpi_message hm;
  678. struct hpi_response hr;
  679. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  680. HPI_OSTREAM_GROUP_GETMAP);
  681. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  682. return HPI_ERROR_INVALID_HANDLE;
  683. hpi_send_recv(&hm, &hr);
  684. if (poutstream_map)
  685. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  686. if (pinstream_map)
  687. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  688. return hr.error;
  689. }
  690. u16 hpi_outstream_group_reset(u32 h_outstream)
  691. {
  692. struct hpi_message hm;
  693. struct hpi_response hr;
  694. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  695. HPI_OSTREAM_GROUP_RESET);
  696. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  697. return HPI_ERROR_INVALID_HANDLE;
  698. hpi_send_recv(&hm, &hr);
  699. return hr.error;
  700. }
  701. u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)
  702. {
  703. struct hpi_message hm;
  704. struct hpi_response hr;
  705. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  706. HPI_ISTREAM_OPEN);
  707. hm.adapter_index = adapter_index;
  708. hm.obj_index = instream_index;
  709. hpi_send_recv(&hm, &hr);
  710. if (hr.error == 0)
  711. *ph_instream =
  712. hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
  713. instream_index);
  714. else
  715. *ph_instream = 0;
  716. return hr.error;
  717. }
  718. u16 hpi_instream_close(u32 h_instream)
  719. {
  720. struct hpi_message hm;
  721. struct hpi_response hr;
  722. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  723. HPI_ISTREAM_HOSTBUFFER_FREE);
  724. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  725. return HPI_ERROR_INVALID_HANDLE;
  726. hpi_send_recv(&hm, &hr);
  727. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  728. HPI_ISTREAM_GROUP_RESET);
  729. hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
  730. hpi_send_recv(&hm, &hr);
  731. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  732. HPI_ISTREAM_CLOSE);
  733. hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
  734. hpi_send_recv(&hm, &hr);
  735. return hr.error;
  736. }
  737. u16 hpi_instream_query_format(u32 h_instream,
  738. const struct hpi_format *p_format)
  739. {
  740. struct hpi_message hm;
  741. struct hpi_response hr;
  742. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  743. HPI_ISTREAM_QUERY_FORMAT);
  744. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  745. return HPI_ERROR_INVALID_HANDLE;
  746. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  747. hpi_send_recv(&hm, &hr);
  748. return hr.error;
  749. }
  750. u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)
  751. {
  752. struct hpi_message hm;
  753. struct hpi_response hr;
  754. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  755. HPI_ISTREAM_SET_FORMAT);
  756. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  757. return HPI_ERROR_INVALID_HANDLE;
  758. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  759. hpi_send_recv(&hm, &hr);
  760. return hr.error;
  761. }
  762. u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)
  763. {
  764. struct hpi_message hm;
  765. struct hpi_response hr;
  766. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  767. HPI_ISTREAM_READ);
  768. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  769. return HPI_ERROR_INVALID_HANDLE;
  770. hm.u.d.u.data.data_size = bytes_to_read;
  771. hm.u.d.u.data.pb_data = pb_data;
  772. hpi_send_recv(&hm, &hr);
  773. return hr.error;
  774. }
  775. u16 hpi_instream_start(u32 h_instream)
  776. {
  777. struct hpi_message hm;
  778. struct hpi_response hr;
  779. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  780. HPI_ISTREAM_START);
  781. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  782. return HPI_ERROR_INVALID_HANDLE;
  783. hpi_send_recv(&hm, &hr);
  784. return hr.error;
  785. }
  786. u16 hpi_instream_wait_start(u32 h_instream)
  787. {
  788. struct hpi_message hm;
  789. struct hpi_response hr;
  790. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  791. HPI_ISTREAM_WAIT_START);
  792. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  793. return HPI_ERROR_INVALID_HANDLE;
  794. hpi_send_recv(&hm, &hr);
  795. return hr.error;
  796. }
  797. u16 hpi_instream_stop(u32 h_instream)
  798. {
  799. struct hpi_message hm;
  800. struct hpi_response hr;
  801. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  802. HPI_ISTREAM_STOP);
  803. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  804. return HPI_ERROR_INVALID_HANDLE;
  805. hpi_send_recv(&hm, &hr);
  806. return hr.error;
  807. }
  808. u16 hpi_instream_reset(u32 h_instream)
  809. {
  810. struct hpi_message hm;
  811. struct hpi_response hr;
  812. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  813. HPI_ISTREAM_RESET);
  814. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  815. return HPI_ERROR_INVALID_HANDLE;
  816. hpi_send_recv(&hm, &hr);
  817. return hr.error;
  818. }
  819. u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size,
  820. u32 *pdata_recorded, u32 *psamples_recorded,
  821. u32 *pauxiliary_data_recorded)
  822. {
  823. struct hpi_message hm;
  824. struct hpi_response hr;
  825. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  826. HPI_ISTREAM_GET_INFO);
  827. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  828. return HPI_ERROR_INVALID_HANDLE;
  829. hpi_send_recv(&hm, &hr);
  830. if (pw_state)
  831. *pw_state = hr.u.d.u.stream_info.state;
  832. if (pbuffer_size)
  833. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  834. if (pdata_recorded)
  835. *pdata_recorded = hr.u.d.u.stream_info.data_available;
  836. if (psamples_recorded)
  837. *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
  838. if (pauxiliary_data_recorded)
  839. *pauxiliary_data_recorded =
  840. hr.u.d.u.stream_info.auxiliary_data_available;
  841. return hr.error;
  842. }
  843. u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame,
  844. u16 mode, u16 alignment, u16 idle_bit)
  845. {
  846. struct hpi_message hm;
  847. struct hpi_response hr;
  848. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  849. HPI_ISTREAM_ANC_RESET);
  850. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  851. return HPI_ERROR_INVALID_HANDLE;
  852. hm.u.d.u.data.format.attributes = bytes_per_frame;
  853. hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
  854. hm.u.d.u.data.format.channels = idle_bit;
  855. hpi_send_recv(&hm, &hr);
  856. return hr.error;
  857. }
  858. u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)
  859. {
  860. struct hpi_message hm;
  861. struct hpi_response hr;
  862. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  863. HPI_ISTREAM_ANC_GET_INFO);
  864. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  865. return HPI_ERROR_INVALID_HANDLE;
  866. hpi_send_recv(&hm, &hr);
  867. if (pframe_space)
  868. *pframe_space =
  869. (hr.u.d.u.stream_info.buffer_size -
  870. hr.u.d.u.stream_info.data_available) /
  871. sizeof(struct hpi_anc_frame);
  872. return hr.error;
  873. }
  874. u16 hpi_instream_ancillary_write(u32 h_instream,
  875. const struct hpi_anc_frame *p_anc_frame_buffer,
  876. u32 anc_frame_buffer_size_in_bytes,
  877. u32 number_of_ancillary_frames_to_write)
  878. {
  879. struct hpi_message hm;
  880. struct hpi_response hr;
  881. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  882. HPI_ISTREAM_ANC_WRITE);
  883. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  884. return HPI_ERROR_INVALID_HANDLE;
  885. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  886. hm.u.d.u.data.data_size =
  887. number_of_ancillary_frames_to_write *
  888. sizeof(struct hpi_anc_frame);
  889. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  890. hpi_send_recv(&hm, &hr);
  891. else
  892. hr.error = HPI_ERROR_INVALID_DATASIZE;
  893. return hr.error;
  894. }
  895. u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)
  896. {
  897. struct hpi_message hm;
  898. struct hpi_response hr;
  899. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  900. HPI_ISTREAM_HOSTBUFFER_ALLOC);
  901. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  902. return HPI_ERROR_INVALID_HANDLE;
  903. hm.u.d.u.data.data_size = size_in_bytes;
  904. hpi_send_recv(&hm, &hr);
  905. return hr.error;
  906. }
  907. u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
  908. struct hpi_hostbuffer_status **pp_status)
  909. {
  910. struct hpi_message hm;
  911. struct hpi_response hr;
  912. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  913. HPI_ISTREAM_HOSTBUFFER_GET_INFO);
  914. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  915. return HPI_ERROR_INVALID_HANDLE;
  916. hpi_send_recv(&hm, &hr);
  917. if (hr.error == 0) {
  918. if (pp_buffer)
  919. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  920. if (pp_status)
  921. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  922. }
  923. return hr.error;
  924. }
  925. u16 hpi_instream_host_buffer_free(u32 h_instream)
  926. {
  927. struct hpi_message hm;
  928. struct hpi_response hr;
  929. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  930. HPI_ISTREAM_HOSTBUFFER_FREE);
  931. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  932. return HPI_ERROR_INVALID_HANDLE;
  933. hpi_send_recv(&hm, &hr);
  934. return hr.error;
  935. }
  936. u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)
  937. {
  938. struct hpi_message hm;
  939. struct hpi_response hr;
  940. u16 adapter;
  941. char c_obj_type;
  942. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  943. HPI_ISTREAM_GROUP_ADD);
  944. hr.error = 0;
  945. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  946. return HPI_ERROR_INVALID_HANDLE;
  947. if (hpi_handle_indexes(h_stream, &adapter,
  948. &hm.u.d.u.stream.stream_index))
  949. return HPI_ERROR_INVALID_HANDLE;
  950. c_obj_type = hpi_handle_object(h_stream);
  951. switch (c_obj_type) {
  952. case HPI_OBJ_OSTREAM:
  953. case HPI_OBJ_ISTREAM:
  954. hm.u.d.u.stream.object_type = c_obj_type;
  955. break;
  956. default:
  957. return HPI_ERROR_INVALID_OBJ;
  958. }
  959. if (adapter != hm.adapter_index)
  960. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  961. hpi_send_recv(&hm, &hr);
  962. return hr.error;
  963. }
  964. u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map,
  965. u32 *pinstream_map)
  966. {
  967. struct hpi_message hm;
  968. struct hpi_response hr;
  969. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  970. HPI_ISTREAM_HOSTBUFFER_FREE);
  971. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  972. return HPI_ERROR_INVALID_HANDLE;
  973. hpi_send_recv(&hm, &hr);
  974. if (poutstream_map)
  975. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  976. if (pinstream_map)
  977. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  978. return hr.error;
  979. }
  980. u16 hpi_instream_group_reset(u32 h_instream)
  981. {
  982. struct hpi_message hm;
  983. struct hpi_response hr;
  984. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  985. HPI_ISTREAM_GROUP_RESET);
  986. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  987. return HPI_ERROR_INVALID_HANDLE;
  988. hpi_send_recv(&hm, &hr);
  989. return hr.error;
  990. }
  991. u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)
  992. {
  993. struct hpi_message hm;
  994. struct hpi_response hr;
  995. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
  996. hm.adapter_index = adapter_index;
  997. hpi_send_recv(&hm, &hr);
  998. if (hr.error == 0)
  999. *ph_mixer =
  1000. hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
  1001. 0);
  1002. else
  1003. *ph_mixer = 0;
  1004. return hr.error;
  1005. }
  1006. u16 hpi_mixer_close(u32 h_mixer)
  1007. {
  1008. struct hpi_message hm;
  1009. struct hpi_response hr;
  1010. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
  1011. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1012. return HPI_ERROR_INVALID_HANDLE;
  1013. hpi_send_recv(&hm, &hr);
  1014. return hr.error;
  1015. }
  1016. u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type,
  1017. u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index,
  1018. u16 control_type, u32 *ph_control)
  1019. {
  1020. struct hpi_message hm;
  1021. struct hpi_response hr;
  1022. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1023. HPI_MIXER_GET_CONTROL);
  1024. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1025. return HPI_ERROR_INVALID_HANDLE;
  1026. hm.u.m.node_type1 = src_node_type;
  1027. hm.u.m.node_index1 = src_node_type_index;
  1028. hm.u.m.node_type2 = dst_node_type;
  1029. hm.u.m.node_index2 = dst_node_type_index;
  1030. hm.u.m.control_type = control_type;
  1031. hpi_send_recv(&hm, &hr);
  1032. if (hr.error == 0)
  1033. *ph_control =
  1034. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1035. hm.adapter_index, hr.u.m.control_index);
  1036. else
  1037. *ph_control = 0;
  1038. return hr.error;
  1039. }
  1040. u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index,
  1041. u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type,
  1042. u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)
  1043. {
  1044. struct hpi_message hm;
  1045. struct hpi_response hr;
  1046. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1047. HPI_MIXER_GET_CONTROL_BY_INDEX);
  1048. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1049. return HPI_ERROR_INVALID_HANDLE;
  1050. hm.u.m.control_index = control_index;
  1051. hpi_send_recv(&hm, &hr);
  1052. if (pw_src_node_type) {
  1053. *pw_src_node_type =
  1054. hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
  1055. *pw_src_node_index = hr.u.m.src_node_index;
  1056. *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
  1057. *pw_dst_node_index = hr.u.m.dst_node_index;
  1058. }
  1059. if (pw_control_type)
  1060. *pw_control_type = hr.u.m.control_index;
  1061. if (ph_control) {
  1062. if (hr.error == 0)
  1063. *ph_control =
  1064. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1065. hm.adapter_index, control_index);
  1066. else
  1067. *ph_control = 0;
  1068. }
  1069. return hr.error;
  1070. }
  1071. u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command,
  1072. u16 index)
  1073. {
  1074. struct hpi_message hm;
  1075. struct hpi_response hr;
  1076. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
  1077. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1078. return HPI_ERROR_INVALID_HANDLE;
  1079. hm.u.mx.store.command = command;
  1080. hm.u.mx.store.index = index;
  1081. hpi_send_recv(&hm, &hr);
  1082. return hr.error;
  1083. }
  1084. static
  1085. u16 hpi_control_param_set(const u32 h_control, const u16 attrib,
  1086. const u32 param1, const u32 param2)
  1087. {
  1088. struct hpi_message hm;
  1089. struct hpi_response hr;
  1090. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1091. HPI_CONTROL_SET_STATE);
  1092. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1093. return HPI_ERROR_INVALID_HANDLE;
  1094. hm.u.c.attribute = attrib;
  1095. hm.u.c.param1 = param1;
  1096. hm.u.c.param2 = param2;
  1097. hpi_send_recv(&hm, &hr);
  1098. return hr.error;
  1099. }
  1100. static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
  1101. short sv1)
  1102. {
  1103. struct hpi_message hm;
  1104. struct hpi_response hr;
  1105. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1106. HPI_CONTROL_SET_STATE);
  1107. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1108. return HPI_ERROR_INVALID_HANDLE;
  1109. hm.u.c.attribute = attrib;
  1110. hm.u.c.an_log_value[0] = sv0;
  1111. hm.u.c.an_log_value[1] = sv1;
  1112. hpi_send_recv(&hm, &hr);
  1113. return hr.error;
  1114. }
  1115. static
  1116. u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1,
  1117. u32 param2, u32 *pparam1, u32 *pparam2)
  1118. {
  1119. struct hpi_message hm;
  1120. struct hpi_response hr;
  1121. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1122. HPI_CONTROL_GET_STATE);
  1123. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1124. return HPI_ERROR_INVALID_HANDLE;
  1125. hm.u.c.attribute = attrib;
  1126. hm.u.c.param1 = param1;
  1127. hm.u.c.param2 = param2;
  1128. hpi_send_recv(&hm, &hr);
  1129. *pparam1 = hr.u.c.param1;
  1130. if (pparam2)
  1131. *pparam2 = hr.u.c.param2;
  1132. return hr.error;
  1133. }
  1134. #define hpi_control_param1_get(h, a, p1) \
  1135. hpi_control_param_get(h, a, 0, 0, p1, NULL)
  1136. #define hpi_control_param2_get(h, a, p1, p2) \
  1137. hpi_control_param_get(h, a, 0, 0, p1, p2)
  1138. static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0,
  1139. short *sv1)
  1140. {
  1141. struct hpi_message hm;
  1142. struct hpi_response hr;
  1143. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1144. HPI_CONTROL_GET_STATE);
  1145. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1146. return HPI_ERROR_INVALID_HANDLE;
  1147. hm.u.c.attribute = attrib;
  1148. hpi_send_recv(&hm, &hr);
  1149. *sv0 = hr.u.c.an_log_value[0];
  1150. if (sv1)
  1151. *sv1 = hr.u.c.an_log_value[1];
  1152. return hr.error;
  1153. }
  1154. static
  1155. u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,
  1156. const u32 param, u32 *psetting)
  1157. {
  1158. struct hpi_message hm;
  1159. struct hpi_response hr;
  1160. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1161. HPI_CONTROL_GET_INFO);
  1162. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1163. return HPI_ERROR_INVALID_HANDLE;
  1164. hm.u.c.attribute = attrib;
  1165. hm.u.c.param1 = index;
  1166. hm.u.c.param2 = param;
  1167. hpi_send_recv(&hm, &hr);
  1168. *psetting = hr.u.c.param1;
  1169. return hr.error;
  1170. }
  1171. static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
  1172. char *psz_string, const u32 string_length)
  1173. {
  1174. unsigned int sub_string_index = 0, j = 0;
  1175. char c = 0;
  1176. unsigned int n = 0;
  1177. u16 err = 0;
  1178. if ((string_length < 1) || (string_length > 256))
  1179. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1180. for (sub_string_index = 0; sub_string_index < string_length;
  1181. sub_string_index += 8) {
  1182. struct hpi_message hm;
  1183. struct hpi_response hr;
  1184. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1185. HPI_CONTROL_GET_STATE);
  1186. if (hpi_handle_indexes(h_control, &hm.adapter_index,
  1187. &hm.obj_index))
  1188. return HPI_ERROR_INVALID_HANDLE;
  1189. hm.u.c.attribute = attribute;
  1190. hm.u.c.param1 = sub_string_index;
  1191. hm.u.c.param2 = 0;
  1192. hpi_send_recv(&hm, &hr);
  1193. if (sub_string_index == 0
  1194. && (hr.u.cu.chars8.remaining_chars + 8) >
  1195. string_length)
  1196. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1197. if (hr.error) {
  1198. err = hr.error;
  1199. break;
  1200. }
  1201. for (j = 0; j < 8; j++) {
  1202. c = hr.u.cu.chars8.sz_data[j];
  1203. psz_string[sub_string_index + j] = c;
  1204. n++;
  1205. if (n >= string_length) {
  1206. psz_string[string_length - 1] = 0;
  1207. err = HPI_ERROR_INVALID_CONTROL_VALUE;
  1208. break;
  1209. }
  1210. if (c == 0)
  1211. break;
  1212. }
  1213. if ((hr.u.cu.chars8.remaining_chars == 0)
  1214. && ((sub_string_index + j) < string_length)
  1215. && (c != 0)) {
  1216. c = 0;
  1217. psz_string[sub_string_index + j] = c;
  1218. }
  1219. if (c == 0)
  1220. break;
  1221. }
  1222. return err;
  1223. }
  1224. u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index,
  1225. u16 *pw_format)
  1226. {
  1227. u32 qr;
  1228. u16 err;
  1229. err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);
  1230. *pw_format = (u16)qr;
  1231. return err;
  1232. }
  1233. u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)
  1234. {
  1235. return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format,
  1236. 0);
  1237. }
  1238. u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)
  1239. {
  1240. u16 err;
  1241. u32 param;
  1242. err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, &param);
  1243. if (!err && pw_format)
  1244. *pw_format = (u16)param;
  1245. return err;
  1246. }
  1247. u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)
  1248. {
  1249. return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE,
  1250. psample_rate);
  1251. }
  1252. u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)
  1253. {
  1254. struct hpi_message hm;
  1255. struct hpi_response hr;
  1256. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1257. HPI_CONTROL_GET_STATE);
  1258. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1259. return HPI_ERROR_INVALID_HANDLE;
  1260. hm.u.c.attribute = HPI_AESEBURX_USERDATA;
  1261. hm.u.c.param1 = index;
  1262. hpi_send_recv(&hm, &hr);
  1263. if (pw_data)
  1264. *pw_data = (u16)hr.u.c.param2;
  1265. return hr.error;
  1266. }
  1267. u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index,
  1268. u16 *pw_data)
  1269. {
  1270. struct hpi_message hm;
  1271. struct hpi_response hr;
  1272. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1273. HPI_CONTROL_GET_STATE);
  1274. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1275. return HPI_ERROR_INVALID_HANDLE;
  1276. hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
  1277. hm.u.c.param1 = index;
  1278. hpi_send_recv(&hm, &hr);
  1279. if (pw_data)
  1280. *pw_data = (u16)hr.u.c.param2;
  1281. return hr.error;
  1282. }
  1283. u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)
  1284. {
  1285. u32 error_data = 0;
  1286. u16 err = 0;
  1287. err = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS,
  1288. &error_data);
  1289. if (pw_error_data)
  1290. *pw_error_data = (u16)error_data;
  1291. return err;
  1292. }
  1293. u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)
  1294. {
  1295. return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE,
  1296. sample_rate, 0);
  1297. }
  1298. u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)
  1299. {
  1300. return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index,
  1301. data);
  1302. }
  1303. u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index,
  1304. u16 data)
  1305. {
  1306. return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS,
  1307. index, data);
  1308. }
  1309. u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index,
  1310. u16 *pw_data)
  1311. {
  1312. return HPI_ERROR_INVALID_OPERATION;
  1313. }
  1314. u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index,
  1315. u16 *pw_format)
  1316. {
  1317. u32 qr;
  1318. u16 err;
  1319. err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);
  1320. *pw_format = (u16)qr;
  1321. return err;
  1322. }
  1323. u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)
  1324. {
  1325. return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT,
  1326. output_format, 0);
  1327. }
  1328. u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)
  1329. {
  1330. u16 err;
  1331. u32 param;
  1332. err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, &param);
  1333. if (!err && pw_output_format)
  1334. *pw_output_format = (u16)param;
  1335. return err;
  1336. }
  1337. u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)
  1338. {
  1339. return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE,
  1340. edge_type, 0);
  1341. }
  1342. u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)
  1343. {
  1344. return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY,
  1345. polarity, 0);
  1346. }
  1347. u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity,
  1348. u16 *pw_data_activity)
  1349. {
  1350. struct hpi_message hm;
  1351. struct hpi_response hr;
  1352. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1353. HPI_CONTROL_GET_STATE);
  1354. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1355. return HPI_ERROR_INVALID_HANDLE;
  1356. hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
  1357. hpi_send_recv(&hm, &hr);
  1358. if (pw_clk_activity)
  1359. *pw_clk_activity = (u16)hr.u.c.param1;
  1360. if (pw_data_activity)
  1361. *pw_data_activity = (u16)hr.u.c.param2;
  1362. return hr.error;
  1363. }
  1364. u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index,
  1365. u16 *pw_mode)
  1366. {
  1367. u32 qr;
  1368. u16 err;
  1369. err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);
  1370. *pw_mode = (u16)qr;
  1371. return err;
  1372. }
  1373. u16 hpi_channel_mode_set(u32 h_control, u16 mode)
  1374. {
  1375. return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode,
  1376. 0);
  1377. }
  1378. u16 hpi_channel_mode_get(u32 h_control, u16 *mode)
  1379. {
  1380. u32 mode32 = 0;
  1381. u16 err = hpi_control_param1_get(h_control,
  1382. HPI_CHANNEL_MODE_MODE, &mode32);
  1383. if (mode)
  1384. *mode = (u16)mode32;
  1385. return err;
  1386. }
  1387. u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count,
  1388. u8 *pb_data)
  1389. {
  1390. struct hpi_msg_cobranet_hmiwrite hm;
  1391. struct hpi_response_header hr;
  1392. hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr, sizeof(hr),
  1393. HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
  1394. if (hpi_handle_indexes(h_control, &hm.h.adapter_index,
  1395. &hm.h.obj_index))
  1396. return HPI_ERROR_INVALID_HANDLE;
  1397. if (byte_count > sizeof(hm.bytes))
  1398. return HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
  1399. hm.p.attribute = HPI_COBRANET_SET;
  1400. hm.p.byte_count = byte_count;
  1401. hm.p.hmi_address = hmi_address;
  1402. memcpy(hm.bytes, pb_data, byte_count);
  1403. hm.h.size = (u16)(sizeof(hm.h) + sizeof(hm.p) + byte_count);
  1404. hpi_send_recvV1(&hm.h, &hr);
  1405. return hr.error;
  1406. }
  1407. u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count,
  1408. u32 *pbyte_count, u8 *pb_data)
  1409. {
  1410. struct hpi_msg_cobranet_hmiread hm;
  1411. struct hpi_res_cobranet_hmiread hr;
  1412. hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
  1413. HPI_OBJ_CONTROL, HPI_CONTROL_GET_STATE);
  1414. if (hpi_handle_indexes(h_control, &hm.h.adapter_index,
  1415. &hm.h.obj_index))
  1416. return HPI_ERROR_INVALID_HANDLE;
  1417. if (max_byte_count > sizeof(hr.bytes))
  1418. return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1419. hm.p.attribute = HPI_COBRANET_GET;
  1420. hm.p.byte_count = max_byte_count;
  1421. hm.p.hmi_address = hmi_address;
  1422. hpi_send_recvV1(&hm.h, &hr.h);
  1423. if (!hr.h.error && pb_data) {
  1424. if (hr.byte_count > sizeof(hr.bytes))
  1425. return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1426. *pbyte_count = hr.byte_count;
  1427. if (hr.byte_count < max_byte_count)
  1428. max_byte_count = *pbyte_count;
  1429. memcpy(pb_data, hr.bytes, max_byte_count);
  1430. }
  1431. return hr.h.error;
  1432. }
  1433. u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus,
  1434. u32 *preadable_size, u32 *pwriteable_size)
  1435. {
  1436. struct hpi_message hm;
  1437. struct hpi_response hr;
  1438. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1439. HPI_CONTROL_GET_STATE);
  1440. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1441. return HPI_ERROR_INVALID_HANDLE;
  1442. hm.u.c.attribute = HPI_COBRANET_GET_STATUS;
  1443. hpi_send_recv(&hm, &hr);
  1444. if (!hr.error) {
  1445. if (pstatus)
  1446. *pstatus = hr.u.cu.cobranet.status.status;
  1447. if (preadable_size)
  1448. *preadable_size =
  1449. hr.u.cu.cobranet.status.readable_size;
  1450. if (pwriteable_size)
  1451. *pwriteable_size =
  1452. hr.u.cu.cobranet.status.writeable_size;
  1453. }
  1454. return hr.error;
  1455. }
  1456. u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)
  1457. {
  1458. u32 byte_count;
  1459. u32 iP;
  1460. u16 err;
  1461. err = hpi_cobranet_hmi_read(h_control,
  1462. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
  1463. (u8 *)&iP);
  1464. *pdw_ip_address =
  1465. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1466. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1467. if (err)
  1468. *pdw_ip_address = 0;
  1469. return err;
  1470. }
  1471. u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)
  1472. {
  1473. u32 iP;
  1474. u16 err;
  1475. iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
  1476. 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
  1477. 8) | ((dw_ip_address & 0x000000ff) << 8);
  1478. err = hpi_cobranet_hmi_write(h_control,
  1479. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
  1480. return err;
  1481. }
  1482. u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)
  1483. {
  1484. u32 byte_count;
  1485. u32 iP;
  1486. u16 err;
  1487. err = hpi_cobranet_hmi_read(h_control,
  1488. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
  1489. (u8 *)&iP);
  1490. *pdw_ip_address =
  1491. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1492. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1493. if (err)
  1494. *pdw_ip_address = 0;
  1495. return err;
  1496. }
  1497. u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)
  1498. {
  1499. u32 iP;
  1500. u16 err;
  1501. iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
  1502. 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
  1503. 8) | ((dw_ip_address & 0x000000ff) << 8);
  1504. err = hpi_cobranet_hmi_write(h_control,
  1505. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
  1506. return err;
  1507. }
  1508. u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *p_mac_msbs,
  1509. u32 *p_mac_lsbs)
  1510. {
  1511. u32 byte_count;
  1512. u16 err;
  1513. u32 mac;
  1514. err = hpi_cobranet_hmi_read(h_control,
  1515. HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
  1516. (u8 *)&mac);
  1517. if (!err) {
  1518. *p_mac_msbs =
  1519. ((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8)
  1520. | ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) <<
  1521. 8);
  1522. err = hpi_cobranet_hmi_read(h_control,
  1523. HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4,
  1524. &byte_count, (u8 *)&mac);
  1525. }
  1526. if (!err) {
  1527. *p_mac_lsbs =
  1528. ((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8)
  1529. | ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) <<
  1530. 8);
  1531. } else {
  1532. *p_mac_msbs = 0;
  1533. *p_mac_lsbs = 0;
  1534. }
  1535. return err;
  1536. }
  1537. u16 hpi_compander_set_enable(u32 h_control, u32 enable)
  1538. {
  1539. return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
  1540. 0);
  1541. }
  1542. u16 hpi_compander_get_enable(u32 h_control, u32 *enable)
  1543. {
  1544. return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
  1545. }
  1546. u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)
  1547. {
  1548. return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
  1549. makeup_gain0_01dB, 0);
  1550. }
  1551. u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)
  1552. {
  1553. return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN,
  1554. makeup_gain0_01dB, NULL);
  1555. }
  1556. u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index,
  1557. u32 attack)
  1558. {
  1559. return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack,
  1560. index);
  1561. }
  1562. u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index,
  1563. u32 *attack)
  1564. {
  1565. return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0,
  1566. index, attack, NULL);
  1567. }
  1568. u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index,
  1569. u32 decay)
  1570. {
  1571. return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay,
  1572. index);
  1573. }
  1574. u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index,
  1575. u32 *decay)
  1576. {
  1577. return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index,
  1578. decay, NULL);
  1579. }
  1580. u16 hpi_compander_set_threshold(u32 h_control, unsigned int index,
  1581. short threshold0_01dB)
  1582. {
  1583. struct hpi_message hm;
  1584. struct hpi_response hr;
  1585. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1586. HPI_CONTROL_SET_STATE);
  1587. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1588. return HPI_ERROR_INVALID_HANDLE;
  1589. hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
  1590. hm.u.c.param2 = index;
  1591. hm.u.c.an_log_value[0] = threshold0_01dB;
  1592. hpi_send_recv(&hm, &hr);
  1593. return hr.error;
  1594. }
  1595. u16 hpi_compander_get_threshold(u32 h_control, unsigned int index,
  1596. short *threshold0_01dB)
  1597. {
  1598. struct hpi_message hm;
  1599. struct hpi_response hr;
  1600. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1601. HPI_CONTROL_GET_STATE);
  1602. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1603. return HPI_ERROR_INVALID_HANDLE;
  1604. hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
  1605. hm.u.c.param2 = index;
  1606. hpi_send_recv(&hm, &hr);
  1607. *threshold0_01dB = hr.u.c.an_log_value[0];
  1608. return hr.error;
  1609. }
  1610. u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)
  1611. {
  1612. return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100,
  1613. index);
  1614. }
  1615. u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)
  1616. {
  1617. return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index,
  1618. ratio100, NULL);
  1619. }
  1620. u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB,
  1621. short *max_gain_01dB, short *step_gain_01dB)
  1622. {
  1623. struct hpi_message hm;
  1624. struct hpi_response hr;
  1625. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1626. HPI_CONTROL_GET_STATE);
  1627. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1628. return HPI_ERROR_INVALID_HANDLE;
  1629. hm.u.c.attribute = HPI_LEVEL_RANGE;
  1630. hpi_send_recv(&hm, &hr);
  1631. if (hr.error) {
  1632. hr.u.c.an_log_value[0] = 0;
  1633. hr.u.c.an_log_value[1] = 0;
  1634. hr.u.c.param1 = 0;
  1635. }
  1636. if (min_gain_01dB)
  1637. *min_gain_01dB = hr.u.c.an_log_value[0];
  1638. if (max_gain_01dB)
  1639. *max_gain_01dB = hr.u.c.an_log_value[1];
  1640. if (step_gain_01dB)
  1641. *step_gain_01dB = (short)hr.u.c.param1;
  1642. return hr.error;
  1643. }
  1644. u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
  1645. )
  1646. {
  1647. return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
  1648. an_gain0_01dB[0], an_gain0_01dB[1]);
  1649. }
  1650. u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
  1651. )
  1652. {
  1653. return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,
  1654. &an_gain0_01dB[0], &an_gain0_01dB[1]);
  1655. }
  1656. u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)
  1657. {
  1658. return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0,
  1659. p_channels);
  1660. }
  1661. u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]
  1662. )
  1663. {
  1664. short i = 0;
  1665. struct hpi_message hm;
  1666. struct hpi_response hr;
  1667. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1668. HPI_CONTROL_GET_STATE);
  1669. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1670. return HPI_ERROR_INVALID_HANDLE;
  1671. hm.obj_index = hm.obj_index;
  1672. hm.u.c.attribute = HPI_METER_PEAK;
  1673. hpi_send_recv(&hm, &hr);
  1674. if (!hr.error)
  1675. memcpy(an_peakdB, hr.u.c.an_log_value,
  1676. sizeof(short) * HPI_MAX_CHANNELS);
  1677. else
  1678. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1679. an_peakdB[i] = HPI_METER_MINIMUM;
  1680. return hr.error;
  1681. }
  1682. u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]
  1683. )
  1684. {
  1685. short i = 0;
  1686. struct hpi_message hm;
  1687. struct hpi_response hr;
  1688. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1689. HPI_CONTROL_GET_STATE);
  1690. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1691. return HPI_ERROR_INVALID_HANDLE;
  1692. hm.u.c.attribute = HPI_METER_RMS;
  1693. hpi_send_recv(&hm, &hr);
  1694. if (!hr.error)
  1695. memcpy(an_rmsdB, hr.u.c.an_log_value,
  1696. sizeof(short) * HPI_MAX_CHANNELS);
  1697. else
  1698. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1699. an_rmsdB[i] = HPI_METER_MINIMUM;
  1700. return hr.error;
  1701. }
  1702. u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)
  1703. {
  1704. return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS,
  1705. attack, decay);
  1706. }
  1707. u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)
  1708. {
  1709. u32 attack;
  1710. u32 decay;
  1711. u16 error;
  1712. error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS,
  1713. &attack, &decay);
  1714. if (pn_attack)
  1715. *pn_attack = (unsigned short)attack;
  1716. if (pn_decay)
  1717. *pn_decay = (unsigned short)decay;
  1718. return error;
  1719. }
  1720. u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)
  1721. {
  1722. return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS,
  1723. attack, decay);
  1724. }
  1725. u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack,
  1726. u16 *pn_decay)
  1727. {
  1728. u32 attack;
  1729. u32 decay;
  1730. u16 error;
  1731. error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS,
  1732. &attack, &decay);
  1733. if (pn_attack)
  1734. *pn_attack = (short)attack;
  1735. if (pn_decay)
  1736. *pn_decay = (short)decay;
  1737. return error;
  1738. }
  1739. u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)
  1740. {
  1741. return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER,
  1742. (u32)on_off, 0);
  1743. }
  1744. u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)
  1745. {
  1746. u16 error = 0;
  1747. u32 on_off = 0;
  1748. error = hpi_control_param1_get(h_control,
  1749. HPI_MICROPHONE_PHANTOM_POWER, &on_off);
  1750. if (pw_on_off)
  1751. *pw_on_off = (u16)on_off;
  1752. return error;
  1753. }
  1754. u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type,
  1755. u16 source_node_index)
  1756. {
  1757. return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE,
  1758. source_node_type, source_node_index);
  1759. }
  1760. u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,
  1761. u16 *source_node_index)
  1762. {
  1763. u32 node, index;
  1764. u16 err = hpi_control_param2_get(h_control,
  1765. HPI_MULTIPLEXER_SOURCE, &node,
  1766. &index);
  1767. if (source_node_type)
  1768. *source_node_type = (u16)node;
  1769. if (source_node_index)
  1770. *source_node_index = (u16)index;
  1771. return err;
  1772. }
  1773. u16 hpi_multiplexer_query_source(u32 h_control, u16 index,
  1774. u16 *source_node_type, u16 *source_node_index)
  1775. {
  1776. struct hpi_message hm;
  1777. struct hpi_response hr;
  1778. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1779. HPI_CONTROL_GET_STATE);
  1780. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1781. return HPI_ERROR_INVALID_HANDLE;
  1782. hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
  1783. hm.u.c.param1 = index;
  1784. hpi_send_recv(&hm, &hr);
  1785. if (source_node_type)
  1786. *source_node_type = (u16)hr.u.c.param1;
  1787. if (source_node_index)
  1788. *source_node_index = (u16)hr.u.c.param2;
  1789. return hr.error;
  1790. }
  1791. u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands,
  1792. u16 *pw_on_off)
  1793. {
  1794. u32 oB = 0;
  1795. u32 oO = 0;
  1796. u16 error = 0;
  1797. error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS,
  1798. &oO, &oB);
  1799. if (pw_number_of_bands)
  1800. *pw_number_of_bands = (u16)oB;
  1801. if (pw_on_off)
  1802. *pw_on_off = (u16)oO;
  1803. return error;
  1804. }
  1805. u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)
  1806. {
  1807. return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS,
  1808. on_off, 0);
  1809. }
  1810. u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type,
  1811. u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)
  1812. {
  1813. struct hpi_message hm;
  1814. struct hpi_response hr;
  1815. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1816. HPI_CONTROL_GET_STATE);
  1817. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1818. return HPI_ERROR_INVALID_HANDLE;
  1819. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  1820. hm.u.c.param2 = index;
  1821. hpi_send_recv(&hm, &hr);
  1822. if (pfrequency_hz)
  1823. *pfrequency_hz = hr.u.c.param1;
  1824. if (pn_type)
  1825. *pn_type = (u16)(hr.u.c.param2 >> 16);
  1826. if (pnQ100)
  1827. *pnQ100 = hr.u.c.an_log_value[1];
  1828. if (pn_gain0_01dB)
  1829. *pn_gain0_01dB = hr.u.c.an_log_value[0];
  1830. return hr.error;
  1831. }
  1832. u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type,
  1833. u32 frequency_hz, short q100, short gain0_01dB)
  1834. {
  1835. struct hpi_message hm;
  1836. struct hpi_response hr;
  1837. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1838. HPI_CONTROL_SET_STATE);
  1839. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1840. return HPI_ERROR_INVALID_HANDLE;
  1841. hm.u.c.param1 = frequency_hz;
  1842. hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
  1843. hm.u.c.an_log_value[0] = gain0_01dB;
  1844. hm.u.c.an_log_value[1] = q100;
  1845. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  1846. hpi_send_recv(&hm, &hr);
  1847. return hr.error;
  1848. }
  1849. u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]
  1850. )
  1851. {
  1852. struct hpi_message hm;
  1853. struct hpi_response hr;
  1854. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1855. HPI_CONTROL_GET_STATE);
  1856. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1857. return HPI_ERROR_INVALID_HANDLE;
  1858. hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
  1859. hm.u.c.param2 = index;
  1860. hpi_send_recv(&hm, &hr);
  1861. coeffs[0] = (short)hr.u.c.an_log_value[0];
  1862. coeffs[1] = (short)hr.u.c.an_log_value[1];
  1863. coeffs[2] = (short)hr.u.c.param1;
  1864. coeffs[3] = (short)(hr.u.c.param1 >> 16);
  1865. coeffs[4] = (short)hr.u.c.param2;
  1866. return hr.error;
  1867. }
  1868. u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index,
  1869. u16 *pw_source)
  1870. {
  1871. u32 qr;
  1872. u16 err;
  1873. err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0,
  1874. &qr);
  1875. *pw_source = (u16)qr;
  1876. return err;
  1877. }
  1878. u16 hpi_sample_clock_set_source(u32 h_control, u16 source)
  1879. {
  1880. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE,
  1881. source, 0);
  1882. }
  1883. u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)
  1884. {
  1885. u16 err = 0;
  1886. u32 source = 0;
  1887. err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE,
  1888. &source);
  1889. if (!err)
  1890. if (pw_source)
  1891. *pw_source = (u16)source;
  1892. return err;
  1893. }
  1894. u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index,
  1895. const u32 source, u16 *pw_source_index)
  1896. {
  1897. u32 qr;
  1898. u16 err;
  1899. err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index,
  1900. source, &qr);
  1901. *pw_source_index = (u16)qr;
  1902. return err;
  1903. }
  1904. u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)
  1905. {
  1906. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
  1907. source_index, 0);
  1908. }
  1909. u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)
  1910. {
  1911. u16 err = 0;
  1912. u32 source_index = 0;
  1913. err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
  1914. &source_index);
  1915. if (!err)
  1916. if (pw_source_index)
  1917. *pw_source_index = (u16)source_index;
  1918. return err;
  1919. }
  1920. u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
  1921. u32 *prate)
  1922. {
  1923. u16 err;
  1924. err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
  1925. index, 0, prate);
  1926. return err;
  1927. }
  1928. u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
  1929. {
  1930. return hpi_control_param_set(h_control,
  1931. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
  1932. }
  1933. u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)
  1934. {
  1935. u16 err = 0;
  1936. u32 sample_rate = 0;
  1937. err = hpi_control_param1_get(h_control,
  1938. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
  1939. if (!err)
  1940. if (psample_rate)
  1941. *psample_rate = sample_rate;
  1942. return err;
  1943. }
  1944. u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)
  1945. {
  1946. u16 err = 0;
  1947. u32 sample_rate = 0;
  1948. err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE,
  1949. &sample_rate);
  1950. if (!err)
  1951. if (psample_rate)
  1952. *psample_rate = sample_rate;
  1953. return err;
  1954. }
  1955. u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)
  1956. {
  1957. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable,
  1958. 0);
  1959. }
  1960. u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)
  1961. {
  1962. return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO,
  1963. penable);
  1964. }
  1965. u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)
  1966. {
  1967. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
  1968. lock, 0);
  1969. }
  1970. u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)
  1971. {
  1972. return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
  1973. plock);
  1974. }
  1975. u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)
  1976. {
  1977. return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY,
  1978. index, 0, frequency, NULL);
  1979. }
  1980. u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)
  1981. {
  1982. return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE,
  1983. state);
  1984. }
  1985. u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)
  1986. {
  1987. return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
  1988. 0);
  1989. }
  1990. u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)
  1991. {
  1992. return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
  1993. }
  1994. u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)
  1995. {
  1996. return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
  1997. (u32)event_enable, 0);
  1998. }
  1999. u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)
  2000. {
  2001. return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
  2002. event_enable);
  2003. }
  2004. u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)
  2005. {
  2006. return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD,
  2007. (u32)threshold, 0);
  2008. }
  2009. u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)
  2010. {
  2011. return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD,
  2012. (u32 *)threshold);
  2013. }
  2014. u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)
  2015. {
  2016. return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE,
  2017. state);
  2018. }
  2019. u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)
  2020. {
  2021. return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
  2022. 0);
  2023. }
  2024. u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)
  2025. {
  2026. return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
  2027. }
  2028. u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)
  2029. {
  2030. return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
  2031. event_enable, 0);
  2032. }
  2033. u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)
  2034. {
  2035. return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
  2036. event_enable);
  2037. }
  2038. u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)
  2039. {
  2040. return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY,
  2041. delay, 0);
  2042. }
  2043. u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)
  2044. {
  2045. return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY,
  2046. delay);
  2047. }
  2048. u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)
  2049. {
  2050. return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD,
  2051. threshold, 0);
  2052. }
  2053. u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)
  2054. {
  2055. return hpi_control_param1_get(h_control,
  2056. HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
  2057. }
  2058. u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)
  2059. {
  2060. u32 qr;
  2061. u16 err;
  2062. err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
  2063. *pw_band = (u16)qr;
  2064. return err;
  2065. }
  2066. u16 hpi_tuner_set_band(u32 h_control, u16 band)
  2067. {
  2068. return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);
  2069. }
  2070. u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)
  2071. {
  2072. u32 band = 0;
  2073. u16 error = 0;
  2074. error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);
  2075. if (pw_band)
  2076. *pw_band = (u16)band;
  2077. return error;
  2078. }
  2079. u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index,
  2080. const u16 band, u32 *pfreq)
  2081. {
  2082. return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);
  2083. }
  2084. u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)
  2085. {
  2086. return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz,
  2087. 0);
  2088. }
  2089. u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)
  2090. {
  2091. return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,
  2092. pw_freq_ink_hz);
  2093. }
  2094. u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)
  2095. {
  2096. u32 qr;
  2097. u16 err;
  2098. err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
  2099. *pw_gain = (u16)qr;
  2100. return err;
  2101. }
  2102. u16 hpi_tuner_set_gain(u32 h_control, short gain)
  2103. {
  2104. return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);
  2105. }
  2106. u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)
  2107. {
  2108. u32 gain = 0;
  2109. u16 error = 0;
  2110. error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);
  2111. if (pn_gain)
  2112. *pn_gain = (u16)gain;
  2113. return error;
  2114. }
  2115. u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)
  2116. {
  2117. struct hpi_message hm;
  2118. struct hpi_response hr;
  2119. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2120. HPI_CONTROL_GET_STATE);
  2121. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2122. return HPI_ERROR_INVALID_HANDLE;
  2123. hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
  2124. hpi_send_recv(&hm, &hr);
  2125. if (pw_level)
  2126. *pw_level = hr.u.cu.tuner.s_level;
  2127. return hr.error;
  2128. }
  2129. u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)
  2130. {
  2131. struct hpi_message hm;
  2132. struct hpi_response hr;
  2133. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2134. HPI_CONTROL_GET_STATE);
  2135. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2136. return HPI_ERROR_INVALID_HANDLE;
  2137. hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
  2138. hpi_send_recv(&hm, &hr);
  2139. if (pw_level)
  2140. *pw_level = hr.u.cu.tuner.s_level;
  2141. return hr.error;
  2142. }
  2143. u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index,
  2144. const u16 band, u32 *pdeemphasis)
  2145. {
  2146. return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band,
  2147. pdeemphasis);
  2148. }
  2149. u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)
  2150. {
  2151. return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS,
  2152. deemphasis, 0);
  2153. }
  2154. u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)
  2155. {
  2156. return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS,
  2157. pdeemphasis);
  2158. }
  2159. u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)
  2160. {
  2161. return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,
  2162. pbitmap_program);
  2163. }
  2164. u16 hpi_tuner_set_program(u32 h_control, u32 program)
  2165. {
  2166. return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program,
  2167. 0);
  2168. }
  2169. u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)
  2170. {
  2171. return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);
  2172. }
  2173. u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version,
  2174. const u32 string_size)
  2175. {
  2176. return hpi_control_get_string(h_control,
  2177. HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
  2178. }
  2179. u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version,
  2180. const u32 string_size)
  2181. {
  2182. return hpi_control_get_string(h_control,
  2183. HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
  2184. }
  2185. u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)
  2186. {
  2187. u32 status = 0;
  2188. u16 error = 0;
  2189. error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);
  2190. if (pw_status) {
  2191. if (!error) {
  2192. *pw_status_mask = (u16)(status >> 16);
  2193. *pw_status = (u16)(status & 0xFFFF);
  2194. } else {
  2195. *pw_status_mask = 0;
  2196. *pw_status = 0;
  2197. }
  2198. }
  2199. return error;
  2200. }
  2201. u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)
  2202. {
  2203. return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);
  2204. }
  2205. u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)
  2206. {
  2207. return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0,
  2208. pn_value, NULL);
  2209. }
  2210. u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)
  2211. {
  2212. return hpi_control_param1_get(h_control,
  2213. HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
  2214. }
  2215. u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)
  2216. {
  2217. return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND,
  2218. pblend);
  2219. }
  2220. u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)
  2221. {
  2222. return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND,
  2223. blend, 0);
  2224. }
  2225. u16 hpi_tuner_get_rds(u32 h_control, char *p_data)
  2226. {
  2227. struct hpi_message hm;
  2228. struct hpi_response hr;
  2229. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2230. HPI_CONTROL_GET_STATE);
  2231. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2232. return HPI_ERROR_INVALID_HANDLE;
  2233. hm.u.c.attribute = HPI_TUNER_RDS;
  2234. hpi_send_recv(&hm, &hr);
  2235. if (p_data) {
  2236. *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
  2237. *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
  2238. *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
  2239. }
  2240. return hr.error;
  2241. }
  2242. u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string,
  2243. const u32 data_length)
  2244. {
  2245. return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
  2246. psz_string, data_length);
  2247. }
  2248. u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)
  2249. {
  2250. return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
  2251. data_length);
  2252. }
  2253. u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)
  2254. {
  2255. return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
  2256. data_length);
  2257. }
  2258. u16 hpi_pad_get_comment(u32 h_control, char *psz_string,
  2259. const u32 data_length)
  2260. {
  2261. return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
  2262. data_length);
  2263. }
  2264. u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)
  2265. {
  2266. return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);
  2267. }
  2268. u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)
  2269. {
  2270. return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);
  2271. }
  2272. u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)
  2273. {
  2274. return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0,
  2275. p_channels);
  2276. }
  2277. u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
  2278. )
  2279. {
  2280. return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
  2281. an_log_gain[0], an_log_gain[1]);
  2282. }
  2283. u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
  2284. )
  2285. {
  2286. return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,
  2287. &an_log_gain[0], &an_log_gain[1]);
  2288. }
  2289. u16 hpi_volume_set_mute(u32 h_control, u32 mute)
  2290. {
  2291. return hpi_control_param_set(h_control, HPI_VOLUME_MUTE, mute, 0);
  2292. }
  2293. u16 hpi_volume_get_mute(u32 h_control, u32 *mute)
  2294. {
  2295. return hpi_control_param1_get(h_control, HPI_VOLUME_MUTE, mute);
  2296. }
  2297. u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB,
  2298. short *max_gain_01dB, short *step_gain_01dB)
  2299. {
  2300. struct hpi_message hm;
  2301. struct hpi_response hr;
  2302. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2303. HPI_CONTROL_GET_STATE);
  2304. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2305. return HPI_ERROR_INVALID_HANDLE;
  2306. hm.u.c.attribute = HPI_VOLUME_RANGE;
  2307. hpi_send_recv(&hm, &hr);
  2308. if (hr.error) {
  2309. hr.u.c.an_log_value[0] = 0;
  2310. hr.u.c.an_log_value[1] = 0;
  2311. hr.u.c.param1 = 0;
  2312. }
  2313. if (min_gain_01dB)
  2314. *min_gain_01dB = hr.u.c.an_log_value[0];
  2315. if (max_gain_01dB)
  2316. *max_gain_01dB = hr.u.c.an_log_value[1];
  2317. if (step_gain_01dB)
  2318. *step_gain_01dB = (short)hr.u.c.param1;
  2319. return hr.error;
  2320. }
  2321. u16 hpi_volume_auto_fade_profile(u32 h_control,
  2322. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms,
  2323. u16 profile)
  2324. {
  2325. struct hpi_message hm;
  2326. struct hpi_response hr;
  2327. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2328. HPI_CONTROL_SET_STATE);
  2329. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2330. return HPI_ERROR_INVALID_HANDLE;
  2331. memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
  2332. sizeof(short) * HPI_MAX_CHANNELS);
  2333. hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
  2334. hm.u.c.param1 = duration_ms;
  2335. hm.u.c.param2 = profile;
  2336. hpi_send_recv(&hm, &hr);
  2337. return hr.error;
  2338. }
  2339. u16 hpi_volume_auto_fade(u32 h_control,
  2340. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
  2341. {
  2342. return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB,
  2343. duration_ms, HPI_VOLUME_AUTOFADE_LOG);
  2344. }
  2345. u16 hpi_volume_query_auto_fade_profile(const u32 h_volume, const u32 i,
  2346. u16 *profile)
  2347. {
  2348. u16 e;
  2349. u32 u;
  2350. e = hpi_control_query(h_volume, HPI_VOLUME_AUTOFADE, i, 0, &u);
  2351. *profile = (u16)u;
  2352. return e;
  2353. }
  2354. u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)
  2355. {
  2356. struct hpi_message hm;
  2357. struct hpi_response hr;
  2358. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2359. HPI_CONTROL_SET_STATE);
  2360. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2361. return HPI_ERROR_INVALID_HANDLE;
  2362. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2363. hm.u.c.an_log_value[0] = an_gain0_01dB;
  2364. hpi_send_recv(&hm, &hr);
  2365. return hr.error;
  2366. }
  2367. u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)
  2368. {
  2369. struct hpi_message hm;
  2370. struct hpi_response hr;
  2371. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2372. HPI_CONTROL_GET_STATE);
  2373. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2374. return HPI_ERROR_INVALID_HANDLE;
  2375. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2376. hpi_send_recv(&hm, &hr);
  2377. *an_gain0_01dB = hr.u.c.an_log_value[0];
  2378. return hr.error;
  2379. }