pojiro

pojiro

I think this is the basic question. I don’t know the I2C protocol details.
I would like to know the linux case.

Do we need to write the atomic operation for i2c bus in Elixir?
Or if we just use cicuits_i2c, it is done by the library or Linux driver?

Thank you

Showing Posts 1 to 4

fhunleth

fhunleth

Co-author of Nerves

I might need more information on what you’re trying to achieve.

Linux schedules messages to devices in the order that they’re requested. If multiple OS or Erlang processes send messages on an I2C bus, they’ll be interleaved. Circuits.I2C directly uses the Linux APIs so it behaves identically.

There’s a way tell Linux to make more than one I2C bus transaction at a time using the I2C_RDWR ioctl. The Circuits.I2C.write_read/5 function uses this ioctl. The main reason is to do an I2C repeated start which is often expected by I2C devices. It also ensures that the write and read operations are issued back-to-back.

The I2C_RDWR lets you string together more I2C bus operations and this might be what you’re looking for with your question.

A PR that adds a Circuits.I2C.transfer/4 that takes a list of I2C operations would be interesting. But before going down that route, it would be good to confirm that this is the right thing to do. Every time I’ve thought I’ve needed to implement this, I’ve found that making multiple Circuits.I2C calls is sufficient. Also take a look at the error semantics as described in i2c-core-base.c.

Hope this helps.

pojiro

pojiro OP

I might need more information on what you’re trying to achieve.

I don’t do achieve something and don’t have any problems.
I just want to know that the parallel accessing the same bus is safe or not.

For example, there are two GenServers, each of them are open same i2c bus, like “i2c-1”, and store the handle to their state. Then both of them write or read the bus with the hundle in parallel.

The bus hundle, reference, includes the file discripter, right?.
I’d like to know that the same timing access to it is safe or not. Does a Linux I2C driver garantee the atomicity?

fhunleth

fhunleth

Co-author of Nerves

You can open as many I2C bus references as you’d like. There won’t be any issues. It’s common to call Circuits.I2C.open/2 for each I2C device that you’re using from Elixir. What you’re describing with two GenServers is the normal way, and that’s how most Elixir libraries that use I2C are written.

Trying to pass around I2C bus references to reduce calls to Circuits.I2C.open/2 is unnecessary. I probably would only do that if it were really convenient.

The Linux kernel ensures that each read and write completes before the next transfer starts. The low level I2C hardware controller can only issue one at a time anyway.

Yes, there’s a file handle behind each I2C bus reference.

pojiro

pojiro OP

I appreciate your answer!!

Thank you

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews