ser.c File Reference
Buffered serial I/O driver.
More...
#include "ser.h"
#include "wdt.h"
#include "ser_p.h"
#include <mware/formatwr.h>
#include <cfg/debug.h>
#include <appconfig.h>
#include <string.h>
#include <drv/timer.h>
Go to the source code of this file.
|
Functions |
| static int | ser_putchar (int c, struct Serial *port) |
| | Insert c in tx FIFO buffer.
|
| static int | ser_getchar (struct Serial *port) |
| | Fetch a character from the rx FIFO buffer.
|
| int | ser_getchar_nowait (struct KFileSerial *fd) |
| | Fetch a character from the rx FIFO buffer.
|
| static size_t | ser_read (struct KFile *fd, void *_buf, size_t size) |
| | Read at most size bytes from port and put them in buf.
|
| static size_t | ser_write (struct KFile *fd, const void *_buf, size_t size) |
| | Write a buffer to serial.
|
| void | ser_resync (struct KFileSerial *fd, mtime_t delay) |
| | Discard input to resynchronize with remote end.
|
|
void | ser_purge (struct KFileSerial *fd) |
| | Flush both the RX and TX buffers.
|
|
void | ser_purgeRx (struct KFileSerial *fd) |
| | Flush RX buffer.
|
|
void | ser_purgeTx (struct KFileSerial *fd) |
| | Flush TX buffer.
|
| static int | ser_flush (struct KFile *fd) |
| | Wait until all pending output is completely transmitted to the other end.
|
| static struct Serial * | ser_open (struct KFileSerial *fd, unsigned int unit) |
| | Initialize a serial port.
|
|
static int | ser_close (struct KFile *fd) |
| | Clean up serial port, disabling the associated hardware.
|
|
static struct KFile * | ser_reopen (struct KFile *fd) |
| | Reopen serial port.
|
|
void | ser_init (struct KFileSerial *fds, unsigned int unit) |
| | Init serial driver for unit.
|
| static size_t | spimaster_read (struct KFile *fd, void *_buf, size_t size) |
| | Read data from SPI bus.
|
|
static size_t | spimaster_write (struct KFile *fd, const void *buf, size_t size) |
| | Write data to SPI bus.
|
| void | spimaster_init (KFileSerial *fds, unsigned int unit) |
| | Init SPI serial driver unit in master mode.
|
Detailed Description
Buffered serial I/O driver.
The serial rx interrupt buffers incoming data in a software FIFO to decouple the higher level protocols from the line speed. Outgoing data is buffered as well for better performance. This driver is not optimized for best performance, but it has proved to be fast enough to handle transfer rates up to 38400bps on a 16MHz 80196.
MODULE CONFIGURATION
CONFIG_SER_HWHANDSHAKE - set to 1 to enable RTS/CTS handshake. Support is incomplete/untested.
CONFIG_SER_TXTIMEOUT - Enable software serial transmission timeouts
- Version:
- Id
- ser.c 1159 2008-03-04 14:31:09Z batt
- Author:
- Bernardo Innocenti <bernie@develer.com>
Definition in file ser.c.
Function Documentation
| static int ser_flush |
( |
struct KFile * |
fd |
) |
[static] |
Wait until all pending output is completely transmitted to the other end.
- Note:
- The current implementation only checks the software transmission queue. Any hardware FIFOs are ignored.
Definition at line 344 of file ser.c.
| static int ser_getchar |
( |
struct Serial * |
port |
) |
[static] |
Fetch a character from the rx FIFO buffer.
- Note:
- This function will switch out the calling process if the rx buffer is empty. If the buffer is empty and port->rxtimeout is 0 return EOF immediatly.
- Returns:
- EOF on error or timeout, c otherwise.
Definition at line 147 of file ser.c.
| int ser_getchar_nowait |
( |
struct KFileSerial * |
fd |
) |
|
Fetch a character from the rx FIFO buffer.
If the buffer is empty, ser_getchar_nowait() returns EOF immediatly.
- Note:
- Deprecated, use ser_getchar with rx_timeout set to 0.
Definition at line 192 of file ser.c.
| static struct Serial* ser_open |
( |
struct KFileSerial * |
fd, |
|
|
unsigned int |
unit | |
|
) |
| | [static, read] |
Initialize a serial port.
- Parameters:
-
| fd | KFile Serial struct interface. |
| unit | Serial unit to open. Possible values are architecture dependant. |
Definition at line 371 of file ser.c.
| static int ser_putchar |
( |
int |
c, |
|
|
struct Serial * |
port | |
|
) |
| | [static] |
Insert c in tx FIFO buffer.
- Note:
- This function will switch out the calling process if the tx buffer is full. If the buffer is full and port->txtimeout is 0 return EOF immediatly.
- Returns:
- EOF on error or timeout, c otherwise.
Definition at line 98 of file ser.c.
| static size_t ser_read |
( |
struct KFile * |
fd, |
|
|
void * |
_buf, |
|
|
size_t |
size | |
|
) |
| | [static] |
Read at most size bytes from port and put them in buf.
- Returns:
- number of bytes actually read.
Definition at line 208 of file ser.c.
| void ser_resync |
( |
struct KFileSerial * |
fd, |
|
|
mtime_t |
delay | |
|
) |
| | |
Discard input to resynchronize with remote end.
Discard incoming data until the port stops receiving characters for at least delay milliseconds.
- Note:
- Serial errors are reset before and after executing the purge.
Definition at line 266 of file ser.c.
| static size_t ser_write |
( |
struct KFile * |
fd, |
|
|
const void * |
_buf, |
|
|
size_t |
size | |
|
) |
| | [static] |
Write a buffer to serial.
- Returns:
- 0 if OK, EOF in case of error.
Definition at line 233 of file ser.c.
| void spimaster_init |
( |
KFileSerial * |
fds, |
|
|
unsigned int |
unit | |
|
) |
| | |
Init SPI serial driver unit in master mode.
This interface implements the SPI master protocol over a serial SPI driver. This is needed because normal serial driver send/receive data at the same time. SPI slaves like memories and other peripherals first receive and *then* send response back instead. To achieve this, when we are master and we are *sending*, we have to discard all incoming data. Then, when we want to receive, we must write fake data to SPI to trigger slave devices.
Definition at line 522 of file ser.c.
| static size_t spimaster_read |
( |
struct KFile * |
fd, |
|
|
void * |
_buf, |
|
|
size_t |
size | |
|
) |
| | [static] |
Read data from SPI bus.
Since we are master, we have to trigger slave by sending fake chars on the bus.
Definition at line 470 of file ser.c.