m2mb API docs  25.20.008
m2mb API sets documentation
m2mb_usb.h File Reference

USB library implementation. More...

Go to the source code of this file.

Data Structures

struct  M2MB_USB_CFG_T
 

Macros

#define NULL   0
 

Typedefs

typedef void(* m2mb_usb_ind_callback) (INT32 fd, M2MB_USB_IND_E usb_event, UINT16 resp_size, void *resp_struct, void *userdata)
 
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_NOF_REQ
}
 
enum  M2MB_USB_IND_E { M2MB_USB_RX_EVENT, M2MB_USB_TX_EVENT }
 

Functions

INT32 m2mb_usb_open (const CHAR *path, INT32 flags,...)
 m2mb_usb_open More...
 
INT32 m2mb_usb_close (INT32 fd)
 m2mb_usb_close More...
 
INT32 m2mb_usb_ioctl (INT32 fd, INT32 request,...)
 m2mb_usb_ioctl 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...
 

Detailed Description

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

Author
Morgan Deidda
Date
30/11/2017

Function Documentation

◆ m2mb_usb_close()

INT32 m2mb_usb_close ( INT32  fd)

m2mb_usb_close

close a USB device

Parameters
[in]fdfile descriptor returned by m2mb_usb_open
Returns
0 on SUCCESS -1 on FAILURE
Note

int main()
{
INT32 fd;
INT32 retVal;
fd = m2mb_usb_open("/dev/USB0", 0);
//... use USB device ...
retVal = m2mb_usb_close(fd);
if ( retVal != -1 )
printf( "m2mb_usb_close succeeded");
}

◆ m2mb_usb_ioctl()

INT32 m2mb_usb_ioctl ( INT32  fd,
INT32  request,
  ... 
)

m2mb_usb_ioctl

configure a USB device

Parameters
[in]fdfile descriptor returned by m2mb_usb_open
[in]requestrequired operation (see M2MB_USB_IOCTL_REQUEST)
[in]cfg_ptrpointer to the configuration struct, casted to void*
Returns
0 on SUCCESS -1 on FAILURE
Note

static void USB_Cb( INT32 fd, M2MB_USB_IND_E usb_event, UINT16 resp_size, void *resp_struct, void *userdata )
{
//...
}
int main()
{
INT32 fd;
INT32 retVal;
fd = m2mb_usb_open("/dev/USB0", 0);
//...
retVal = m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_GET_CFG, &cfg);
if ( retVal != -1 )
printf( "m2mb_usb_ioctl: get cfg struct succeeded");
// modify some configuration structure fields...
cfg.m2mb_usb_app_cb_func = USB_Cb;
//...
retVal = m2mb_usb_ioctl(fd, M2MB_USB_IOCTL_SET_CFG, &cfg);
if ( retVal != -1 )
printf( "m2mb_usb_ioctl: set cfg struct succeeded");
}

◆ m2mb_usb_open()

INT32 m2mb_usb_open ( const CHAR *  path,
INT32  flags,
  ... 
)

m2mb_usb_open

open a USB device

Parameters
[in]path/dev/USB# where # is in decimal format
[in]flagscurrently unused
[in]...
Returns
file descriptor on SUCCESS -1 on FAILURE
Note

int main()
{
INT32 fd;
fd = m2mb_usb_open("/dev/USB0", 0);
if ( fd != -1 )
printf( "m2mb_usb_open succeeded");
}

◆ m2mb_usb_read()

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

Parameters
[in]fdfile descriptor returned by m2mb_usb_open
[in]bufdestination buffer, previously allocated
[in]nbytelength of destination buffer in Bytes
Returns
number of read Bytes on SUCCESS -1 on FAILURE
Note

#define BUF_LEN 32
int main()
{
INT32 fd;
INT32 rdBytes;
UINT8 dstBuf[BUF_LEN];
fd = m2mb_usb_open("/dev/USB0", 0);
//...
rdBytes = m2mb_usb_read(fd, dstBuf, BUF_LEN);
if ( rdBytes >= 0 )
printf( "m2mb_usb_read succeeded");
}

◆ m2mb_usb_write()

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

Parameters
[in]fdfile descriptor returned by m2mb_usb_open
[in]bufsource buffer, previously allocated
[in]nbytelength of source buffer in Bytes
Returns
number of written Bytes on SUCCESS -1 on FAILURE
Note

#define BUF_LEN 32
#define WR_BYTE_VAL 0xAB
int main()
{
INT32 fd;
INT32 wrBytes;
UINT8 srcBuf[BUF_LEN];
fd = m2mb_usb_open("/dev/USB0", 0);
//...
memset(srcBuf, WR_BYTE_VAL, BUF_LEN);
wrBytes = m2mb_usb_write(fd, srcBuf, BUF_LEN);
if ( wrBytes >= 0 )
printf( "m2mb_usb_write succeeded");
}
m2mb_usb_write
SSIZE_T m2mb_usb_write(INT32 fd, const void *buf, SIZE_T nbyte)
m2mb_usb_write
M2MB_USB_CFG_T
Definition: m2mb_usb.h:61
m2mb_usb_read
SSIZE_T m2mb_usb_read(INT32 fd, void *buf, SIZE_T nbyte)
m2mb_usb_read
m2mb_usb_close
INT32 m2mb_usb_close(INT32 fd)
m2mb_usb_close
m2mb_usb_ioctl
INT32 m2mb_usb_ioctl(INT32 fd, INT32 request,...)
m2mb_usb_ioctl
m2mb_usb_open
INT32 m2mb_usb_open(const CHAR *path, INT32 flags,...)
m2mb_usb_open