tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
tvm::runtime::micro_rpc::Session Class Reference

CRT communication session management class. Assumes the following properties provided by the underlying transport: More...

#include <session.h>

Collaboration diagram for tvm::runtime::micro_rpc::Session:

Public Types

typedef void(* MessageReceivedFunc) (void *context, MessageType message_type, FrameBuffer *buf)
 Callback invoked when a full message is received. More...
 

Public Member Functions

 Session (Framer *framer, FrameBuffer *receive_buffer, MessageReceivedFunc message_received_func, void *message_received_func_context)
 
tvm_crt_error_t Initialize (uint8_t initial_session_nonce)
 Send a session terminate message, usually done at startup to interrupt a hanging remote. More...
 
tvm_crt_error_t TerminateSession ()
 Terminate any previously-established session. More...
 
tvm_crt_error_t StartSession ()
 Start a new session regardless of state. Sends kStartSessionMessage. More...
 
WriteStreamReceiver ()
 Obtain a WriteStream implementation for use by the framing layer. More...
 
tvm_crt_error_t SendMessage (MessageType message_type, const uint8_t *message_data, size_t message_size_bytes)
 Send a full message including header, payload, and CRC footer. More...
 
tvm_crt_error_t StartMessage (MessageType message_type, size_t message_size_bytes)
 Send the framing and session layer headers. More...
 
tvm_crt_error_t SendBodyChunk (const uint8_t *chunk_data, size_t chunk_size_bytes)
 Send a part of the message body. More...
 
tvm_crt_error_t FinishMessage ()
 Finish sending the message by sending the framing layer footer. More...
 
bool IsEstablished () const
 Returns true if the session is in the established state. More...
 
void ClearReceiveBuffer ()
 Clear the receive buffer and prepare to receive next message. More...
 

Static Public Attributes

static constexpr const uint8_t kInvalidNonce = 0
 An invalid nonce value that typically indicates an unknown nonce. More...
 
static constexpr const uint8_t kVersion = 0x01
 A version number used to check compatibility of the remote session implementation. More...
 

Detailed Description

CRT communication session management class. Assumes the following properties provided by the underlying transport:

Specifically, designed for use with UARTs. Will probably work over semihosting, USB, and TCP; will probably not work reliably enough over UDP.

Member Typedef Documentation

◆ MessageReceivedFunc

typedef void(* tvm::runtime::micro_rpc::Session::MessageReceivedFunc) (void *context, MessageType message_type, FrameBuffer *buf)

Callback invoked when a full message is received.

This function is called in the following situations:

  • When a new session is established (this typically indicates the remote end reset). In this case, buf is NULL.
  • When a log message or normal traffic is received. In this case, buf points to a valid buffer containing the message content.
Parameters
contextThe value of message_received_func_context passed to the constructor.
message_typeThe type of session message received. Currently, this is always either kNormal or kLog.
bufWhen message_type is not kStartSessionMessage, a FrameBuffer whose read cursor is at the first byte of the message payload. Otherwise, NULL.

Constructor & Destructor Documentation

◆ Session()

tvm::runtime::micro_rpc::Session::Session ( Framer framer,
FrameBuffer receive_buffer,
MessageReceivedFunc  message_received_func,
void *  message_received_func_context 
)
inline

Member Function Documentation

◆ ClearReceiveBuffer()

void tvm::runtime::micro_rpc::Session::ClearReceiveBuffer ( )

Clear the receive buffer and prepare to receive next message.

Call this function after MessageReceivedFunc is invoked. Any SessionReceiver::Write() calls made will return errors until this function is called to prevent them from corrupting the valid message in the receive buffer.

◆ FinishMessage()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::FinishMessage ( )

Finish sending the message by sending the framing layer footer.

Returns
kTvmErrorNoError on success, or an error code otherwise.

◆ Initialize()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::Initialize ( uint8_t  initial_session_nonce)

Send a session terminate message, usually done at startup to interrupt a hanging remote.

Parameters
initial_session_nonceInitial nonce that should be used on the first session start message. Callers should ensure this is different across device resets.
Returns
kTvmErrorNoError on success, or an error code otherwise.

◆ IsEstablished()

bool tvm::runtime::micro_rpc::Session::IsEstablished ( ) const
inline

Returns true if the session is in the established state.

◆ Receiver()

WriteStream* tvm::runtime::micro_rpc::Session::Receiver ( )
inline

Obtain a WriteStream implementation for use by the framing layer.

Returns
A WriteStream to which received data should be written. Owned by this class.

◆ SendBodyChunk()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::SendBodyChunk ( const uint8_t *  chunk_data,
size_t  chunk_size_bytes 
)

Send a part of the message body.

This function allows messages to be sent in pieces.

Parameters
chunk_dataThe data contained in this message body chunk.
chunk_size_bytesThe number of valid bytes in chunk_data.
Returns
kTvmErrorNoError on success, or an error code otherwise.

◆ SendMessage()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::SendMessage ( MessageType  message_type,
const uint8_t *  message_data,
size_t  message_size_bytes 
)

Send a full message including header, payload, and CRC footer.

Parameters
message_typeOne of MessageType; distinguishes the type of traffic at the session layer.
message_dataThe data contained in the message.
message_size_bytesThe number of valid bytes in message_data.
Returns
kTvmErrorNoError on success, or an error code otherwise.

◆ StartMessage()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::StartMessage ( MessageType  message_type,
size_t  message_size_bytes 
)

Send the framing and session layer headers.

This function allows messages to be sent in pieces.

Parameters
message_typeOne of MessageType; distinguishes the type of traffic at the session layer.
message_size_bytesThe size of the message body, in bytes. Excludes the framing and session layer headers.
Returns
0 on success, negative error code on failure.
kTvmErrorNoError on success, or an error code otherwise.

◆ StartSession()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::StartSession ( )

Start a new session regardless of state. Sends kStartSessionMessage.

Generally speaking, this function should be called once per device reset by exactly one side in the system. No traffic can flow until this function is called.

Returns
kTvmErrorNoError on success, or an error code otherwise.

◆ TerminateSession()

tvm_crt_error_t tvm::runtime::micro_rpc::Session::TerminateSession ( )

Terminate any previously-established session.

Returns
kTvmErrorNoError on success, or an error code otherwise.

Member Data Documentation

◆ kInvalidNonce

constexpr const uint8_t tvm::runtime::micro_rpc::Session::kInvalidNonce = 0
staticconstexpr

An invalid nonce value that typically indicates an unknown nonce.

◆ kVersion

constexpr const uint8_t tvm::runtime::micro_rpc::Session::kVersion = 0x01
staticconstexpr

A version number used to check compatibility of the remote session implementation.


The documentation for this class was generated from the following file: