FreeCalypso > hg > tcs211-fcmodem
comparison chipsetsw/services/mks/mks_functions.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /** | |
2 * @file mks_functions.c | |
3 * | |
4 * Implementation of MKS functions. | |
5 * | |
6 * @author Laurent Sollier (l-sollier@ti.com) | |
7 * @version 0.1 | |
8 */ | |
9 | |
10 /* | |
11 * History: | |
12 * | |
13 * Date Author Modification | |
14 * ---------------------------------------- | |
15 * 11/16/2001 L Sollier Create | |
16 * | |
17 * | |
18 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved | |
19 */ | |
20 | |
21 #include "mks/mks_i.h" | |
22 #include "mks/mks_api.h" | |
23 #include "mks/mks_env.h" | |
24 | |
25 #include "kpd/kpd_api.h" | |
26 | |
27 #include "rvm/rvm_use_id_list.h" | |
28 #include "rv/rv_general.h" | |
29 | |
30 #include <string.h> | |
31 | |
32 | |
33 /* This value is set in the T_KEY_SEQUENCE_INFOS structure when post-sequence is on going */ | |
34 #define POST_SEQUENCE_COMPLETED 0x10 | |
35 | |
36 /** This structure defines */ | |
37 typedef struct { char name[KPD_MAX_CHAR_NAME+1]; | |
38 T_KPD_VIRTUAL_KEY_ID sequence_key[MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE]; | |
39 UINT8 nb_key_of_sequence; | |
40 UINT8 completion_type; | |
41 UINT8 nb_key_for_post_sequence; | |
42 UINT8 nb_key_sent_for_post_sequence; | |
43 T_RV_RETURN return_path; | |
44 } T_KEY_SEQUENCE_INFOS; | |
45 | |
46 | |
47 | |
48 | |
49 /** Definition of the different magic key sequence. | |
50 * Note that the magic key sequence is defined by a KPD_KEY_NULL key Id. | |
51 */ | |
52 static T_KEY_SEQUENCE_INFOS* key_sequence_table[MKS_NB_MAX_OF_KEY_SEQUENCE] = {0}; | |
53 | |
54 /* Subscriber Id for keypad driver */ | |
55 static T_KPD_SUBSCRIBER subscriber_id; | |
56 | |
57 /* Number of key sequence registered */ | |
58 static UINT8 nb_key_sequence = 0; | |
59 | |
60 /* Key pressed history */ | |
61 static T_KPD_VIRTUAL_KEY_ID key_history[MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE]; | |
62 | |
63 | |
64 /** External declaration */ | |
65 extern T_MKS_ENV_CTRL_BLK* mks_env_ctrl_blk; | |
66 | |
67 /** | |
68 * @name Functions implementation | |
69 * | |
70 */ | |
71 /*@{*/ | |
72 | |
73 | |
74 /** | |
75 * function: mks_add_key_sequence_i | |
76 */ | |
77 T_RV_RET mks_add_key_sequence_i(T_MKS_INFOS_KEY_SEQUENCE_MSG* infos_key_sequence_p) | |
78 { | |
79 UINT8 i; | |
80 T_RVF_MB_STATUS mb_status; | |
81 T_RV_RET ret = RV_OK; | |
82 T_MKS_INFOS_KEY_SEQUENCE* infos_p = &(infos_key_sequence_p->key_sequence_infos); | |
83 | |
84 if (nb_key_sequence < MKS_NB_MAX_OF_KEY_SEQUENCE) | |
85 { | |
86 /* Reserve memory for message */ | |
87 mb_status = rvf_get_buf (mks_env_ctrl_blk->prim_id, sizeof(T_KEY_SEQUENCE_INFOS), (void **) &key_sequence_table[nb_key_sequence]); | |
88 | |
89 if (mb_status != RVF_RED) /* Memory allocation success */ | |
90 { | |
91 /* Fill the structure */ | |
92 for (i = 0; i < infos_p->nb_key_of_sequence; i++) | |
93 key_sequence_table[nb_key_sequence]->sequence_key[i] = infos_p->key_id[i]; | |
94 | |
95 key_sequence_table[nb_key_sequence]->nb_key_of_sequence = infos_p->nb_key_of_sequence; | |
96 key_sequence_table[nb_key_sequence]->completion_type = infos_p->completion_type; | |
97 key_sequence_table[nb_key_sequence]->return_path = infos_p->return_path; | |
98 key_sequence_table[nb_key_sequence]->nb_key_for_post_sequence = infos_p->nb_key_for_post_sequence; | |
99 infos_p->name[KPD_MAX_CHAR_NAME] = 0; | |
100 strcpy(key_sequence_table[nb_key_sequence]->name, infos_p->name); | |
101 | |
102 key_sequence_table[nb_key_sequence]->nb_key_sent_for_post_sequence = 0; | |
103 | |
104 /* Update number of key sequence */ | |
105 nb_key_sequence++; | |
106 | |
107 ret = RV_OK; | |
108 } | |
109 else | |
110 { | |
111 MKS_SEND_TRACE("MKS: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
112 ret = RV_MEMORY_ERR; | |
113 } | |
114 } | |
115 else | |
116 { | |
117 /* Maximum of magic key sequence registered*/ | |
118 ret = RV_INTERNAL_ERR; | |
119 } | |
120 | |
121 return ret; | |
122 } | |
123 | |
124 /** | |
125 * function: mks_remove_key_sequence_i | |
126 * | |
127 */ | |
128 T_RV_RET mks_remove_key_sequence_i(T_MKS_REMOVE_KEY_SEQUENCE_MSG* remove_key_sequence_p) | |
129 { | |
130 UINT8 i; | |
131 | |
132 for (i = 0; i < nb_key_sequence; i++) | |
133 { | |
134 /* Compare name of the key sequence */ | |
135 if ( !(strcmp(key_sequence_table[i]->name, remove_key_sequence_p->name)) ) | |
136 { | |
137 /* Free memory used for the key sequence */ | |
138 rvf_free_buf(key_sequence_table[i]); | |
139 nb_key_sequence--; | |
140 | |
141 /* Sort out the table of key sequence */ | |
142 key_sequence_table[i] = key_sequence_table[nb_key_sequence]; | |
143 key_sequence_table[nb_key_sequence] = 0; | |
144 break; | |
145 } | |
146 } | |
147 | |
148 return RV_OK; | |
149 } | |
150 | |
151 /** | |
152 * function: mks_check_key_sequence | |
153 */ | |
154 void mks_check_key_sequence(T_KPD_KEY_EVENT_MSG* key_event_p) | |
155 { | |
156 UINT8 i,j, nb_key_of_sequence; | |
157 BOOL key_sequence_completed = TRUE; | |
158 | |
159 /* Stop timer */ | |
160 rvf_stop_timer(RVF_TIMER_0); | |
161 | |
162 /* Update key pressed history */ | |
163 for (i = 0; i < MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE-1; i++) | |
164 key_history[i] = key_history[i+1]; | |
165 | |
166 key_history[MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE-1] = key_event_p->key_info.virtual_key_id; | |
167 | |
168 /* Check each key sequence */ | |
169 for (i = 0; i < nb_key_sequence; i++) | |
170 { | |
171 if (!(key_sequence_table[i]->completion_type & POST_SEQUENCE_COMPLETED)) | |
172 { | |
173 /* Verify if magic key sequence is completed */ | |
174 nb_key_of_sequence = key_sequence_table[i]->nb_key_of_sequence; | |
175 for (j = 0; j < nb_key_of_sequence; j++) | |
176 { | |
177 if (key_sequence_table[i]->sequence_key[nb_key_of_sequence-j-1] != key_history[MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE-j-1]) | |
178 { | |
179 key_sequence_completed = FALSE; | |
180 break; | |
181 } | |
182 } | |
183 if (key_sequence_completed == TRUE) | |
184 { | |
185 if (key_sequence_table[i]->completion_type == MKS_SEQUENCE_COMPLETED) | |
186 { | |
187 /* Process sequence completed */ | |
188 mks_send_key_sequence_completed_msg(MKS_SEQUENCE_COMPLETED, | |
189 KPD_KEY_NULL, | |
190 key_sequence_table[i]->return_path, | |
191 key_sequence_table[i]->name); | |
192 } | |
193 else | |
194 { | |
195 /* Store info that post-sequence is on going */ | |
196 key_sequence_table[i]->completion_type |= POST_SEQUENCE_COMPLETED; | |
197 } | |
198 } | |
199 else | |
200 key_sequence_completed = TRUE; | |
201 } | |
202 else | |
203 { | |
204 /* Notify that magic key sequence is completed */ | |
205 mks_send_key_sequence_completed_msg(MKS_POST_SEQUENCE, | |
206 key_event_p->key_info.virtual_key_id, | |
207 key_sequence_table[i]->return_path, | |
208 key_sequence_table[i]->name); | |
209 | |
210 key_sequence_table[i]->nb_key_sent_for_post_sequence++; | |
211 | |
212 if (key_sequence_table[i]->nb_key_sent_for_post_sequence == key_sequence_table[i]->nb_key_for_post_sequence) | |
213 { | |
214 key_sequence_table[i]->nb_key_sent_for_post_sequence = 0; | |
215 key_sequence_table[i]->completion_type &= ~POST_SEQUENCE_COMPLETED; | |
216 } | |
217 } | |
218 } | |
219 | |
220 rvf_start_timer(RVF_TIMER_0, RVF_MS_TO_TICKS(MKS_TIME_RESET_KEY_SEQUENCE), FALSE); | |
221 } | |
222 | |
223 | |
224 | |
225 /** | |
226 * function: mks_send_key_sequence_completed_msg | |
227 */ | |
228 void mks_send_key_sequence_completed_msg(UINT8 completion_level, | |
229 T_KPD_VIRTUAL_KEY_ID key_id, | |
230 T_RV_RETURN return_path, | |
231 char* name) | |
232 { | |
233 T_MKS_SEQUENCE_COMPLETED_MSG* msg_sequence_completed = 0; | |
234 T_RVF_MB_STATUS mb_status; | |
235 | |
236 /* Reserve memory for message */ | |
237 mb_status = rvf_get_buf (mks_env_ctrl_blk->prim_id, sizeof(T_MKS_SEQUENCE_COMPLETED_MSG), (void **) &msg_sequence_completed); | |
238 | |
239 if (mb_status != RVF_RED) /* Memory allocation success */ | |
240 { | |
241 /* Fill the message */ | |
242 msg_sequence_completed->hdr.msg_id = MKS_SEQUENCE_COMPLETED_MSG; | |
243 strcpy(msg_sequence_completed->name, name); | |
244 msg_sequence_completed->completion_type = completion_level; | |
245 msg_sequence_completed->key_pressed = key_id; | |
246 | |
247 /* Send message to the client */ | |
248 if (return_path.callback_func != 0) | |
249 { | |
250 return_path.callback_func((void*) msg_sequence_completed); | |
251 rvf_free_buf(msg_sequence_completed); | |
252 } | |
253 else | |
254 { | |
255 rvf_send_msg(return_path.addr_id, msg_sequence_completed); | |
256 } | |
257 } | |
258 else | |
259 { | |
260 MKS_SEND_TRACE("MKS: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
261 } | |
262 } | |
263 | |
264 | |
265 /** | |
266 * function: mks_reset_sequence | |
267 */ | |
268 void mks_reset_sequence(void) | |
269 { | |
270 UINT8 i; | |
271 | |
272 for (i = 0; i < MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE; i++) | |
273 key_history[i] = KPD_KEY_NULL; | |
274 } | |
275 | |
276 | |
277 /** | |
278 * function: mks_initialize_swe | |
279 */ | |
280 void mks_initialize_swe(void) | |
281 { | |
282 T_RV_RET ret; | |
283 T_KPD_VIRTUAL_KEY_TABLE notified_keys; | |
284 T_RV_RETURN return_path; | |
285 UINT8 i; | |
286 | |
287 /* Initialize key pressed history structure */ | |
288 for (i = 0; i < MKS_NB_MAX_OF_KEY_IN_KEY_SEQUENCE; i++) | |
289 key_history[i] = KPD_KEY_NULL; | |
290 | |
291 /* Subscription to the keypad */ | |
292 return_path.addr_id = mks_env_ctrl_blk->addr_id; | |
293 return_path.callback_func = 0; | |
294 notified_keys.nb_notified_keys = KPD_NB_PHYSICAL_KEYS; | |
295 ret = kpd_subscribe (&subscriber_id, KPD_DEFAULT_MODE, ¬ified_keys, return_path); | |
296 | |
297 if (ret != RV_OK) | |
298 { | |
299 MKS_SEND_TRACE("MKS: Unable to subscribe to the keypad", RV_TRACE_LEVEL_DEBUG_HIGH); | |
300 } | |
301 } | |
302 | |
303 | |
304 /** | |
305 * function: mks_stop_swe | |
306 */ | |
307 void mks_stop_swe(void) | |
308 { | |
309 T_RV_RET ret; | |
310 | |
311 /* Unsubscribe to the keypad */ | |
312 ret = kpd_unsubscribe(&subscriber_id); | |
313 | |
314 if (ret != RV_OK) | |
315 { | |
316 MKS_SEND_TRACE("MKS: Unsubscription error", RV_TRACE_LEVEL_DEBUG_HIGH); | |
317 } | |
318 } | |
319 | |
320 | |
321 /*@}*/ |