1 / 22

Serial Driver APIs

Serial Driver APIs. Standard Serial API SPI HDLC API. Serial Driver State Diagram. open(). write(). Sending Data. Opened. Gathering Data. ioctl(). Configuration Change. read(). close(). Closed. Example open(). prototype: int open( char port, int Options);.

lang
Download Presentation

Serial Driver APIs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Serial Driver APIs Standard Serial API SPI HDLC API 1-1

  2. Serial Driver State Diagram open() write() Sending Data Opened Gathering Data ioctl() Configuration Change read() close() Closed 1-2

  3. Example 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 1-3

  4. Example 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. 1-4

  5. Serial read() Blocking Blocking* Non-Blocking Wait here until driver returns at least one byte Num = read() Num = read() Return Immediately Num always > 0 Num = -1 if data not available *Note: BSP Default 1-5

  6. Serial 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 SIO_MODE_SET SIO_HW_OPTS_GET SIO_HW_OPTS_SET SIO_GET_STATUS_DCD SIO_GET_STATUS_DTR SIO_TERM_SEND_CR SIO_TERM_ECHO SIO_BAUD_ERROR_SET SIO_BAUD_ERROR_GET 1-6

  7. Serial 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)); 1-7

  8. Serial 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; result = 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 1-8

  9. SPI - 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 1-9

  10. Serial Output SPI – 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 1-10

  11. SPI Mode - Master • Master (NET+ARM 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 – NET+ARM 50 • SPI enable signal active until after each byte (NET+ARM 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 1-11

  12. NET+ARM 50 SPI Device MASTER *SPI-M-ENABLE-A (portC7) *CS CLK SPI-M-CLK-OUT-A (portA4) 0305 TXDA (portA7) SI (serial input) fghij RXDA (portA3) SO (serial output) Master Mode – Controller 1-12

  13. SPI Mode - Slave • Slave(NET+ARM 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 ) 1-13

  14. NET+ARM 50 SLAVE Master SPI-S-ENABLE-A (portC7 ) *EN SPI-S-CLK-IN-A (portA4 ) CLK TXDA (portA7) abcde RXD RXDA (portA3) 0300 TXD Slave Mode - Peripheral 1-14

  15. NET+ARM Hardware Serial Module DMA Module GEN Module ENI Module/GPIO SPI Driver SPI 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 1-15

  16. SPI Driver - Library • Source files located in \netos\src\bsp\devices\SPI • netos_spi.c • netos_spi.h • Include file located in \netos\h\ • #include <spiDev.h> • Enable SPI Library • Undefined BSP_INCLUDE_SERIAL_DRIVER_2 in <\netos\h\bspconf.h> • Undefined NETOS_LED in <\netos\h\narmled.h> • Recompile BSP build file located <\netos\src\bsp\bsp.bld> 1-16

  17. High 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 send&receive function call • Supports Hardware hand shaking only 1-17

  18. HDLC Open and Close Channel Opening and Closing the HDLC Channel 1-18

  19. HDLC 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->header, pframe->hlen , pframe->data and pframe->dlen. 4. Call naHdlcFrameSend(channel, pframe, urgent, release) to queue the frame to send. 1-19

  20. HDLC Transmit Sending HDLC Frames 1-20

  21. HDLC 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 can’t 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(). . 1-21

  22. HDLC Receive Receiving HDLC Frames 1-22

More Related