BeRTOS
Functions
ser.c File Reference

Buffered serial I/O driver. More...

#include "ser.h"
#include "wdt.h"
#include "timer.h"
#include "ser_p.h"
#include "cfg/cfg_ser.h"
#include "cfg/cfg_proc.h"
#include <cfg/debug.h>
#include <mware/formatwr.h>
#include <cpu/power.h>
#include <string.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 Serial *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_setbaudrate (struct Serial *fd, unsigned long rate)
 Set the baudrate for the serial port.
void ser_setparity (struct Serial *fd, int parity)
 Set the parity for the fd serial port.
void ser_purge (struct Serial *fd)
 Flush both the RX and TX buffers.
void ser_purgeRx (struct Serial *fd)
 Flush RX buffer.
void ser_purgeTx (struct Serial *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 Serialser_open (struct Serial *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 KFileser_reopen (struct KFile *fd)
 Reopen serial port.
void ser_init (struct Serial *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 (Serial *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

Author:
Bernie Innocenti <bernie@codewiz.org>

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 323 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 140 of file ser.c.

int ser_getchar_nowait ( struct Serial 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 183 of file ser.c.

void ser_init ( struct Serial fds,
unsigned int  unit 
)

Init serial driver for unit.

Use values SER_UARTn as values for unit.

Definition at line 421 of file ser.c.

static struct Serial* ser_open ( struct Serial fd,
unsigned int  unit 
) [static, read]

Initialize a serial port.

Parameters:
fdKFile Serial struct interface.
unitSerial unit to open. Possible values are architecture dependant.

Definition at line 344 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 94 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 199 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 224 of file ser.c.

void spimaster_init ( Serial fds,
unsigned int  unit 
)

Init SPI serial driver unit in master mode.

Use SER_SPIn for unit parameter.

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 496 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 442 of file ser.c.