comparison src/cs/services/audio/audio_mode_volume.c @ 0:92470e5d0b9e

src: partial import from FC Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 15 May 2020 01:28:16 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:92470e5d0b9e
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_mode_volume.c */
4 /* */
5 /* Purpose: This file contains all the functions used for audio mode */
6 /* speaker volume services. */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------------------------------------------*/
12 /* 14 Jan 2002 Create */
13 /* */
14 /* Author Francois Mazard */
15 /* */
16 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/
17 /****************************************************************************/
18
19 #include "rv/rv_defined_swe.h"
20
21 #ifdef RVM_AUDIO_MAIN_SWE
22 #ifndef _WINDOWS
23 #include "config/swconfig.cfg"
24 #include "config/sys.cfg"
25 #include "config/chipset.cfg"
26 #endif
27
28 #include "l1_confg.h"
29 #include "rv/rv_general.h"
30 #include "rvm/rvm_gen.h"
31 #include "audio/audio_ffs_i.h"
32 #include "audio/audio_api.h"
33 #include "audio/audio_structs_i.h"
34 #include "audio/audio_error_hdlr_i.h"
35 #include "audio/audio_var_i.h"
36 #include "audio/audio_messages_i.h"
37 #include "audio/audio_macro_i.h"
38 #include "rvf/rvf_target.h"
39 #include "audio/audio_const_i.h"
40
41 /* include the usefull L1 header */
42 #ifdef _WINDOWS
43 #define BOOL_FLAG
44 //#define CHAR_FLAG
45 #endif
46 #include "l1_types.h"
47 #include "l1audio_const.h"
48 #include "l1audio_cust.h"
49 #include "l1audio_defty.h"
50 #include "l1audio_msgty.h"
51 #include "l1audio_signa.h"
52 #if TESTMODE
53 #include "l1tm_defty.h"
54 #endif
55 #if (L1_GTT == 1)
56 #include "l1gtt_const.h"
57 #include "l1gtt_defty.h"
58 #endif
59 #include "l1_const.h"
60 #include "l1_defty.h"
61 #include "l1_msgty.h"
62 #include "l1_signa.h"
63 #ifdef _WINDOWS
64 #define L1_ASYNC_C
65 #endif
66 #include "l1_varex.h"
67
68 #ifdef _WINDOWS
69 #include "audio/tests/audio_test.h"
70 #endif
71
72 /* external functions */
73 /* write */
74 extern T_AUDIO_RET audio_mode_speaker_volume_write (T_AUDIO_SPEAKER_LEVEL *data);
75 /* read */
76 extern T_AUDIO_RET audio_mode_speaker_volume_read (T_AUDIO_SPEAKER_LEVEL *data);
77
78 /********************************************************************************/
79 /* */
80 /* Function Name: audio_mode_speaker_volume_send_status */
81 /* */
82 /* Purpose: This function sends the audio mode speaker volume status to */
83 /* the entity. */
84 /* */
85 /* Input Parameters: */
86 /* status, */
87 /* return path */
88 /* */
89 /* Output Parameters: */
90 /* None. */
91 /* */
92 /* Note: */
93 /* None. */
94 /* */
95 /* Revision History: */
96 /* None. */
97 /* */
98 /********************************************************************************/
99 void audio_mode_speaker_volume_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
100 {
101 void *p_send_message = NULL;
102 T_RVF_MB_STATUS mb_status = RVF_RED;
103
104 while (mb_status == RVF_RED)
105 {
106 /* allocate the message buffer */
107 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
108 sizeof (T_AUDIO_VOLUME_DONE),
109 (T_RVF_BUFFER **) (&p_send_message));
110
111 /* If insufficient resources, then report a memory error and abort. */
112 /* and wait until more ressource is given */
113 if (mb_status == RVF_RED)
114 {
115 audio_mode_error_trace(AUDIO_ENTITY_NO_MEMORY);
116 rvf_delay(RVF_MS_TO_TICKS(1000));
117 }
118 }
119 /*fill the header of the message */
120 ((T_AUDIO_VOLUME_DONE *)(p_send_message))->os_hdr.msg_id =
121 AUDIO_SPEAKER_VOLUME_DONE;
122
123 /* fill the status parameters */
124 ((T_AUDIO_VOLUME_DONE *)(p_send_message))->status = status;
125
126 if (return_path.callback_func == NULL)
127 {
128 /* send the message to the entity */
129 rvf_send_msg (return_path.addr_id,
130 p_send_message);
131 }
132 else
133 {
134 /* call the callback function */
135 (*return_path.callback_func)((void *)(p_send_message));
136 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
137 }
138 }
139
140 /********************************************************************************/
141 /* */
142 /* Function Name: audio_mode_speaker_volume_manager */
143 /* */
144 /* Purpose: This function manage the audio mode save services. */
145 /* */
146 /* Input Parameters: */
147 /* Audio message. */
148 /* */
149 /* Output Parameters: */
150 /* None. */
151 /* */
152 /* Note: */
153 /* None. */
154 /* */
155 /* Revision History: */
156 /* None. */
157 /* */
158 /********************************************************************************/
159 void audio_mode_speaker_volume_manager (T_RV_HDR *p_message)
160 {
161 T_AUDIO_SPEAKER_LEVEL volume;
162 #ifndef _WINDOWS
163 T_FFS_FD audio_volume_ffs_fd;
164 #endif
165
166 switch (((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->volume.volume_action)
167 {
168 case AUDIO_SPEAKER_VOLUME_INCREASE:
169 {
170 if ( (audio_mode_speaker_volume_read(&volume)) == AUDIO_ERROR )
171 {
172 AUDIO_SEND_TRACE("AUDIO MODE SPEAKER VOLUME: can't read the current volume", RV_TRACE_LEVEL_ERROR);
173 audio_mode_speaker_volume_send_status (AUDIO_ERROR,
174 ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->return_path);
175 return;
176 }
177
178 if (volume.audio_speaker_level == AUDIO_SPEAKER_VOLUME_MUTE)
179 {
180 volume.audio_speaker_level = AUDIO_SPEAKER_VOLUME_24dB;
181 }
182 else
183 if (volume.audio_speaker_level == AUDIO_SPEAKER_VOLUME_24dB)
184 {
185 volume.audio_speaker_level = AUDIO_SPEAKER_VOLUME_18dB;
186 }
187 else
188 if (volume.audio_speaker_level == AUDIO_SPEAKER_VOLUME_0dB)
189 {
190 volume.audio_speaker_level = AUDIO_SPEAKER_VOLUME_0dB;
191 }
192 else
193 {
194 volume.audio_speaker_level += 50;
195 }
196 break;
197 }
198 case AUDIO_SPEAKER_VOLUME_DECREASE:
199 {
200 if ( (audio_mode_speaker_volume_read(&volume)) == AUDIO_ERROR )
201 {
202 AUDIO_SEND_TRACE("AUDIO MODE SPEAKER VOLUME: can't read the current volume", RV_TRACE_LEVEL_ERROR);
203 audio_mode_speaker_volume_send_status (AUDIO_ERROR,
204 ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->return_path);
205 return;
206 }
207
208 if (volume.audio_speaker_level == AUDIO_SPEAKER_VOLUME_MUTE)
209 {
210 volume.audio_speaker_level = AUDIO_SPEAKER_VOLUME_MUTE;
211 }
212 else
213 if (volume.audio_speaker_level == AUDIO_SPEAKER_VOLUME_24dB)
214 {
215 volume.audio_speaker_level = AUDIO_SPEAKER_VOLUME_MUTE;
216 }
217 else
218 if (volume.audio_speaker_level == AUDIO_SPEAKER_VOLUME_18dB)
219 {
220 volume.audio_speaker_level = AUDIO_SPEAKER_VOLUME_24dB;
221 }
222 else
223 {
224 volume.audio_speaker_level -= 50;
225 }
226 break;
227 }
228 case AUDIO_SPEAKER_VOLUME_SET:
229 {
230 volume.audio_speaker_level = ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->volume.value;
231 break;
232 }
233 }
234
235 /* Open the volume file */
236 #ifndef _WINDOWS
237 audio_volume_ffs_fd = ffs_open(p_audio_gbl_var->audio_mode_var.audio_volume_var.audio_volume_path_name,
238 FFS_O_CREATE | FFS_O_WRONLY | FFS_O_TRUNC | FFS_O_APPEND);
239 if (audio_volume_ffs_fd <= 0)
240 {
241 AUDIO_SEND_TRACE("AUDIO MODE SPEAKER VOLUME: can't open the current volume file", RV_TRACE_LEVEL_ERROR);
242 /* Close the file */
243 ffs_close(audio_volume_ffs_fd);
244
245 audio_mode_speaker_volume_send_status (AUDIO_ERROR,
246 ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->return_path);
247 return;
248 }
249
250 /* Save the audio speaker volume structure from the FFS */
251 if ( (ffs_write (audio_volume_ffs_fd,
252 &volume,
253 sizeof(T_AUDIO_SPEAKER_LEVEL))) < EFFS_OK )
254 {
255 AUDIO_SEND_TRACE("AUDIO MODE SPEAKER VOLUME: impossible to save the current speaker volume", RV_TRACE_LEVEL_ERROR);
256
257 /* Close the file */
258 ffs_close(audio_volume_ffs_fd);
259
260 /* send the status message */
261 audio_mode_speaker_volume_send_status (AUDIO_ERROR,
262 ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->return_path);
263 return;
264 }
265
266 /* Close the file */
267 ffs_close(audio_volume_ffs_fd);
268 #else
269 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
270 p_audio_test->speaker_volume_1.audio_speaker_level = volume.audio_speaker_level;
271 #endif
272 #endif
273
274 /* Fill the audio volume structure */
275 if ( (audio_mode_speaker_volume_write(&volume)) == AUDIO_ERROR)
276 {
277 AUDIO_SEND_TRACE("AUDIO MODE LOAD: error in the the audio speaker volume set function", RV_TRACE_LEVEL_ERROR);
278
279 /* send the status message */
280 audio_mode_speaker_volume_send_status (AUDIO_ERROR,
281 ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->return_path);
282
283 return;
284 }
285
286 /* send the good status message */
287 audio_mode_speaker_volume_send_status (AUDIO_OK,
288 ((T_AUDIO_SPEAKER_VOLUME_REQ *)p_message)->return_path);
289 }
290 #endif /* RVM_AUDIO_MAIN_SWE */