FORGOT YOUR DETAILS?

CREATE ACCOUNT

Unison Help

  1. Unison Kernel
    1. Pthreads
      1. pthread_create()
      2. pthread_exit()
      3. pthread_self()
      4. pthread_equal()
      5. pthread_join()
      6. pthread_detach()
      7. pthread_setschedparam()
      8. pthread_getschedparam()
      9. pthread_attr_init()
      10. pthread_attr_destroy()
      11. pthread_attr_setstackaddr()
      12. pthread_attr_getstackaddr()
      13. pthread_attr_setstacksize()
      14. pthread_attr_getstacksize()
      15. pthread_attr_setschedparam()
      16. pthread_attr_getschedparam()
      17. pthread_attr_setdetachstate()
      18. pthread_attr_getdetachstate()
      19. pthread_stackinfo()
      20. pthread_setprio()
      21. pthread_getprio()
      22. sched_get_priority_max()
      23. sched_get_priority_min()
      24. sched_yield()
    2. Pthread Cancellation
      1. pthread_cleanup_pop()
      2. pthread_cleanup_push()
      3. pthread_cancel()
      4. pthread_setcanceltype()
      5. pthread_setcancelstate()
      6. pthread_testcancel()
    3. Mutex
      1. pthread_mutex_init()
      2. pthread_mutex_destroy()
      3. pthread_mutex_lock()
      4. pthread_mutex_trylock()
      5. pthread_mutex_unlock()
    4. Semaphores
      1. sem_open()
      2. sem_close()
      3. sem_unlink()
      4. sem_init()
      5. sem_destroy()
      6. sem_wait()
      7. sem_trywait()
      8. sem_timedwait()
      9. sem_post()
      10. sem_getvalue()
    5. Message Queues
      1. mq_open()
      2. mq_close()
      3. mq_unlink()
      4. mq_send()
      5. mq_receive()
      6. mq_notify()
      7. mq_setattr()
      8. mq_getattr()
      9. mq_timedreceive()
      10. mq_timedsend()
    6. Conditional Variables
      1. pthread_cond_init()
      2. pthread_cond_destroy()
      3. pthread_cond_wait()
      4. pthread_cond_timedwait()
      5. pthread_cond_signal()
      6. pthread_cond_broadcast()
      7. pthread_condattr_init()
      8. pthread_condattr_destroy()
    7. Barriers
      1. pthread_barrier_init()
      2. pthread_barrier_destroy()
      3. pthread_barrier_wait()
    8. Timers
      1. timer_create()
      2. timer_delete()
      3. timer_settime()
      4. timer_gettime()
      5. timer_getoverrun()
      6. timer_tick()
      7. nanosleep()
    9. Clocks
      1. time()
      2. uptime()
      3. sleep()
      4. clock_settime()
      5. clock_gettime()
      6. clock_getres()
      7. clock_init()
    10. Memory Allocation
      1. POSIX.1
        1. malloc()
        2. free()
      2. Variable Length (Pools)
        1. pool_create()
        2. pool_destroy()
        3. pool_alloc()
        4. pool_free()
      3. Fixed Length (Partitions)
        1. pt_create()
        2. pt_destroy()
        3. pt_getblock()
        4. pt_freeblock()
    11. Rendezvous
      1. mr_init()
      2. mr_send()
      3. mr_receive()
      4. mr_reply()
      5. mr_sigrecv()
      6. mr_sigpost()
    12. Interrupts
      1. interrupts
      2. i_disable()
      3. i_restore()
    13. Directory Services
      1. dir_register()
      2. dir_deregister()
      3. dir_lookup()
      4. dir_lookup_string()
    14. Miscellaneous
      1. checkIstack()
      2. NanoStart() or DSPexec_Start()
      3. _isrStackFill
      4. Kernel Scaling
      5. kfatal()
      6. kalloc()
      7. kfree()
      8. mpu or mmu
      9. pthreadStackFill
      10. thread_numb()
      11. thread_utilization_start()
      12. thread_utilization_stop()
      13. xprintf()
      14. xputs()
      15. xputchar()
  2. Unison I/O Library
    1. accept()
    2. bind()
    3. chmod()
    4. close()
    5. connect()
    6. creat()
    7. fstat()
    8. getpeername()
    9. getsockname()
    10. getsockopt()
    11. ioctl()
    12. link()
    13. listen()
    14. lseek()
    15. mkdir()
    16. mkfs()
    17. mount()
    18. open()
    19. read()
    20. recv()
    21. recvfrom()
    22. rename()
    23. renameat()
    24. rmdir()
    25. select()
    26. send()
    27. sendto()
    28. setsockopt()
    29. shutdown()
    30. socket()
    31. stat()
    32. sync()
    33. umount()
    34. unlink()
    35. write()
  3. Unison STDIO Library
    1. STDIO Library Calls
      1. clearerr()
      2. dprintf()
      3. fclose()
      4. fdopen()
      5. feof()
      6. ferror()
      7. fileno()
      8. fflush()
      9. fgetc()
      10. fgetpos()
      11. fgets()
      12. fopen()
      13. fprintf()
      14. fputc()
      15. fputs()
      16. fread()
      17. freopen()
      18. fscanf()
      19. fseek()
      20. fseeko()
      21. fsetpos()
      22. ftell()
      23. ftello()
      24. fwrite()
      25. getc()
      26. getc_unlocked()
      27. getchar()
      28. getchar_unlocked()
      29. getdelim()
      30. getline()
      31. gets()
      32. get_stderr_ptr()
      33. get_stdin_ptr()
      34. get_stdout_ptr()
      35. noperprintf()
      36. perprintf()
      37. perror()
      38. posix_compat()
      39. printf()
      40. putc()
      41. putc_unlocked()
      42. putchar()
      43. putchar_unlocked()
      44. puts()
      45. remove()
      46. rewind()
      47. scanf()
      48. setbuf()
      49. setvbuf()
      50. snprintf()
      51. sprintf()
      52. sscanf()
      53. stderr_init()
      54. stderr_close()
      55. stdin_init()
      56. stdin_close()
      57. stdout_init()
      58. stdout_close()
      59. vdprintf()
      60. vscanf()
      61. vsscanf()
      62. vfscanf()
      63. vprintf()
      64. vsnprintf()
      65. vsprintf()
      66. vfprintf()
      67. ungetc()
    2. Do-nothing Stubs
      1. ctermid()
      2. flockfile()
      3. fmemopen()
      4. ftrylockfile()
      5. open_memstream()
      6. pclose()
      7. popen()
      8. tempnam()
      9. tmpfile()
      10. tmpnam()
  4. Unison LIBC Library
    1. LIBC Library Calls
      1. assert()
      2. realloc()
      3. strcasecmp()
      4. strdup()
      5. strncasecmp()
      6. strftime()
    2. Do-nothing Stubs
      1. abort()
      2. execve()
      3. exit()
      4. _Exit()
      5. fork()
      6. getpid()
      7. isatty()
      8. kill()
      9. sbrk()
      10. times()
      11. wait()
    3. Do-nothing Wide-character Stubs
      1. <wchar.h>
      2. <wctype.h>
  5. Unison I/O Servers
    1. File Servers
      1. Multimedia File Server - fsys
      2. FAT File System - fatfs
      3. NAND File Server - nandfsys
      4. NOR File Server - norfsys
      5. Network File Server - nfs
  6. Graphics, Camera, Video, Audio
    1. Vendor Graphics
    2. Prism++ Graphics
    3. ADPCM Services - adpcmd
    4. Camera
  7. Network Protocols
    1. TCP and UDP Server - tcpd
      1. IPv4 only server
      2. IPv4/IPv6 server
    2. DHCP Client Service - dhcp client
    3. DHCP Server - dhcpd
    4. Telnet Server - telnetd
    5. Tiny FTP Server - tftpd
    6. Point to Point - pppd
    7. Network Translation - NAT with PAT
    8. Firewall
      1. Packet filter: pf
      2. Packet filter control: pfctl
      3. Fitler rules: pf.filtering
      4. Translation rules: pf.nat
    9. Tiny HTTP Server - thttpd
    10. Tiny HTTP Server with TLS
    11. POP3 Server
    12. Simple Mail Transfer Protocol Services (SMTP)
    13. Bootp Protocol
    14. File Transfer Protocol Server (FTP)
    15. File Transfer Client Services
    16. RPC / XDR
    17. DNS Client
    18. HTTP/HTTPS Client
    19. REST Client
    20. AutoIP Service - autoip client
    21. mDNS server - mdnsd
    22. SNTP Client
    23. SNMP Agent - Snmpd server
    24. SSL/TLS library
    25. SSH server
    26. IP security
      1. IPsec description
      2. IPsec administration: ipsecadm
      3. Virtual Private Network: VPN
    27. Power Control
      1. Motor and Motion Control Servers
      2. PWM, Encoders
    28. Serial I/O
      1. Asynchronous Serial I/O Server - ttyserver
      2. CAN Server - cand
      3. I2C Server - i2cd
      4. I2S Server - i2sd
    29. System Services
      1. Power Management Servers
      2. Login Service - login_services
      3. XML
      4. POSIX Shell and Login Service - posh
    30. Universal Serial Bus (USB)
      1. USB Server
      2. USB Device Server
      3. USB Embedded Host Server
    31. Wireless
      1. Wireless Servers and Drivers
      2. 802.15.4 Radio Servers
      3. TCP/v6 with 6loWPAN
      4. ZigBee
      5. BlueTooth Server
      6. 802.11 Wi-Fi
      7. GPRS, UHF and GPS Radio Servers
    32. Remedy Tools for Unison
      1. Remedy Data Logging and Event Display Tools
      2. Remedy Diagnostics
      3. Remedy Flash Downloader/Bootloader
      4. Remedy Power On Self Test - POST
      5. Remedy OS Object Viewer
      6. Remedy Remote Control Tools

