Shared Memory
A small module that can manage a list of pre-allocaed memory pools so that multiple modules can use them in non-overlapping manner.
Usage
All API functions have the first argument configuration of framer.
Use rs_shm_init to initialize the logic
Use rs_shm_add to create an entry
Use rs_shm_request to request a shared memory
5. Use the memory and then release it using rs_shm_release 4. Return codes of API functions are defined in header file.
Function |
Description |
|---|---|
rs_shm_init |
Function to initialize the shared memory manager |
rs_shm_add |
Function to add a memory to the shared memory pool |
rs_shm_request |
Function to request shared memory with given ID |
rs_shm_release |
Function to release shared memory with given ID |
Error Code
Every API’s for the message queue module returns some success or failure values.
Please refer below section,
Shared Memory Header Details
Documentation from the relevant header as follows:
Shared Memorry Specific APIs.
Defines macros and functions specific to shared memory functionality
- Author
Embien RAPIDSEA Team
- Copyright
Embien Technologies India Pvt. Ltd.
Defines
-
RS_SHM_MAX_NUM_POOLS
Typedefs
-
typedef struct tag_rs_shm_info rs_shm_info_t
Structure for each shared memory information.
Functions
-
rs_ret_val_t rs_shm_init()
Initializes the shared memory pool.
This function initializes internal parameters associated with shared memory.
- Returns:
return 0 for success
-
rs_ret_val_t rs_shm_add(uint8_t u8_shm_id, void *ptr_buf, uint32_t u32_buf_len)
Adds the given shared memory to the pool.
This function adds the given buffer and matches it to the shared memory id given.
- Parameters:
u8_shm_id – [in] - Shared memory ID
ptr_buf – [in] - Pointer to the buffer allocated
u32_buf_len – [in] - Size of the buffer.
- Returns:
return 0 for success or error code on failure
-
void *rs_shm_request(uint8_t u8_shm_id, uint8_t u8_requestor_id)
Requests the shared memory corresponding to the given requester ID.
This function checks if the given shared memory ID is free and returns the base pointer.
- Parameters:
u8_shm_id – [in] - Shared memory ID
u8_requestor_id – [in] - Requester ID
- Returns:
return shared memory pointer on success or NULL
-
rs_ret_val_t rs_shm_release(uint8_t u8_shm_id, uint8_t u8_requestor_id)
Releases the shared memory ID already held by requester.
This function releases the shared memory that is currently being held by the requester.
- Parameters:
u8_shm_id – [in] - Shared memory ID
u8_requestor_id – [in] - Requester ID
- Returns:
return 0 for success or error code
-
struct tag_rs_shm_info
- #include <rs_shm.h>
Structure for each shared memory information.