tdef: Introduce OSMO_TDEF_US unit
Some applications may need submillisecond timers, such as those
interacting with modbus serial lines (RS-485, RTU), which require
timers of values around 1.5 char-time (T1.5), where a data char is
composed of 11 bits sent on the line: 1 start bit, 8 data bits,
1 stop bit, and and parity bit (or 2nd stop bits if no parity).
For instance, for a baudrate of 9600:
1.5 * 11 / 9600 = 1.718 ms = 1718 us
So having a granularity of MS is not enough here.
Change-Id: I71848d7c1ee0649929ce07680ee7320bb2a42f0e
diff --git a/src/tdef.c b/src/tdef.c
index 71a3315..897a92f 100644
--- a/src/tdef.c
+++ b/src/tdef.c
@@ -93,6 +93,17 @@
return 1;
switch (b) {
+ case OSMO_TDEF_US:
+ switch (a) {
+ case OSMO_TDEF_MS:
+ return 1000;
+ case OSMO_TDEF_S:
+ return 1000*1000;
+ case OSMO_TDEF_M:
+ return 60*1000*1000;
+ default:
+ return 0;
+ }
case OSMO_TDEF_MS:
switch (a) {
case OSMO_TDEF_S:
@@ -351,6 +362,7 @@
{ OSMO_TDEF_MS, "ms" },
{ OSMO_TDEF_M, "m" },
{ OSMO_TDEF_CUSTOM, "custom-unit" },
+ { OSMO_TDEF_US, "us" },
{}
};