7.30.2.USB Device Server #

NAME

USB Embedded Device Server – usbd

SYNOPSIS

#include <sys.h>

#include <usb/usb.h>

 

USB Device general API functions definition

int usbd_start(tUSB_core_conf * core_config);

function that called from usb server for initialization USB device core

void usbd_add_serial_driver(void);

register serial device class driver for USB device core.

void usbd_add_msc_driver(void);

register mass storage class device driver for USB device core

void usbd_add_mouse_driver(void);

register HID mouse device driver for USB device core

void usbd_add_keyboard_driver(void);

register HID keyboard device driver for USB device core

void usbd_add_extended_keyboard_driver(void);

register HID extension keyboard device driver for USB device core

void usbd_add_audio_driver(void);

register Audio device driver for USB device core

void usbd_add_audio_control_driver(void);

register Audio device driver for USB device core

int usbd_get_connect_state(uchar port);

return 1 – USB device connected to USB host and ready to work

return 0 – USB device disconnected or not ready to work.

USB HID Device API functions definition

int usbd_hid_keyboard_send_keys(char port, unsigned char key, unsigned char press);

Description

Send standard keyboard key code and state to USB Host.

Parameters

port – physical number of USB device controller at target

key – key code according to USB HID coding, see “usbd_hid_keyboard.h” for details.

