1 /************************************************
2 *FILE: netapi_timer.h
3 *Purpose: netapi timer related functions
4 **************************************************************
5 * FILE: netapi_timer.h
6 *
7 * DESCRIPTION: netapi timer library header file for user space transport
8 * library
9 *
10 * REVISION HISTORY: rev 0.0.1
11 *
12 * Copyright (c) Texas Instruments Incorporated 2010-2011
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ***********************************************/
43 #ifndef __NETAPI_TIMER__H
44 #define __NETAPI_TIMER__H
45 #include "netapi.h"
47 extern volatile unsigned long * t64_virt_addr;
48 extern unsigned int cpu_cycles_sec;
50 //return clock ticks per second
51 unsigned long t64_ticks_sec(void);
52 #define netapi_getTicksPerSec t64_ticks_sec
54 //return 64 bit timestamp
55 static inline unsigned long long netapi_getTimestamp(void)
56 {
57 volatile unsigned long long t1;
58 volatile unsigned long long t2;
59 unsigned long long val;
60 t1 = t64_virt_addr[0x10/4]; //lo
61 t2 = t64_virt_addr[0x14/4]; //hi
62 val = ((unsigned long long) t2) <<32 | t1;
63 return val;
64 }
66 /******************************************************/
67 /*******************TIMER API***************************/
68 /******************************************************/
69 typedef void * NETAPI_TIMER_GROUP_HANDLE_T;
70 typedef void * NETAPI_TIMER_T;
71 typedef void * NETAPI_TIMER_LIST_T;
72 typedef int NETAPI_TIMER_FILTER_T;
73 #define NETAPI_TIMER_NA (void*) NULL
74 #define NETAPI_TIMER_FILTER_GLOBAL 0x1
75 #define NETAPI_TIMER_FILTER_LOCAL 0x2
76 #define NETAPI_TIMER_FILTER_E2F 0x4
77 #define NETAPI_TIMER_FILTER_E2C 0x8
78 #define NETAPI_TIMER_FITLER_ALL 0xf
80 //iterator on TIMER_LIST_T
81 NETAPI_TIMER_T netapi_TimerGetFirst( NETAPI_TIMER_LIST_T list);
82 NETAPI_TIMER_T netapi_TimerGetNext( NETAPI_TIMER_LIST_T list,NETAPI_TIMER_T prev);
83 void * netapi_TimerGetCookie(NETAPI_TIMER_T timer);
84 unsigned long long netapi_TimerGetTs(NETAPI_TIMER_T timer); //debug
86 //timer callback
87 typedef void (*NETAPI_TIMER_CB_T) (
88 NETAPI_TIMER_GROUP_HANDLE_T th,
89 int n_fired, //# timers fired
90 NETAPI_TIMER_LIST_T fired_list,
91 uint64_t currentTime);
93 //create a timer group
94 NETAPI_TIMER_GROUP_HANDLE_T netapi_TimerGroupCreate(
95 NETAPI_T netHandle, //netapi instance
96 char * name, //name of the timer block
97 NETAPI_TIMER_CB_T cb, //the callback function
98 int local, //1 if timers local to thread
99 int exp2cancel,//1 if expect to cancel
100 int timerTicksPerGroupTick, //resolution for this timer block, in timer ticks
101 int maxTimers, //max # of timer objects for this group
102 int *pErr);
104 //open a [global] timer group
105 NETAPI_TIMER_GROUP_HANDLE_T netapi_TimerGroupOpen(
106 NETAPI_T netHandle,
107 NETAPI_TIMER_CB_T cb,
108 int *pErr);
110 //start an individual timer
111 NETAPI_TIMER_T netapi_TimerGroupStartiTimer(
112 NETAPI_TIMER_GROUP_HANDLE_T th,
113 void * cookie,
114 uint64_t offs2fire, //offset in timerGroup ticks (eg msc)
115 int * pErr);
117 //Cancel a timer
118 void netapi_TimerGroupCancel(
119 NETAPI_TIMER_GROUP_HANDLE_T th,
120 NETAPI_TIMER_T timerId,
121 int *pErr);
123 //close an opened timer group
124 void netapi_TimerGroupClose(
125 NETAPI_TIMER_GROUP_HANDLE_T th,
126 int *pErr);
128 //close an opened timer group
129 void netapi_TimerGroupDelete(
130 NETAPI_TIMER_GROUP_HANDLE_T th,
131 int *pErr);
133 //extract netapi handle from timer group handle
134 NETAPI_T netap_TimerGroupGetNH( NETAPI_TIMER_GROUP_HANDLE_T th);
136 //poll a specific timer group
137 int netapi_TimerGroupPoll(NETAPI_TIMER_GROUP_HANDLE_T th, int maxTimers);
139 //poll all timers
140 int netapi_TimerGroupPollAll(NETAPI_T nh, NETAPI_TIMER_FILTER_T f, int maxTimers);
142 /*****************END API*********************************/
145 #endif