Developer World
Spresense SDK Library v3.2.0-ebc0364
mpcomm.h File Reference
#include <stdbool.h>
#include <asmp/types.h>
#include <asmp/mpmq.h>

Go to the source code of this file.

Classes

struct  helper_info
 
struct  mpcomm_context
 
struct  mpcomm_init_msg
 
struct  mpcomm_malloc_msg
 
struct  mpcomm_free_msg
 
struct  mpcomm_error_msg
 
struct  mpcomm_log_msg
 

Macros

#define MPCOMM_MSG_ID_INIT   1
 
#define MPCOMM_MSG_ID_DEINIT   2
 
#define MPCOMM_MSG_ID_USER_FUNC   3
 
#define MPCOMM_MSG_ID_DONE   4
 
#define MPCOMM_MSG_ID_MALLOC   5
 
#define MPCOMM_MSG_ID_FREE   6
 
#define MPCOMM_MSG_ID_ERROR   7
 
#define MPCOMM_MSG_ID_LOG   8
 
#define MPCOMM_MAX_HELPERS   4
 
#define MPCOMM_CPUID_MAX   8
 
#define MPCOMM_MODE_CONTROLLER   0
 
#define MPCOMM_MODE_HELPER   1
 
#define MEM_V2P(addr)   mpcomm_memory_virt_to_phys(addr)
 

Typedefs

typedef void(* mpcomm_user_func_t) (void *data)
 
typedef struct helper_info helper_info_t
 
typedef struct mpcomm_context mpcomm_context_t
 
typedef struct mpcomm_init_msg mpcomm_init_msg_t
 
typedef struct mpcomm_malloc_msg mpcomm_malloc_msg_t
 
typedef struct mpcomm_free_msg mpcomm_free_msg_t
 
typedef struct mpcomm_error_msg mpcomm_error_msg_t
 
typedef struct mpcomm_log_msg mpcomm_log_msg_t
 

Functions

int mpcomm_main (mpcomm_user_func_t controller_user_func, mpcomm_user_func_t helper_user_func)
 
int mpcomm_send_helper (uint8_t helper_index, void *data)
 
int mpcomm_wait_helper_done (uint8_t helper_index)
 
int mpcomm_wait_helpers_done (void)
 
int mpcomm_get_helpers_num (void)
 
bool mpcomm_is_controller (void)
 
void * mpcomm_memory_virt_to_phys (void *addr)
 
int mpcomm_send_malloc (void **ptr, size_t size)
 
int mpcomm_send_free (void *ptr)
 
int mpcomm_send_error (int err)
 
int mpcomm_send_log (char *log)
 

Macro Definition Documentation

◆ MPCOMM_MSG_ID_INIT

#define MPCOMM_MSG_ID_INIT   1

The helper and controller initialization message ID.

◆ MPCOMM_MSG_ID_DEINIT

#define MPCOMM_MSG_ID_DEINIT   2

The helper and controller deinitialization message ID.

◆ MPCOMM_MSG_ID_USER_FUNC

#define MPCOMM_MSG_ID_USER_FUNC   3

Message ID to send user data to controller and helper.

◆ MPCOMM_MSG_ID_DONE

#define MPCOMM_MSG_ID_DONE   4

Message ID confirming that the message has been processed.

◆ MPCOMM_MSG_ID_MALLOC

#define MPCOMM_MSG_ID_MALLOC   5

Message ID to request malloc() from supervisor.

◆ MPCOMM_MSG_ID_FREE

#define MPCOMM_MSG_ID_FREE   6

Message ID to request free() from supervisor.

◆ MPCOMM_MSG_ID_ERROR

#define MPCOMM_MSG_ID_ERROR   7

Message ID to send error code to supervisor.

◆ MPCOMM_MSG_ID_LOG

#define MPCOMM_MSG_ID_LOG   8

Message ID to send log message to supervisor.

◆ MPCOMM_MAX_HELPERS

#define MPCOMM_MAX_HELPERS   4

Maximum number of helpers.

◆ MPCOMM_CPUID_MAX

#define MPCOMM_CPUID_MAX   8

Maximum CPU ID.

◆ MPCOMM_MODE_CONTROLLER

#define MPCOMM_MODE_CONTROLLER   0

Controller mode.

◆ MPCOMM_MODE_HELPER

#define MPCOMM_MODE_HELPER   1

Helper mode.

◆ MEM_V2P

#define MEM_V2P (   addr)    mpcomm_memory_virt_to_phys(addr)

Convert address from virtual to physical

Typedef Documentation

◆ mpcomm_user_func_t

typedef void(* mpcomm_user_func_t) (void *data)

Definition of callback function.

User-defined callback that is called by mpcomm_main() after receiving data from the supervisor or controller.

Parameters
[in]data: User data.

◆ helper_info_t

◆ mpcomm_context_t

◆ mpcomm_init_msg_t

◆ mpcomm_malloc_msg_t

◆ mpcomm_free_msg_t

◆ mpcomm_error_msg_t

◆ mpcomm_log_msg_t

Function Documentation

◆ mpcomm_main()

int mpcomm_main ( mpcomm_user_func_t  controller_user_func,
mpcomm_user_func_t  helper_user_func 
)

Start the MPCOMM framework on the controller or the helper. The user can register a callbacks that will handle the data received from the supervisor and controller.

Parameters
[in]controller_user_funcUser-defined callback for the contoller.
[in]helper_user_funcUser-defined callback for the helper.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_send_helper()

int mpcomm_send_helper ( uint8_t  helper_index,
void *  data 
)

Send the user data to the helper for processing.

Parameters
[in]helper_indexHelper index.
[in]dataUser data.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_wait_helper_done()

int mpcomm_wait_helper_done ( uint8_t  helper_index)

Wait until user data has been processed by helper.

Parameters
[in]helper_indexHelper index.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_wait_helpers_done()

int mpcomm_wait_helpers_done ( void  )

Wait until user data has been processed by all helpers.

Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_get_helpers_num()

int mpcomm_get_helpers_num ( void  )

Return number of helpers.

Returns
Number of helpers.

◆ mpcomm_is_controller()

bool mpcomm_is_controller ( void  )

Return true if it is controller. Otherwise, return false.

Returns
True, if it is controller.

◆ mpcomm_memory_virt_to_phys()

void * mpcomm_memory_virt_to_phys ( void *  addr)

Convert address from virtual to physical.

Parameters
[in]addrVirtual address.
Returns
Physical address.

◆ mpcomm_send_malloc()

int mpcomm_send_malloc ( void **  ptr,
size_t  size 
)

Send a request to the supervisor to call malloc() and save the address of the allocated memory in the ptr.

Parameters
[out]ptrThe address of the allocated memory received from the supervisor.
[in]sizeRequested size.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_send_free()

int mpcomm_send_free ( void *  ptr)

Send a request to the supervisor to call free() on the ptr.

Parameters
[in]ptrThe address of the allocated memory to be freed by the supervisor.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_send_error()

int mpcomm_send_error ( int  err)

Send the error number to the supervisor.

Parameters
[in]errError code.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.

◆ mpcomm_send_log()

int mpcomm_send_log ( char *  log)

Send the log for printing by supervisor.

Parameters
[in]logLog to be printed.
Returns
On success, 0 is returned. On failure, negative value is returned according to <errno.h>.