press – specify is key pressed or released. Could be HID_KEY_SET/HID_KEY_CLEAR, see “usbd_hid_keyboard.h” for details.

Return

0 – success

-1 – error

int usbd_hid_keyboard_send_keys_extended(char port, unsigned char key, unsigned char press);

Description

Send Extended keyboard key (Volume_Up, Volume_Dn, Stop/Eject, Play/Pause, Mute, ….) code and state to USB Host.

Parameters

port – physical number of USB device controller at target

key – extended key code according to USB HID coding (“Consumer Page”), see “usbd_hid_keyboard.h” for details.

press – specify is key pressed or released. Could be HID_KEY_SET/HID_KEY_CLEAR, see “usbd_hid_keyboard.h” for details.

Return

0 – success

-1 – error

int usbd_hid_mouse_send_state(char port, signed char x, signed char y, unsigned char button);

Description

Send mouse state.

Parameters

port – physical number of USB device controller at target

x – change (increment/decrement) for X coordinate. Min val ±1, Max val ±127

y – change (increment/decrement) for Y coordinate. Min val ±1, Max val ±127

button – buttons state. Could be combination of buttons: HID_MOUSE_BUTTON1 | HID_MOUSE_BUTTON2 | HID_MOUSE_BUTTON3

Return

0 – success

-1 – error

Additional headers for HID devices.

#include <usb/usbd_hid_mouse.h>

define Mouse button codes for HID class

#include <usb/usbd_hid_keyboard.h>

define Keyboard key codes for HID class

USB Audio Device API functions definition

void usbd_audio_on(void);

Description

