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>
81*53ee8cc1Swenshuai.xi
82*53ee8cc1Swenshuai.xi #include "include/drvConfig.h"
83*53ee8cc1Swenshuai.xi #include "include/drvCompiler.h"
84*53ee8cc1Swenshuai.xi #include "include/drvErrno.h"
85*53ee8cc1Swenshuai.xi #include "include/drvPorts.h"
86*53ee8cc1Swenshuai.xi #include "include/drvTimer.h"
87*53ee8cc1Swenshuai.xi #include "include/drvKernel.h"
88*53ee8cc1Swenshuai.xi #include "include/drvList.h"
89*53ee8cc1Swenshuai.xi
90*53ee8cc1Swenshuai.xi U32 volatile jiffies;
91*53ee8cc1Swenshuai.xi
92*53ee8cc1Swenshuai.xi //void SW_Timer_Tick(U32 u32Value);
93*53ee8cc1Swenshuai.xi void SW_Timer_Tick(U32 u32StTimer, U32 u32TimerID);
94*53ee8cc1Swenshuai.xi
95*53ee8cc1Swenshuai.xi static struct list_head sw_timer_vec_head;
96*53ee8cc1Swenshuai.xi
97*53ee8cc1Swenshuai.xi S32 g_Timer_ID;
98*53ee8cc1Swenshuai.xi
99*53ee8cc1Swenshuai.xi #ifdef TIMER_NO_ALL_INT_DISABLE
100*53ee8cc1Swenshuai.xi #include "drvHUB.h"
101*53ee8cc1Swenshuai.xi extern struct s_ChipUsbHostDef *pCurrentChip;
disable_USB_interrupts(void)102*53ee8cc1Swenshuai.xi void disable_USB_interrupts(void)
103*53ee8cc1Swenshuai.xi {
104*53ee8cc1Swenshuai.xi U8 i;
105*53ee8cc1Swenshuai.xi
106*53ee8cc1Swenshuai.xi for (i=0; i<pCurrentChip->nRootHub; i++)
107*53ee8cc1Swenshuai.xi MsOS_DisableInterrupt(pCurrentChip->reg[i].uhcIRQ);
108*53ee8cc1Swenshuai.xi }
109*53ee8cc1Swenshuai.xi
enable_USB_interrupts(void)110*53ee8cc1Swenshuai.xi void enable_USB_interrupts(void)
111*53ee8cc1Swenshuai.xi {
112*53ee8cc1Swenshuai.xi U8 i;
113*53ee8cc1Swenshuai.xi
114*53ee8cc1Swenshuai.xi for (i=0; i<pCurrentChip->nRootHub; i++)
115*53ee8cc1Swenshuai.xi MsOS_EnableInterrupt(pCurrentChip->reg[i].uhcIRQ);
116*53ee8cc1Swenshuai.xi }
117*53ee8cc1Swenshuai.xi #endif
118*53ee8cc1Swenshuai.xi
119*53ee8cc1Swenshuai.xi S32 _s32MutexUTimer;
init_timers(void)120*53ee8cc1Swenshuai.xi void init_timers(void)
121*53ee8cc1Swenshuai.xi {
122*53ee8cc1Swenshuai.xi INIT_LIST_HEAD(&sw_timer_vec_head);
123*53ee8cc1Swenshuai.xi // Register software timer dispatch program
124*53ee8cc1Swenshuai.xi // Base 1 ms, interruptted every 1 ms
125*53ee8cc1Swenshuai.xi
126*53ee8cc1Swenshuai.xi BOOL err;
127*53ee8cc1Swenshuai.xi
128*53ee8cc1Swenshuai.xi g_Timer_ID = MsOS_CreateTimer((TimerCb) SW_Timer_Tick,100, 100, FALSE, "USB_TIMER");
129*53ee8cc1Swenshuai.xi //err = OS_DefineCyclicHandler(&g_Timer_ID, SW_Timer_Tick, (void*) 0, 100);
130*53ee8cc1Swenshuai.xi //USB_ASSERT((err == TRUE), "Define USB timer fail");
131*53ee8cc1Swenshuai.xi
132*53ee8cc1Swenshuai.xi //err = OS_ActivateCyclicHandler(g_Timer_ID);
133*53ee8cc1Swenshuai.xi //
134*53ee8cc1Swenshuai.xi err=MsOS_StartTimer(g_Timer_ID);
135*53ee8cc1Swenshuai.xi USB_ASSERT((err == TRUE), "Activate USB timer fail");
136*53ee8cc1Swenshuai.xi //kdbg("Init Software Timer ok %s","\n");
137*53ee8cc1Swenshuai.xi printk("Init Software Timer ok \n");
138*53ee8cc1Swenshuai.xi _s32MutexUTimer = MsOS_CreateMutex(E_MSOS_FIFO, "UTimer_MUTEX", MSOS_PROCESS_SHARED);
139*53ee8cc1Swenshuai.xi }
140*53ee8cc1Swenshuai.xi
remove_timers(void)141*53ee8cc1Swenshuai.xi void remove_timers(void)
142*53ee8cc1Swenshuai.xi {
143*53ee8cc1Swenshuai.xi MsOS_DeleteTimer(g_Timer_ID);
144*53ee8cc1Swenshuai.xi printk("Remove Software Timer ok \n");
145*53ee8cc1Swenshuai.xi MsOS_DeleteMutex(_s32MutexUTimer);
146*53ee8cc1Swenshuai.xi }
147*53ee8cc1Swenshuai.xi
148*53ee8cc1Swenshuai.xi /*
149*53ee8cc1Swenshuai.xi * Timer ISR: It's responsible for dispatching tasks registered to software-timer
150*53ee8cc1Swenshuai.xi * task queue. It need to be implemented as Bottom-Half mechanism of Linux
151*53ee8cc1Swenshuai.xi * Timer and USB IRQ have the same priority and cannot be interrupted by each other
152*53ee8cc1Swenshuai.xi */
153*53ee8cc1Swenshuai.xi //void SW_Timer_Tick(U32 pData)
SW_Timer_Tick(U32 u32StTimer,U32 u32TimerID)154*53ee8cc1Swenshuai.xi void SW_Timer_Tick(U32 u32StTimer, U32 u32TimerID)
155*53ee8cc1Swenshuai.xi {
156*53ee8cc1Swenshuai.xi struct timer_list *timer;
157*53ee8cc1Swenshuai.xi struct list_head *tmp;
158*53ee8cc1Swenshuai.xi
159*53ee8cc1Swenshuai.xi jiffies+=100;
160*53ee8cc1Swenshuai.xi
161*53ee8cc1Swenshuai.xi if ( Timer_task_lock == 1 )
162*53ee8cc1Swenshuai.xi goto sw_done;
163*53ee8cc1Swenshuai.xi
164*53ee8cc1Swenshuai.xi // Dispath task from task queue of software-timer here
165*53ee8cc1Swenshuai.xi if (!list_empty(&sw_timer_vec_head))
166*53ee8cc1Swenshuai.xi {
167*53ee8cc1Swenshuai.xi tmp = sw_timer_vec_head.next;
168*53ee8cc1Swenshuai.xi while (tmp != &sw_timer_vec_head)
169*53ee8cc1Swenshuai.xi {
170*53ee8cc1Swenshuai.xi timer = list_entry (tmp, struct timer_list, entry);
171*53ee8cc1Swenshuai.xi tmp = tmp->next;
172*53ee8cc1Swenshuai.xi //list_entry (tmp, struct timer_list, entry, struct list_head, timer);
173*53ee8cc1Swenshuai.xi // Check if time expired ?
174*53ee8cc1Swenshuai.xi timer->expires -= 100;
175*53ee8cc1Swenshuai.xi if ( timer->expires <= 0 )
176*53ee8cc1Swenshuai.xi {
177*53ee8cc1Swenshuai.xi void (*fn)(U32);
178*53ee8cc1Swenshuai.xi U32 data;
179*53ee8cc1Swenshuai.xi // If lock ==> don't dispatch task
180*53ee8cc1Swenshuai.xi /*
181*53ee8cc1Swenshuai.xi if ( Timer_task_lock == 1 )
182*53ee8cc1Swenshuai.xi {
183*53ee8cc1Swenshuai.xi timer->expires++;
184*53ee8cc1Swenshuai.xi continue;
185*53ee8cc1Swenshuai.xi }
186*53ee8cc1Swenshuai.xi */
187*53ee8cc1Swenshuai.xi fn = timer->function;
188*53ee8cc1Swenshuai.xi data = timer->data;
189*53ee8cc1Swenshuai.xi del_timer(timer);
190*53ee8cc1Swenshuai.xi // Call registered function
191*53ee8cc1Swenshuai.xi if ( (U32)fn )
192*53ee8cc1Swenshuai.xi {
193*53ee8cc1Swenshuai.xi lock_usb_core();
194*53ee8cc1Swenshuai.xi fn(data);
195*53ee8cc1Swenshuai.xi unlock_usb_core();
196*53ee8cc1Swenshuai.xi }
197*53ee8cc1Swenshuai.xi else
198*53ee8cc1Swenshuai.xi {
199*53ee8cc1Swenshuai.xi printk("ERROR: fun is NULL\n");
200*53ee8cc1Swenshuai.xi while(1);
201*53ee8cc1Swenshuai.xi }
202*53ee8cc1Swenshuai.xi //Current version only support dispatch one task each time
203*53ee8cc1Swenshuai.xi //break;
204*53ee8cc1Swenshuai.xi }
205*53ee8cc1Swenshuai.xi /*
206*53ee8cc1Swenshuai.xi if ( (U32)tmp->next == (U32)0x1 )
207*53ee8cc1Swenshuai.xi while(1);
208*53ee8cc1Swenshuai.xi if ( tmp->next == NULL )
209*53ee8cc1Swenshuai.xi while(1);*/
210*53ee8cc1Swenshuai.xi }
211*53ee8cc1Swenshuai.xi }
212*53ee8cc1Swenshuai.xi sw_done:
213*53ee8cc1Swenshuai.xi return;
214*53ee8cc1Swenshuai.xi // End of dispatching
215*53ee8cc1Swenshuai.xi }
216*53ee8cc1Swenshuai.xi
217*53ee8cc1Swenshuai.xi #ifdef TIMER_NO_ALL_INT_DISABLE
timerSectionIn(void)218*53ee8cc1Swenshuai.xi void timerSectionIn(void)
219*53ee8cc1Swenshuai.xi {
220*53ee8cc1Swenshuai.xi MsOS_StopTimer(g_Timer_ID);
221*53ee8cc1Swenshuai.xi disable_USB_interrupts();
222*53ee8cc1Swenshuai.xi MsOS_ObtainMutex(_s32MutexUTimer, MSOS_WAIT_FOREVER);
223*53ee8cc1Swenshuai.xi }
timerSectionOut(void)224*53ee8cc1Swenshuai.xi void timerSectionOut(void)
225*53ee8cc1Swenshuai.xi {
226*53ee8cc1Swenshuai.xi enable_USB_interrupts();
227*53ee8cc1Swenshuai.xi MsOS_StartTimer(g_Timer_ID);
228*53ee8cc1Swenshuai.xi MsOS_ReleaseMutex(_s32MutexUTimer);
229*53ee8cc1Swenshuai.xi }
del_timer_body(struct timer_list * timer)230*53ee8cc1Swenshuai.xi int del_timer_body(struct timer_list *timer)
231*53ee8cc1Swenshuai.xi {
232*53ee8cc1Swenshuai.xi //MsOS_StopTimer(g_Timer_ID);
233*53ee8cc1Swenshuai.xi //disable_USB_interrupts();
234*53ee8cc1Swenshuai.xi
235*53ee8cc1Swenshuai.xi if( timer->entry.next != NULL && timer->entry.prev != NULL )
236*53ee8cc1Swenshuai.xi {
237*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
238*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
239*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
240*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
241*53ee8cc1Swenshuai.xi list_del_init(&timer->entry);
242*53ee8cc1Swenshuai.xi }
243*53ee8cc1Swenshuai.xi
244*53ee8cc1Swenshuai.xi //enable_USB_interrupts();
245*53ee8cc1Swenshuai.xi //MsOS_StartTimer(g_Timer_ID);
246*53ee8cc1Swenshuai.xi
247*53ee8cc1Swenshuai.xi //TIMER_TASK_LOCK = flags;
248*53ee8cc1Swenshuai.xi return 1;
249*53ee8cc1Swenshuai.xi }
del_timer(struct timer_list * timer)250*53ee8cc1Swenshuai.xi int del_timer(struct timer_list *timer)
251*53ee8cc1Swenshuai.xi {
252*53ee8cc1Swenshuai.xi //timerSectionIn();
253*53ee8cc1Swenshuai.xi del_timer_body(timer);
254*53ee8cc1Swenshuai.xi //timerSectionOut();
255*53ee8cc1Swenshuai.xi return 1;
256*53ee8cc1Swenshuai.xi }
del_timer_sync_body(struct timer_list * timer)257*53ee8cc1Swenshuai.xi int del_timer_sync_body(struct timer_list *timer)
258*53ee8cc1Swenshuai.xi {
259*53ee8cc1Swenshuai.xi //MsOS_StopTimer(g_Timer_ID);
260*53ee8cc1Swenshuai.xi //disable_USB_interrupts();
261*53ee8cc1Swenshuai.xi
262*53ee8cc1Swenshuai.xi if( timer->entry.next != NULL && timer->entry.prev != NULL )
263*53ee8cc1Swenshuai.xi {
264*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
265*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
266*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
267*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
268*53ee8cc1Swenshuai.xi list_del_init(&timer->entry);
269*53ee8cc1Swenshuai.xi }
270*53ee8cc1Swenshuai.xi
271*53ee8cc1Swenshuai.xi //enable_USB_interrupts();
272*53ee8cc1Swenshuai.xi //MsOS_StartTimer(g_Timer_ID);
273*53ee8cc1Swenshuai.xi
274*53ee8cc1Swenshuai.xi //TIMER_TASK_LOCK = flags;
275*53ee8cc1Swenshuai.xi return 1;
276*53ee8cc1Swenshuai.xi }
del_timer_sync(struct timer_list * timer)277*53ee8cc1Swenshuai.xi int del_timer_sync(struct timer_list *timer)
278*53ee8cc1Swenshuai.xi {
279*53ee8cc1Swenshuai.xi timerSectionIn();
280*53ee8cc1Swenshuai.xi del_timer_sync_body(timer);
281*53ee8cc1Swenshuai.xi timerSectionOut();
282*53ee8cc1Swenshuai.xi return 1;
283*53ee8cc1Swenshuai.xi }
add_timer_body(struct timer_list * timer)284*53ee8cc1Swenshuai.xi void add_timer_body(struct timer_list *timer)
285*53ee8cc1Swenshuai.xi {
286*53ee8cc1Swenshuai.xi //MsOS_StopTimer(g_Timer_ID);
287*53ee8cc1Swenshuai.xi //disable_USB_interrupts();
288*53ee8cc1Swenshuai.xi
289*53ee8cc1Swenshuai.xi if ( (timer->tmout_step > 0) && (timer->tmout_value > timer->tmout_step) )
290*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_step;
291*53ee8cc1Swenshuai.xi else
292*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_value;
293*53ee8cc1Swenshuai.xi
294*53ee8cc1Swenshuai.xi list_add_tail(&timer->entry, &sw_timer_vec_head);
295*53ee8cc1Swenshuai.xi
296*53ee8cc1Swenshuai.xi //enable_USB_interrupts();
297*53ee8cc1Swenshuai.xi //MsOS_StartTimer(g_Timer_ID);
298*53ee8cc1Swenshuai.xi
299*53ee8cc1Swenshuai.xi //TIMER_TASK_LOCK = flags;
300*53ee8cc1Swenshuai.xi }
add_timer(struct timer_list * timer)301*53ee8cc1Swenshuai.xi void add_timer(struct timer_list *timer)
302*53ee8cc1Swenshuai.xi {
303*53ee8cc1Swenshuai.xi timerSectionIn();
304*53ee8cc1Swenshuai.xi add_timer_body(timer);
305*53ee8cc1Swenshuai.xi timerSectionOut();
306*53ee8cc1Swenshuai.xi }
mod_timer_body(struct timer_list * timer,U32 expires,U32 steps)307*53ee8cc1Swenshuai.xi int mod_timer_body(struct timer_list *timer, U32 expires, U32 steps)
308*53ee8cc1Swenshuai.xi {
309*53ee8cc1Swenshuai.xi //U32 flags;
310*53ee8cc1Swenshuai.xi int ret = 0;
311*53ee8cc1Swenshuai.xi
312*53ee8cc1Swenshuai.xi //MsOS_StopTimer(g_Timer_ID);
313*53ee8cc1Swenshuai.xi //disable_USB_interrupts();
314*53ee8cc1Swenshuai.xi
315*53ee8cc1Swenshuai.xi timer->tmout_value = expires;
316*53ee8cc1Swenshuai.xi timer->tmout_step = steps;
317*53ee8cc1Swenshuai.xi
318*53ee8cc1Swenshuai.xi //ret = del_timer(timer);
319*53ee8cc1Swenshuai.xi if( timer->entry.next != NULL && timer->entry.prev != NULL )
320*53ee8cc1Swenshuai.xi {
321*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
322*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
323*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
324*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
325*53ee8cc1Swenshuai.xi list_del_init(&timer->entry);
326*53ee8cc1Swenshuai.xi }
327*53ee8cc1Swenshuai.xi
328*53ee8cc1Swenshuai.xi //add_timer(timer);
329*53ee8cc1Swenshuai.xi if ( (timer->tmout_step > 0) && (timer->tmout_value > timer->tmout_step) )
330*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_step;
331*53ee8cc1Swenshuai.xi else
332*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_value;
333*53ee8cc1Swenshuai.xi list_add_tail(&timer->entry, &sw_timer_vec_head);
334*53ee8cc1Swenshuai.xi
335*53ee8cc1Swenshuai.xi //enable_USB_interrupts();
336*53ee8cc1Swenshuai.xi //MsOS_StartTimer(g_Timer_ID);
337*53ee8cc1Swenshuai.xi
338*53ee8cc1Swenshuai.xi return ret;
339*53ee8cc1Swenshuai.xi }
mod_timer(struct timer_list * timer,U32 expires,U32 steps)340*53ee8cc1Swenshuai.xi int mod_timer(struct timer_list *timer, U32 expires, U32 steps)
341*53ee8cc1Swenshuai.xi {
342*53ee8cc1Swenshuai.xi int ret = 0;
343*53ee8cc1Swenshuai.xi //timerSectionIn();
344*53ee8cc1Swenshuai.xi ret = mod_timer_body(timer, expires, steps);
345*53ee8cc1Swenshuai.xi //timerSectionOut();
346*53ee8cc1Swenshuai.xi return ret;
347*53ee8cc1Swenshuai.xi }
348*53ee8cc1Swenshuai.xi #else // Disable All Interrupts
349*53ee8cc1Swenshuai.xi /***
350*53ee8cc1Swenshuai.xi * del_timer - deactive a timer.
351*53ee8cc1Swenshuai.xi * @timer: the timer to be deactivated
352*53ee8cc1Swenshuai.xi *
353*53ee8cc1Swenshuai.xi * del_timer() deactivates a timer - this works on both active and inactive
354*53ee8cc1Swenshuai.xi * timers.
355*53ee8cc1Swenshuai.xi *
356*53ee8cc1Swenshuai.xi * The function returns whether it has deactivated a pending timer or not.
357*53ee8cc1Swenshuai.xi * (ie. del_timer() of an inactive timer returns 0, del_timer() of an
358*53ee8cc1Swenshuai.xi * active timer returns 1.)
359*53ee8cc1Swenshuai.xi */
del_timer(struct timer_list * timer)360*53ee8cc1Swenshuai.xi int del_timer(struct timer_list *timer)
361*53ee8cc1Swenshuai.xi {
362*53ee8cc1Swenshuai.xi //U32 flags;
363*53ee8cc1Swenshuai.xi
364*53ee8cc1Swenshuai.xi //flags = TIMER_TASK_LOCK;
365*53ee8cc1Swenshuai.xi //lock_TmrTaskDispatch();
366*53ee8cc1Swenshuai.xi //save_and_disable_firqs(&flags);
367*53ee8cc1Swenshuai.xi //HAL_DISABLE_INTERRUPTS(flags);
368*53ee8cc1Swenshuai.xi //OS_DisableDispatch();yuwen
369*53ee8cc1Swenshuai.xi //MsOS_DisableInterrupt(E_IRQ_FIQ_ALL);
370*53ee8cc1Swenshuai.xi U32 u32OldIntr;
371*53ee8cc1Swenshuai.xi u32OldIntr = MsOS_DisableAllInterrupts();
372*53ee8cc1Swenshuai.xi
373*53ee8cc1Swenshuai.xi if( timer->entry.next != NULL && timer->entry.prev != NULL )
374*53ee8cc1Swenshuai.xi {
375*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
376*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
377*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
378*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
379*53ee8cc1Swenshuai.xi list_del_init(&timer->entry);
380*53ee8cc1Swenshuai.xi }
381*53ee8cc1Swenshuai.xi
382*53ee8cc1Swenshuai.xi //restore_firqs(&flags);
383*53ee8cc1Swenshuai.xi //HAL_RESTORE_INTERRUPTS(flags);
384*53ee8cc1Swenshuai.xi //OS_EnableDispatch();yuwen
385*53ee8cc1Swenshuai.xi //MsOS_EnableInterrupt(E_IRQ_FIQ_ALL);
386*53ee8cc1Swenshuai.xi MsOS_RestoreAllInterrupts(u32OldIntr);
387*53ee8cc1Swenshuai.xi
388*53ee8cc1Swenshuai.xi //TIMER_TASK_LOCK = flags;
389*53ee8cc1Swenshuai.xi return 1;
390*53ee8cc1Swenshuai.xi }
391*53ee8cc1Swenshuai.xi
392*53ee8cc1Swenshuai.xi /***
393*53ee8cc1Swenshuai.xi * del_timer_sync - deactive a timer.
394*53ee8cc1Swenshuai.xi * @timer: the timer to be deactivated
395*53ee8cc1Swenshuai.xi *
396*53ee8cc1Swenshuai.xi * del_timer_sync() deactivates a timer - this works on both active and inactive
397*53ee8cc1Swenshuai.xi * timers.
398*53ee8cc1Swenshuai.xi *
399*53ee8cc1Swenshuai.xi * The function will protect synchronization problem before deactivating timer
400*53ee8cc1Swenshuai.xi */
del_timer_sync(struct timer_list * timer)401*53ee8cc1Swenshuai.xi int del_timer_sync(struct timer_list *timer)
402*53ee8cc1Swenshuai.xi {
403*53ee8cc1Swenshuai.xi //U32 flags;
404*53ee8cc1Swenshuai.xi
405*53ee8cc1Swenshuai.xi //flags = TIMER_TASK_LOCK;
406*53ee8cc1Swenshuai.xi //lock_TmrTaskDispatch();
407*53ee8cc1Swenshuai.xi //save_and_disable_firqs(&flags);
408*53ee8cc1Swenshuai.xi //HAL_DISABLE_INTERRUPTS(flags);
409*53ee8cc1Swenshuai.xi //OS_DisableDispatch();
410*53ee8cc1Swenshuai.xi //MsOS_DisableInterrupt(E_IRQ_FIQ_ALL);
411*53ee8cc1Swenshuai.xi U32 u32OldIntr;
412*53ee8cc1Swenshuai.xi u32OldIntr = MsOS_DisableAllInterrupts();
413*53ee8cc1Swenshuai.xi
414*53ee8cc1Swenshuai.xi if( timer->entry.next != NULL && timer->entry.prev != NULL )
415*53ee8cc1Swenshuai.xi {
416*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
417*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
418*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
419*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
420*53ee8cc1Swenshuai.xi list_del_init(&timer->entry);
421*53ee8cc1Swenshuai.xi }
422*53ee8cc1Swenshuai.xi
423*53ee8cc1Swenshuai.xi //restore_firqs(&flags);
424*53ee8cc1Swenshuai.xi //HAL_RESTORE_INTERRUPTS(flags);
425*53ee8cc1Swenshuai.xi //OS_EnableDispatch();
426*53ee8cc1Swenshuai.xi //MsOS_EnableInterrupt(E_IRQ_FIQ_ALL);
427*53ee8cc1Swenshuai.xi MsOS_RestoreAllInterrupts(u32OldIntr);
428*53ee8cc1Swenshuai.xi
429*53ee8cc1Swenshuai.xi //TIMER_TASK_LOCK = flags;
430*53ee8cc1Swenshuai.xi return 1;
431*53ee8cc1Swenshuai.xi }
432*53ee8cc1Swenshuai.xi
433*53ee8cc1Swenshuai.xi /***
434*53ee8cc1Swenshuai.xi * add_timer - start a timer
435*53ee8cc1Swenshuai.xi * @timer: the timer to be added
436*53ee8cc1Swenshuai.xi *
437*53ee8cc1Swenshuai.xi * The kernel will do a ->function(->data) callback from the
438*53ee8cc1Swenshuai.xi * timer interrupt at the ->expired point in the future. The
439*53ee8cc1Swenshuai.xi * current time is 'jiffies'.
440*53ee8cc1Swenshuai.xi *
441*53ee8cc1Swenshuai.xi * The timer's ->expired, ->function (and if the handler uses it, ->data)
442*53ee8cc1Swenshuai.xi * fields must be set prior calling this function.
443*53ee8cc1Swenshuai.xi *
444*53ee8cc1Swenshuai.xi * Timers with an ->expired field in the past will be executed in the next
445*53ee8cc1Swenshuai.xi * timer tick. It's illegal to add an already pending timer.
446*53ee8cc1Swenshuai.xi */
add_timer(struct timer_list * timer)447*53ee8cc1Swenshuai.xi void add_timer(struct timer_list *timer)
448*53ee8cc1Swenshuai.xi {
449*53ee8cc1Swenshuai.xi //U32 flags;
450*53ee8cc1Swenshuai.xi
451*53ee8cc1Swenshuai.xi //flags = TIMER_TASK_LOCK;
452*53ee8cc1Swenshuai.xi //lock_TmrTaskDispatch();
453*53ee8cc1Swenshuai.xi //save_and_disable_firqs(&flags);
454*53ee8cc1Swenshuai.xi //HAL_DISABLE_INTERRUPTS(flags);
455*53ee8cc1Swenshuai.xi //OS_DisableDispatch();
456*53ee8cc1Swenshuai.xi //MsOS_DisableInterrupt(E_IRQ_FIQ_ALL);
457*53ee8cc1Swenshuai.xi U32 u32OldIntr;
458*53ee8cc1Swenshuai.xi u32OldIntr = MsOS_DisableAllInterrupts();
459*53ee8cc1Swenshuai.xi
460*53ee8cc1Swenshuai.xi if ( (timer->tmout_step > 0) && (timer->tmout_value > timer->tmout_step) )
461*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_step;
462*53ee8cc1Swenshuai.xi else
463*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_value;
464*53ee8cc1Swenshuai.xi
465*53ee8cc1Swenshuai.xi list_add_tail(&timer->entry, &sw_timer_vec_head);
466*53ee8cc1Swenshuai.xi
467*53ee8cc1Swenshuai.xi //restore_firqs(&flags);
468*53ee8cc1Swenshuai.xi //HAL_RESTORE_INTERRUPTS(flags);
469*53ee8cc1Swenshuai.xi //OS_EnableDispatch();
470*53ee8cc1Swenshuai.xi //MsOS_EnableInterrupt(E_IRQ_FIQ_ALL);
471*53ee8cc1Swenshuai.xi MsOS_RestoreAllInterrupts(u32OldIntr);
472*53ee8cc1Swenshuai.xi
473*53ee8cc1Swenshuai.xi //TIMER_TASK_LOCK = flags;
474*53ee8cc1Swenshuai.xi }
475*53ee8cc1Swenshuai.xi
mod_timer(struct timer_list * timer,U32 expires,U32 steps)476*53ee8cc1Swenshuai.xi int mod_timer(struct timer_list *timer, U32 expires, U32 steps)
477*53ee8cc1Swenshuai.xi {
478*53ee8cc1Swenshuai.xi //U32 flags;
479*53ee8cc1Swenshuai.xi int ret = 0;
480*53ee8cc1Swenshuai.xi
481*53ee8cc1Swenshuai.xi //save_and_disable_firqs(&flags);
482*53ee8cc1Swenshuai.xi //OS_DisableDispatch();
483*53ee8cc1Swenshuai.xi //MsOS_DisableInterrupt(E_IRQ_FIQ_ALL);
484*53ee8cc1Swenshuai.xi U32 u32OldIntr;
485*53ee8cc1Swenshuai.xi u32OldIntr = MsOS_DisableAllInterrupts();
486*53ee8cc1Swenshuai.xi
487*53ee8cc1Swenshuai.xi timer->tmout_value = expires;
488*53ee8cc1Swenshuai.xi timer->tmout_step = steps;
489*53ee8cc1Swenshuai.xi
490*53ee8cc1Swenshuai.xi //ret = del_timer(timer);
491*53ee8cc1Swenshuai.xi if( timer->entry.next != NULL && timer->entry.prev != NULL )
492*53ee8cc1Swenshuai.xi {
493*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev->next == &timer->entry, "timer->entry.prev->next error!!!!\n");
494*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next != 0, "timer->entry.next!!!!\n");
495*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.next->prev == &timer->entry, "timer->entry.next->prev error!!!!\n");
496*53ee8cc1Swenshuai.xi USB_ASSERT(timer->entry.prev != 0, "timer->entry.prev error!!!!\n");
497*53ee8cc1Swenshuai.xi list_del_init(&timer->entry);
498*53ee8cc1Swenshuai.xi }
499*53ee8cc1Swenshuai.xi
500*53ee8cc1Swenshuai.xi //add_timer(timer);
501*53ee8cc1Swenshuai.xi if ( (timer->tmout_step > 0) && (timer->tmout_value > timer->tmout_step) )
502*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_step;
503*53ee8cc1Swenshuai.xi else
504*53ee8cc1Swenshuai.xi timer->expires = timer->tmout_value;
505*53ee8cc1Swenshuai.xi list_add_tail(&timer->entry, &sw_timer_vec_head);
506*53ee8cc1Swenshuai.xi
507*53ee8cc1Swenshuai.xi //restore_firqs(&flags);
508*53ee8cc1Swenshuai.xi //OS_EnableDispatch();
509*53ee8cc1Swenshuai.xi //MsOS_EnableInterrupt(E_IRQ_FIQ_ALL);
510*53ee8cc1Swenshuai.xi MsOS_RestoreAllInterrupts(u32OldIntr);
511*53ee8cc1Swenshuai.xi
512*53ee8cc1Swenshuai.xi return ret;
513*53ee8cc1Swenshuai.xi }
514*53ee8cc1Swenshuai.xi #endif //#ifdef
515*53ee8cc1Swenshuai.xi
516