Unison Help

- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
7.28.1.Asynchronous Serial I/O Server - ttyserver #
NAME
Asynchronous Serial I/O – ttyserver
SYNOPSIS
#include <sys/ioctl.h>
#include <sys.h>
#include <fcntl.h>
pthread_create(&pid, &attr, &tty_shell, 0)
int _tty_server(char *init, int_8 *arg)
DESCRIPTION
The asynchronous serial I/O server or ttyserver provides the ability to input and output serial characters at baud rates upto and including 115200 using a variety of stop,
data and parity options. It has a variety of flow control choices which may be set including hardware flow control, software flow control and no flow control. It has a variety of setpoints
which can be used to generate early interrupts and achieve maximum throughput for the server.
The ttyserver provides the target with simple terminal communications in both the standard COOKED and RAW modes.
SPECIFIC OPTIONS (Compile time)
Option | Default | Description | Values |
---|---|---|---|
TTY_RAW_SUPPORT | 1 | Enable/disable RAW discipline support. | Dec: 0 | 1 |
TTY_NETDISC_SUPPORT | 0 | Enable/disable line discipline support for debugger. | Dec: 0 | 1 |
TTY_PPP_SUPPORT | 1 | Enable/disable PPP discipline support. | Dec: 0 | 1 |
TTY_RS485_RS422 | 1 | Enable/disable RS-485/RS-422 support. | Dec: 0 | 1 |
TTY_POLLING_TO | 100 | TTY polling timeout, in milliseconds. | Decimal |
Line Disciplines
The server supports specific ioctl() flags (commands) to initialize and control various line disiplines.
TIOCSETD
This option allows you to setup the terminal I/O line discipline. The following are arguments that can be used:
• NETLDISC
This is a special option required to support communication with Remedy over serial lines.
• TTYLDISC
This option sets the TTY line discipline for COOKED mode (regular edit mode). This means that backspace characters etc. will be performed by the TTY server in its receive buffer before the data is handed to the
user. It will only pass the data to the user when a carriage return has been received.
• RAWLDISC
This line discipline is called RAW mode. This means that the server will not interpret received characters in any way before passing them to the user. This option also turns off flow control in RAW mode.
• RAWFLDISC
This option turns on flow control in RAW mode.
• ECHO
This option turns on local echo of characters being transmitted in COOKED mode.
• NOECHO
This option turns off local echo of characters being transmitted in COOKED mode.
• PPPLDISC
ppp discipline
• PPPFSLDISC
ppp discipline with flow control software
• PPPFHLDISC
ppp discipline with flow control hardware
SET_TTY_MODE
Allows you to set mode parameters for each serial port channel. Parameters are passed as members of the structure set_tty.
This structure can be found in the file ioctl.h
struct set_tty { uint_8 csize; uint_8 parity; uint_8 flow; uint_32 speed; uint_8 stop_bits; uint_8 tty_int_level; uint_16 timeout_write; uint_16 rx_buf_size; uint_16 tx_buf_size; }
Note:
• The csize parameter specifies the character size to use. For example: 5,6,7 or 8.
• The parity parameter specifies the parity bits to use. This value should be: NO_PARITY, EVEN_PARITY or ODD_PARITY.
• The flow parameter specifies whether or not to use hardware flow control. Specify: NO_FLOWCONTROL, CTS_FLOWCONTROL, RTS_FLOWCONTROL, RTSCTS_FLOWCONTROL or XONXOFF_FLOWCONTROL.
• The speed parameter specifies the channel speed. This value will be written into the chip UART baudrate register, and must be calculated depending on the chip clock settings.
• The stop_bits parameter specifies the channel stop bits to use.
• The tty_int_level parameter must be set to the interrupt vector that the channel of the corresponding hardware UART will be using.
• The timeout_write parameter specifies the channel data write timeout. This value will be used if flow control is used. If the timeout_write parameter is set to zero, the timeout mechanism will not be used.
• The rx_buf_size is the size of the receive buffer.
• The tx_buf_size is the size of the transmit buffer.
Access Options
The server can be accessed in both blocking and non-blocking mode. By default the server is set to blocking mode. To use non-blocking I/O, use the O_NONBLOCK flag (defined in fcntl.h) with the open() function.
/* open path as read-only and non-blocking. */ open (path, O_RDONLY|O_NONBLOCK);
The server also supports use the select() function.
int tty0_fd; fd_set read_fds; struct timeval tv; . . . FD_ZERO (&read_fds); FD_SET (tty0_fd, &read_fds); /* set the timeout value (10 seconds). */ tv.tv_sec = 10; tv.tv_usec = 0; /* block on a select */ select (tty0_fd+1, &read_fds, NULL, NULL, &tv));
Server Initialization
To initialize, the server is passed two parameters. The first parameter is an array of configuration structures for each of the ports that will be used.
For example:
struct set_tty tty_setup[2]; tty_setup[0].csize = 8; tty_setup[0].parity = NO_PARITY; tty_setup[0].flow = NO_FLOWCONTROL; tty_setup[0].speed = BAUD_VALUE; tty_setup[0].stop_bits = 1; tty_setup[0].tty_int_level = 5; tty_setup[0].timeout_write = 0; tty_setup[0].rx_buf_size = 64; tty_setup[0].tx_buf_size = 32; tty_setup[1].csize = 8; tty_setup[1].parity = NO_PARITY; tty_setup[1].flow = NO_FLOWCONTROL; tty_setup[1].speed = BAUD_VALUE; tty_setup[1].stop_bits = 1; tty_setup[1].tty_int_level = 5; tty_setup[1].timeout_write = 0; tty_setup[1].rx_buf_size = 128; tty_setup[1].tx_buf_size = 32;
The second parameter is an array of port numbers that will be initialized. Set the number of ports to initialize in an array with -1 terminating the list.
For example:
char tty_map[]= { 0, 2, …-1};
Where:
‘0’ – ttyS0 (UART0 on hardware)
‘2’ – ttyS2 (UART2 on hardware)
EXAMPLE
... THREAD Main() { pthread_t pid; pthread_attr_t attr; struct sched_param myNewPriority; pthread_t serverid; struct set_tty *set_tty; int ioctl_arg; pthread_attr_init(&attr); myNewPriority.sched_priority = 5; pthread_attr_setschedparam(&attr, &myNewPriority); pthread_attr_setstacksize(&attr,1024); if(pthread_create(&pid, &attr, &tty_shell, 0)!=0) { xprintf("pthread_create = %d\n", errno); pthread_exit(0); } sched_yield(); // let tty server initialize before any sends to it if(dir_register("/dev/ttyS", pid, TYPE_SERVER)==0) { xprintf("dir_register = %d\n", errno); pthread_exit(0); } set_tty = malloc(sizeof(struct set_tty)); set_tty->csize = 8; set_tty->parity = NO_PARITY; set_tty->flow = NO_FLOWCONTROL; set_tty->speed = BAUD_RATE; set_tty->stop_bits = 1; set_tty->tty_int_level = 4; set_tty->timeout_write = 0; ioctl(fd1,SET_TTY_MODE,set_tty); ioctl_arg = ECHO; ioctl( fd1, TIOCSETD, &ioctl_arg); ... } THREAD tty_shell(void *arg) { struct set_tty tty_setup[1]; int_8 tty_map[]= {1,-1}; /* ttyS1*/ tty_setup[0].csize = 8; tty_setup[0].parity = NO_PARITY; tty_setup[0].flow = NO_FLOWCONTROL; tty_setup[0].speed = BAUD_VALUE; tty_setup[0].stop_bits = 1; tty_setup[0].tty_int_level = 5; tty_setup[0].timeout_write = 0; tty_setup[0].rx_buf_size = 64; tty_setup[0].tx_buf_size = 32; /* Start tty server */ if(_tty_server((char*)&tty_setup, &tty_map[0])==-1) { xprintf("Error init tty server ERRNO=%x\n",errno); pthread_exit(0); } return 0; // just to avoid warning }
NOTES
There is a demo available for the Unison and DSPnano Asynchronous Serial I/O which can be found in installdir/demos.