This function is called from the stack in response to a request from USB HOST to enable audio output

void usbd_audio_off(void);

Description

This function is called from the stack in response to a request from USB HOST to disable audio output

void usbd_audio_data(void);

Description

This function is called from the stack when USB device have available part of audio data stream for playback.

Return

pointer to audio data stream buffer.

void usbd_audio_data_size(void);

Description

This function is called from the USB device stack to inform stack with playback buffer size.

Return

buffer size.

Additional headers for Audio devices.

#include <usb/usbd_audio.h>

 

DESCRIPTION

The USB device stack designed for embedded systems equipped with a USB device controller.

The USB device stack is a modular architecture with three software elements providing functionality between the application and the hardware.

 

USB Device server structure


USB Server – run and manage usb device and usb host stack.

USB Device core – controls the reception and transmission of packets to and from the user application. It is a general framework providing a standardized interface between the application and the specific USB hardware.

USB Device function driver – implements the required USB device functionality (i.e. serial communications, mass storage, human interface …). The function driver provides the selected class implementation.

USB Device hardware port – provides the low-level interface between USB device controller hardware and USB device software stack.

The Unison USB Device solution consists of sets of libraries, which implement the stack (as shown in the figure, above). These libraries are organized as follows:

  • USB Server

– usb_server

  • USB Device core

usbd_core

  • USB Device function drivers

usbd_cdc_serial_driver

usbd_msc_driver

usbd_hid_keyboard_driver

usbd_hid_mouse_driver

– usbd_audio_driver

and so on, for any device class which is supported by The Unison USB Device solution

  • USB Device hardware porting layer

usbd_xxxxxxx_port, where xxxxxxx is chip type.

 

Initialization usb device

Additional parametrs for start USB Device describing below.

To start a USB device need to fill the following structures:

1. Firs – general usb device port info configurations:

typedef struct
{
        unsigned short       idVendor;            // Vendor ID for the USB product
        unsigned short       idProduct;           // Product ID for the USB product
        unsigned short       bcdDevice;           // Device release number in BCD format
        const char          *pManufacturer;       // Manufacturer string descriptor
        const char          *pProduct;            // Product string descriptor
        const char          *pSerialNumber;       // Serial number string descriptor
        tUSBD_configuration *pConfigurations;      
        unsigned char        NumConfigurations;   // Number of possible configurations for current port
} tUSBD_port_info;

the user needs to describe the general data about the device

idVendor – the vendor ID is assigned by the USB Implementers forum (www.usb.org).

For test, the default number above can be used.

However, you may not bring a product on the market without having been assigned your own vendor ID.

idProduct – the product ID build in combination with the vendor ID a worldwide unique identifier.

For test, the default number above can be used.

bcdDevice – the device release number

pManufacturer – the pointer on string describing manufacturer.

pProduct – the pointer on string describing product.

pSerialNumber – the pointer on string describing device’s serial number

NumConfigurations – the number of possible configurations for usb device

pConfigurations – the pointer on structure describing configurations for this usb device

Example:

        tUSBD_port_info     usbd_port;
        usbd_port.idVendor          = 0x0123;                     // Vendor ID for the USB product
        usbd_port.idProduct         = 0x4567;                     // Product ID for the USB product
        usbd_port.bcdDevice         = 0x0001;                     // Device release number in BCD format
        usbd_port.pManufacturer     = "RoweBots";                 // Manufacturer string descriptor
        usbd_port.pProduct          = "Unison RTOS USB Serial";   // Product string descriptor
        usbd_port.pSerialNumber     = "111004";                   // Serial number string descriptor
        usbd_port.pConfigurations   = &usbd_config;                
        usbd_port.NumConfigurations = 1;                          // Number of configurations for current port

2. Second description of possible configurations and electrical parameters:

typedef struct
{
        tUSBD_interface     *pInterfaces;
        unsigned char        NumInterfaces;       // Number of interfaces for current port
        const char          *pStrConfiguration;   // String Configuration Name
        char                 MaxPower;
        char                 Attributes;
} tUSBD_configuration;

pInterfacespointer in struct that description interface for this configuration

NumInterfaces – Number of interfaces supported by this configuration

pStrConfiguration pointer on string that description this configuration

MaxPower – maximum power consumpion of the USB device from the bus in this specific configuration when the device

