FreeCalypso > hg > fc-tourmaline
comparison src/cs/drivers/drv_app/kpd/kpd_functions.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:23:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e78acac3d88 |
---|---|
1 /** | |
2 * @file kpd_functions.c | |
3 * | |
4 * Implementation of Keypad functions. | |
5 * These functions implement the keypad processing. | |
6 * | |
7 * @author Laurent Sollier (l-sollier@ti.com) | |
8 * @version 0.1 | |
9 */ | |
10 | |
11 /* | |
12 * History: | |
13 * | |
14 * Date Author Modification | |
15 * ---------------------------------------- | |
16 * 10/10/2001 L Sollier Create | |
17 * | |
18 * | |
19 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved | |
20 */ | |
21 | |
22 #include "kpd/kpd_i.h" | |
23 #include "kpd/kpd_virtual_key_table_mgt.h" | |
24 #include "kpd/kpd_env.h" | |
25 #include "kpd/kpd_messages_i.h" | |
26 | |
27 #include "rvf/rvf_api.h" | |
28 #include "rvm/rvm_use_id_list.h" | |
29 | |
30 extern T_KPD_ENV_CTRL_BLK* kpd_env_ctrl_blk; | |
31 | |
32 | |
33 /* Define the max of subscribers supported by the keypad driver */ | |
34 #define MAX_SUBSCRIBERS 32 | |
35 | |
36 | |
37 #define KEY_MASK_SIZE_FOR_SN_MODE 20 | |
38 | |
39 /* This structure gather general informations about keypad */ | |
40 typedef struct { UINT32 reserved_subscriber_id; | |
41 UINT8 keypad_mode; | |
42 char sn_mode_notified_keys[KEY_MASK_SIZE_FOR_SN_MODE]; | |
43 T_SUBSCRIBER_ID owner_keypad_id; | |
44 } T_KEYPAD_DRIVER_INFOS; | |
45 | |
46 /* Keypad informations */ | |
47 static T_KEYPAD_DRIVER_INFOS keypad_driver_infos; | |
48 | |
49 /* Mutex used to protect reserved_subscriber_id variable */ | |
50 static T_RVF_MUTEX mutex; | |
51 | |
52 | |
53 /** | |
54 * @name Functions implementation | |
55 * | |
56 */ | |
57 /*@{*/ | |
58 | |
59 | |
60 /** | |
61 * function: kpd_initialize_keypad_driver | |
62 */ | |
63 T_RV_RET kpd_initialize_keypad_driver(void) | |
64 { | |
65 T_RV_RET ret = RV_OK; | |
66 UINT8 i; | |
67 | |
68 /* Initialization of keypad_driver_infos */ | |
69 keypad_driver_infos.reserved_subscriber_id = 0; | |
70 keypad_driver_infos.keypad_mode = MN_MODE; | |
71 for (i = 0; i < KEY_MASK_SIZE_FOR_SN_MODE; i++) | |
72 keypad_driver_infos.sn_mode_notified_keys[i] = 0; | |
73 keypad_driver_infos.owner_keypad_id = 0; | |
74 | |
75 /* Initialize ASCII table */ | |
76 if (kpd_initialize_ascii_table() != RV_OK) | |
77 ret = RV_INTERNAL_ERR; | |
78 | |
79 /* Check if number max of subscriber is supported by the driver */ | |
80 else if (KPD_MAX_SUBSCRIBER > MAX_SUBSCRIBERS) | |
81 ret = RV_INTERNAL_ERR; | |
82 | |
83 /* Check validity of the vpm table */ | |
84 else if (kpd_vpm_table_is_valid() == FALSE) | |
85 ret = RV_INTERNAL_ERR; | |
86 | |
87 /* Mutex initialization */ | |
88 else if (rvf_initialize_mutex(&mutex) != RVF_OK) | |
89 ret = RV_INTERNAL_ERR; | |
90 | |
91 /* Hardware initialization */ | |
92 kpd_initialize_keypad_hardware(); | |
93 | |
94 if (ret == RV_INTERNAL_ERR) | |
95 KPD_SEND_TRACE("Keypad driver initialization failed", RV_TRACE_LEVEL_ERROR); | |
96 | |
97 return ret; | |
98 } | |
99 | |
100 /** | |
101 * function: kpd_kill_keypad_driver | |
102 */ | |
103 T_RV_RET kpd_kill_keypad_driver(void) | |
104 { | |
105 return rvf_delete_mutex(&mutex); | |
106 } | |
107 | |
108 | |
109 /** | |
110 * function: kpd_add_subscriber | |
111 */ | |
112 T_RV_RET kpd_add_subscriber(T_SUBSCRIBER_ID* subscriber_id) | |
113 { | |
114 UINT8 i; | |
115 UINT8 nb_subscriber = 0; | |
116 T_RV_RET ret = RV_OK; | |
117 | |
118 rvf_lock_mutex(&mutex); | |
119 | |
120 /* Check number of subscribers */ | |
121 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) | |
122 if (keypad_driver_infos.reserved_subscriber_id & (1<<i)) | |
123 nb_subscriber++; | |
124 | |
125 if (nb_subscriber >= KPD_MAX_SUBSCRIBER) | |
126 { | |
127 KPD_SEND_TRACE("KPD: Max of subscriber reached", RV_TRACE_LEVEL_WARNING); | |
128 ret = RV_INTERNAL_ERR; | |
129 } | |
130 else | |
131 { | |
132 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) | |
133 if ( (keypad_driver_infos.reserved_subscriber_id & (1<<i)) == 0) | |
134 { | |
135 keypad_driver_infos.reserved_subscriber_id |= 1<<i; | |
136 *subscriber_id = i; | |
137 break; | |
138 } | |
139 } | |
140 | |
141 rvf_unlock_mutex(&mutex); | |
142 | |
143 return ret; | |
144 } | |
145 | |
146 /** | |
147 * function: kpd_remove_subscriber | |
148 */ | |
149 T_RV_RET kpd_remove_subscriber(T_SUBSCRIBER_ID subscriber_id) | |
150 { | |
151 T_RV_RET ret = RV_OK; | |
152 | |
153 rvf_lock_mutex(&mutex); | |
154 | |
155 /* Check if subscriber id is correct */ | |
156 if (keypad_driver_infos.reserved_subscriber_id & (1<<subscriber_id) ) | |
157 { | |
158 /* Unreserve the id */ | |
159 keypad_driver_infos.reserved_subscriber_id &= ~(1<<subscriber_id); | |
160 } | |
161 else | |
162 { | |
163 KPD_SEND_TRACE("KPD: Subscriber Id unknown", RV_TRACE_LEVEL_ERROR); | |
164 ret = RV_INVALID_PARAMETER; | |
165 } | |
166 | |
167 rvf_unlock_mutex(&mutex); | |
168 | |
169 return ret; | |
170 } | |
171 | |
172 /** | |
173 * function: kpd_subscriber_id_used | |
174 */ | |
175 BOOL kpd_subscriber_id_used(T_KPD_SUBSCRIBER subscriber, T_SUBSCRIBER_ID* subscriber_id) | |
176 { | |
177 BOOL ret = FALSE; | |
178 T_SUBSCRIBER_ID id; | |
179 | |
180 rvf_lock_mutex(&mutex); | |
181 | |
182 if (subscriber != 0) | |
183 { | |
184 id = ((T_SUBSCRIBER*) subscriber)->subscriber_id; | |
185 *subscriber_id = id; | |
186 | |
187 /* Check if subscriber id is correct */ | |
188 if ( keypad_driver_infos.reserved_subscriber_id & (1<<id) ) | |
189 ret = TRUE; | |
190 } | |
191 | |
192 rvf_unlock_mutex(&mutex); | |
193 | |
194 return ret; | |
195 } | |
196 | |
197 | |
198 /** | |
199 * function: kpd_send_key_event_message | |
200 */ | |
201 void kpd_send_key_event_message(T_KPD_PHYSICAL_KEY_ID physical_key_pressed_id, | |
202 T_KPD_KEY_STATE state, | |
203 T_KPD_PRESS_STATE press_state, | |
204 T_KPD_MODE mode, | |
205 T_RV_RETURN return_path) | |
206 { | |
207 T_RVF_MB_STATUS mb_status; | |
208 T_KPD_KEY_EVENT_MSG* key_event; | |
209 char* ascii_code; | |
210 | |
211 | |
212 /* Subscriber must be notified by the pressed key */ | |
213 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_KEY_EVENT_MSG), (void **) &key_event); | |
214 | |
215 if (mb_status != RVF_RED) /* Memory allocation success */ | |
216 { | |
217 /* Fill the message */ | |
218 key_event->hdr.msg_id = KPD_KEY_EVENT_MSG; | |
219 key_event->key_info.virtual_key_id = kpd_get_virtual_key(physical_key_pressed_id, | |
220 mode); | |
221 key_event->key_info.state = state; | |
222 key_event->key_info.press_state = press_state; | |
223 kpd_get_ascii_key_value(physical_key_pressed_id, | |
224 mode, | |
225 &ascii_code); | |
226 key_event->key_info.ascii_value_p = ascii_code; | |
227 | |
228 KPD_SEND_TRACE_PARAM("KPD: Virtual key Id sent: ", key_event->key_info.virtual_key_id, RV_TRACE_LEVEL_DEBUG_HIGH); | |
229 | |
230 /* Send message to the client */ | |
231 if (return_path.callback_func != 0) | |
232 { | |
233 return_path.callback_func((void*) key_event); | |
234 rvf_free_buf(key_event); | |
235 } | |
236 else | |
237 { | |
238 rvf_send_msg(return_path.addr_id, key_event); | |
239 } | |
240 } | |
241 else | |
242 { | |
243 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
244 } | |
245 } | |
246 | |
247 | |
248 /** | |
249 * function: kpd_send_status_message | |
250 */ | |
251 void kpd_send_status_message(UINT8 operation, UINT8 status_value, T_RV_RETURN return_path) | |
252 { | |
253 T_RVF_MB_STATUS mb_status; | |
254 T_KPD_STATUS_MSG* msg_status; | |
255 | |
256 /* Reserve memory for message */ | |
257 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_STATUS_MSG), (void **) &msg_status); | |
258 | |
259 if (mb_status != RVF_RED) /* Memory allocation success */ | |
260 { | |
261 /* Fill the message */ | |
262 msg_status->hdr.msg_id = KPD_STATUS_MSG; | |
263 msg_status->operation = operation; | |
264 msg_status->status_value = status_value; | |
265 | |
266 /* Send message to the client */ | |
267 if (return_path.callback_func != 0) | |
268 { | |
269 return_path.callback_func((void*) msg_status); | |
270 rvf_free_buf(msg_status); | |
271 | |
272 } | |
273 else | |
274 { | |
275 rvf_send_msg(return_path.addr_id, msg_status); | |
276 } | |
277 KPD_SEND_TRACE_PARAM("KPD: Sent status message, Id:", status_value, RV_TRACE_LEVEL_DEBUG_LOW); | |
278 } | |
279 else | |
280 { | |
281 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
282 } | |
283 } | |
284 | |
285 | |
286 /** | |
287 * function: kpd_is_key_in_sn_mode | |
288 */ | |
289 BOOL kpd_is_key_in_sn_mode(T_KPD_PHYSICAL_KEY_ID physical_key_pressed_id) | |
290 { | |
291 return ( (keypad_driver_infos.keypad_mode == SN_MODE) | |
292 && (keypad_driver_infos.sn_mode_notified_keys[physical_key_pressed_id >> 3] & (1<<(physical_key_pressed_id & 0x07))) ); | |
293 } | |
294 | |
295 | |
296 /** | |
297 * function: kpd_set_keys_in_sn_mode | |
298 */ | |
299 void kpd_set_keys_in_sn_mode(T_KPD_VIRTUAL_KEY_TABLE* keys_owner, T_KPD_MODE mode) | |
300 { | |
301 UINT8 i; | |
302 INT8 position; | |
303 | |
304 for (i = 0; i < keys_owner->nb_notified_keys; i++) | |
305 { | |
306 /* Retrieve position in vpm table */ | |
307 kpd_retrieve_virtual_key_position(keys_owner->notified_keys[i], | |
308 mode, | |
309 &position); | |
310 | |
311 keypad_driver_infos.sn_mode_notified_keys[position >> 3] |= (1<<(position & 0x07)); | |
312 } | |
313 } | |
314 | |
315 | |
316 /** | |
317 * function: kpd_is_owner_keypad | |
318 */ | |
319 BOOL kpd_is_owner_keypad(T_SUBSCRIBER_ID subscriber_id) | |
320 { | |
321 return ( (keypad_driver_infos.keypad_mode == SN_MODE) | |
322 && (keypad_driver_infos.owner_keypad_id == subscriber_id) ); | |
323 } | |
324 | |
325 | |
326 /** | |
327 * function: kpd_get_keypad_mode | |
328 */ | |
329 UINT8 kpd_get_keypad_mode(void) | |
330 { | |
331 return keypad_driver_infos.keypad_mode; | |
332 } | |
333 | |
334 /** | |
335 * function: kpd_set_keypad_mode | |
336 */ | |
337 void kpd_set_keypad_mode(UINT8 mode) | |
338 { | |
339 UINT8 i; | |
340 | |
341 keypad_driver_infos.keypad_mode = mode; | |
342 | |
343 if (mode == MN_MODE) | |
344 { | |
345 for (i = 0; i < KEY_MASK_SIZE_FOR_SN_MODE; i++) | |
346 keypad_driver_infos.sn_mode_notified_keys[i] = 0; | |
347 } | |
348 } | |
349 | |
350 /** | |
351 * function: kpd_get_owner_keypad_id | |
352 */ | |
353 T_SUBSCRIBER_ID kpd_get_owner_keypad_id(void) | |
354 { | |
355 return keypad_driver_infos.owner_keypad_id; | |
356 } | |
357 | |
358 /** | |
359 * function: kpd_set_owner_keypad_id | |
360 */ | |
361 void kpd_set_owner_keypad_id(T_SUBSCRIBER_ID subscriber_id) | |
362 { | |
363 keypad_driver_infos.owner_keypad_id = subscriber_id; | |
364 } | |
365 | |
366 | |
367 /*@}*/ |