0
|
1 |
/*
|
|
2 |
* timerclient.cpp
|
|
3 |
*
|
|
4 |
* Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
|
|
5 |
* All rights reserved.
|
|
6 |
*
|
|
7 |
* This program and the accompanying materials are made available under the
|
|
8 |
* terms of the Eclipse Public License v1.0 or BSD License which accompanies
|
|
9 |
* this distribution. The Eclipse Public License is available at
|
|
10 |
* http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.
|
|
11 |
*
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
14 |
* are met:
|
|
15 |
*
|
|
16 |
* * Redistributions of source code must retain the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
18 |
* * Redistributions in binary form must reproduce the above copyright
|
|
19 |
* notice, this list of conditions and the following disclaimer in
|
|
20 |
* the documentation and/or other materials provided with the
|
|
21 |
* distribution.
|
|
22 |
* * Neither the name Texas Instruments nor the names of its
|
|
23 |
* contributors may be used to endorse or promote products derived
|
|
24 |
* from this software without specific prior written permission.
|
|
25 |
*
|
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
27 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
28 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
29 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
30 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
31 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
32 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
33 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
34 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37 |
*/
|
|
38 |
|
|
39 |
|
|
40 |
#include "TIWhaDef.h"
|
|
41 |
#include "wlantimer.h"
|
|
42 |
#include "timerclient.h"
|
|
43 |
#define __FILE_ID__ FILE_ID_139
|
|
44 |
|
|
45 |
/* Make sure that while converting Ms to Us we are not exceeding max value of TInt */
|
|
46 |
#define MAX_US_TIMEOUT (0x7FFFFFFF)
|
|
47 |
#define MAX_MS_TIMEOUT (MAX_US_TIMEOUT / 1000)
|
|
48 |
|
|
49 |
/**
|
|
50 |
* \fn TimerClient
|
|
51 |
* \brief Constructor
|
|
52 |
*
|
|
53 |
* Create a new timer object, icluding creating a timer in OSA
|
|
54 |
*
|
|
55 |
* \param hOs - The OS handle
|
|
56 |
*/
|
|
57 |
TimerClient::TimerClient (void* hOs, fTimerFunction pRoutine, TI_HANDLE hFuncHandle) :
|
|
58 |
iWlanOSA (GET_OSA(hOs)),
|
|
59 |
iWlanTimer (iWlanOSA->TimerCreate()),
|
|
60 |
fCb(pRoutine),
|
|
61 |
hCtx(hFuncHandle)
|
|
62 |
{}
|
|
63 |
|
|
64 |
/**
|
|
65 |
* \fn ~TimerClient
|
|
66 |
* \brief Destructor
|
|
67 |
*
|
|
68 |
* Destroy Timer
|
|
69 |
*
|
|
70 |
* \param
|
|
71 |
*/
|
|
72 |
TimerClient::~TimerClient()
|
|
73 |
{
|
|
74 |
if (iWlanTimer && iWlanOSA)
|
|
75 |
{
|
|
76 |
iWlanOSA->TimerDestroy(iWlanTimer);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* \fn OnTimeout
|
|
82 |
* \brief On Timer expiry
|
|
83 |
*
|
|
84 |
* Call the registered call back in TWD (timer.c)
|
|
85 |
*
|
|
86 |
* \param aCtx - not used
|
|
87 |
*/
|
|
88 |
void TimerClient::OnTimeout(TInt aCtx)
|
|
89 |
{
|
|
90 |
fCb(hCtx);
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* \fn Start
|
|
95 |
* \brief start timer
|
|
96 |
*
|
|
97 |
* Save parameters and start timer in OSA
|
|
98 |
*
|
|
99 |
*/
|
|
100 |
void TimerClient::Start(TI_UINT32 uIntervalMsec)
|
|
101 |
{
|
|
102 |
/* Make sure we are not exceeding the maximum value of TInt. */
|
|
103 |
TInt iIntervalUsec = (uIntervalMsec > MAX_MS_TIMEOUT) ? (MAX_US_TIMEOUT) : (uIntervalMsec * 1000);
|
|
104 |
|
|
105 |
if (iIntervalUsec == 0)
|
|
106 |
{
|
|
107 |
/* we will mark it as 1us to avoid errors. This is actually used to schedule context switch */
|
|
108 |
iIntervalUsec = 1;
|
|
109 |
}
|
|
110 |
/* Wlan Timer expects microseconds */
|
|
111 |
iWlanTimer->Enqueue(*this, 0, iIntervalUsec, TI_FALSE);
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* \fn Stop
|
|
116 |
* \brief stop timer
|
|
117 |
*
|
|
118 |
* stop timer
|
|
119 |
*
|
|
120 |
*/
|
|
121 |
void TimerClient::Stop()
|
|
122 |
{
|
|
123 |
iWlanTimer->Dequeue();
|
|
124 |
}
|
|
125 |
|