Title: Serial%20Driver%20APIs
1Serial Driver APIs
- Standard Serial API
- SPI
- HDLC API
2Serial Driver State Diagram
open()
write()
Sending Data
Opened
Gathering Data
ioctl()
Configuration Change
read()
close()
Closed
3Example open()
prototype int open(char port, int Options)
File_Descriptor open(/com/0, (O_RDWR
O_NONBLOCK) )
Note Returns Unique File Descriptor,
or -1 if unsuccessful.
Available Ports /com/0
/com/1
Available Options O_RDONLY O_WRONLY
O_RDWR O_NONBLOCK O_DMA
4Example write(), read()
prototype int write(int fd, char Buffer, int
BufferSize)
Num_Bytes write(fd, SendBuffer, SizeBuffer)
Note Returns Number of bytes sent.
prototype int read(int fd, char Buffer, int
BufferSize)
Num_Bytes read(fd, SendBuffer, SizeBuffer)
Note Returns Number of bytes retrieved, or -1
if no data available.
5Serial read() Blocking
Blocking
Non-Blocking
Wait here until driver returns at least one byte
Num read()
Num read()
Return Immediately
Num always gt 0
Num -1 if data not available
Note BSP Default
6Serial I/O Options
prototype int ioctl(int fd, int command, void
args)
Result ioctl(fd, SIO_BAUD_SET, Options)
Note Returns -1 if error, otherwise 0.
Possible
Commands SIO_BAUD_GET SIO_BAUD_SET SIO_MODE_GET SI
O_MODE_SET SIO_HW_OPTS_GET SIO_HW_OPTS_SET
SIO_GET_STATUS_DCD SIO_GET_STATUS_DTR SIO_TERM_SE
ND_CR SIO_TERM_ECHO SIO_BAUD_ERROR_SET SIO_BAUD_ER
ROR_GET
7Serial Driver for UART
- Serial Driver for standard UART MODE ONLY
- The following include files are required for the
Serial Port APIs - netosio.h
- netos_serl.h
- The standard device driver APIs are supported.
- Use the open(), write(), read(), close(), and
ioctl() functions to access the serial ports. - Example
- fd open ("/com/1", (O_RDWR O_ NONBLOCK))
8Serial Driver For UART (Cont.)
The following example demonstrates calls used to
send data through a serial port. fd open
("/com/0", O_RDWR) -OPEN PORT / set to 57600
baud rate / iOptions SIO_57600_BAUD result
ioctl(fd, SIO_BAUD_SET, iOptions) -CONFIGURE
BAUD RATE / set to 8 bit / 2 stop bits / even
parity / hardwarehandshaking / iOptions
SIO_EIGHT_BIT_DATA_WIDTH SIO_TWO_STOP_BITS
SIO_EVEN_PARITY SIO_HW_RTS_CTS_HANDSHAKING re
sult ioctl(fd, SIO_HW_OPTS_SET, iOptions)-
CONFIGURE HARDWARE numBytesSent write (fd,
sndBuffer, szBuffer) - WRITE BUFFER numBytesRecv
read (fd, rcvBuffer, szBuffer) - READ
BUFFER close (fd) - CLOSE PORT
9SPI - Serial Peripheral Interface
- Communication between 2 Integrated Circuit
- Full duplex, Synchronous interface
- Physical Layer (TXD, RXD, CLK, EN)
- Character-oriented data channel
- Shorter distances (6 inches)
- Maximum port rate (SYSCLK/8)
- SPI Driver
10SPI cont.
SPI Device
Chip Select
Serial Input
? 0x06 0x05
Serial Clock
10.168.4.0 ?
- Clock signal
- Enable and disable signal
- Input and output channels
11SPI Mode - Master
- Master (NETARM 40/50 is a controller)
- Provides the Enable
- Generate SPI enable signal by hardware
(SPI-M-ENABLE-A and SPI-M-ENABLE-B) - Manually generate enable signal by firmware thru
GPIO - SPI enable signal active until entire buffer is
transferred NETARM 50 - SPI enable signal active until after each byte
(NETARM 40 Master and possibly Slave Mode - Provides the SPI Clock
- Generate SPI clock signal (SPI-M-CLK-IN-A and
SPI-M-CLK-IN-B) - Data Transfer
- Transfer output data from TX FIFO (TXDA)
- Receive input data into RX FIFO (RXDA)
- Receive and transfer same number of bytes
- Read and write simultaneously
- Control one or more SPI peripheral
12Master Mode Controller
13SPI Mode - Slave
- Slave (NETARM 40/50 is a peripheral)
- Controlled by external SPI clock
- Receive input clock signal ( SPI_S_CLK_IN_A and
SPI_S_CLK_IN_B ) - Controlled by external SPI enable
- Receive input enable signal ( SPI_S_ENABLE_A
and SPI_S_ENABLE_B ) - Data Transfer
- Transfer output data from TX FIFO ( TXDA )
- Receive input data into RX FIFO ( RXDA )
14Slave Mode - Peripheral
15SPI Driver Objective
- Objective
- Provide easy and faster access to SPI channels
- Make hardware transparent to the users
- Remove burden with manipulating internal
registers - No duplication of code
16SPI Driver - Library
- Source files located in \netos\src\bsp\devices\SPI
- netos_spi.c
- netos_spi.h
- Include file located in \netos\h\
- include ltspiDev.hgt
- Enable SPI Library
- Undefined BSP_INCLUDE_SERIAL_DRIVER_2 in
lt\netos\h\bspconf.hgt - Undefined NETOS_LED in lt\netos\h\narmled.hgt
- Recompile BSP build file located
lt\netos\src\bsp\bsp.bldgt
17High Speed Serial Driver
- Uses DMA channels 7,8,9 and 10
- Reaches up to a speed of 518400 baud along with
33.1776 Mhz crystal - However the max baud rate for the 50 chip is
691200 based on 44 MHz Clock. Reminder that the
speed varies with the system clock - Sends and receives more than 500,000 bytes per
single sendreceive function call - Supports Hardware hand shaking only
18HDLC Open and Close Channel
- Opening and Closing the HDLC Channel
19HDLC Transmit
- Allocating and Freeing HDLC Frames
- To allocate a frame, call pframe
naHdlcFrameAlloc(size). - The size argument can be any number less than or
equal to the large frame size. Size 0is used to
allocate empty frames. The actual frame buffer
size is equal to the largeframe size, the small
frame size, or 0. - To free the frame, call naHdlcFrameFree(pframe).
- Sending HDLC Frames
- Use naHdlcFrameSend() to send a frame. Use the
following procedure - 1. Allocate a frame.
- 2. Copy data to the frame buffer, if needed.
- 3. Set pframe-gtheader, pframe-gthlen ,
pframe-gtdata and pframe-gtdlen. - 4. Call naHdlcFrameSend(channel, pframe, urgent,
release) to queue - the frame to send.
20HDLC Transmit
21HDLC Receive
- Receiving HDLC Frames
- The HDLC driver processes received frames as
follows - 1. The driver calls the naHdlcAcceptFun routine
if this callback has been - registered. If the callback returns FALSE, the
driver discards the frame. - 2. The driver allocates a frame structure of the
size to fit the received frame. If the driver
cant allocate the frame structure, it discards
the frame. - 3. If a small frame has been allocated, the
driver copies received frame data to the buffer
of the allocated frame. If a large frame has been
allocated, the driver swaps the DMA buffer with
the allocated frame buffer. - 4. The driver sets data pointer to the received
frame buffer and dlen to the actual frame size.
header, hlen, and flags are equal to zero. - 5. The driver calls the naHdlcReceivedFun routine
if this callback routine has - been registered. Otherwise, the driver queues the
received frame. - The user application should call the naHdlcFrame
naHdlcFrameRecv(int - channel) function to retrieve a frame queued by
the driver. An application should free all
received frames by calling naHdlcFrameFree(). - .
22HDLC Receive