Teridian Semiconductor Corporation makes no warranty for the use of its products, other than expressly
contained in the Company’s warranty detailed in the Teridian Semiconductor Corporation standard Terms
and Conditions. The company assumes no responsibility for any errors which may appear in this
document, reserves the right to change devices or specifications detailed herein at any time without
notice and does not make any commitment to update the information contained herein. Accordingly, the
reader is cautioned to verify that this document is current by comparing it to the latest version on
http://www.teridian.com or by checking with your sales representative.
Teridian Semiconductor Corp., 6440 Oak Canyon, Suite 100, Irvine, CA 92618
TEL (714) 508-8800, FAX (714) 508-8877, http:// w ww. ter id ian.c om
6 Related Documentation .................................................................................................................... 65
7 Contact Information .......................................................................................................................... 65
Revision History ........................................................................................................................................ 66
Figures
Figure 1: Driver API ....................................................................................................................................... 5
Tables
Table 1: API Overview .................................................................................................................................. 8
This document describes the application programming interface (API) of the Teridian M1x66 Reference
Driver. The API is defined as a simplified functional interface allows an application program written in “C”
language to communicate with the driver without going through complicate and cumbersome Linux
IOCTL. In addition, the API subsystem also encapsulates the FXO asynchronous event notification and
provides a much simpler mechanism to the user application via a callback function.
The API subsystem resides between the user application and the driver layer as shown in Figure 1.
®
driver
Figure 1: Driver API
Rev. 2.1 5
Page 6
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
1.1 Overview
The FXOAPI is a user -friendly programming conduit used to access and manage the FXO device/channel
via the Reference Driver. This section describes the programming flow and how the application program
can be implemented using the FXOAPIs.
First, the concept of device versus channel, the Teridian FXO driver supports multiple FXO channels.
The application layer communicates with the driver using this channel descriptor. However, the driver
reports asynchronous FXO channel events through the device descriptor. At this point, the only use for
the device descriptor is for conveying event notification and for retrieving events from the driver.
The application program must first initialize the FXOAPI by calling FXO API Initialization and Termination
M1x66_FxoApiInit(). This initializes internal data structures and prepares the API subsystem for
subsequent calls to other APIs.
After the FXO API is initialized, the application program opens the FXO device and channel descriptors to
access and manage the FXO device and channel(s) by calling Device/Channel Open, Close and
Initialization APIs
M1x66_OpenDevice() and M1x66_OpenChannel() respectively. If more than one FXO channel exists
in the hardware platform, each channel is opened separately by calling M1x66_OpenChannel().
To simplify the usage of the driver, the API encapsulates all relevant data components required to
operate the FXO device and the channels into a data structure whose pointer is referred to as a “handle”.
This handle is returned from a successful call to open device/channel APIs and is used thro ugh out the lif e
of the FXO device and channels.
The PCM Interface Config data is programmed by the M1x66_PcmIfConfig() API, and the PCM
timeslot config data by the M1x66_PcmConfig() API. Generally, the PCM Interface config data remains
static while the PCM timeslot may be dynamically allocated and set for each call establishment.
By default, the PCM channel is disabled and should remain disabled when there is no voice call on the
channel. The application program can use the M1x66_PcmActivation() to enable and
M1x66_PcmDeActivation() to disable the PCM channel as needed.
Upon exiting the application program it is recommended that all device and channels descriptors be
closed, using
M1x66_CloseDevice() and M1x66_CloseChannel(), and the API subsystem be shutdown using
M1x66_FxoApiRelease() to ensure that the system resources are free up when the application
program terminates.
As mentioned earlier, the asynchronous FXO events from each channel are reported through the opened
device descriptor. The event message contains the channel ID from which the event occurred on. The
application program must distinguish the event for each channel and act accordingly. The way this event
is conveyed to the application program is via the callback function provided as one of the parameters
passed into Device/Channel Open, Close and Initialization APIs
M1x66_OpenDevice(). The callback function serves as a “hook” for the API subsystem and notifies the
application whenever an FXO event is generated.
Section 5 provides a sample application using FXOAPI.
6 Rev. 2.1
Page 7
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
1.2 Conventions Use d in this Guide
This document uses the following conventions:
• Software code, IOCTL names and data types are presented in Courier font.
• A table with a blue header is a summary table. A table with a gray header is a detail table.
1.3 Acronyms
API – Application Programming Interface
APOH – Another Phone Off Hook
BSP – Board Support Package
DAA – Data Access Arrangement
FXO – Foreign eXchange Office
GPIO – General Purpose Input/Output
IET – Interval Event Table
IOCTL – I/O Control
NOPOH – No Phone Off Hook
PCM – Pulse-code Modulation
POH – Phone Off Hook
SPI – Serial Peripheral Interface
Rev. 2.1 7
Page 8
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_FxoApiRelease
M1x66_CloseDevice
M1x66_OpenChannel
M1x66_CloseChannel
M1x66_InitChannel
M1x66_PCMIfConfig
M1x66_PcmConfig
M1x66_PcmActivation
M1x66_PcmDeActivation
M1x66_HookSwitch
2 API Descriptions
This section contains the detail description of each API. T able 1 provides a summar y of the APIs.
Table 1: API Overview
IOCTL Name Description
FXO API Initialization and Termination
M1x66_FxoApiInit
Device/Channel Open, Close and
Initialization APIs
M1x66_OpenDevice
API subsystem initialization.
API subsystem release or termination.
Open FXO device of event reporting.
Open FXO channel for operation.
Close an opened channel.
Initialize channel for specific region.
Configure PCM interface parameter.
Configure PCM timeslots and codec.
Activate PCM channel.
De-activate PCM channel.
Perform hook switching – on/off-hook.
Pulse dialing.
Data Type Name Description
M1x66_HANDLE channel
M1x66_HOOK_SWITCH hookSwitch
Return Values
Data Type Description
M1x66_RET
8 Rev. 2.1
Channel
handle from
FXO open
channel.
Type of
hook switch
requested.
M1x66_SUCCESS – Successfully
performed hook switch.
Page 9
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_FAILED – Failure.
M1x66_PulseDialCancel
M1x66_GetGpioConfig
M1x66_SetGpioData
M1x66_GpioEnable
M1x66_GpioDisable
M1x66_GetPulseDialParam
M1x66_LoopbackClear
M1x66_SetCountryParam
M1x66_BillingToneFilterDisable
M1x66_ThresholdOverride
M1x66_HWRegisterReadAll
M1x66_HWRegisterWrite
M1x66_SetDebugTrace
M1x66_CallProgressMonitor
M1x66_SelectSampleRate
IOCTL Name Description
M1x66_PulseDial
Terminate pulse dial session.
M1x66_SetPulseDialParam
GPIO Management APIs
Adapt to the line condition instead of
default values.
Read a GPIO configuration.
M1x66_SetGpioConfig
M1x66_GetGpioData
Loopback Control APIs
M1x66_LoopbackGet
M1x66_LoopbackSet
Country Default Parameter and Override
APIs
M1x66_GetCountryParam
M1x66_GetHWRevision
Billing Tone Filter Control APIs
M1x66_BillingToneFilterEnable
Configure the GPIO.
Write data to GPIO pin.
Read data from GPIO pin.
Enable the GPIO.
Disable the GPIO.
Read the pulse dial timing parameter s .
Read the status of the loopback.
Set the transmit/receive data path into
loopback mode.
Disable the loopback.
Read the default country parameter.
Change the default country parameter.
Read the device hardware revision
number.
Filters out the billing tone.
1x66 H/W Register Access and Debugging aid
APIs
M1x66_HWRegisterRead
M1x66_SetPhoneVolume
Rev. 2.1 9
Disable the billing tone filter.
Override the FXO channel parameters.
Read 1x66 register.
Read all registers.
Write to 1x66 register.
Set debug trace mask.
Set speaker phone and micro phone
volume.
Monitor activities on the line.
Set new PCM sample rate – 8 or 16 kHz.
Get file descriptor from a handle.
Update current IET entry.
Delete the current IET table entry.
Read the voltage IET table entry.
Update voltage IET entry.
Delete the voltage IET table entry.
Start current measurement.
Start voltage measurement.
Stop current measurement.
Stop voltage measurement.
Set Ring Cadence filtering criteria.
10 Rev. 2.1
Page 11
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
void
void
void
void
2.2 FXO API Initialization and Termination
2.2.1 M1x66_FxoApiInit
Description
This API allocates and initializes required internal data structures; make necessary preparation before
other API members can be invoked. The FXO API Initialization and Termination
M1x66_FxoApiInit() must be called once during application program’s initialization, or prior to accessing
other API members. Upon exiting of the application program a reversed operation must be performed to
release resources using M1x66_FxoApiRelease.
Prototype
M1x66_RET M1x66_FxoApiInit (void);
Parameters
Data Type Name Description
No parameter is required.
Return Values
Data Type Description
M1x66_RET
2.2.2 M1x66_FxoApiRelease
M1x66_SUCCESS – Successful FXO API initialization.
M1x66_FAILED – Failed.
Description
This API de-allocates the resources acquired during initialization - FXO API Initialization and Termination
M1x66_FxoApiInit. It must be called prior to application program termination, or when access to FXOAPI
is no longer needed. Any FXO channels or device remain open when this API is called will be closed.
Prototype
M1x66_RET M1x66_FxoApiRelease (void);
Parameters
Data Type Name Description
No parameter is required.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successful FXO API termination.
M1x66_FAILED – Unsuccessful.
Rev. 2.1 11
Page 12
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
char *
devName
unsigned int evtData4)
M1x66_EVENT_RING_START
M1x66_EVENT_GPIO_INTERRUPT
2.3 Device/Channe l Open, Close and Initialization AP Is
2.3.1 M1x66_OpenDevice
Description
This API performs the low level opening of the device descriptor. By default, the device descriptor name
is known as “/dev/ter10”; however, since this is configurable during driver installation, a different
device descriptor name may be used. Refer to dri ver c onf igurat ion and inst al latio n more detail. Calling to
this open device API is mandatory before any channel descriptor can be opened, and it must be called
after the FXO API Init function.
In addition to opening the device for accessing this API also requires a callback function. This function is
called by the API subsystem to convey the FOX events to the application program. Six parameters are
returned when this callback function is invoked:
eventId: This parameter is the event identification of type M1x66_EVENT_ID.
chanId: This parameter contains the FXO channel ID from which the event is generated.
evtData1: are reserved for special purpose in event handling.
evtData2:
evtData3:
evtData4:
A successful open device returns a non-zero device handle that can be used to access other device
related APIs.
(*eventCallback)(
M1x66_EVENT_ID eventId,
unsigned int chanId,
unsigned int evtData1,
unsigned int evtData2,
unsigned int evtData3,
Event status callback function. The parameters
returned by this callback function are event ID,
channel ID and 4 event data that are specific to the
event ID. Most of these event data are not
applicable except those listed in the
“EventCallback Parameters” table below.
EventCallback Parameters
Event Name Parameters
evtData1 – Ring burst frequency (in Hz)
M1x66_EVENT_RING_END
evtData1 – Ring burst frequency (in Hz)
evtData2 – Ring burst duration (in milliseconds)
M1x66_EVENT_LINE_STATE
evtData1 – Channel Hook state (0-on-hook, 1-off-hook)
evtData2 – 0-line current, 1- voltage
evtData3 – IET index
evtData4 – Application defined event
evtData1 – GPIO number
12 Rev. 2.1
Page 13
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_HANDLE
devHandle
Return Values
Data Type Description
M1x66_HANDLE
Non-ZERO value if the device is opened successfully.
ZERO if the device fails to open.
2.3.2 M1x66_CloseDevice
Description
This API performs the low level closing of the device handle. It should be called before exiting application
program to release all resource associated with the open device. Closing this device will automatically
force the closing of any opened channel handles.
M1x66_SUCCESS – Successfully close the device handle.
M1x66_FAILED – Failed to close the handle.
Rev. 2.1 13
Page 14
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
char *
pChanName
M1x66_HANDLE
devHandle
int
chanNum
M1x66_HANDLE
chanHandle
2.3.3 M1x66_OpenChannel
Description
This API performs the low level opening of the channel descriptor. B y default, the channel descriptor is
known as “/dev/terXX”, where XX varies from 11 to 26 representing channel 0 to 15 respectively.
Calling to the open channel API is mandatory before any access to the channel can be performed, and it
must be called after the open device as this API requires the device handle to be passed in as the second
parameter. A successful open channel returns a non-zero channel handle that can be used to access
other channel related APIs.
Prototype
M1x66_RET M1x66_OpenChannel (
char *pChanName,
M1x66_HANDLE devHandle,
int chanNum);
Parameters
Data Type Name Description
FXO channel descriptor name. (Default: /dev/ter11...26).
Device handle obtained from FXO open device.
FXO channel number from 0 to 15.
Return Values
Data Type Description
M1x66_HANDLE
0 – Failed to open channel.
None-zero handle – Successful.
2.3.4 M1x66_CloseChannel
Description
This API performs the low level closing of the channel handle. It should be called before exiting
application program, or when the channel is no longer needed, to release all resources associated with
the open channel.
M1x66_SUCCESS – Successfully close the channel.
M1x66_FAILED – Failed to close the channel.
14 Rev. 2.1
Page 15
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_HANDLE
chanHandle
M1x66_COUNTRY_CODE
cntryCode
2.3.5 M1x66_InitChannel
Description
This API performs the channel initialization and prepares the FXO channel to operate in conformance
with specific region where the FXO line is being deployed. Teridian FXO device supports globalcompliance parameter in countries listed in M1x66_COUNTRY_CODE.
Channel handle obtained from FXO open channel.
Country code as listed in M1x66_COUNTRY_CODE.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully initialize the channel.
M1x66_FAILED – Failed to initialize the channel.
Rev. 2.1 15
Page 16
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_HANDLE
channel
M1x66_PCM_IF_CFG
*pIfConfig
M1x66_HANDLE
channel
M1x66_PCM_CFG
*pConfig
2.4 PCM Manage m ent and Control APIs
2.4.1 M1x66_PcmIfConfig
Description
This API is called to program the PCM interface configuration. It is anticipated that this PCM interface
configuration should never change, thus, only need to program once during initialization for each channel.
Channel handle from FXO open channel.
Pointer to the PCM interface config data structure.
Return Values
Data Type Description
M1x66_RET
2.4.2 M1x66_PcmConfig
M1x66_SUCCESS – Successfully configured the PCM interface.
M1x66_FAILED – Failure.
Description
This API is called to program the PCM configuration. The PCM configuration contains the actual PCM
timeslots, thus, may change from session to session depend on the peer termination. The PCM transmit
and receive timeslots are used to establish connection to another device on the PCM bus.
Note: this PCM config API only sets up the PCM connection for both direction (tx and rx) but it does not
enable it until the M1x66_PcmActivation is called.
Prototype
M1x66_RET M1x66_PcmConfig (
M1x66_HANDLE channel,
M1x66_PCM_CFG *pConfig );
Parameters
Data Type Name Description
Channel handle from FXO open channel.
Pointer to PCM config data structure.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully program the PCM config.
M1x66_FAILED – Failure.
16 Rev. 2.1
Page 17
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_HANDLE
channel
M1x66_HANDLE
channel
2.4.3 M1x66_PcmActivation
Description
This API activates the PCM timeslot configured for this channel. It enables the PCM data stream for both
directions.
Prototype
M1x66_RET M1x66_PcmActivation (
M1x66_HANDLE channel );
Parameters
Data Type Name Description
Channel handle from FXO open channel.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully activated the PCM timeslots.
M1x66_FAILED – Failure.
2.4.4 M1x66_PcmDeActivation
Description
This API de-activates the PCM timeslot configured for this channel.
Prototype
M1x66_RET M1x66_PcmActivation (
M1x66_HANDLE channel );
Parameters
Data Type Name Description
Channel handle from FXO open channel.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully de-activated the PCM timeslots.
M1x66_FAILED – Failure.
Channel handle from FXO open channel.
Type of hook switch requested.
Return Values
Data Type Description
M1x66_RET
2.5.2 M1x66_PulseDial
M1x66_SUCCESS – Successfully performed hook switch.
M1x66_FAILED – Failure.
Description
Perform pulse dialing on the FXO channel. T his A PI w il l bring the FXO channel off-hook then perform
pulse dialing with the digit string provided. Once the dialing is completed the FXO channel will remain
off-hook indefinitely, or until it is manually brought back on-hook.
Up to 30 numeric digits is supported. Valid numeric digit is from ASCII 0 to 9 (i.e., 0x30 to 0x39).
Prototype
M1x66_RET M1x66_PulseDial (
M1x66_HANDLE channel,
char *dialSting );
Parameters
Data Type Name Description
Channel handle from FXO open channel.
Numeric dial string of up to 30 characters max.
Channel handle from FXO open channel.
Type of hook switch requested.
Return Values
Data Type Description
M1x66_RET
M1x66_PulseDial ioctl. The actual cancelation of the pulse dial session occurs in the background and
when complete the application should receive a pulse dial aborted event.
The pulse dial API employs three timing parameters to perform dialing. Upon initialization these timers
are set to their default values, however, they can be changed to adapt to the line condition using this API:
These parameters are as follow:
1. On-hook duration (default 40 ms)
2. Off-hook duration and (default 60 ms)
3. Inter-digits duration (default 1 sec)
Prototype
20 Rev. 2.1
Page 21
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_HANDLE
chanHandle
int
onHookDuration
int
offHookDuration
int
interDigitDuration
M1x66_HANDLE
chanHandle
M1966_GPIO_NUMBER
gpio
int
*pOnHookDuration
int
*pOffHookDuration
int
*pInterDigitDuration
M1x66_RET M1x66_SetPulseDialParam (M1x66_HANDLE chanHandle,
int onHookDuration,
int offHookDuration,
int interDigitDuration);
Parameters
Data Type Name Description
Channel handle from FXO open channel.
On-hook duration.
Off-hook duration.
Inter-digits duration.
This API reads the pulse dial timing parameters. If reading is successful the pulse dial timing parameters
will be returned in those three passed in parameters.
Prototype
M1x66_RET M1x66_GetPulseDialParam (M1x66_HANDLE chanHandle,
int *pOnHookDuration,
int *pOffHookDuration,
int *pInterDigitDuration)
Parameters
Data Type Name Description
Channel handle from FXO open channel.
GPIO number
Pointer to on-hook duration variable (output)
Pointer to off-hook duration variable (output)
Pointer to inter-digit duration variable (output)
This is an API for reading the configuration of a GPIO. If reading is successful the driver returns the
direction and the polarity of the GPIO parameter.
This API configures the selected GPIO per “direction” and “polarity” selected. Configuring the GPIO does
not activate it; the GPIO must be “enabled” using M1x66_GpioEnable.
When configured as input (direction), the GPIO signal transition can cause interrupt which in turn sends
an M1966_EVENT_GPIO_INTERRUPT event to the upper layer application. This depends on the interrupt
detection polarity. For example if the polarity is set for detection on the rising edge
(M1966_GPIO_POL_RISING), then interrupt will occur when the GPIO data pin signal transitions from
low to high, and vice-versa.
This API writes data to a GPIO pin. This applies only to a GPIO configured with output direction. The
GPIO data signal (data) will be written to the selected GPIO pin.
This is an API for reading data from a GPIO pin. This applies only to a GPIO configured w ith input
direction. The selected GPIO pin signal level will be read into the variable pointed to by the parameter
*data.
This is an API for enable the GPIO. After a GPIO pin is configured using M1x66_SetGpioConfig it must
be enabled to start the operation. Once enabled the GPIO signal can be manipulated using
M1x66_SetGpioData for those configured for output direction, or the signal can be read for those
configured for input direction.
This API reads the default country parameter. To retrieve the country parameter set the desired country
code in the field “cnum”. If the reading is successful the desired country parameter will be returned in the
country structure passed in.
The country parameters are set to their default value upon startup. This default country parameter can be
found in ref [1]. This API can be used to change the default parameter.
Pointer to structure containing the new default country
parameters.
Rev. 2.1 27
Page 28
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_HANDLE
chanHandle
2.9.3 M1x66_ThresholdOverride
Description
Various FXO channel parameters are conveniently grouped and predefined in the default country
parameter. These parameters are programmed during channel initialization API (M1x66_InitChannel).
However, these parameters can be overridden at runtime to fine tune to the desired threshold for the
specific installation using this threshold override API.
Note: This API must be invoked after the M1x66_InitChannel API to prevent the parameter from over
written.
Large amplitude out-of-band tones can be used to measure call duration and to allow remote central
office to determine the duration of the call for billing purposes. These tones can saturate or distort the
input signal, thus, it is important to be able to reject them. This API provides the ability to filter out the
billing tone.
2.11 1x66 H/W Register Access and Debugging aid APIs
2.11.1 M1x66_HWRegisterRead
Description
Perform H/W register reading from the 73M1x66B device that carries the FXO channel. This API is not
recommended for use in normal operation but only for diagnostic or testing purpose.
The channel handle contains the corresponding SPI channel ID (cid) of the 73M1x66B device in the daisy
chain. This SPI cid is passed to the driver to retrieve the value of the specified register.
Channel handle from FXO open channel.
1x66 Register
Pointer to a single byte of returned data.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully read the register.
M1x66_FAILED – Failure.
2.11.2 M1x66_HWRegisterReadAll
Description
This API is similar to the 1x66 H/W Register Access and Debugging aid APIs
M1x66_HWRegisterRead, but all 73M1x66B registers will be read. The register contents will be returned
via the pRetData. It is the responsibility of the caller application to insure that this data pointer contains
enough space for the return data. A 0x25 bytes buffer is required to store all returned register where the
first byte corresponds to the first register (RG00) and so on.
Prototype
M1x66_RET M1x66_HWRegisterReadAll (
M1x66_HANDLE channel,
char *pRetData );
Parameters
Data Type Name Description
Channel handle from FXO open channel.
Pointer to return data for all 0x25 (byte) registers.
Return Values
Data Type Description
30 Rev. 2.1
M1x66_SUCCESS – Successfully read all registers.
Page 31
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_HANDLE
channel
M1x66_REG_TYPE
Register
char
value
M1x66_HANDLE
deviceHandle
M1x66_DEBUG_TRACE_MASK
debugTraceMask
M1x66_FAILED – Failure.
2.11.3 M1x66_HWRegisterWrite
Description
Perform H/W register writing to the 73M1x66B device that carries the FXO channel. This API is not
recommended for use in normal operation but only for diagnostic or testing purpose.
The channel handle contains the corresponding SPI channel ID (cid) of the 73M1x66B d evic e in the daisy
chain. This SPI cid is passed to the driver to set the value of the specified register.
Prototype
M1x66_RET M1x66_HWRegisterWrite (
M1x66_HANDLE channel,
char value );
Parameters
Data Type Name Description
Channel handle from FXO open channel.
1x66 Register.
Data value to be written.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully written the register.
M1x66_FAILED – Failure.
2.11.4 M1x66_SetDebugTrace
Description
The M1966 Reference Driver provides run-time debugging facility via tracing. The application program
can turn on various trace masks to display debug message for trouble shooting purposes. Due to the
potential amount of messages resulting from setting this trace mask at kernel level the use of this facility
is not recommended under normal operation.
Note: the trace mask occupies a unique bit field, therefore, multiple masks can be “or” together.
Prototype
M1x66_SUCCESS – Successfully set the trace mask.
M1x66_FAILED – Failure.
Page 32
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_HANDLE
pHandle
M1x66_HANDLE
chanHandle
unsigned int
*pHWRevision
2.11.5 M1x66_GetFileDrescriptor
Description
To provide full flexibility to the driver access, this API can be called by an application program to obtain
the file descriptor for a given device or channel handle. With this returned file descriptor, the user has
direct access to the driver via its native IOCTL as described in the 73M1866B/73M1966B Reference Driver User Guide.
Caution: Accessing directly to the driver via IOCTL in mix mode with API is generally not recommended.
However, if this becomes necessary it is strongly advised that the user carefully review the API
implementation and be aware of any potential conflicts that may exist as a result of this change.
Prototype
int M1x66_GetFileDescriptor (M1x66_HANDLE pHandle);
Parameters
Data Type Name Description
Device or channel handle obtains from open API.
Return Values
Data Type Description
int
Device or channel file descriptor.
A NULL value indicates invalid, or not opened file des cr iptor.
2.11.6 M1x66_GetHWRevision
Description
This API reads the device hardware revision number. If the reading is successful, the device revision
number will be stored in the variable pointed to by the pHWRevision parameter.
Prototype
M1x66_RET M1x66_GetHWRevision (M1x66_HANDLE chanHandle,
unsigned int *pHWRevision)
Parameters
Data Type Name Description
Channel handle from FXO open channel.
Pointer to hardware revision number.
M1x66_HANDLE channel,
unsigned int ietIndex,
M1966_IET_t *pIET );
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
IET entry index – row number (0 – 9).
Pointer to an output structure M1966_IET_t.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully read the IET entry.
M1x66_FAILED - Failure.
2.12.2 M1x66_UpdateCurrentIET
Description
Perform the line current IET table update.
Prototype
int M1x66_UpdateCurrentIET (
M1x66_HANDLE channel,
unsigned int ietIndex,
M1966_IET_t *pIET );
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
IET entry index – row number (0 – 9).
Pointer to an input structure M1966_IET_t.
Return Values
Rev. 2.1 33
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully update the IET entry.
M1x66_FAILED – Failure.
Page 34
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_HANDLE
channel
unsigned int
ietIndex
M1x66_HANDLE
channel
unsigned int
ietIndex
M1966_IET_t
*pIET
2.12.3 M1x66_ClearCurrentIET
Description
Delete the line current IET table entry.
Prototype
int M1x66_ClearCurrentIET (
M1x66_HANDLE channel,
unsigned int ietIndex);
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
IET entry index – row number (0 – 9).
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully clear the IET entry.
M1x66_FAILED – Failure.
2.12.4 M1x66_GetVoltageIET
Description
Read the line voltage IET table entry.
Prototype
int M1x66_GetVoltageIET (
M1x66_HANDLE channel,
unsigned int ietIndex,
M1966_IET_t *pIET );
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
IET entry index – row number (0 – 9).
Pointer to an output structure M1966_IET_t.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully read the IET entry.
M1x66_FAILED – Failure.
34 Rev. 2.1
Page 35
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_HANDLE
channel
unsigned int
ietIndex
M1966_IET_t
*pIET
M1x66_HANDLE
channel
unsigned int
ietIndex
2.12.5 M1x66_UpdateVoltageIET
Description
Perform the line voltage IET table update.
Prototype
int M1x66_UpdateVoltageIET (
M1x66_HANDLE channel,
unsigned int ietIndex,
M1966_IET_t *pIET );
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
IET entry index – row number (0 – 9).
Pointer to an input structure M1966_IET_t.
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully update the IET entry.
M1x66_FAILED – Failure.
2.12.6 M1x66_ClearVoltageIET
Description
Delete the line voltage IET table entry.
Prototype
int M1x66_ClearVoltageIET (
M1x66_HANDLE channel,
unsigned int ietIndex);
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
IET entry index – row number (0 – 9).
Return Values
Data Type Description
M1x66_RET
M1x66_SUCCESS – Successfully clear the IET entry.
M1x66_FAILED – Failure.
Rev. 2.1 35
Page 36
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_HANDLE
channel
unsigned int
sampleTime
unsigned int
averageSampleCount
M1x66_HANDLE
channel
unsigned int
sampleTime
unsigned int
averageSampleCount
2.13 Current/Voltage Measurement APIs
2.13.1 M1x66_StartMeasureCurrent
Description
Start the line current measurement process. This API starts measuring the line current of the specified
channel at a sampling interval time of “sampleTime” with averaging count of “averageSampleCount”.
Prototype
int M1x66_StartMeasureCurrent (
M1x66_HANDLE channel,
unsigned int sampleTime,
unsigned int averageSampleCount );
Parameters
Data Type Name Description
Channel handle obtained from FXO open channel.
Time interval between two consec utive samples.
Sample count for average calculation.
Set the ring cadence parameter for ring qualification process. The driver can be programmed to filter and
qualify incoming ring by discarding spurious signals that can be caused by line noises or distortions.
When set with these cadence parameters the driver will evaluate each incoming ring cycle based on
these parameters and emits an M1x66_EVENT_QUALIFIED_RING event only when the ring cadence
matches at the specified number of cycles.
The ring cadence parameter consists of the frequency, cycle duration, period-1 “on”, period-1 “off”,
period-2 “on”, period-2 “off”, and number of cycles. This last parameter (number of cycle) is the number
of ring cycles matched before the ring is qualified. The sum of the period-1 “on”, period-1 “off”, period-2
“on” and period-2 “off” must be equal to the cycle duration parameter.
Remark
The system is defaulted to ring cadence screening disabled upon startup. Enabling or disabling the filter
using this API will not affect the behavior of the ring detection events (M1x66_EVENT_RING_START and
M1x66_EVENT_RING_END). The application may chose to ignore these two events if the qualified ring
event is preferred. To turn off this filter the same API can be used with the frequency or cycle duration
parameter equal ZERO.
Prototype
int M1x66_SetRingCadence (
M1x66_HANDLE channel,
unsigned int frequency,
unsigned int cycleDuration,
unsigned int periodOneOn,
unsigned int periodOneOff,
unsigned int periodTwoOn,
unsigned int periodTwoOff,
unsigned int numOfCycles );
Parameters
Data Type Name Description
Return Values
Data Type Description
M1x66_RET
38 Rev. 2.1
Channel handle obtained from FXO open channel.
Ring frequency to be detected.
Duration of the cadence cycle (in milliseconds).
Period-1 “On” duration (in milliseconds).
Period-1 “Off” duration (in milliseconds).
Period-2 “On” duration (in milliseconds).
Period-2 “Off” duration (in milliseconds).
Detect at the end of this cycle number (1 – 5).
Set the speaker phone and microphone volume. This API sets transmit and receive dB gain of the FXO
channel. Teridian FXO supports transmit gain from -26 to +12 dB, and receive gain from -24 to +10 dB.
Select PCM sample rate. The 73M1x66B device can operate in one of two sample rates – 8 kHz or
16 kHz sample rate. The device defaults to 8 kHz operation upon startup and can be changed to run at
16 kHz using this API.
Notes: Changing the PCM sample rate will affect the following:
1. Data pres ent ed in PCM tim es lots – reallocation of transmit and receive timeslots may be necessary
or required to properly communicate with peer interface.
2. Barrier interface operation – a momentary loss of synchronization on the barrier interface is expected.
However, the driver will automatically attempt to recover barrier synchronization. The SYNC lost
event is sent and should be followed by SYNC restored event when the barrier is synced up again.
This section contains the detail description of the data structure used in this API subsystem. Table 2
contains the summary of the reference structure.
Table 2: Structure Overview
Name Description
Device or Channel handle.
Channel Init structure.
PCM interface config structure.
PCM timeslot config structure.
Defines the country default parameters.
Overrides the threshold parameter of the FXO line.
Rev. 2.1 41
Page 42
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
int
chanNum
int
fd
void
(*eventCallback)()
int
Initialized
3.1 M1x66_HANDLE_t
Description
The device or channel handle is a pointer to a device or channel control data structure where information
pertaining to device or channel is being kept. This control data structure is creat ed when the de vic e or
channel is opened and is used by the API internal subsystem to indentify the device or channel until it is
closed.
Prototype
/*
**************************************************************************
** Device/Channel Control block
*************************************************************************/
typedef struct {
int chanNum;
int fd;
void (*eventCallback)(M1x66_EVENT_ID,
unsigned int,
unsigned int,
unsigned int,
unsigned int,
unsigned int);
int initialized;
}
m1966_DevChanHandle;
/* Device or channel handle */
typedef m1966_DevChanHandle *M1x66_HANDLE_t;
Parameters
Data Type Name Description
Device or channel num ber .
Device or channel corresponding file descriptor.
An event callback function pointer, used only for device.
Initialization flag.
42 Rev. 2.1
Page 43
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
char
nMode
M1x66_COUNTRY_CODE
nCountry
void *
pProc
3.2 M1x66_CHAN_INIT_t
Description
Channel initialization structure. This structure contains mainly the country code. The
M1x66_InitChannel API passes the pointer to this data structure to configure the channel to operate in
a specific region. Refer to M1x66_COUNTRY_CODE for the list of countries supported.
PCM interface config structure. This structure contains the PCM interface configuration parameter.
These parameters are usually static and do not change from session to session. The
M1x66_PcmIfConfig API passes the pointer to this structure to configure the PCM interface.
Prototype
/*
**************************************************************************
** PCM Interface Config Structure
*************************************************************************/
typedef struct {
int pcmOperMode;
int pcmFrequency;
int pcmRxEdgePolarity;
int pcmTxEdgePolarity;
int pcmRxClockSlot;
int pcmTxClockSlot;
}
m1966_PcmIfConfig;
typedef m1966_PcmIfConfig M1x66_PCM_IF_CFG_t;
Edge polarity to be considered for the PCM
receive direction.
0 – Falling edge.
1 – Rising edge.
Edge polarity to be considered for the PCM
transmit direction.
0 – Falling edge.
1 – Rising edge.
Receive clock slot bit offset.
Transmit clock slot bit offset.
44 Rev. 2.1
Page 45
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
Int
pcmTimeslotRX
Int
pcmTimeslotTX
3.4 M1x66_PCM_CFG_t
Description
PCM config structure. This structure contains the PCM timeslots and codec parameter. These
parameters are not static and may change from session to session. The M1x66_PcmConfig API passes
the pointer to this structure to configure the PCM timeslots and codec.
Prototype
/*
**************************************************************************
** PCM Config Structure
*************************************************************************/
typedef struct {
int pcmResolution;
int pcmTimeslotRX;
int pcmTimeslotTX;
}
m1966_PcmConfig;
typedef m1966_PcmConfig M1x66_PCM_CFG_t;
PCM timeslot for receive direction.
PCM timeslot for transmit direction.
Rev. 2.1 45
Page 46
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
unsigned int
cnum
M1x66_COUNTRY_CODE
unsigned char
ccode[4]
unsigned char
country[16]
unsigned int
ac_impedance
unsigned int
dc_vi_mask
unsigned int
rgth_value
int
auto_cid_enable
int
use_seize_mode
unsigned char
acz
unsigned char
dciv
DC current voltage characteristic control
unsigned char
rgth
3.5 M1966_CNTRY_STRUCT_t
Description
This structure defines the country default parameters.
Prototype
typedef struct m1966_cntry_struct
{
unsigned int cnum; /* Country code */
unsigned char ccode[4]; /* Two letter internet country code */
unsigned char country[16]; /* Country Name */
unsigned int ac_impedance;
unsigned int dc_vi_mask;
unsigned int rgth_value;
int auto_cid_enable; /* automatically enable CID */
int use_seize_state; /* ring tone, silent duration */
} M1966_CNTRY_STRUCT_t;
Parameters
Data Type Name Transmit
Country code (see
Two letter country code.
Country name.
AC impedance.
DC VI mask.
Ring voltage threshold.
Automatic CID enable.
Seize mode enable.
).
3.6 M1966_THRESH_OVERRIDE_t
Description
This structure can be used to override the threshold parameter of the FXO line.
Prototype
typedef struct
{
unsigned char acz; /* Active Termination Loop */
unsigned char dciv; /* DC current voltage charac. control */
unsigned char rgth; /* Ring threshold
}
M1966_THRESH_OVERRIDE_t;
Parameters
Data Type Name Description
Active termination loop
Ring threshold
46 Rev. 2.1
Page 47
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
M1x66_RET
M1x66_EVENT_ID
M1x66_COUNTRY_CODE
M1x66_DCL_FREQUENCY
M1x66_HOOK_SWITCH
M1x66_REG_TYPE
M1x66_REG_ACCESS_TYPE
M1966_GPIO_NUMBER
M1966_GPIO_CONFIG_COMMAND
M1966_GPIO_CONTROL_TYPE
M1966_GPIO_DATA_COMMAND
M1966_GPIO_DATA_TYPE
M1966_GPIO_SIGNAL_DIRECTION
M1966_GPIO_INTR_POLARITY
M1x66_DEBUG_TRACE_MASK
4 Enumerator Reference
This section contains the detail description of the enumerated data reference used in this API subsystem.
Table 3 contains the summary of the enumerated data reference.
Table 3: Enumerator Overview
Name Description
Return status code from API.
FXO event identification.
List of country code supported.
DCL frequency supported.
On and off hook.
List of 1x66 device H/W register.
Register access type.
List of GPIO pin definition.
GPIO configuration command.
GPIO control type definition.
GPIO data access command.
GPIO data types.
Designate the GPIO pin as either input or output.
GPIO Interrupt signal transition edge selection.
Defines all debug trace masks.
Rev. 2.1 47
Page 48
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_SUCCESS
0
M1x66_FAILED
-1
4.1 M1x66_RET
Description
API function return code. All APIs, expect the open device and open channel, return with M1x66_RET
code. For additional error inform ation when an API retur ns M1x66_FAILED the application program can
issue a get last error – M1x66_GetLastError.
GPIO interrupt event.
No other phone off-hook.
Another phone off-hook.
FXO line polarity changed.
Battery – FXO line is not feeded.
Battery – FXO line is feeded.
FXO line stopped ringing.
FXO line starts ringing.
FXO device lost synchronization.
SPI device error detected.
FXO line goes on-hook.
Over voltage condition detected.
Over current condition detected.
Over load condition detected.
Under voltage condition detected.
Rev. 2.1 49
Page 50
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1x66_EVENT_LINE_STATE
0x00000100
M1x66_EVENT_QUALIFIED_RING
0x00000080
Line state event – current/voltage.
Qualified ring cadence detected.
50 Rev. 2.1
Page 51
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
4.3 M1x66_COUNTRY_CODE
Description
List of country codes supported by the API subsystem.
GPIO5 – pin 25 of 73M1906B 32-pin QFN.
GPIO6 – pin 32 of 73M1906B 32-pin QFN.
GPIO7 – pin 1 of 73M1906B 32-pin QFN.
Rev. 2.1 57
Page 58
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1966_GPIO_CONFIG_GET
0
M1966_GPIO_CONFIG_SET
1
M1966_GPIO_CONTROL_DISABLE
0
M1966_GPIO_CONTROL_ENABLE
1
4.9 M1966_GPIO_CONFIG_COMMAND
Description
This is the GPIO configuration command. The GPIO can be configured using the
M1966_GPIO_CONFIG_SET command. Its configuration can be read using M1966_GPIO_CONFIG_GET
command. The GPIO must be enabled using the M1966_GPIO_CONTROL ioctl for the new configuration
to take effect.
GPIO data access command. If the M1966_GPIO_SIGNAL_DIRECTION is set to
M1966_GPIO_DIR_INPUT, perform the M1966_GPIO_DATA_GET returns the logical value of type
M1966_GPIO_DATA_TYPE of the appropriate GPIO as an input. If the
M1966_GPIO_SIGNAL_DIRECTION is set to M1966_GPIO_DIR_OUTPUT, the corresponding GPIO port
GPIO data types – this is the GPIO data returned from the M1966_GPIO_DATA_GET access command,
or data to be written to the GPIO port using the M1966_GPIO_DATA_SET access command.
Prototype
typedef enum
{
M1966_GPIO_DATA_LOW = 0, /* GPIO data - low */
M1966_GPIO_DATA_HIGH = 1 /* GPIO data - high */
}
M1966_GPIO_DATA_TYPE;
Parameters
Name Value Description
GPIO data - low
GPIO data - high
Rev. 2.1 59
Page 60
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
M1966_GPIO_DIR_INPUT
0
M1966_GPIO_DIR_OUTPUT
1
M1966_GPIO_POL_RISING
0
M1966_GPIO_POL_FALLING
1
4.13 M1966_GPIO_SIGNAL_DIRECTION
Description
GPIO pin signal direction. This control bit is used to designate the GPIO pin as either input or output.
Prototype
typedef enum {
M1966_GPIO_DIR_INPUT = 0, /* GPIO pin signal direction – INPUT */
M1966_GPIO_DIR_OUTPUT = 1 /* GPIO pin signal direction - OUTPUT */
}
M1966_GPIO_SIGNAL_DIRECTION;
Parameters
Name Value Description
GPIO pin signal direction – INPUT
GPIO pin signal direction - OUTPUT
4.14 M1966_GPIO_INTR_POLARITY
Description
GPIO Interrupt signal transition edge selection. The defines the interrupt source as being either on a
rising or a falling edge of the corresponding GPIO pin. If configured as M1966_GPIO_POL_RISING a
rising edge will trigger an interrupt from the corresponding GPIO pin. If configured as
M1966_GPIO_POL_FALLING a falling edge will trigger an interrupt from the corresponding GPIO pin.
Event trace mask.
Initialization trace mask.
Ring path analysis trace mask.
Function level trace mask.
Country code processing trace mask.
Line state analysis path trace mask.
IOCTL trace mask.
PCM trace mask.
Barrier related function trace mask.
Interrupt trace mask.
Phone hung up in off-hook trace mask.
TAPI related trace mask.
Kernel processing trace mask.
SPI related trace mask.
Error trace mask.
Rev. 2.1 61
Page 62
73M1866B/73M1966B FXOAPI User Guide UG_1x66B_046
5 Sample Application
This section illustrates how an FXO application can be implemented using the FXOAPIs. The sample
program is a typical telephony application that automatically answers the call when a ring burst is
detected. This is accomplished by simply going off -hook.
Note: this sample program will definitely not compile and is not a complete application. It is intended only
for demonstration purpose to show the capability and to illustrate the interaction between the application
program and the FXOAPI.
/****************************************************************
**
** FXO sample application
**
** Perform the following:
** - Initialize the API subsystem – M1x66_ApiInit()
** - Open the FXO device - M1x66_OpenDevice()
** - Open each channel - M1x66_OpenChannel()
** - Config PCM interface - M1x66_PcmIfConfig()
** - Initialize channel - M1x66_InitChannel()
**
*****************************************************************/
int main (int argc, char **argv)
{
ret = M1x66_PcmIfConfig (channels[i].pHandle, &pcmIfConfig);
if (ret != M1x66_SUCCESS)
return (-1);
62 Rev. 2.1
Page 63
UG_1x66B_046 73M1866B/73M1966B FXOAPI User Guide
/* Initialize the channel for operation in US */
if (M1x66_InitChannel (channels[i].pHandle, M1x66_CNTRY_CODE_US)
!= M1x66_SUCCESS)
return (-1);
}
/* program main loop */
While (1)
{
/* this is the main program loop…
/* . . . */
}
/* Release the API subsystem before exiting */
M1x66_RET M1x66_FxoApiRelease (void);
Return (0);
}
/*
*****************************************************************************
***********************
* FUNCTION NAME:
* fxoEventCallback
*
* DESCRIPTION:
* This is the FXO event callback function. It is invoked by the API
* subsystem when an FOX event occurs. Currently, this callback function
* only handles the RING start event. It takes the FXO line off-hook when
* the ring burst is detected.
*
* PARAMETERS:
* event_id - Event ID
* channelId - FXO channel where event is occurring
* data1 - Additional data (1)
* data2 - Additional data (2)
* data3 - Additional data (3)
* data4 - Additional data (4)
*
* RETURNS:
* N/A
*****************************************************************************
***********************
*/
void fxoEventCallback (M1x66_EVENT_ID event_id,
unsigned int channelId,
unsigned int data1,
unsigned int data2,
unsigned int data3,
unsigned int data4)
{
int ret;
M1x66_HANDLE pHandle;
M1x66_PCM_CFG pcmConfig;