Coder Social home page Coder Social logo

9bit's Introduction

Microchip

SAMA5 9-bit / Multidrop Serial Mode

This repository contains some examples to work with and evaluate 9-bit UART solutions on Microchip SAMA5 processors. Some processors support hardware 9-bit mode and features surrounding this mode, and some do not. However, even in those cases it is still possible to make use of 9-bit mode. In all cases, the Linux kernel API does not provide a standard way of using all of the necessary features.

Building Examples

When cross compiling, put the compiler in your PATH or use an absolute path for CC.

CC=arm-linux-gcc make

This will generate several example binaries.

SAMA5D2 (FLEXCOM) / SAMA5D3 9-bit Mode

Usage Notes

  • Custom kernel patch must be applied to driver to support SENDA term bit.
  • This method provides a way to use the SENDA bit of the UART (only available on FLEXCOM UART on SAMA5D2).
  • The original patches are available at: https://www.spinics.net/lists/linux-serial/msg25997.html
  • Provides a method to use hardware driven RTS in RS485 mode on SAMA5D2.

Example

./senda_example /dev/ttyS2 20000

Example Message

Example message showing address set on first byte and tag-along RTS line while transmitting.

senda_message_w_rts

SAMA5D2 (Non FLEXCOM) 9-bit Support

Usage Notes

  • Custom kernel patch must be applied to driver to support P9BIT term bit.
  • Assume userspace has no control of parity. The driver hijacks this bit.
  • Must enable RS485 in term setup. A side effect of RS485 mode is it requires the transmitter to be idle before the next byte is sent.
  • Must disable DMA/PDC for UART port transfers in driver.
  • It does not appear RTS is supported directly by the UART.

Disable DMA in Device Tree

To disable DMA for a specific port, this can be done in device tree. Optionally, DMA can be disabled for all ports in the kernel config.

uart3: serial@fc008000 {
    /*atmel,use-dma-rx;*/
    /*atmel,use-dma-tx;*/
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_uart3_default>;
    status = "okay";
};

Example

./p9bit_example /dev/ttyS1 20000

Example Messages

Inter-byte delay is minimal and there is no timing difference between 9-bit high and 9-bit low bytes. The following shows the 9th bit is set high on the first message and following bytes in the message have the 9th bit set low.

message

The minimum inter-message delay (not to be confused with inter-byte delay) is around 22 milliseconds. There is room to optimize this at the cost of more custom interfaces.

inter_message_delay

Global Userspace Solution

It is possible to essentially perform 9-bit emulation from userspace without any kernel modification and this functionally works as expected on almost any UART that supports parity. However, do to the extra calls between the address byte and the data byte, this can induce a long delay that may not be desirable.

TX Address Byte

term.c_cflag = PARENB | CMSPAR| PARODD;
tcsetattr(fd,  TCSADRAIN, &term);
write(fd, buffer, 1);

TX Data Bytes

term.c_cflag = PARENB | CMSPAR;
tcsetattr(fd,  TCSADRAIN, &term);
write(fd, buffer+1, size-1);

RX

term.c_iflag = INPCK | PARMRK;
tcsetattr(fd, TCSANOW, &term);
...
read(fd, buffer, size);

Example

./user_example /dev/ttyS2 20000

Example Messages

There is about a 28 millisecond delay between the address byte and the data bytes of the message.

inter_message_delay

License

The example code is released under the terms of the MIT license. See the COPYING file for more information.

9bit's People

Contributors

joshua-henderson avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.