comparison src/cs/services/tty/tty.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: tty.c */
4 /* */
5 /* Purpose: This file contains all the functions used to manage the */
6 /* TTY feature. */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------ */
12 /* 18 Jan 2003 Create */
13 /* */
14 /* Author */
15 /* Frederic Turgis */
16 /* */
17 /* (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved*/
18 /****************************************************************************/
19
20 #ifndef _WINDOWS
21 #include "config/l1sw.cfg"
22 #endif
23
24 #if (L1_GTT == 1)
25
26 #include "tty/tty_api.h"
27 #include "tty/tty_i.h"
28
29 #include "rv/rv_general.h"
30 #include "rvf/rvf_target.h"
31
32 #include "l1gtt_signa.h"
33 #include "audio/audio_structs_i.h"
34 #include "audio/audio_const_i.h"
35
36 /* extern variables & prototypes */
37
38 extern T_TTY_ENV_CTRL_BLK *tty_env_ctrl_blk_p;
39 extern T_AUDIO_ENV_CTRL_BLK *p_audio_gbl_var;
40
41 extern void *audio_allocate_l1_message (UINT16 size);
42 extern T_RV_RET audio_send_l1_message (INT16 message_id, void *message);
43
44 /********************************************************************************/
45 /* */
46 /* Function Name: tty_send_status */
47 /* */
48 /* Purpose: This function sends the TTY status to the entity. */
49 /* */
50 /* Input Parameters: */
51 /* status, */
52 /* return path */
53 /* */
54 /* Output Parameters: */
55 /* None. */
56 /* */
57 /* Note: */
58 /* None. */
59 /* */
60 /* Revision History: */
61 /* None. */
62 /* */
63 /********************************************************************************/
64 void tty_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
65 {
66 T_AUDIO_TTY_STATUS *p_send_message = NULL;
67 T_RVF_MB_STATUS mb_status = RVF_RED;
68
69 while (mb_status == RVF_RED)
70 {
71 /* allocate the message buffer */
72 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
73 sizeof (T_AUDIO_TTY_STATUS),
74 (T_RVF_BUFFER **) (&p_send_message));
75
76 /* If insufficient resources, then report a memory error and abort. */
77 /* and wait until more ressource is given */
78 if (mb_status == RVF_RED)
79 {
80 TTY_SEND_TRACE("TTY: Not Enough Memory (Red!) ",RV_TRACE_LEVEL_ERROR);
81 rvf_delay(RVF_MS_TO_TICKS(1000));
82 }
83 }
84 /* fill the header of the message */
85 ((T_AUDIO_TTY_STATUS *)p_send_message)->os_hdr.msg_id = AUDIO_TTY_STATUS_MSG;
86
87 /* fill the status parameters */
88 ((T_AUDIO_TTY_STATUS *)p_send_message)->status = status;
89
90 if (return_path.callback_func == NULL)
91 {
92 /* send the message to the entity */
93 rvf_send_msg (return_path.addr_id, p_send_message);
94 }
95 else
96 {
97 /* call the callback function */
98 (*return_path.callback_func)((void *)(p_send_message));
99 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
100 }
101 }
102
103 /********************************************************************************/
104 /* */
105 /* Function Name: tty_manager */
106 /* */
107 /* Purpose: This function is called to manage TTY */
108 /* */
109 /* Input Parameters: */
110 /* message */
111 /* */
112 /* Output Parameters: */
113 /* None. */
114 /* */
115 /* Note: */
116 /* None. */
117 /* */
118 /* Revision History: */
119 /* None. */
120 /* */
121 /********************************************************************************/
122 void tty_manager (T_RV_HDR *p_message)
123 {
124 /* Declare local variables. */
125 void *p_send_message;
126
127 /**************** tty_manager function begins *********************/
128 switch(tty_env_ctrl_blk_p->state)
129 {
130 case TTY_IDLE:
131 {
132 switch(p_message->msg_id)
133 {
134 case TTY_START_REQ:
135 {
136 /* save the return path */
137 tty_env_ctrl_blk_p->return_path.callback_func = ((T_TTY_START *)p_message)->return_path.callback_func;
138 tty_env_ctrl_blk_p->return_path.addr_id = ((T_TTY_START *)p_message)->return_path.addr_id;
139
140 /* allocate the buffer for the message to the L1 */
141 p_send_message = audio_allocate_l1_message(0);
142 if (p_send_message != NULL)
143 {
144 /* send the start command to the audio L1 */
145 audio_send_l1_message(MMI_GTT_START_REQ, p_send_message);
146 }
147
148 /* change state */
149 tty_env_ctrl_blk_p->state = TTY_WAIT_START_CON;
150 }
151 break;
152 case TTY_STOP_REQ:
153 {
154 TTY_SEND_TRACE("TTY: STOP ERROR EVENT ",RV_TRACE_LEVEL_ERROR);
155 }
156 break;
157 }
158 } /* case TTY_IDLE */
159 break;
160
161 case TTY_WAIT_START_CON:
162 {
163 switch(p_message->msg_id)
164 {
165 case MMI_GTT_START_CON:
166 {
167 /* change state */
168 tty_env_ctrl_blk_p->state = TTY_WAIT_STOP_COMMAND;
169 }
170 break;
171 case TTY_STOP_REQ:
172 {
173 /* change state */
174 tty_env_ctrl_blk_p->state = TTY_WAIT_START_CON_TO_STOP;
175 }
176 break;
177 }
178 } /* case TTY_WAIT_START_CON */
179 break;
180
181 case TTY_WAIT_START_CON_TO_STOP:
182 {
183 switch(p_message->msg_id)
184 {
185 case MMI_GTT_START_CON:
186 {
187 /* send the stop command to the audio L1 */
188 p_send_message = audio_allocate_l1_message(0);
189 if (p_send_message != NULL)
190 {
191 audio_send_l1_message(MMI_GTT_STOP_REQ, p_send_message);
192 }
193
194 /* change state */
195 tty_env_ctrl_blk_p->state = TTY_WAIT_STOP_CON;
196 }
197 break;
198 case TTY_STOP_REQ:
199 {
200 TTY_SEND_TRACE("TTY: STOP ERROR EVENT ",RV_TRACE_LEVEL_ERROR);
201 }
202 break;
203 }
204 }
205 break;
206
207 case TTY_WAIT_STOP_COMMAND:
208 {
209 switch(p_message->msg_id)
210 {
211 case TTY_STOP_REQ:
212 {
213 /* send the stop command to the audio L1 */
214 p_send_message = audio_allocate_l1_message(0);
215 if (p_send_message != NULL)
216 {
217 audio_send_l1_message(MMI_GTT_STOP_REQ, p_send_message);
218 }
219
220 /* change state */
221 tty_env_ctrl_blk_p->state = TTY_WAIT_STOP_CON;
222 }
223 break;
224 case MMI_GTT_STOP_CON:
225 {
226 tty_send_status (AUDIO_OK, tty_env_ctrl_blk_p->return_path);
227
228 /* change state */
229 tty_env_ctrl_blk_p->state = TTY_IDLE;
230 }
231 break;
232 }
233 } /* case TTY_WAIT_STOP_COMMAND */
234 break;
235
236 case TTY_WAIT_STOP_CON:
237 {
238 switch(p_message->msg_id)
239 {
240 case MMI_GTT_STOP_CON:
241 {
242 tty_send_status (AUDIO_OK, tty_env_ctrl_blk_p->return_path);
243
244 /* change state */
245 tty_env_ctrl_blk_p->state = TTY_IDLE;
246 }
247 break;
248 case TTY_STOP_REQ:
249 {
250 TTY_SEND_TRACE("TTY: STOP ERROR EVENT ",RV_TRACE_LEVEL_ERROR);
251 }
252 break;
253 }
254 } /* case TTY_WAIT_STOP_CON */
255 break;
256
257 } /* switch(tty_env_ctrl_blk_p->state) */
258 }
259 #endif /* L1_GTT */