![]() |
m2mb API docs
25.30.003
m2mb API sets documentation
|
USB library implementation. More...
Go to the source code of this file.
Data Structures | |
| struct | M2MB_USB_CFG_T |
| USB ioctl configuration. More... | |
Macros | |
| #define | NULL 0 |
| #define | M2MB_USB_CABLE_ATTACHED TRUE |
| #define | M2MB_USB_CABLE_DETACHED FALSE |
Typedefs | |
| typedef void(* | m2mb_usb_ind_callback) (INT32 fd, M2MB_USB_IND_E usb_event, UINT16 resp_size, void *resp_struct, void *userdata) |
| Transmit and receive operation callback type. More... | |
| typedef struct M2MB_USB_HANDLE_TAG * | M2MB_USB_HANDLE |
Enumerations | |
| enum | M2MB_USB_IOCTL_REQUEST { M2MB_USB_IOCTL_SET_CFG = 0, M2MB_USB_IOCTL_GET_CFG, M2MB_USB_IOCTL_SET_CB, M2MB_USB_IOCTL_GET_CB, M2MB_USB_IOCTL_SET_USERDATA, M2MB_USB_IOCTL_GET_USERDATA, M2MB_USB_IOCTL_SET_DCD, M2MB_USB_IOCTL_GET_RTS_STATE, M2MB_USB_IOCTL_GET_DTR_STATE, M2MB_USB_IOCTL_GET_CABLE_STATE, M2MB_USB_IOCTL_SET_DTR_FCTL, M2MB_USB_IOCTL_GET_DTR_FCTL, M2MB_USB_IOCTL_SET_DSR, M2MB_USB_IOCTL_SET_RING, M2MB_USB_IOCTL_SET_TX_TIMEOUT, M2MB_USB_IOCTL_GET_TX_TIMEOUT, M2MB_USB_IOCTL_SET_RX_TIMEOUT, M2MB_USB_IOCTL_GET_RX_TIMEOUT, M2MB_USB_IOCTL_NOF_REQ } |
| USB configuration requests. More... | |
| enum | M2MB_USB_IND_E { M2MB_USB_RX_EVENT, M2MB_USB_TX_EVENT, M2MB_USB_CABLE_CONNECTED_EVENT, M2MB_USB_DTR_EVENT } |
| USB event type. More... | |
| enum | M2MB_USB_SIGNAL_VALUE_E { M2MB_USB_LOW_VALUE, M2MB_USB_HIGH_VALUE } |
| USB control signal value. More... | |
Functions | |
| INT32 | m2mb_usb_open (const CHAR *path, INT32 flags,...) |
| m2mb_usb_open opens a USB device. More... | |
| INT32 | m2mb_usb_close (INT32 fd) |
| m2mb_usb_close closes a USB device. More... | |
| INT32 | m2mb_usb_ioctl (INT32 fd, INT32 request,...) |
| m2mb_usb_ioctl configures an open USB device. More... | |
| SSIZE_T | m2mb_usb_read (INT32 fd, void *buf, SIZE_T nbyte) |
| m2mb_usb_read More... | |
| SSIZE_T | m2mb_usb_write (INT32 fd, const void *buf, SIZE_T nbyte) |
| m2mb_usb_write More... | |
| INT32 | m2mb_usb_isCableAttached (const CHAR *path) |
| m2mb_usb_isCableAttached More... | |
USB library implementation.
m2m/m2m_generic/common/m2mb_inc/m2mb_usb.h
The following functions are implemented: m2mb_usb_ioctl m2mb_usb_open m2mb_usb_read m2mb_usb_write m2mb_usb_close
@notes Dependencies: m2m/m2m_generic/common/m2mb_inc/m2mb_types.h
| typedef void( * m2mb_usb_ind_callback) (INT32 fd, M2MB_USB_IND_E usb_event, UINT16 resp_size, void *resp_struct, void *userdata) |
Transmit and receive operation callback type.
This type defines the callback functions that the client can register by m2mb_usb_ioctl API. The user callback function is called when an event is received.
| enum M2MB_USB_IND_E |
USB configuration requests.
This enum defines the requests wich can be passed to the function m2mb_usb_ioctl()
| INT32 m2mb_usb_close | ( | INT32 | fd | ) |
m2mb_usb_close closes a USB device.
m2mb_usb_close closes a USB device freeing the data associated to the file descriptor passed as parameter.
| [in] | fd | file descriptor returned by m2mb_usb_open() |
m2mb_usb_close(fd);
| INT32 m2mb_usb_ioctl | ( | INT32 | fd, |
| INT32 | request, | ||
| ... | |||
| ) |
m2mb_usb_ioctl configures an open USB device.
m2mb_usb_ioctl sets/gets the USB device settings by means of requests listed in enum M2MB_USB_IOCTL_REQUEST.
| [in] | fd | File Descriptor returned by m2mb_usb_open() |
| [in] | request | the action to be performed. The allowed values are those listed in enum M2MB_USB_IOCTL_REQUEST. |
| [in,out] | cfg | parameter of the request: can be a pointer to a previously defined variable or a value, depending on the action requested by the second parameter (see following note for further details). |
Action: M2MB_USB_IOCTL_SET_CFG
Description: set usb device configuration for setting user callback and data
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pCfgStruct(M2MB_USB_CFG_T *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_CFG, &cfgStruct)
Action: M2MB_USB_IOCTL_GET_CFG
Description: get usb device configuration with current user callback and data
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pCfgStruct(M2MB_USB_CFG_T *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_CFG, &cfgStruct)
Action: M2MB_USB_IOCTL_SET_CB
Description: set callback function pointer (if NULL, action is synchronous)
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), cb_fn(m2mb_usb_ind_callback)
Note: When a USB callback is set, the m2mb_usb_read can be used inside the callback with the M2MB_USB_RX_EVENT event or outside the callback in another thread, where it will get the data if it has not been already read
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_CB, cb_fn)
Action: M2MB_USB_IOCTL_GET_CB
Description: get callback function pointer (if NULL, action is synchronous)
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pCb_fn(m2mb_usb_ind_callback *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_CB, &cb_fn)
Action: M2MB_USB_IOCTL_SET_USERDATA
Description: set callback data pointer
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), cbData(void *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_USERDATA, cbData)
Action: M2MB_USB_IOCTL_GET_USERDATA
Description: get callback data pointer
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pCbData(void **)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_USERDATA, &cbData)
Action: M2MB_USB_IOCTL_SET_DCD
Description: set usb DCD level
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), dcdLevel(M2MB_USB_SIGNAL_VALUE_E)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_DCD, dcdLevel)
Action: M2MB_USB_IOCTL_SET_DSR
Description: set usb DSR level
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), dsrLevel(M2MB_USB_SIGNAL_VALUE_E)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_DSR, dsrLevel)
Action: M2MB_USB_IOCTL_SET_RING
Description: set usb RING level
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), ringLevel(M2MB_USB_SIGNAL_VALUE_E)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_RING, ringLevel)
Action: M2MB_USB_IOCTL_GET_RTS_STATE
Description: get usb RTS state
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pRtsLevel(M2MB_USB_SIGNAL_VALUE_E *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_RTS_STATE, &rtsLevel)
Action: M2MB_USB_IOCTL_GET_DTR_STATE
Description: get usb DTR state
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pDtrLevel(M2MB_USB_SIGNAL_VALUE_E *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_DTR_STATE, &dtrLevel)
Action: M2MB_USB_IOCTL_GET_CABLE_STATE
Description: get usb cable state attached or detached
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pCableState(BOOLEAN *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_CABLE_STATE, &cableState)
Action: M2MB_USB_IOCTL_SET_DTR_FCTL
Description: set usb DTR flow control
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), dtrFctl(INT32)
Note: This command configures the behavior of the outbound flow according to the DTR control line level transitions. Admitted parameter values are: 1 : DTR level transitions control the outbound data flow. If DTR is asserted, the output data is sent; if DTR is not asserted, the output data is blocked. 2 : Like setting 1, but receiving input data has the same effect of a low to high level transition. Therefore, if the DTR is not asserted, or if it is asserted but its level has not been signaled by the DTE to the DCE, after receiving input data the DTR is considered asserted. A new DTR level transition from asserted to not asserted will block again the outbound flow.
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_DTR_FCTL, dtrFctl)
Action: M2MB_USB_IOCTL_GET_DTR_FCTL
Description: get usb DTR flow control
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pDtrFctl(INT32 *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_DTR_FCTL, &dtrFctl)
Action: M2MB_USB_IOCTL_SET_TX_TIMEOUT
Description: set synchronous write timeout in ms (if 0, waits indefinitely until the write is completed)
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), timeout(UINT16)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_TX_TIMEOUT, 100)
Action: M2MB_USB_IOCTL_GET_TX_TIMEOUT
Description: get synchronous write timeout in ms (if 0, waits indefinitely until the write is completed)
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pTimeout(UINT16 *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_TX_TIMEOUT, &timeout)
Action: M2MB_USB_IOCTL_SET_RX_TIMEOUT
Description: set synchronous read timeout in ms (if 0, waits indefinitely until the read is completed)
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), timeout(UINT16)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_RX_TIMEOUT, 100)
Action: M2MB_USB_IOCTL_GET_RX_TIMEOUT
Description: get synchronous read timeout in ms (if 0, waits indefinitely until the read is completed)
Params(in): fd(INT32), request(M2MB_USB_IOCTL_REQUEST), pTimeout(UINT16 *)
Example: m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_RX_TIMEOUT, &timeout)
m2mb_uSB_ioctl(fd, request, cfg);
| INT32 m2mb_usb_isCableAttached | ( | const CHAR * | path | ) |
m2mb_usb_isCableAttached
Check if the USB cable is connected
| [in] | path | /dev/USB# where # is in decimal format. path can be NULL and checks the connection of the primary or the unique USB cable, otherwise only USB channel related cable is checked |
@code
int main() { INT32 is_cable_conn; is_cable_conn = m2mb_usb_isCableAttached("/dev/USB0");
if( is_cable_conn == 1 ) printf( "USB cable connected"); else if( is_cable_conn == 0 ) printf( "USB cable disconnected"); else printf( "Error reading usb connection"); }
| INT32 m2mb_usb_open | ( | const CHAR * | path, |
| INT32 | flags, | ||
| ... | |||
| ) |
m2mb_usb_open opens a USB device.
m2mb_usb_open opens a USB device returning the file descriptor that must be passed as first parameter for all the other USB actions. Calling the m2mb_usb_open is mandatory before using the USB device.
| [in] | path | first parameter is the path to the USB device, that will be initialized by the function. It is a string like "/dev/usbX" where X is the USB instance index in decimal format. Path "/dev/usb" is equivalent to default "/dev/usb0". |
| [in] | flags | second parameter is the access mode flags. Currently unused |
m2mb_usb_open(path, flags);
| SSIZE_T m2mb_usb_read | ( | INT32 | fd, |
| void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
m2mb_usb_read
read nbyte Bytes from a USB device into the array pointed to by buf
| [in] | fd | file descriptor returned by m2mb_usb_open |
| [in] | buf | destination buffer, previously allocated |
| [in] | nbyte | length of destination buffer in Bytes |
| SSIZE_T m2mb_usb_write | ( | INT32 | fd, |
| const void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
m2mb_usb_write
write nbyte Bytes from the array pointed to by buf to a USB device
| [in] | fd | file descriptor returned by m2mb_usb_open |
| [in] | buf | source buffer, previously allocated |
| [in] | nbyte | length of source buffer in Bytes |