-
Notifications
You must be signed in to change notification settings - Fork 222
Getting Started
This chapter is about creating simple eRPC client/server application. From eRPC point of view creating application contains two steps:
- Generating and importing eRPC shim code
- Import eRPC common files and call functions to init environment.
As an application demo will be shown matrix multiplication client/server baremetal application which is using UART transport.
This chapter contains three topics. As a first IDL file needs be created. Then use it for generating shim code. As a last step client application needs import client relevant files, server needs import server relevant files.
IDL files contains all declarations used in eRPC calls. Simple example can looks like.
IDL.erpc:
/*!
* You can write copyrights rules here. Will be copied into outputs.
*/
@outputDir("erpc_outputs") // output directory
program erpc_matrix_multiply; // specify name of output files
/*! This const defines the matrix size. The value has to be the same as the
Matrix array dimension. Do not forget to re-generate the erpc code once the
matrix size is changed in the erpc file */
int const matrix_size = 5;
/*! This is the matrix array type. The dimension has to be the same as the
matrix size const. Do not forget to re-generate the erpc code once the
matrix size is changed in the erpc file */
type Matrix = int32[matrix_size][matrix_size];
interface MatrixMultiplyService // cover functions for same topic
{
erpcMatrixMultiply(in Matrix matrix1, in Matrix matrix2, out Matrix result_matrix) -> void
}
That is everything. This function will send two matrixes from client to server and one matrix with result will be sent back.
For generating shim code is needed two things:
- eRPC generator tool - See erpcgen documentation section.
- IDL file - Created in previous topic.
Simplest way for generating code is have both the tool and the IDL file in same directory. Then this command need be executed:
erpcgen.exe IDL.erpc
This action will create four files in erpc_outputs folder:
- erpc_matrix_multiply.h
- erpc_matrix_multiply_client.cpp
- erpc_matrix_multiply_server.h
- erpc_matrix_multiply_server.cpp
Client project
needs count with erpc_matrix_multiply.h and erpc_matrix_multiply_client.cpp files. In source file where eRPC functions are called needs be included erpc_matrix_multiply.h header file.
Server project
needs count with erpc_matrix_multiply.h, erpc_matrix_multiply_server.h and erpc_matrix_multiply_server.cpp files. In source file where eRPC functions calls are implemented needs be included erpc_matrix_multiply_server.h header file.
This chapter contains three topics:
- Common contains information which common files needs be imported for client and server application.
- Client contains information which client files needs be imported for client and server application.
- Server contains information which server files needs be imported for client and server application.
Basic rule is that files don't contain "client" or "server" string in their names. These files need server and client application:
- From ERPCRootDir/erpc_c/config file erpc_config.h. This file should be copied to application specific directory and used it instead of using this global file.
- From ERPCRootDir/erpc_c/infra files codec.h, basic_codec.h, basic_codec.cpp, erpc_common.h, erpc_version.h, framed_transport.h, framed_transport.cpp, manually_constructed.h, message_buffer.h transport.h and message_buffer.cpp
- From ERPCRootDir/erpc_c/port files erpc_config_internal.h, erpc_port.h and erpc_port_stdlib.cpp
- From ERPCRootDir/erpc_c/setup files erpc_mbf_setup.h, erpc_setup_mbf_dynamic.cpp, erpc_transport_setup.h and erpc_setup_uart_cmsis.cpp
- From ERPCRootDir/erpc_c/transports files uart_cmsis_transport.h and uart_cmsis_transport.cpp
Basic rule is client files contains "client" string in their names.
- From ERPCRootDir/erpc_c/infra files client_manager.h and client_manager.cpp
- From ERPCRootDir/erpc_c/setup files erpc_client_setup.h and erpc_client_setup.cpp
In source file where eRPC client environment init functions are called needs be included erpc_client_setup.h header file.
Basic rule is client files contains "server" string in their names.
- From ERPCRootDir/erpc_c/infra files server.h, server.cpp, simple_server.h and simple_server.cpp
- From _ERPCRootDir/erpc_c/setup files erpc_server_setup.h and erpc_server_setup.cpp
In source file where eRPC server environment init functions are called needs be included erpc_server_setup.h header file.
This chapter shows simplest main source file for client and server side.
#include "erpc_matrix_multiply.h"
#include "erpc_client_setup.h"
#include "fsl_uart_cmsis.h" /* Not eRPC file. Need be replaced with include of transport type. */
int main()
{
/* Matrixes definitions */
Matrix matrix1, matrix2, result_matrix = {{0}};
/* init eRPC client environment */
/* UART transport layer initialization */
erpc_transport_t transport = erpc_transport_cmsis_uart_init((void *)&DEMO_UART); /* DEMO_UART defined in fsl_uart_cmsis.h */
/* MessageBufferFactory initialization */
erpc_mbf_t message_buffer_factory = erpc_mbf_dynamic_init();
/* eRPC client side initialization */
erpc_client_init(transport, message_buffer_factory);
/* other code like init matrix1 and matrix2 values */
...
/* call eRPC functions */
erpcMatrixMultiply(matrix1, matrix2, result_matrix);
/* other code like print result matrix */
...
return 0;
}
#include "erpc_matrix_multiply_server.h"
#include "erpc_server_setup.h"
#include "fsl_uart_cmsis.h" /* Not eRPC file. Need be replaced with include of transport type. */
/* implementation of function call */
void erpcMatrixMultiply(Matrix matrix1, Matrix matrix2, Matrix result_matrix)
{
/* code for multiplication of matrixes */
...
}
int main()
{
/* init eRPC server environment */
/* UART transport layer initialization */
erpc_transport_t transport = erpc_transport_cmsis_uart_init((void *)&DEMO_UART); /* DEMO_UART defined in fsl_uart_cmsis.h */
/* MessageBufferFactory initialization */
erpc_mbf_t message_buffer_factory = erpc_mbf_dynamic_init();
/* eRPC server side initialization */
erpc_server_init(transport, message_buffer_factory);
// connect generated service into server, look into erpc_matrix_multiply_server.h
erpc_add_service_to_server(create_MatrixMultiplyService_service());
// run server
erpc_server_run(); /* or erpc_server_poll(); */
return 0;
}