mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-27 09:12:32 +00:00
ed7d6c74f4
Introduces the notion of a transaction that consists of one or more messages. Whereby a message has a read or write direction and consists of one or more bytes. Issue #4170 Fixes #4169
98 lines
2.1 KiB
C++
98 lines
2.1 KiB
C++
/*
|
|
* \brief I2C session client implementation
|
|
* \author Jean-Adrien Domage <jean-adrien.domage@gapfruit.com>
|
|
* \date 2021-02-25
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2013-2021 Genode Labs GmbH
|
|
* Copyright (C) 2021 gapfruit AG
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__I2C_SESSION__I2C_SESSION_H_
|
|
#define _INCLUDE__I2C_SESSION__I2C_SESSION_H_
|
|
|
|
#include <session/session.h>
|
|
#include <base/stdint.h>
|
|
#include <util/array.h>
|
|
|
|
namespace I2c {
|
|
using namespace Genode;
|
|
struct Session;
|
|
}
|
|
|
|
|
|
struct I2c::Session : public Genode::Session
|
|
{
|
|
/**
|
|
* \noapi
|
|
*/
|
|
static char const *service_name() { return "I2c"; }
|
|
|
|
enum { CAP_QUOTA = 2 };
|
|
|
|
|
|
/***************
|
|
** Exception **
|
|
***************/
|
|
|
|
/**
|
|
* Exception thrown in case of a bus error
|
|
*
|
|
* This exception is thrown by the driver in case of a timeout, device missing
|
|
* acknowledgement and bus arbitration lost.
|
|
*/
|
|
class Bus_error : public Exception {};
|
|
|
|
using Byte_array = Array<uint8_t, 8>;
|
|
|
|
/**
|
|
* A message to an I2C slave is either a read or write of one or more bytes
|
|
*/
|
|
struct Message : Byte_array
|
|
{
|
|
enum Type { READ, WRITE };
|
|
|
|
Type type { READ };
|
|
|
|
Message() {}
|
|
|
|
template<typename ... ARGS>
|
|
Message(Type type, ARGS ... args)
|
|
: Byte_array(args...), type(type) {}
|
|
};
|
|
|
|
/**
|
|
* A transaction to an I2C slave consists of one, or several messages
|
|
*/
|
|
struct Transaction : Array<Message,2>
|
|
{
|
|
using Base = Array<Message,2>;
|
|
using Base::Base;
|
|
};
|
|
|
|
|
|
/***********************
|
|
** Session interface **
|
|
***********************/
|
|
|
|
/**
|
|
* Initiate a transaction on the bus
|
|
*
|
|
* \param transaction The transaction to be transmitted to the I2c host
|
|
*
|
|
* \throw I2c::Session::Bus_error An error occured while performing an operation on the bus
|
|
*/
|
|
virtual void transmit(Transaction & transaction) = 0;
|
|
|
|
GENODE_RPC_THROW(Rpc_transmit, void, transmit,
|
|
GENODE_TYPE_LIST(Bus_error), Transaction &);
|
|
|
|
GENODE_RPC_INTERFACE(Rpc_transmit);
|
|
};
|
|
|
|
#endif /* _INCLUDE__I2C_SESSION__I2C_SESSION_H_ */
|