comparison src/g23m-gprs/sm/sm_timer_handler.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*----------------------------------------------------------------------------
2 | Project : 3G PS
3 | Module : SM
4 +-----------------------------------------------------------------------------
5 | Copyright 2003 Texas Instruments.
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments .
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments.
15 +-----------------------------------------------------------------------------
16 | Purpose: 3G timer handler functions implementation in the SM entity.
17 | For design details, see:
18 | 8010.908 SM Detailed Specification
19 +---------------------------------------------------------------------------*/
20
21 /*==== DECLARATION CONTROL =================================================*/
22
23 /*==== INCLUDES =============================================================*/
24
25 #include "sm.h"
26
27 #include "sm_timer_handler.h"
28
29 /*==== CONSTS ===============================================================*/
30
31 /*==== TYPES ================================================================*/
32
33 /*==== LOCALS ===============================================================*/
34
35 /*==== PRIVATE FUNCTIONS ====================================================*/
36
37 /*==== PUBLIC FUNCTIONS =====================================================*/
38
39 /*
40 +------------------------------------------------------------------------------
41 | Function : sm_timer_start
42 +------------------------------------------------------------------------------
43 | Description : Start specified timer for the given NSAPI/context
44
45 | Parameters : context - Context data
46 | timer - 3G timer (T3380, T3381, or T3390)
47 +------------------------------------------------------------------------------
48 */
49 void sm_timer_start(struct T_SM_CONTEXT_DATA *context, T_SM_TIMER_TYPE timer)
50 {
51 T_TIME timeout;
52 #ifdef DEBUG
53 (void)TRACE_EVENT_P2("sm_timer_start: %s on NSAPI %d",
54 sm_timer_name((U8)timer), context->nsapi);
55 #endif
56
57 switch (timer) {
58 case SM_TIMER_T3380:
59 timeout = (T_TIME)NWSM_T3380_TIMEOUT;
60 break;
61 case SM_TIMER_T3381:
62 timeout = (T_TIME)NWSM_T3381_TIMEOUT;
63 break;
64 case SM_TIMER_T3390:
65 timeout = (T_TIME)NWSM_T3390_TIMEOUT;
66 break;
67 case SM_TIMER_NONE:
68 default:
69 (void)TRACE_ERROR("sm_timer_start: Invalid timer specified - No timers started!");
70 return;
71 }
72
73 if ((T_SM_TIMER_TYPE)context->active_timer == SM_TIMER_NONE) {
74 context->active_timer = (U8)timer;
75 context->timeouts = (U8)NWSM_MAX_TIMEOUTS;
76 (void)vsi_t_start(sm_handle, sm_nsapi_to_index(context->nsapi), timeout);
77 } else {
78 /* W00t?!? Timer already active? Bug? */
79 (void)TRACE_ERROR("A timer is already active for this NSAPI -- overriding!");
80 (void)vsi_t_stop (sm_handle, sm_nsapi_to_index(context->nsapi));
81 (void)vsi_t_start(sm_handle, sm_nsapi_to_index(context->nsapi), timeout);
82 }
83 }
84
85 /*
86 +------------------------------------------------------------------------------
87 | Function : sm_timer_restart
88 +------------------------------------------------------------------------------
89 | Description : Restart timer after timeout for the given NSAPI/context
90
91 | Parameters : context - Context data
92 +------------------------------------------------------------------------------
93 */
94 void sm_timer_restart(struct T_SM_CONTEXT_DATA *context)
95 {
96 T_TIME timeout;
97
98 #ifdef DEBUG
99 (void)TRACE_EVENT_P3("sm_timer_restart: %s on NSAPI %d; %d timeouts remaining",
100 sm_timer_name(context->active_timer),
101 context->nsapi, context->timeouts);
102 #endif
103
104 switch (context->active_timer) {
105 case SM_TIMER_T3380:
106 timeout = (T_TIME)NWSM_T3380_TIMEOUT;
107 break;
108 case SM_TIMER_T3381:
109 timeout = (T_TIME)NWSM_T3381_TIMEOUT;
110 break;
111 case SM_TIMER_T3390:
112 timeout = (T_TIME)NWSM_T3390_TIMEOUT;
113 break;
114 case SM_TIMER_NONE:
115 default:
116 (void)TRACE_ERROR("sm_timer_restart: Attempted to restart void timer - Aborted!");
117 return;
118 }
119
120 (void)vsi_t_start(sm_handle, sm_nsapi_to_index(context->nsapi), timeout);
121 }
122
123 /*
124 +------------------------------------------------------------------------------
125 | Function : sm_timer_stop
126 +------------------------------------------------------------------------------
127 | Description : Stop active timer for the given NSAPI/context
128
129 | Parameters : context - Context data
130 +------------------------------------------------------------------------------
131 */
132 void sm_timer_stop(struct T_SM_CONTEXT_DATA *context)
133 {
134 #ifdef DEBUG
135 (void)TRACE_EVENT_P2("sm_timer_stop: %s on NSAPI %d",
136 sm_timer_name(context->active_timer),
137 context->nsapi);
138 #endif
139
140 if ((T_SM_TIMER_TYPE)context->active_timer != SM_TIMER_NONE) {
141 (void)vsi_t_stop (sm_handle, sm_nsapi_to_index(context->nsapi));
142 context->active_timer = (U8)SM_TIMER_NONE;
143 context->timeouts = (U8)0;
144 }
145 /* If no timers active: No action */
146 }
147
148 /*==== END OF FILE ==========================================================*/