|Tollos – stmVCom.c|
stmVCom.c – Virtual COM device I/O functionsThe vcom functions communicate with the host computer using a USB link.
Note that on Windows a driver may need to be installed for this to work. This should be found automatically; if not, try the stmvirtcom.inf driver.
The primary functions here provide initialization, the usual getc and putc, and stop. Additional exposed functions are the callback function for interfacing with the USB library and ‘USART’ functions which are called when the data terminal is reset or is started.
For reading, up to 35 characters will be buffered here; if the buffer fills (the host sends them faster than the application can read them) then characters will be lost.
Similarly, up to 320 characters will be buffered for output; again, characters will be lost if too many are sent. Neither vcomPutc nor vcomGetc will block. The host application may also discard characters (for example, if the terminal emulator is stopped then restarted, the USB device is not informed of this and characters sent while the terminal is not running are accepted but then lost).
EP1_IN_Callback – called by USB library for endpoint 1 (IN)
Called when inbound transmission is complete.
EP3_OUT_Callback – called by USB library for endpoint 3 (OUT)
Called when a packet of bytes has been received from the host.
SOF_Callback – called by USB library on frame start
The device is polled by the host every 1ms; this callback is then invoked.
USART_Config – called by library when terminal exists
This is called when a ‘real’ host terminal device is attached.
USART_Config_Default – called by library when device started
This is called when explicit initialization of the Virtual COM port is requested. This implies no terminal yet.
vcomGetcIO – get character
returns character read from host, or −1 if none there
This function does not block.
vcomInitIO – initialize USB port for I/O
returns 0 if OK, negative if interrupt already in use
This does not switch a software connection as this is device-dependent (port, pin, and direction), so the caller should use bitSet to make the connection before calling this.
vcomPutcIO – send character to virtal com port
int vcomPutcIO(int ch);
ch – character to send
returns 0 if OK, or −1 if vcom has not been initialized, or
−2 if there is a data overrun (bytes have been queued faster
than they could be sent to the host)
This function does not block.
Note that this must not be called from an interrupt handler that has a higher priority than USB.
vcomStopIO – stop the device cleanly
This releases the interrupt handler after stopping the device.
This does not switch a software connection as this is device-dependent (port, pin, and direction), so the caller should use bitSet to make the connection an input after calling this.
|Tollos and these web pages were written by Mike Cowlishaw; Please send me any corrections, suggestions, etc.|
All content © Mike Cowlishaw, 2010–2012, except where marked
otherwise. All rights reserved. The pages here are for non-commercial
use only (see the separate licence for Tollos source code).
records no personal information and sets no ‘cookies’.
However, statistics, etc. might be recorded by the web hosting
This page was last updated on 2011-01-09 by c2wiki.