xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/newhost/drvTimer.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi //<MStar Software>
2*53ee8cc1Swenshuai.xi //******************************************************************************
3*53ee8cc1Swenshuai.xi // MStar Software
4*53ee8cc1Swenshuai.xi // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5*53ee8cc1Swenshuai.xi // All software, firmware and related documentation herein ("MStar Software") are
6*53ee8cc1Swenshuai.xi // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7*53ee8cc1Swenshuai.xi // law, including, but not limited to, copyright law and international treaties.
8*53ee8cc1Swenshuai.xi // Any use, modification, reproduction, retransmission, or republication of all
9*53ee8cc1Swenshuai.xi // or part of MStar Software is expressly prohibited, unless prior written
10*53ee8cc1Swenshuai.xi // permission has been granted by MStar.
11*53ee8cc1Swenshuai.xi //
12*53ee8cc1Swenshuai.xi // By accessing, browsing and/or using MStar Software, you acknowledge that you
13*53ee8cc1Swenshuai.xi // have read, understood, and agree, to be bound by below terms ("Terms") and to
14*53ee8cc1Swenshuai.xi // comply with all applicable laws and regulations:
15*53ee8cc1Swenshuai.xi //
16*53ee8cc1Swenshuai.xi // 1. MStar shall retain any and all right, ownership and interest to MStar
17*53ee8cc1Swenshuai.xi //    Software and any modification/derivatives thereof.
18*53ee8cc1Swenshuai.xi //    No right, ownership, or interest to MStar Software and any
19*53ee8cc1Swenshuai.xi //    modification/derivatives thereof is transferred to you under Terms.
20*53ee8cc1Swenshuai.xi //
21*53ee8cc1Swenshuai.xi // 2. You understand that MStar Software might include, incorporate or be
22*53ee8cc1Swenshuai.xi //    supplied together with third party`s software and the use of MStar
23*53ee8cc1Swenshuai.xi //    Software may require additional licenses from third parties.
24*53ee8cc1Swenshuai.xi //    Therefore, you hereby agree it is your sole responsibility to separately
25*53ee8cc1Swenshuai.xi //    obtain any and all third party right and license necessary for your use of
26*53ee8cc1Swenshuai.xi //    such third party`s software.
27*53ee8cc1Swenshuai.xi //
28*53ee8cc1Swenshuai.xi // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29*53ee8cc1Swenshuai.xi //    MStar`s confidential information and you agree to keep MStar`s
30*53ee8cc1Swenshuai.xi //    confidential information in strictest confidence and not disclose to any
31*53ee8cc1Swenshuai.xi //    third party.
32*53ee8cc1Swenshuai.xi //
33*53ee8cc1Swenshuai.xi // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34*53ee8cc1Swenshuai.xi //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35*53ee8cc1Swenshuai.xi //    without limitation, any warranties of merchantability, non-infringement of
36*53ee8cc1Swenshuai.xi //    intellectual property rights, fitness for a particular purpose, error free
37*53ee8cc1Swenshuai.xi //    and in conformity with any international standard.  You agree to waive any
38*53ee8cc1Swenshuai.xi //    claim against MStar for any loss, damage, cost or expense that you may
39*53ee8cc1Swenshuai.xi //    incur related to your use of MStar Software.
40*53ee8cc1Swenshuai.xi //    In no event shall MStar be liable for any direct, indirect, incidental or
41*53ee8cc1Swenshuai.xi //    consequential damages, including without limitation, lost of profit or
42*53ee8cc1Swenshuai.xi //    revenues, lost or damage of data, and unauthorized system use.
43*53ee8cc1Swenshuai.xi //    You agree that this Section 4 shall still apply without being affected
44*53ee8cc1Swenshuai.xi //    even if MStar Software has been modified by MStar in accordance with your
45*53ee8cc1Swenshuai.xi //    request or instruction for your use, except otherwise agreed by both
46*53ee8cc1Swenshuai.xi //    parties in writing.
47*53ee8cc1Swenshuai.xi //
48*53ee8cc1Swenshuai.xi // 5. If requested, MStar may from time to time provide technical supports or
49*53ee8cc1Swenshuai.xi //    services in relation with MStar Software to you for your use of
50*53ee8cc1Swenshuai.xi //    MStar Software in conjunction with your or your customer`s product
51*53ee8cc1Swenshuai.xi //    ("Services").
52*53ee8cc1Swenshuai.xi //    You understand and agree that, except otherwise agreed by both parties in
53*53ee8cc1Swenshuai.xi //    writing, Services are provided on an "AS IS" basis and the warranty
54*53ee8cc1Swenshuai.xi //    disclaimer set forth in Section 4 above shall apply.
55*53ee8cc1Swenshuai.xi //
56*53ee8cc1Swenshuai.xi // 6. Nothing contained herein shall be construed as by implication, estoppels
57*53ee8cc1Swenshuai.xi //    or otherwise:
58*53ee8cc1Swenshuai.xi //    (a) conferring any license or right to use MStar name, trademark, service
59*53ee8cc1Swenshuai.xi //        mark, symbol or any other identification;
60*53ee8cc1Swenshuai.xi //    (b) obligating MStar or any of its affiliates to furnish any person,
61*53ee8cc1Swenshuai.xi //        including without limitation, you and your customers, any assistance
62*53ee8cc1Swenshuai.xi //        of any kind whatsoever, or any information; or
63*53ee8cc1Swenshuai.xi //    (c) conferring any license or right under any intellectual property right.
64*53ee8cc1Swenshuai.xi //
65*53ee8cc1Swenshuai.xi // 7. These terms shall be governed by and construed in accordance with the laws
66*53ee8cc1Swenshuai.xi //    of Taiwan, R.O.C., excluding its conflict of law rules.
67*53ee8cc1Swenshuai.xi //    Any and all dispute arising out hereof or related hereto shall be finally
68*53ee8cc1Swenshuai.xi //    settled by arbitration referred to the Chinese Arbitration Association,
69*53ee8cc1Swenshuai.xi //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70*53ee8cc1Swenshuai.xi //    Rules of the Association by three (3) arbitrators appointed in accordance
71*53ee8cc1Swenshuai.xi //    with the said Rules.
72*53ee8cc1Swenshuai.xi //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73*53ee8cc1Swenshuai.xi //    be English.
74*53ee8cc1Swenshuai.xi //    The arbitration award shall be final and binding to both parties.
75*53ee8cc1Swenshuai.xi //
76*53ee8cc1Swenshuai.xi //******************************************************************************
77*53ee8cc1Swenshuai.xi //<MStar Software>
78*53ee8cc1Swenshuai.xi 
79*53ee8cc1Swenshuai.xi //=============================================================================
80*53ee8cc1Swenshuai.xi //#include <MsCommon.h> // NUSED
81*53ee8cc1Swenshuai.xi 
82*53ee8cc1Swenshuai.xi //#include "include/drvConfig.h" // NUSED
83*53ee8cc1Swenshuai.xi //#include "include/drvCompiler.h" // NUSED
84*53ee8cc1Swenshuai.xi //#include "include/drvErrno.h" // NUSED
85*53ee8cc1Swenshuai.xi //#include "include/drvPorts.h" // NUSED
86*53ee8cc1Swenshuai.xi //#include "include/drvTimer.h" // NUSED
87*53ee8cc1Swenshuai.xi #include "include/drvKernel.h"
88*53ee8cc1Swenshuai.xi //#include "include/drvList.h" // NUSED
89*53ee8cc1Swenshuai.xi 
90*53ee8cc1Swenshuai.xi U32 volatile jiffies;
91*53ee8cc1Swenshuai.xi 
92*53ee8cc1Swenshuai.xi static void ms_SW_Timer_Tick(U32 u32StTimer, U32 u32TimerID);
93*53ee8cc1Swenshuai.xi static struct list_head sw_timer_vec_head;
94*53ee8cc1Swenshuai.xi 
95*53ee8cc1Swenshuai.xi S32 g_Timer_ID;
96*53ee8cc1Swenshuai.xi S32 _s32MutexUTimer;
ms_init_timers(void)97*53ee8cc1Swenshuai.xi void ms_init_timers(void)
98*53ee8cc1Swenshuai.xi {
99*53ee8cc1Swenshuai.xi     ms_list_init(&sw_timer_vec_head);
100*53ee8cc1Swenshuai.xi     // Register software timer dispatch program
101*53ee8cc1Swenshuai.xi     // Base 1 ms, interruptted every 1 ms
102*53ee8cc1Swenshuai.xi 
103*53ee8cc1Swenshuai.xi     BOOL err;
104*53ee8cc1Swenshuai.xi 
105*53ee8cc1Swenshuai.xi     g_Timer_ID = MsOS_CreateTimer((TimerCb) ms_SW_Timer_Tick,100, USB_SW_TIMER_TICK, FALSE, "USB_TIMER");
106*53ee8cc1Swenshuai.xi     //err = OS_DefineCyclicHandler(&g_Timer_ID, ms_SW_Timer_Tick, (void*) 0, 100);
107*53ee8cc1Swenshuai.xi     //USB_ASSERT((err == TRUE), "Define USB timer fail");
108*53ee8cc1Swenshuai.xi 
109*53ee8cc1Swenshuai.xi     //err = OS_ActivateCyclicHandler(g_Timer_ID);
110*53ee8cc1Swenshuai.xi     //
111*53ee8cc1Swenshuai.xi     err=MsOS_StartTimer(g_Timer_ID);
112*53ee8cc1Swenshuai.xi     USB_ASSERT((err == TRUE), "Activate USB timer fail");
113*53ee8cc1Swenshuai.xi     diag_printf("Init Software Timer ok \n");
114*53ee8cc1Swenshuai.xi     _s32MutexUTimer = MsOS_CreateMutex(E_MSOS_FIFO, "UTimer_MUTEX", MSOS_PROCESS_SHARED);
115*53ee8cc1Swenshuai.xi }
116*53ee8cc1Swenshuai.xi 
ms_remove_timers(void)117*53ee8cc1Swenshuai.xi void ms_remove_timers(void)
118*53ee8cc1Swenshuai.xi {
119*53ee8cc1Swenshuai.xi     MsOS_DeleteTimer(g_Timer_ID);
120*53ee8cc1Swenshuai.xi     diag_printf("Remove Software Timer ok \n");
121*53ee8cc1Swenshuai.xi     MsOS_DeleteMutex(_s32MutexUTimer);
122*53ee8cc1Swenshuai.xi }
123*53ee8cc1Swenshuai.xi 
124*53ee8cc1Swenshuai.xi /*
125*53ee8cc1Swenshuai.xi  * Timer ISR: It's responsible for dispatching tasks registered to software-timer
126*53ee8cc1Swenshuai.xi  * task queue. It need to be implemented as Bottom-Half mechanism of Linux
127*53ee8cc1Swenshuai.xi  * Timer and USB IRQ have the same priority and cannot be interrupted by each other
128*53ee8cc1Swenshuai.xi  */
ms_SW_Timer_Tick(U32 u32StTimer,U32 u32TimerID)129*53ee8cc1Swenshuai.xi static void ms_SW_Timer_Tick(U32 u32StTimer, U32 u32TimerID)
130*53ee8cc1Swenshuai.xi {
131*53ee8cc1Swenshuai.xi     struct timer_list *timer;
132*53ee8cc1Swenshuai.xi     struct list_head  *tmp;
133*53ee8cc1Swenshuai.xi 
134*53ee8cc1Swenshuai.xi     jiffies += USB_SW_TIMER_TICK;
135*53ee8cc1Swenshuai.xi 
136*53ee8cc1Swenshuai.xi     //if ( Timer_task_lock == 1 )
137*53ee8cc1Swenshuai.xi         //goto sw_done;
138*53ee8cc1Swenshuai.xi 
139*53ee8cc1Swenshuai.xi     if (!ms_is_empty_list(&sw_timer_vec_head))
140*53ee8cc1Swenshuai.xi     {
141*53ee8cc1Swenshuai.xi         tmp = sw_timer_vec_head.next;
142*53ee8cc1Swenshuai.xi         while (tmp != &sw_timer_vec_head)
143*53ee8cc1Swenshuai.xi         {
144*53ee8cc1Swenshuai.xi             timer = entry_to_container (tmp, struct timer_list, entry);
145*53ee8cc1Swenshuai.xi             tmp = tmp->next;
146*53ee8cc1Swenshuai.xi             // decrease expire time
147*53ee8cc1Swenshuai.xi             timer->expires -= USB_SW_TIMER_TICK;
148*53ee8cc1Swenshuai.xi         }
149*53ee8cc1Swenshuai.xi     }
150*53ee8cc1Swenshuai.xi 
151*53ee8cc1Swenshuai.xi     // Dispath task from task queue of software-timer here
152*53ee8cc1Swenshuai.xi     if (!ms_is_empty_list(&sw_timer_vec_head))
153*53ee8cc1Swenshuai.xi     {
154*53ee8cc1Swenshuai.xi         tmp = sw_timer_vec_head.next;
155*53ee8cc1Swenshuai.xi         while (tmp != &sw_timer_vec_head)
156*53ee8cc1Swenshuai.xi         {
157*53ee8cc1Swenshuai.xi             timer = entry_to_container (tmp, struct timer_list, entry);
158*53ee8cc1Swenshuai.xi             tmp = tmp->next;
159*53ee8cc1Swenshuai.xi             //list_entry (tmp, struct timer_list, entry, struct list_head, timer);
160*53ee8cc1Swenshuai.xi             // Check if time expired ?
161*53ee8cc1Swenshuai.xi             if ( timer->expires <= 0 )
162*53ee8cc1Swenshuai.xi             {
163*53ee8cc1Swenshuai.xi                 void (*pFunc)(U32);
164*53ee8cc1Swenshuai.xi                 U32 data;
165*53ee8cc1Swenshuai.xi                 // If lock ==> don't dispatch task
166*53ee8cc1Swenshuai.xi                 /*
167*53ee8cc1Swenshuai.xi                                         if ( Timer_task_lock == 1 )
168*53ee8cc1Swenshuai.xi                                         {
169*53ee8cc1Swenshuai.xi                                         timer->expires++;
170*53ee8cc1Swenshuai.xi                                         continue;
171*53ee8cc1Swenshuai.xi                                         }
172*53ee8cc1Swenshuai.xi                                         */
173*53ee8cc1Swenshuai.xi                 pFunc = timer->function;
174*53ee8cc1Swenshuai.xi                 data = timer->data;
175*53ee8cc1Swenshuai.xi                 ms_del_timer(timer);
176*53ee8cc1Swenshuai.xi                 // Call registered function
177*53ee8cc1Swenshuai.xi                 if ( (U32)pFunc )
178*53ee8cc1Swenshuai.xi                 {
179*53ee8cc1Swenshuai.xi                     //lock_usb_core(); // NUSED
180*53ee8cc1Swenshuai.xi                     pFunc(data);
181*53ee8cc1Swenshuai.xi                     //unlock_usb_core(); // NUSED
182*53ee8cc1Swenshuai.xi                 }
183*53ee8cc1Swenshuai.xi                 else
184*53ee8cc1Swenshuai.xi                     USB_ASSERT( 0, "ERROR: fun is NULL\n");
185*53ee8cc1Swenshuai.xi 
186*53ee8cc1Swenshuai.xi                 //Current version only support dispatch one task each time
187*53ee8cc1Swenshuai.xi                 //break;
188*53ee8cc1Swenshuai.xi             }
189*53ee8cc1Swenshuai.xi         }
190*53ee8cc1Swenshuai.xi     }
191*53ee8cc1Swenshuai.xi 
192*53ee8cc1Swenshuai.xi //sw_done:
193*53ee8cc1Swenshuai.xi     return;
194*53ee8cc1Swenshuai.xi     // End of dispatching
195*53ee8cc1Swenshuai.xi }
196*53ee8cc1Swenshuai.xi 
197*53ee8cc1Swenshuai.xi /***
198*53ee8cc1Swenshuai.xi  * ms_del_timer - deactive a timer.
199*53ee8cc1Swenshuai.xi  * @timer: the timer to be deactivated
200*53ee8cc1Swenshuai.xi  *
201*53ee8cc1Swenshuai.xi  * ms_del_timer() deactivates a timer - this works on both active and inactive
202*53ee8cc1Swenshuai.xi  * timers.
203*53ee8cc1Swenshuai.xi  *
204*53ee8cc1Swenshuai.xi  * The function returns whether it has deactivated a pending timer or not.
205*53ee8cc1Swenshuai.xi  * (ie. ms_del_timer() of an inactive timer returns 0, del_timer() of an
206*53ee8cc1Swenshuai.xi  * active timer returns 1.)
207*53ee8cc1Swenshuai.xi  */
ms_del_timer(struct timer_list * timer)208*53ee8cc1Swenshuai.xi int ms_del_timer(struct timer_list *timer)
209*53ee8cc1Swenshuai.xi {
210*53ee8cc1Swenshuai.xi     U32 u32OldIntr;
211*53ee8cc1Swenshuai.xi 
212*53ee8cc1Swenshuai.xi     osapi_spin_lock_irqsave(&sw_timer_lock, u32OldIntr);
213*53ee8cc1Swenshuai.xi     if( timer->entry.next != NULL && timer->entry.prev != NULL )
214*53ee8cc1Swenshuai.xi     {
215*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
216*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
217*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
218*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
219*53ee8cc1Swenshuai.xi         ms_list_remove_and_init(&timer->entry);
220*53ee8cc1Swenshuai.xi     }
221*53ee8cc1Swenshuai.xi 
222*53ee8cc1Swenshuai.xi     osapi_spin_unlock_irqrestore(&sw_timer_lock, u32OldIntr);
223*53ee8cc1Swenshuai.xi     return 1;
224*53ee8cc1Swenshuai.xi }
225*53ee8cc1Swenshuai.xi 
226*53ee8cc1Swenshuai.xi /***
227*53ee8cc1Swenshuai.xi  * ms_del_timer_sync - deactive a timer.
228*53ee8cc1Swenshuai.xi  * @timer: the timer to be deactivated
229*53ee8cc1Swenshuai.xi  *
230*53ee8cc1Swenshuai.xi  * ms_del_timer_sync() deactivates a timer - this works on both active and inactive
231*53ee8cc1Swenshuai.xi  * timers.
232*53ee8cc1Swenshuai.xi  *
233*53ee8cc1Swenshuai.xi  * The function will protect synchronization problem before deactivating timer
234*53ee8cc1Swenshuai.xi  */
ms_del_timer_sync(struct timer_list * timer)235*53ee8cc1Swenshuai.xi int ms_del_timer_sync(struct timer_list *timer)
236*53ee8cc1Swenshuai.xi {
237*53ee8cc1Swenshuai.xi     U32 u32OldIntr;
238*53ee8cc1Swenshuai.xi 
239*53ee8cc1Swenshuai.xi     osapi_spin_lock_irqsave(&sw_timer_lock, u32OldIntr);
240*53ee8cc1Swenshuai.xi     if( timer->entry.next != NULL && timer->entry.prev != NULL )
241*53ee8cc1Swenshuai.xi     {
242*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
243*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
244*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
245*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
246*53ee8cc1Swenshuai.xi         ms_list_remove_and_init(&timer->entry);
247*53ee8cc1Swenshuai.xi     }
248*53ee8cc1Swenshuai.xi 
249*53ee8cc1Swenshuai.xi     osapi_spin_unlock_irqrestore(&sw_timer_lock, u32OldIntr);
250*53ee8cc1Swenshuai.xi     return 1;
251*53ee8cc1Swenshuai.xi }
252*53ee8cc1Swenshuai.xi 
253*53ee8cc1Swenshuai.xi /***
254*53ee8cc1Swenshuai.xi  * ms_add_timer - start a timer
255*53ee8cc1Swenshuai.xi  * @timer: the timer to be added
256*53ee8cc1Swenshuai.xi  *
257*53ee8cc1Swenshuai.xi  * The kernel will do a ->function(->data) callback from the
258*53ee8cc1Swenshuai.xi  * timer interrupt at the ->expired point in the future. The
259*53ee8cc1Swenshuai.xi  * current time is 'jiffies'.
260*53ee8cc1Swenshuai.xi  *
261*53ee8cc1Swenshuai.xi  * The timer's ->expired, ->function (and if the handler uses it, ->data)
262*53ee8cc1Swenshuai.xi  * fields must be set prior calling this function.
263*53ee8cc1Swenshuai.xi  *
264*53ee8cc1Swenshuai.xi  * Timers with an ->expired field in the past will be executed in the next
265*53ee8cc1Swenshuai.xi  * timer tick. It's illegal to add an already pending timer.
266*53ee8cc1Swenshuai.xi  */
ms_add_timer(struct timer_list * timer)267*53ee8cc1Swenshuai.xi void ms_add_timer(struct timer_list *timer)
268*53ee8cc1Swenshuai.xi {
269*53ee8cc1Swenshuai.xi     U32 u32OldIntr;
270*53ee8cc1Swenshuai.xi 
271*53ee8cc1Swenshuai.xi     osapi_spin_lock_irqsave(&sw_timer_lock, u32OldIntr);
272*53ee8cc1Swenshuai.xi     if ( (timer->tmout_step > 0) && (timer->tmout_value > timer->tmout_step) )
273*53ee8cc1Swenshuai.xi         timer->expires = timer->tmout_step;
274*53ee8cc1Swenshuai.xi     else
275*53ee8cc1Swenshuai.xi         timer->expires = timer->tmout_value;
276*53ee8cc1Swenshuai.xi 
277*53ee8cc1Swenshuai.xi     ms_insert_list_before(&timer->entry, &sw_timer_vec_head);
278*53ee8cc1Swenshuai.xi 
279*53ee8cc1Swenshuai.xi     osapi_spin_unlock_irqrestore(&sw_timer_lock, u32OldIntr);
280*53ee8cc1Swenshuai.xi }
281*53ee8cc1Swenshuai.xi 
ms_update_timer(struct timer_list * timer,U32 expires,U32 steps)282*53ee8cc1Swenshuai.xi int ms_update_timer(struct timer_list *timer, U32 expires, U32 steps)
283*53ee8cc1Swenshuai.xi {
284*53ee8cc1Swenshuai.xi     int ret = 0;
285*53ee8cc1Swenshuai.xi     U32 u32OldIntr;
286*53ee8cc1Swenshuai.xi 
287*53ee8cc1Swenshuai.xi     osapi_spin_lock_irqsave(&sw_timer_lock, u32OldIntr);
288*53ee8cc1Swenshuai.xi     timer->tmout_value = expires;
289*53ee8cc1Swenshuai.xi     timer->tmout_step = steps;
290*53ee8cc1Swenshuai.xi 
291*53ee8cc1Swenshuai.xi     if( timer->entry.next != NULL && timer->entry.prev != NULL )
292*53ee8cc1Swenshuai.xi     {
293*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
294*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
295*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
296*53ee8cc1Swenshuai.xi         USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
297*53ee8cc1Swenshuai.xi         ms_list_remove_and_init(&timer->entry);
298*53ee8cc1Swenshuai.xi     }
299*53ee8cc1Swenshuai.xi 
300*53ee8cc1Swenshuai.xi     if ( (timer->tmout_step > 0) && (timer->tmout_value > timer->tmout_step) )
301*53ee8cc1Swenshuai.xi         timer->expires = timer->tmout_step;
302*53ee8cc1Swenshuai.xi     else
303*53ee8cc1Swenshuai.xi         timer->expires = timer->tmout_value;
304*53ee8cc1Swenshuai.xi     ms_insert_list_before(&timer->entry, &sw_timer_vec_head);
305*53ee8cc1Swenshuai.xi 
306*53ee8cc1Swenshuai.xi     osapi_spin_unlock_irqrestore(&sw_timer_lock, u32OldIntr);
307*53ee8cc1Swenshuai.xi     return ret;
308*53ee8cc1Swenshuai.xi }
309*53ee8cc1Swenshuai.xi 
310*53ee8cc1Swenshuai.xi #define MS_MSEC_PER_SEC    1000L
ms_jiffies_to_msecs(unsigned long jiffies_n)311*53ee8cc1Swenshuai.xi unsigned int ms_jiffies_to_msecs(unsigned long jiffies_n)
312*53ee8cc1Swenshuai.xi {
313*53ee8cc1Swenshuai.xi     unsigned int retval;
314*53ee8cc1Swenshuai.xi 
315*53ee8cc1Swenshuai.xi     retval = (MS_MSEC_PER_SEC / HZ) * jiffies_n;
316*53ee8cc1Swenshuai.xi 
317*53ee8cc1Swenshuai.xi     return retval;
318*53ee8cc1Swenshuai.xi }
319