DMCP interface 03.18_025
Loading...
Searching...
No Matches
Serial Console Functions

Macros

#define USIN_CHAN_CNT   4
 Number of input channels allocated.
 
#define USIN_CHAN_SIZE   256
 Single channel buffer (FIFO) size.
 
#define USIN_MAX_READLINES   16
 Max. number of lines supported in input buffer.
 
#define US_OVERFLOW_CHAR   '\x0f'
 Character at end of the line when buffer overflow occurs.
 
#define US_LINEEND_CHAR   '\n'
 End of line character.
 
#define US_CHAN0_CHAR   '\x10'
 Channel ID for channel 0, other channel IDs sequentially follow.
 
#define US_MAX_CHANS   11
 Theoretical limit of serial console protocol.
 
#define SER_IOCTL_READ   ((int)(1<<31))
 ioctl argument value to read data
 
#define SER_IOCTL_INVALID   ((int)(1<<31))
 ioctl return value indicating unknown operation
 
#define SERIO_IS_ENABLED   0x01
 ioctl op (RW) - Serial console on/off
 
#define SERIO_IS_ACTIVE   0x02
 ioctl op (R) - Enabled and USB connected -> active
 
#define SERIO_IS_CONNECTED   0x03
 ioctl op (R) - Client connected
 
#define SERIO_LINE_READY   0x08
 ioctl op (R) val=channel, Line is ready in input channel
 
#define SERIO_LINE_LENGTH   0x09
 ioctl op (R) val=channel, Line length if line is ready, 0 otherwise
 
#define SERIO_SEND_PRINTF   0x10
 ioctl op (RW) - Send printf output to serial console
 
#define SERIO_SEND_LCD   0x11
 ioctl op (RW) - Send LCD contents over serial console
 
#define SERIO_SEND_KEYS   0x12
 ioctl op (RW) - Send key scan changes to serial console
 
#define SERIO_SEND_IR   0x13
 ioctl op (RW) - Send IR traffic over serial console
 
#define US_ICHAN_KEY   0
 dedicated input channel
 
#define US_ICHAN_SYS   1
 dedicated input channel
 
#define US_OCHAN_SYS   0
 dedicated output channel
 
#define US_OCHAN_PRINTF   1
 dedicated output channel
 

Functions

void usb_serial_write (uint8_t chan_nr, const char *buf, int len)
 Serial console write to channel.
 
void usb_serial_puts (uint8_t chan_nr, const char *str)
 Serial console write string to channel.
 
int usb_serial_read_line (uint8_t chan_nr, uint8_t *buf, int buflen, uint8_t *is_overflow)
 Serial console read line.
 
int usb_serial_ioctl (int op, int val)
 Serial console ioclt.
 

Detailed Description

Function Documentation

◆ usb_serial_ioctl()

int usb_serial_ioctl ( int op,
int val )

Serial console ioclt.

Parameters
opIOCTL operation
valOperation parameter, use SER_IOCTL_READ to read R/W values
Returns
Return value of requested operation

Table of ...

+------------------------------------------------------------------------------------------------------------+
|   Operation               mode        val*        Description                                              |
+------------------------------------------------------------------------------------------------------------+
|  SERIO_IS_ENABLED      |   R/W   |   0/1     |  1 = Serial console is enabled                              |
|  SERIO_IS_ACTIVE       |   R     |   0/1     |  1 = Serial console is enabled and active over USB, i.e.    |
|                        |         |           |      if serial console is enabled, it can be still inactive |
|                        |         |           |      because USB isn't connected to PC or USB port is used  |
|                        |         |           |      by other USB service with higher priority (e.g. MSC)   |
|  SERIO_IS_CONNECTED    |   R     |   0/1     |  1 = Client connected, i.e DTR is active                    |
|                        |         |           |                                                             |
|  SERIO_LINE_READY      |   R     |  chan_nr  |  1 = Line is ready in input channel                         |
|  SERIO_LINE_LENGTH     |   R     |  chan_nr  |  Line length if line is ready, 0 otherwise                  |
|                        |         |           |                                                             |
|  SERIO_SEND_PRINTF     |   R/W   |   0/1     |  1 = Enable sending printf output to serial console         |
|  SERIO_SEND_LCD        |   R/W   |   0/1     |  1 = Enable sending LCD contents over serial console        |
|  SERIO_SEND_KEYS       |   R/W   |   0/1     |  1 = Enable sending key scan changes to serial console      |
|  SERIO_SEND_IR         |   R/W   |   0/1     |  1 = Enable sending IR traffic over serial console (not     |
|                        |         |           |      implemented yet)                                       |
+------------------------------------------------------------------------------------------------------------+
| *) Use SER_IOCTL_READ as val to read R/W values                                                            |

◆ usb_serial_puts()

void usb_serial_puts ( uint8_t chan_nr,
const char * str )

Serial console write string to channel.

Parameters
chan_nrChannel number
strString to write

◆ usb_serial_read_line()

int usb_serial_read_line ( uint8_t chan_nr,
uint8_t * buf,
int buflen,
uint8_t * is_overflow )

Serial console read line.

Parameters
chan_nrChannel number
bufBuffer for read data (or NULL to discard the line)
buflenNumber of bytes available in buf
is_overflowPointer to overflow flag
Returns
0 if line isn't ready,
-1 buf cannot accommodate available line (buflen < line length),
otherwise, number of characters copied into buf (or discarded if buf == NULL).

Note that if number of read characters is < buflen, the read string is properly ended with '\0' character in buf.

Last character of line should be either '\n' (US_LINEEND_CHAR) or US_OVERFLOW_CHAR. Indicating whether line was read from serial line correctly (US_LINEEND_CHAR) or whether input buffer overflow occurred during line read (US_OVERFLOW_CHAR). The line is incomplete in later case. *is_overflow is set to 1 if is_overflow pointer is provided and read buffer overflow occurred while reading the line.

Before calling usb_serial_read_line the state of current line can be probed with usb_serial_ioctl calls:

usb_serial_ioctl(SERIO_LINE_READY,  chan_nr); // To check whether line is ready
usb_serial_ioctl(SERIO_LINE_LENGTH, chan_nr); // To check line length if line is ready

◆ usb_serial_write()

void usb_serial_write ( uint8_t chan_nr,
const char * buf,
int len )

Serial console write to channel.

Parameters
chan_nrChannel number
bufData to write
lenNumber of bytes to write