To slow down transmission of many ABIS frames at a time, a delay timer
is used for the E1's time slot. This timer replaces the "usleep()"
function, so the process will not block the execution of libbsc. The
timer is started after a frame is transmitted. If another frame is in
the transmit queue, the frame will only be queued until the timer times
out. If the timer is not running or times out, the frame is transmitted
and the timer is restarted.

The problem with partly provisioned TRX (locks show on LMT) is solved.
The adjustment for the inter frame delay of 50 miliseconds is for
further study.
(Andreas Eversberg)

diff --git a/src/input/misdn.c b/src/input/misdn.c
index d6ba63c..77da77c 100644
--- a/src/input/misdn.c
+++ b/src/input/misdn.c
@@ -171,6 +171,27 @@
 	return ret;
 }
 
+static int ts_want_write(struct e1inp_ts *e1i_ts)
+{
+	/* We never include the mISDN B-Channel FD into the
+	 * writeset, since it doesn't support poll() based
+	 * write flow control */		
+	if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
+		return 0;
+
+	e1i_ts->driver.misdn.fd.when |= BSC_FD_WRITE;
+
+	return 0;
+}
+
+static void timeout_ts1_write(void *data)
+{
+	struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
+
+	/* trigger write of ts1, due to tx delay timer */
+	ts_want_write(e1i_ts);
+}
+
 static int handle_ts1_write(struct bsc_fd *bfd)
 {
 	struct e1inp_line *line = bfd->data;
@@ -183,10 +204,12 @@
 	u_int8_t *l2_data;
 	int ret;
 
+	bfd->when &= ~BSC_FD_WRITE;
+
 	/* get the next msg for this timeslot */
 	msg = e1inp_tx_ts(e1i_ts, &sign_link);
 	if (!msg) {
-		bfd->when &= ~BSC_FD_WRITE;
+		/* no message after tx delay timer */
 		return 0;
 	}
 
@@ -211,8 +234,10 @@
 		fprintf(stderr, "%s sendto failed %d\n", __func__, ret);
 	msgb_free(msg);
 
-	/* FIXME: this has to go */
-	usleep(100000);
+	/* set tx delay timer for next event */
+	e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
+	e1i_ts->sign.tx_timer.data = e1i_ts;
+	bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000);
 
 	return ret;
 }
@@ -349,19 +374,6 @@
 	return ret;
 }
 
-static int ts_want_write(struct e1inp_ts *e1i_ts)
-{
-	/* We never include the mISDN B-Channel FD into the
-	 * writeset, since it doesn't support poll() based
-	 * write flow control */		
-	if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
-		return 0;
-
-	e1i_ts->driver.misdn.fd.when |= BSC_FD_WRITE;
-
-	return 0;
-}
-
 struct e1inp_driver misdn_driver = {
 	.name = "mISDNuser",
 	.want_write = ts_want_write,