comparison g23m-gsm/alr/alr_rach.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS
4 | Modul : ALR_RACH
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This Modul defines the SDL process RACH_Control.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ALR_RACH_C
22 #define ALR_RACH_C
23
24 #include "config.h"
25 #include "fixedconf.h"
26 #include "condat-features.h"
27
28 #define ENTITY_PL
29
30 /*==== INCLUDES ===================================================*/
31 #include <string.h>
32 #include <stdlib.h>
33 #include <ctype.h>
34 #include "typedefs.h"
35 #include "pconst.cdg"
36 #include "mconst.cdg"
37 #include "message.h"
38 #include "ccdapi.h"
39 #include "vsi.h"
40 #include "custom.h"
41 #include "gsm.h"
42 #include "prim.h"
43 #include "cnf_alr.h"
44 #include "mon_alr.h"
45 #include "pei.h"
46 #include "tok.h"
47 #include "pcm.h"
48 #ifdef GPRS
49 #include "alr_gprs.h"
50 #endif
51
52 #include "alr.h"
53 #include "alr_em.h"
54
55 /*==== EXPORT =====================================================*/
56 /*==== PRIVAT =====================================================*/
57 LOCAL void rach_send_mphc_ra_req (T_MPH_RANDOM_ACCESS_REQ *random_req);
58 /*==== VARIABLES ==================================================*/
59 #if defined (WIN32)
60 #define TRACING
61 #endif
62
63 #if defined (TRACING)
64 #define ALR_TRACE_RACH(a) ALR_TRACE(a)
65 #else
66 #define ALR_TRACE_RACH(a)
67 #endif
68
69 #if defined (TRACING)
70
71 #define ALR_TRACE_RACH_CLASS(x) TRACE_EVENT_P1 ("class %d",x)
72 #define ALR_TRACE_RACH_POWER(p) TRACE_EVENT_P1 ("configured power = %d", p)
73
74 #else
75
76 #define ALR_TRACE_RACH_CLASS(x)
77 #define ALR_TRACE_RACH_POWER(p)
78
79 #endif
80
81 /*==== FUNCTIONS ==================================================*/
82
83 /*
84 +--------------------------------------------------------------------+
85 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
86 | STATE : code ROUTINE : rach_init |
87 +--------------------------------------------------------------------+
88
89 PURPOSE : Initialize RACH Control Process.
90
91 */
92
93 GLOBAL void rach_init (void)
94 {
95 GET_INSTANCE_DATA;
96 alr_data->state[STATE_RA] = RA_NULL;
97 }
98
99 /*
100 +--------------------------------------------------------------------+
101 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
102 | STATE : code ROUTINE : rach_configure_class |
103 +--------------------------------------------------------------------+
104
105 PURPOSE : Process signal rach_configure_class from SDL process
106 Main_Control.
107
108 */
109 GLOBAL void rach_configure_class (UBYTE ms_class,
110 UBYTE dcs_class)
111 {
112 GET_INSTANCE_DATA;
113 /*
114 * +1 because of interface difference between RR and TI
115 */
116 alr_data->rach_data.ms_class = (UBYTE)(ms_class + 1);
117 alr_data->rach_data.dcs_class = (UBYTE)(dcs_class + 1);
118
119 ALR_TRACE_RACH_CLASS (alr_data->rach_data.ms_class);
120 }
121
122 /*
123 +--------------------------------------------------------------------+
124 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
125 | STATE : code ROUTINE : rach_configure_power |
126 +--------------------------------------------------------------------+
127
128 PURPOSE : Process signal rach_configure_power from SDL process
129 Main_Control.
130
131 */
132
133 GLOBAL void rach_configure_power (UBYTE power)
134 {
135 GET_INSTANCE_DATA;
136 ALR_TRACE_RACH_POWER(power);
137
138 alr_data->rach_data.max_tx_pwr_ccch = power;
139 }
140 /*
141 +--------------------------------------------------------------------+
142 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
143 | STATE : code ROUTINE : rach_stop |
144 +--------------------------------------------------------------------+
145
146 PURPOSE : Process signal rach_stop from SDL process
147 Main_Control.
148 */
149
150 GLOBAL void rach_stop (void)
151 {
152 GET_INSTANCE_DATA;
153 switch (GET_STATE (STATE_RA))
154 {
155 case RA_ACTIVE:
156 ma_rach_stop_ra_req ();
157 /*lint -fallthrough*/
158 case RA_LISTEN_TO_CCCH:
159 SET_STATE (STATE_RA, RA_NULL);
160 break;
161
162 default:
163 break;
164 }
165 }
166
167
168 /*
169 +--------------------------------------------------------------------+
170 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
171 | STATE : code ROUTINE : rach_random_req |
172 +--------------------------------------------------------------------+
173
174 PURPOSE : Process signal rach_random_req from SDL process
175 Main_Control.
176
177 */
178
179 GLOBAL void rach_random_req (T_MPH_RANDOM_ACCESS_REQ *random_req)
180 {
181 GET_INSTANCE_DATA;
182 switch (GET_STATE (STATE_RA))
183 {
184 case RA_NULL:
185 if (random_req->send_mode.no NEQ 0)
186 {
187 rach_send_mphc_ra_req (random_req);
188 }
189 break;
190
191 case RA_ACTIVE:
192 if (random_req->send_mode.no EQ 0)
193 {
194
195 ALR_EM_STOP_CONNECTION_ESTABLISHMENT;
196
197 SET_STATE (STATE_RA, RA_LISTEN_TO_CCCH);
198 ma_rach_stop_ra_req ();
199 }
200 else
201 {
202 /*stop to be safe */
203 ma_rach_stop_ra_req ();
204 {
205 rach_send_mphc_ra_req (random_req);
206 } /*PALLOC*/
207 } /* if */
208 break;
209 default:
210 break;
211 }
212 }
213
214 /*
215 +--------------------------------------------------------------------+
216 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
217 | STATE : code ROUTINE : rach_ra_cnf |
218 +--------------------------------------------------------------------+
219
220 PURPOSE : Process signal rach_ra_cnf from SDL process
221 Main_Control.
222
223 */
224
225 GLOBAL void rach_ra_cnf (T_MPHC_RA_CON *ra_cnf)
226 {
227 GET_INSTANCE_DATA;
228 UBYTE c_burst = alr_data->rach_data.c_burst-1; /* confirmed index */
229
230 switch (GET_STATE (STATE_RA))
231 {
232 case RA_ACTIVE:
233 {
234 PALLOC (random_cnf, MPH_RANDOM_ACCESS_CNF);
235
236 ra_cnf->fn %= 42432L;
237 #ifdef GPRS
238 alr_data->rach_data.t1[c_burst] =
239 random_cnf->frame_no.t1=
240 (UBYTE)((ra_cnf->fn / 1326) % 32);
241 alr_data->rach_data.t2[c_burst] =
242 random_cnf->frame_no.t2=
243 (UBYTE)(ra_cnf->fn % 26);
244 alr_data->rach_data.t3[c_burst] =
245 random_cnf->frame_no.t3=
246 (UBYTE)(ra_cnf->fn % 51);
247 #else
248 random_cnf->frame_no.t1= (UBYTE)((ra_cnf->fn / 1326) % 32);
249 random_cnf->frame_no.t2= (UBYTE)(ra_cnf->fn % 26);
250 random_cnf->frame_no.t3= (UBYTE)(ra_cnf->fn % 51);
251 #endif
252 ma_rach_random_cnf (random_cnf);
253
254 c_burst++; /* next index */
255 if (c_burst >= alr_data->rach_data.max_bursts)
256 {/* last index ? */
257 SET_STATE (STATE_RA, RA_LISTEN_TO_CCCH);
258 ma_rach_stop_ra_req ();
259 #if !defined(TNNN_WITH_TIMER)
260 ma_fake_rr_report();
261 #endif /* !TNNN_WITH_TIMER */
262 }
263 else
264 {
265 PALLOC (ra_req, MPHC_RA_REQ);
266
267 /*
268 * power limitation
269 */
270 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
271 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
272 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
273 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
274 #endif
275
276 /*
277 * Modification: Add 1 to the time of RR !!!!
278 */
279 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[c_burst]+1);
280 ra_req->channel_request = alr_data->rach_data.channel_request[c_burst];
281 ma_rach_ra_req (ra_req);
282 alr_data->rach_data.c_burst++; /* the next index */
283 }
284 break;
285 }
286 default:
287 break;
288 }
289 }
290
291
292
293 /*
294 +--------------------------------------------------------------------+
295 | PROJECT : GSM-PS (6103) MODULE : ALR_RACH |
296 | STATE : code ROUTINE : cut_power_value |
297 +--------------------------------------------------------------------+
298
299 PURPOSE : Cut the nominal maximum output power to the
300 associated power class.
301 (Reference for the tables with the associated
302 power classes, control levels and nominal output power
303 is 3GPP TS 05.05, 4.1)
304
305 */
306
307 GLOBAL UBYTE cut_power_value (UBYTE power, T_MPH_DEDICATED_REQ *mph_dedicated_req)
308 {
309 GET_INSTANCE_DATA;
310 UBYTE new_power = power;
311 UBYTE sc_band;
312
313 if(mph_dedicated_req == NULL)
314 {
315 sc_band = alr_data->sc_band;
316 }
317 else
318 {
319 if(mph_dedicated_req->ch_type.h)
320 sc_band = get_band(mph_dedicated_req->ch_type.ma[0]);
321 else
322 sc_band = get_band(mph_dedicated_req->ch_type.arfcn);
323 }
324
325 switch (sc_band)
326 {
327 case BAND_GSM_900:
328 case BAND_E_GSM:
329 case BAND_GSM_850:
330 switch (alr_data->rach_data.ms_class)
331 {
332 case POW_CLASS_1: /* doesn't exist */
333 case POW_CLASS_2: /* power class 2, 8W, 39 dBm, level 0..2 */
334 /* highest level allowed => no cut necessary */
335 break;
336 case POW_CLASS_3: /* power class 3, 5W, 37 dBm, level 3 */
337 if (new_power < 3)
338 new_power = 3;
339 break;
340 case POW_CLASS_4: /* power class 4, 2W, 33 dBm, level 5 */
341 if (new_power < 5)
342 new_power = 5;
343 break;
344 case POW_CLASS_5: /* power class 5, 0.8W, 29 dBm, level 7 */
345 if (new_power < 7)
346 new_power = 7;
347 break;
348 }
349 break;
350 case BAND_DCS_1800:
351 switch (alr_data->rach_data.dcs_class)
352 {
353 case POW_CLASS_1: /* power class 1, 1W, 30 dBm, level 0 */
354 if (new_power > 28)
355 new_power = 0;
356 break;
357 case POW_CLASS_2: /* power class 2, 0.25W, 24 dBm, level 3 */
358 if (!INRANGE (3, new_power, 28))
359 new_power = 3;
360 break;
361 case POW_CLASS_3: /* power class 3, 4W, 36 dBm , level 29 */
362 /* highest level allowed => no cut necessary */
363 break;
364 }
365 break;
366 case BAND_PCS_1900:
367 switch (alr_data->rach_data.dcs_class)
368 {
369 case POW_CLASS_1: /* power class 1, 1W, 30 dBm, level 0 */
370 if (!INRANGE (0, new_power, 15))
371 new_power = 0;
372 break;
373 case POW_CLASS_2: /* power class 2, 0.25W, 24 dBm, level 3 */
374 if (!INRANGE (3, new_power, 15))
375 new_power = 3;
376 break;
377 default:
378 case POW_CLASS_3: /* power class 3, 2W, 33 dBm , level 30 */
379 /* highest level allowed => no cut necessary */
380 break;
381 }
382 break;
383 }
384 return new_power;
385 }
386
387 /*
388 +--------------------------------------------------------------------+
389 | PROJECT : MODULE : ALR_RACH |
390 | STATE : code ROUTINE : rach_send_mphc_ra_req |
391 +--------------------------------------------------------------------+
392
393 PURPOSE : Function to send the MPHC_RA_REQ primitive.
394 Called from function 'rach_random_req'
395 This function handles:
396 1) Starts Random Burst Sending.
397 2) Power limitation.
398 3) Adds 1 to the time of RR.
399 */
400 LOCAL void rach_send_mphc_ra_req (T_MPH_RANDOM_ACCESS_REQ *random_req)
401 {
402 GET_INSTANCE_DATA;
403 PALLOC (ra_req, MPHC_RA_REQ);
404 ALR_TRACE_RACH("rach_send_mphc_ra_req");
405 ALR_EM_START_CONNECTION_ESTABLISHMENT;
406
407 /*
408 * Start Random Burst Sending
409 */
410 memcpy (alr_data->rach_data.delta, random_req->send_mode.delta,
411 sizeof (alr_data->rach_data.delta));
412 memcpy (alr_data->rach_data.channel_request, random_req->send_mode.rach,
413 sizeof (alr_data->rach_data.channel_request));
414 alr_data->rach_data.max_bursts = random_req->send_mode.no;
415 alr_data->rach_data.c_burst = 0;
416 /*
417 * power limitation
418 */
419 ra_req->txpwr = cut_power_value (alr_data->rach_data.max_tx_pwr_ccch, NULL);
420 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
421 ra_req->powerclass_gsm = alr_data->rach_data.ms_class;
422 ra_req->powerclass_dcs = alr_data->rach_data.dcs_class;
423 #endif
424
425 /*
426 * Modification: Add 1 to the time of RR !!!!
427 */
428 ra_req->rand = (UBYTE)(alr_data->rach_data.delta[alr_data->rach_data.c_burst]+1);
429 ra_req->channel_request = alr_data->rach_data.channel_request[alr_data->rach_data.c_burst++];
430 SET_STATE (STATE_RA, RA_ACTIVE);
431 ma_rach_ra_req (ra_req);
432 }
433
434 #endif