is fully operational. Expressed in 2 mA units (i.e. 50 = 100 mA).

AttributesConfiguration chracteristics

 

#define _DEFAULT          (0x01<<7)       // Default Value Bit 7 is set
#define _SELF_POWER       (0x01<<6)       // Self-powered  - Supports if set
#define _REMOTE_WAKEUP    (0x01<<5)       // Remote Wakeup - Supports if set

2.Third description of possible interases

typedef struct
{
        void                *param;
        char                 type;       // type of interfases
} tUSBD_interface;

type – variable that describe wthat usd device class will used on current interfaces.

#define USBD_CDC_SERIAL_DEVICE          0x01
#define USBD_CDC_ETHERNET_DEVICE        0x02
#define USBD_MSC_DEVICE                 0x03
#define USBD_HID_MOUSE_DEVICE           0x04
#define USBD_HID_KEYBOARD_DEVICE        0x05
#define USBD_HID_EXT_KEYBOARD_DEVICE    0x06
#define USBD_AUDIO_DEVICE               0x07
#define USBD_AUDIO_CONTROL_DEVICE       0x08

param – pointer on specific interface parameters

The following example demonstrates how to use Unison’s USB device solution with a USB CDC serial device class. All other device classes use a similar initialization method and usage.

EXAMPLE

Instantiating a USB CDC Serial device server:

THREAD Main(void *arg)
{
        pthread_t pid;
        pthread_attr_t attr;
        struct sched_param myNewPriority;

        /* USB server structs */
        tUSB_config    usb_config;
        tUSB_core_conf usb_cores[2];
  
        /* USB device general structs */
        tUSBD_port_info     usbd_port;
        tUSBD_configuration usbd_config;

          /* USB device CDC interface structs */
        tUSBD_interface     usbd_interface;
        tUSBD_cdc_serial    usbd_cdc_serial;

        #if RTOS_DEBUG
                dir_register("Main thread", pthread_self(), TYPE_THREAD);
        #endif


        usbd_port.idVendor          = 0x0123;                     // Vendor ID for the USB product
        usbd_port.idProduct         = 0x4567;                     // Product ID for the USB product
        usbd_port.bcdDevice         = 0x0001;                     // Device release number in BCD format
        usbd_port.pManufacturer     = "RoweBots";                 // Manufacturer string descriptor
        usbd_port.pProduct          = "Unison RTOS USB Serial";   // Product string descriptor
        usbd_port.pSerialNumber     = "111004";                   // Serial number string descriptor
        usbd_port.pConfigurations   = &usbd_config;                
        usbd_port.NumConfigurations = 1;                          // Number of configurations for current port

        
        usbd_config.NumInterfaces     = 1;
        usbd_config.pInterfaces       = &usbd_interface;
        usbd_config.pStrConfiguration = "CDC Configuration";
        usbd_config.MaxPower          = 0x0;
        usbd_config.Attributes        = _DEFAULT | _SELF_POWER;

        /* Setup serial device specific parameters*/
        usbd_cdc_serial.vport_num      = 1;  // ttyUSB1 
        usbd_cdc_serial.rx_buf_size    = 512;
        usbd_cdc_serial.tx_buf_size    = 512;


        usbd_interface.type   =  USBD_CDC_SERIAL_DEVICE;
        usbd_interface.param  = &usbd_cdc_serial;

        /* Register serial device driver in USB device server*/
        usbd_add_serial_driver();

        /********************
        Start USB server
        ********************/
        usb_config.core_conf = usb_cores;
        usb_config.host      = NULL;
        usb_config.dev       = (void*)usbd_start;

        usb_cores[0].usb_callback = USB_event;
        usb_cores[0].CoreID = 0;                //physical USB controller number
        usb_cores[0].mode   = _USB_DEV;
        usb_cores[0].param.dev_param = &usbd_port;

        usb_cores[1].CoreID = -1;

        if (usb_server(&usb_config))
        {
                xprintf("pthread_create = %d\n", errno);
                pthread_exit(0);
        }

}

NOTES

In the above example, the user application uses the following USB libraries to implement the serial device:

  • usb_server
  • ubd_core
  • ubd_cdc_serial_driver
  • usbd_xxxxxxx_port

SEE ALSO

ttyserver usb

Suggest Edit

CONTACT US

TO GET YOUR PROJECT STARTED

TOP