[asterisk-commits] russell: branch group/timing r122363 - in /team/group/timing: include/asteris...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 12 15:12:11 CDT 2008
Author: russell
Date: Thu Jun 12 15:12:10 2008
New Revision: 122363
URL: http://svn.digium.com/view/asterisk?view=rev&rev=122363
Log:
Implement timer_open and timer_close, and document these API calls
Modified:
team/group/timing/include/asterisk/timing.h
team/group/timing/res/res_timing_dahdi.c
Modified: team/group/timing/include/asterisk/timing.h
URL: http://svn.digium.com/view/asterisk/team/group/timing/include/asterisk/timing.h?view=diff&rev=122363&r1=122362&r2=122363
==============================================================================
--- team/group/timing/include/asterisk/timing.h (original)
+++ team/group/timing/include/asterisk/timing.h Thu Jun 12 15:12:10 2008
@@ -57,12 +57,35 @@
AST_TIMING_EVENT_CONTINUOUS = 2,
};
+/*!
+ * \brief Timing module interface
+ */
struct ast_timing_functions {
+ /*!
+ * \brief Open a timing fd
+ *
+ * \arg rate number of timer ticks per second
+ *
+ * \retval -1 error, with errno set
+ * \retval >=0 success
+ */
int (*timer_open)(unsigned int rate);
+
+ /*!
+ * \brief Close an opened timing handle
+ *
+ * \arg handle timing handle returned from timer_open()
+ *
+ * \return nothing
+ */
void (*timer_close)(int handle);
+
void (*timer_ack)(int handle, unsigned int quantity);
+
int (*timer_enable_continuous)(int handle);
+
int (*timer_disable_continuous)(int handle);
+
enum ast_timing_event (*timer_get_event)(int handle);
};
Modified: team/group/timing/res/res_timing_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/res/res_timing_dahdi.c?view=diff&rev=122363&r1=122362&r2=122363
==============================================================================
--- team/group/timing/res/res_timing_dahdi.c (original)
+++ team/group/timing/res/res_timing_dahdi.c Thu Jun 12 15:12:10 2008
@@ -34,6 +34,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <math.h>
#include "asterisk/module.h"
#include "asterisk/timing.h"
@@ -60,11 +61,32 @@
static int dahdi_timer_open(unsigned int rate)
{
- return 0;
+ int fd;
+ int samples;
+
+ fd = open("/dev/dahdi/timer", O_RDWR);
+
+ if (fd < 0) {
+ return -1;
+ }
+
+ /* DAHDI timers are configured using a number of samples,
+ * based on an 8 kHz sample rate. */
+ samples = (unsigned int) roundf((8000.0 / ((float) rate)));
+
+ if (ioctl(fd, DAHDI_TIMERCONFIG, &samples)) {
+ ast_log(LOG_ERROR, "Failed to configure DAHDI timing fd for %u sample timer ticks\n",
+ samples);
+ close(fd);
+ return -1;
+ }
+
+ return fd;
}
static void dahdi_timer_close(int handle)
{
+ close(handle);
}
static void dahdi_timer_ack(int handle, unsigned int quantity)
More information about the asterisk-commits
mailing list