Purpose of interface
The Zaptel timer is used by userspace applications to ensure timing when using zaptel channels. The timer is normally tied to the hardware interrupts generated by the communication device.
How the timer is implemented in the kernel
The timer period is configured via an ioctl() call. Each time the master span calls zt_receive() to send zaptel a chunk of incoming data, zaptel decrements the timer counter by ZT_CHUNKSIZE (usually 8). For many cards, this happens for each interrupt event. When the timer counter reaches zero, it is considered to be “tripped”. Once tripped, a process polling the file descriptor will awaken.
ioctl() interface
- ZT_TIMER_CONFIG
- Set the period of the zaptel timer, in number of bytes
- ZT_TIMERCONFIG
- Set the period of the zaptel timer, in number of bytes
- ZT_TIMERACK
- Decrements the “tripped” counter by the specified value
- ZT_GETEVENT
- Get the current event state, one of:
-
- ZT_EVENT_NONE: Nothing happened
- ZT_EVENT_TIMER_EXPIRED: timer->tripped > 0, meaning the timer expired and has not been ACKed yet.
- ZT_EVENT_TIMER_PING : timer->ping > 0
- ZT_TIMERPING
- Sets timer->ping = 1
- ZT_TIMERPONG
- Sets timer->ping = 0
select()/poll() interface
The kernel select()/poll() interface reports events based on the internal “tripped” and “ping” conditions. In other words, when the timer expires or when it is pinged via ZT_TIMERPING.
Usage
In its simplest form, you can just use the ZT_TIMERCONFIG and ZT_TIMERACK commands. You configure the period, call select() on the timer device, and ACK it when you get an event. See timertest.c included with zaptel for an example of this.
The ping/pong interface is a more recent addition to the zaptel timer. Asterisk uses this in channel.c.