High level interface for communicating between processors on a multi-core device.
The IPC driver allows communication between multiple CPUs or between multiple tasks operating in different domains within a single CPU. It supports binary semaphores and message queues, similar to how they are used for task interactions in an RTOS envrionment.
To initialize the driver, call the mtb_ipc_init on the first task/CPU to boot and mtb_ipc_get_handle on other cores. Please see your device documentation to determine which core to start on. This will setup shared memory and the binary semaphore for protecting internal functionality.
For binary semaphores, only one task/CPU may initialize ( mtb_ipc_semaphore_init) a semaphore. Other tasks/CPUs then get the handle ( mtb_ipc_semaphore_get_handle) of the created semaphore. Then take/give the semaphore ( mtb_ipc_semaphore_take/ mtb_ipc_semaphore_give).
For queues, only one task/CPU may initialize ( mtb_ipc_queue_init) a queue. Other tasks/CPUs then get the handle ( mtb_ipc_queue_get_handle) of the created queue. Use the get/put functions to take out or put in items to the queue ( mtb_ipc_queue_put, mtb_ipc_queue_get).
mtb_ipc_semaphore_init function semaphore_num parameter valid range is from 0 to (including) CY_IPC_SEMA_COUNT - 2
For all IPC library constructs, some data must be put in the shared memory regions so that all cores can access. This must satisfy a few requirements:
Shared data memory allocation can be done with help of MTB_IPC_SHARED_DATA_ALLOC macro, but using it is not mandatory, so user can allocate memory for the shared memory in any convenient for them way. This struct is necessary to store and keep track of all shared objects during operation.
semaphore data memory allocation can be done with help of MTB_IPC_SEMAPHORE_DATA_ALLOC macro, but using it is not mandatory, so user can allocate memory for the semaphore data in any convenient for them way as long as such allocation satisfies next parameters:
Mailbox data memory allocation can be done with help of MTB_IPC_MBOX_DATA_ALLOC macro, but using it is not mandatory, so user can allocate memory for the mailbox data in any way convenient for them as long as such allocation satisfies next parameters:
Queue pool memory allocation can be done with help of MTB_IPC_QUEUE_POOL_ALLOC macro, but using it is not mandatory, so user can allocate memory for the queue pool in any convenient for them way as long as such allocation satisfies next parameters:
Queue data memory allocation can be done with help of MTB_IPC_QUEUE_DATA_ALLOC macro, but using it is not mandatory, so user can allocate memory for the queue data in any convenient for them way as long as such allocation satisfies next parameters:
If preemptable is enabled (true), the user must ensure that there are no deadlocks in the system, which can be caused by an interrupt that occurs after the IPC channel is locked. Unless the user is ready to handle IPC channel locks correctly at the application level, set preemptable to false.
In current IPC library implementation, each core has two of its "own" IPC INTR structures, which services all possible IPC library channels. One IRQ structure is for semaphores, and the other for queues.
Callbacks may execute in an ISR context, so IPC queue put/get operations cannot be performed in callbacks with a timeout != 0 Such operations will result in MTB_IPC_RSLT_ERR_CANT_OPERATE_IN_ISR_W_TIMEOUT. IPC semaphore take/give operations cannot be performed in ISR context with a timeout != 0. Such operations will result in MTB_IPC_RSLT_ERR_CANT_OPERATE_IN_ISR_W_TIMEOUT.
On some devices (currently, Traveo, XMC72, and PSE84 devices), startup code does not initialize IPC PDL driver semaphores, so it is done by mtb_ipc_init(). In general, the init function should be called by the first core to boot. Please see your device datasheet for details. This core will do the initialization and set up a pointer using an IPC channel so that all Cores can read and use the same variables. if it has not already been done on that core. The corresponding mtb_ipc_get_handle will be used on other cores to receive this data.
Calling mtb_ipc_semaphore_get_handle() before mtb_ipc_semaphore_init() will result in MTB_IPC_RSLT_ERR_NO_SEMA_AVAILABLE. The correct way of using mtb_ipc_semaphore_get_handle() is to call mtb_ipc_semaphore_init() before using mtb_ipc_semaphore_get_handle(), and pass the same semaphore number that was used for the initialization. Semaphores can be initialized on any core and accessed from any core.
Calling mtb_ipc_queue_get_handle() before mtb_ipc_queue_init() will result in MTB_IPC_RSLT_ERR_QUEUE_NOT_FOUND. The correct way of using mtb_ipc_queue_get_handle() is to call mtb_ipc_queue_init() before using mtb_ipc_queue_get_handle(), and pass the same channel and queue number that was used for the queue initialization. Queues can be initialized on any core and accessed from any core.
Calling mtb_ipc_mbox_sender_get_handle() before mtb_ipc_mbox_receiver_init() will result in MTB_IPC_RSLT_ERR_MBOX_NOT_FOUND. The correct way of using mtb_ipc_mbox_sender_get_handle() is to call it after mtb_ipc_mbox_receiver_init() , and pass the same mailbox index that was used for the mailbox initialization. Mailboxes can be initialized on any core and accessed from any core, however initialization must be done on the receiving core for that individual mailbox.
of deadlocks, any modification of the Queue besides its notifications must be done using the queue's semaphore. To ensure less arbitration in ISR context, notifications are instead protected by the lock on the channel the queue is part of.
API Reference | |
| IPC Results | |
| IPC specific return codes. | |
| IPC | |
| Implementation specific interface for using the IPC library. | |
Data Structures | |
| struct | mtb_ipc_semaphore_config_t |
| User Config Struct to set up a Semaphore Items to be populated by caller before initialization Semaphore number defines a specific semaphore and should be less than _MTB_IPC_SEMA_COUNT. More... | |
| struct | mtb_ipc_mbox_config_t |
| User Config Struct to set up a Mailbox Items to be populated by caller before initialization Read/Write Semaphore number defines a specific semaphore and should be less than _MTB_IPC_SEMA_COUNT. More... | |
| struct | mtb_ipc_queue_config_t |
| User Config Struct to set up a Queue Items to be populated by caller before initialization Combination of channel_num and queue_num uniquely defines a specific Queue. More... | |
| struct | mtb_ipc_config_t |
| IPC object config struct. More... | |
Macros | |
| #define | MTB_IPC_QUEUE_ALL_EVENTS ( MTB_IPC_QUEUE_WRITE | MTB_IPC_QUEUE_READ | MTB_IPC_QUEUE_FULL | MTB_IPC_QUEUE_EMPTY | MTB_IPC_QUEUE_RESET ) |
| Aggregate of all the Queue events. | |
| #define | MTB_IPC_NEVER_TIMEOUT (0xFFFFFFFFFFFFFFFFUL) |
| This define can be used as timeout argument for the IPC HAL driver functions, that take timeout as input parameter, in order to make function never time out (wait forever) | |
| #define | MTB_IPC_NEVER_TIMEOUT_MS (0xFFFFFFFFUL) |
| This define can be used as timeout argument for the IPC driver functions, that take timeout as input parameter, in order to make function never time out (wait forever) in functions that take ms an an argument. | |
Typedefs | |
| typedef void(* | mtb_ipc_queue_event_callback_t) (void *callback_arg, mtb_ipc_queue_event_t event) |
| Queue Event handler for IPC interrupts. | |
| typedef void(* | mtb_ipc_mbox_event_callback_t) (void *callback_arg, mtb_ipc_mbox_event_t event) |
| Callback handler for IPC mailbox interrupts. | |
Enumerations | |
| enum | mtb_ipc_mbox_event_t { MTB_IPC_MBOX_FULL = 1 << 0UL , MTB_IPC_MBOX_EMPTY = 1 << 1UL } |
| Flags enum of IPC Mailbox events. More... | |
| enum | mtb_ipc_queue_event_t { MTB_IPC_NO_INTR = 0UL , MTB_IPC_QUEUE_WRITE = 1 << 0UL , MTB_IPC_QUEUE_READ = 1 << 1UL , MTB_IPC_QUEUE_FULL = 1 << 2UL , MTB_IPC_QUEUE_EMPTY = 1 << 3UL , MTB_IPC_QUEUE_RESET = 1 << 4UL } |
| Flags enum of IPC events. More... | |
Functions | |
| cy_rslt_t | mtb_ipc_init (mtb_ipc_t *obj, mtb_ipc_shared_t *shared_data, const mtb_ipc_config_t *config) |
| Initialize IPC library Driver. More... | |
| cy_rslt_t | mtb_ipc_reinit_hw (const mtb_ipc_t *obj) |
| Reinitialize IPC Hardware. More... | |
| cy_rslt_t | mtb_ipc_get_handle (mtb_ipc_t *obj, const mtb_ipc_config_t *config, uint64_t timeout_ms) |
| Get initialized IPC library Driver Call before any other IPC library functions. More... | |
| void | mtb_ipc_semaphore_process_interrupt (mtb_ipc_t *obj) |
| Process IPC library interrupt for Semaphores Place inside an ISR registered for the semaphore interrupt specified for this core during init. More... | |
| void | mtb_ipc_queue_process_interrupt (const mtb_ipc_t *obj) |
| Process IPC library interrupt for Queues Place inside an ISR registered for the queue interrupt specified for this core during init. More... | |
| cy_rslt_t | mtb_ipc_semaphore_init (mtb_ipc_t *obj, mtb_ipc_semaphore_t *semaphore, mtb_ipc_semaphore_data_t *sema_obj, const mtb_ipc_semaphore_config_t *config) |
| Creates a single semaphore based on a given number. More... | |
| cy_rslt_t | mtb_ipc_semaphore_get_handle (mtb_ipc_t *obj, mtb_ipc_semaphore_t *semaphore, uint32_t semaphore_num, uint64_t timeout_us) |
| Finds an already initialized semaphore based on a given number. More... | |
| void | mtb_ipc_semaphore_free (const mtb_ipc_semaphore_t *semaphore) |
| Frees the IPC semaphore. More... | |
| cy_rslt_t | mtb_ipc_semaphore_take (const mtb_ipc_semaphore_t *semaphore, uint64_t timeout_us) |
| Takes/acquires a semaphore. More... | |
| cy_rslt_t | mtb_ipc_semaphore_give (const mtb_ipc_semaphore_t *semaphore) |
| Gives/releases a semaphore. More... | |
| cy_rslt_t | mtb_ipc_queue_init (mtb_ipc_t *obj, mtb_ipc_queue_t *queue, mtb_ipc_queue_data_t *queue_obj, const mtb_ipc_queue_config_t *config) |
| Creates a new queue for a given IPC channel based on the given queue number and other parameters. More... | |
| void | mtb_ipc_queue_free (mtb_ipc_queue_t *queue) |
| Frees the queue. More... | |
| cy_rslt_t | mtb_ipc_queue_get_handle (mtb_ipc_t *obj, mtb_ipc_queue_t *queue, uint32_t channel_num, uint32_t queue_num) |
| Gets a handle pointer for a given IPC channel and queue number. More... | |
| void | mtb_ipc_queue_register_callback (mtb_ipc_queue_t *queue, mtb_ipc_queue_event_callback_t callback, void *callback_arg) |
| Registers a callback to be executed when certain events occur. More... | |
| void | mtb_ipc_queue_enable_event (mtb_ipc_queue_t *queue, mtb_ipc_queue_event_t event, bool enable) |
| Enables which events trigger the callback execution. More... | |
| cy_rslt_t | mtb_ipc_queue_put (mtb_ipc_queue_t *queue, void *msg, uint64_t timeout_us) |
| Adds one item to the queue. More... | |
| cy_rslt_t | mtb_ipc_queue_get (mtb_ipc_queue_t *queue, void *msg, uint64_t timeout_us) |
| Removes one item from the queue. More... | |
| uint32_t | mtb_ipc_queue_count (const mtb_ipc_queue_t *queue) |
| Returns how many items are in the queue. More... | |
| cy_rslt_t | mtb_ipc_queue_reset (const mtb_ipc_queue_t *queue) |
| Clears all the items in the queue. More... | |
| cy_rslt_t | mtb_ipc_mbox_receiver_init (mtb_ipc_t *obj, mtb_ipc_mbox_receiver_t *receiver, mtb_ipc_mbox_data_t *mbox_obj, const mtb_ipc_mbox_config_t *config) |
| Creates a single mailbox based on a given number. More... | |
| cy_rslt_t | mtb_ipc_mbox_sender_get_handle (mtb_ipc_t *obj, mtb_ipc_mbox_sender_t *sender, uint32_t mbox_idx) |
| Gets a handle pointer for a given mailbox index. More... | |
| void | mtb_ipc_mbox_receiver_free (mtb_ipc_mbox_receiver_t *receiver) |
| Frees the mailbox and disconnects the receiver handle. More... | |
| void | mtb_ipc_mbox_sender_free (mtb_ipc_mbox_sender_t *sender) |
| Disconnects the sender handle from the shared mailbox object. More... | |
| void | mtb_ipc_mbox_receiver_register_callback (mtb_ipc_mbox_receiver_t *receiver, mtb_ipc_mbox_event_callback_t callback, void *callback_arg) |
| Registers a callback to be executed on the receiver core when certain events occur. More... | |
| void | mtb_ipc_mbox_sender_register_callback (mtb_ipc_mbox_sender_t *sender, mtb_ipc_mbox_event_callback_t callback, void *callback_arg) |
| Registers a callback to be executed on the sender core when certain events occur. More... | |
| cy_rslt_t | mtb_ipc_mbox_sender_put (mtb_ipc_mbox_sender_t *sender, void *payload, uint64_t timeout_us) |
| Adds item to the mailbox. More... | |
| cy_rslt_t | mtb_ipc_mbox_receiver_get (mtb_ipc_mbox_receiver_t *receiver, void **payload, uint64_t timeout_us) |
| Removes one item from the mailbox. More... | |
| void | mtb_ipc_mbox_receiver_enable_event (mtb_ipc_mbox_receiver_t *receiver, mtb_ipc_mbox_event_t event, bool enable) |
| Enables which events trigger the callback execution for the receiver. More... | |
| void | mtb_ipc_mbox_sender_enable_event (mtb_ipc_mbox_sender_t *sender, mtb_ipc_mbox_event_t event, bool enable) |
| Enables which events trigger the callback execution for the sender. More... | |
| struct mtb_ipc_semaphore_config_t |
| struct mtb_ipc_mbox_config_t |
| struct mtb_ipc_queue_config_t |
| Data Fields | ||
|---|---|---|
| mtb_ipc_channel_t | channel_num |
IPC channel number (e.g. MTB_IPC_CHAN_0) Please refer to implementation specific documentation for number of available IPC channels for particular device. |
| uint32_t | queue_num | Queue number, which must be unique for each queue in scope of one IPC channel. |
| uint32_t | max_num_items | Maximum number of items (packets) allowed in the queue. |
| uint32_t | item_size | Size of each packet (item) in the Queue. |
| void * | queue_pool |
Pointer to the queue packets in shared memory. This memory will be cleared by IPC library Queue Initialization. Packet list is an array of packets of max_num_items. It is used as a circular array, first_item is an index to first item stored. |
| uint32_t | semaphore_num | Semaphore number to use with this queue. |
| struct mtb_ipc_config_t |
| Data Fields | ||
|---|---|---|
| mtb_ipc_channel_t | internal_channel_index |
IPC channel number (e.g. MTB_IPC_CHAN_0) Please refer to implementation specific documentation for number of available IPC channels for particular device. This must match the IPC object initialized on the other core for this core to access the shared memory. |
| uint32_t | semaphore_irq |
User Defined IRQ for use on this core for all semaphores. A unique IRQ must be used for each core |
| uint32_t | queue_irq |
User Defined IRQ for use on this core for all queues. A unique IRQ must be used for each core |
| uint32_t | semaphore_num | User defined semaphore number to use for access to shared region and all MTB IPC operations. |
| enum mtb_ipc_mbox_event_t |
Flags enum of IPC Mailbox events.
Multiple events can be enabled via mtb_ipc_mbox_receiver_enable_event mtb_ipc_mbox_sender_enable_event and the callback from mtb_ipc_mbox_receiver_register_callback or mtb_ipc_mbox_sender_register_callback will be run to notify.
| Enumerator | |
|---|---|
| MTB_IPC_MBOX_FULL | Mailbox is full. |
| MTB_IPC_MBOX_EMPTY | Mailbox is empty. |
Flags enum of IPC events.
Multiple events can be enabled via mtb_ipc_queue_enable_event and the callback from mtb_ipc_queue_register_callback will be run to notify.
| cy_rslt_t mtb_ipc_init | ( | mtb_ipc_t * | obj, |
| mtb_ipc_shared_t * | shared_data, | ||
| const mtb_ipc_config_t * | config | ||
| ) |
Initialize IPC library Driver.
Call before any other IPC library functions. Must be called before any other core calls mtb_ipc_get_handle. The initialization of the semaphore must be done by the init core on startup or during cybsp_init() as the IPC driver assumes it has already been done. The MTB IPC has no way of ensuring it hasn't been already initialized on the channel, so it is up to user to ensure that init is called once on one core and mtb_ipc_get_handle is called on remaining core(s).
| obj | - Object for the IPC library instance |
| shared_data | - pointer to the allocated shared memory object. MTB_IPC_SHARED_DATA_ALLOC macro can (and not mandatory) be used in order to allocate memory for shared data (mtb_ipc_shared_t) in shared section. |
| config | - The user-provided configuration. Fields internal_channel_index, semaphore_irq, queue_irq, semaphore_num are expected to be filled by user before initialization. Please refer to Snippet 1: Binary semaphore example for initialization guidance. |
| cy_rslt_t mtb_ipc_reinit_hw | ( | const mtb_ipc_t * | obj | ) |
Reinitialize IPC Hardware.
If the underlying IPC hardware is reset (for example, because its containing power domain was powered off and then subsequently powered back on), this function must be called immediately after the IPC hardware is powered back on, before any other IPC operations are performed by any core.
mtb_ipc_init was previously called. This function may only be called from the core which originally called mtb_ipc_init.| obj | - Object for the IPC library instance |
| cy_rslt_t mtb_ipc_get_handle | ( | mtb_ipc_t * | obj, |
| const mtb_ipc_config_t * | config, | ||
| uint64_t | timeout_ms | ||
| ) |
Get initialized IPC library Driver Call before any other IPC library functions.
Call from Cores other than that which called mtb_ipc_init to initialize the system, timeout_ms is the timeout for waiting the initializing core to finish initialization. This function initializes the Shared Memory Data structures for IPC library Semaphore and IPC library Queue usage.
IRQ channels provided must be different than those used in mtb_ipc_init on the initialization core.
| obj | - Object for the IPC library instance |
| timeout_ms | - time in milliseconds for non-initializing core to wait for initializing core to complete initialization |
| config | - User provided configuration of the IPC library instance, whose fields internal_ipc_channel, semaphore_num must match config on the core that initialized to ensure compatibility. Please refer to Snippet 1: Binary semaphore example for initialization guidance. |
| void mtb_ipc_semaphore_process_interrupt | ( | mtb_ipc_t * | obj | ) |
Process IPC library interrupt for Semaphores Place inside an ISR registered for the semaphore interrupt specified for this core during init.
This function is used to perform interrupt functionality for instantiated semaphore objects.
| obj | - Object for the IPC library instance |
Process IPC library interrupt for Semaphores Place inside an ISR registered for the semaphore interrupt specified for this core during init.
It iterates through associated RTOS semaphores so it only is looking for relevant semaphores instead of whole linked list.
Set index to unused as the interrupt has signaled it was given
| void mtb_ipc_queue_process_interrupt | ( | const mtb_ipc_t * | obj | ) |
Process IPC library interrupt for Queues Place inside an ISR registered for the queue interrupt specified for this core during init.
This function is used to perform interrupt functionality for instantiated queue objects.
| obj | - Object for the IPC library instance |
Process IPC library interrupt for Queues Place inside an ISR registered for the queue interrupt specified for this core during init.
| cy_rslt_t mtb_ipc_semaphore_init | ( | mtb_ipc_t * | obj, |
| mtb_ipc_semaphore_t * | semaphore, | ||
| mtb_ipc_semaphore_data_t * | sema_obj, | ||
| const mtb_ipc_semaphore_config_t * | config | ||
| ) |
Creates a single semaphore based on a given number.
The semaphore number range starts at 0. the max number depends on a few factors max = _MTB_IPC_SEMA_COUNT - 1 (IPC driver semaphore) - num_queues - (num_queues * num_processes_per_queue)
| [out] | obj | Pointer to an IPC object. Must be initialized by mtb_ipc_init before initializing a semaphore. |
| [out] | semaphore | Handle to an IPC semaphore. This handle exists per core and is for api access to the shared sema_obj. |
| [in] | sema_obj | Semaphore data stored in shared memory. |
| [in] | config | The user-provided configuration. Please refer to Snippet 1: Binary semaphore example for initialization guidance |
| cy_rslt_t mtb_ipc_semaphore_get_handle | ( | mtb_ipc_t * | obj, |
| mtb_ipc_semaphore_t * | semaphore, | ||
| uint32_t | semaphore_num, | ||
| uint64_t | timeout_us | ||
| ) |
Finds an already initialized semaphore based on a given number.
This function must be called before accessing the semaphore from a different Core than it was initialized on. mtb_ipc_semaphore_init must be called on the initializing core before this function is called, else it will timeout.
| [out] | obj | Handle to an IPC object pointer. |
| [out] | semaphore | Handle to an IPC semaphore. This handle exists per core and is for api access to the shared semaphore data. |
| [in] | semaphore_num | The semaphore number to get a pointer for |
| [in] | timeout_us | Timeout (in uSec) to wait while trying to get the handle |
Finds an already initialized semaphore based on a given number.
| void mtb_ipc_semaphore_free | ( | const mtb_ipc_semaphore_t * | semaphore | ) |
Frees the IPC semaphore.
This function frees the resources associated with the semaphore.
| [in] | semaphore | The semaphore object. |
Frees the IPC semaphore.
| cy_rslt_t mtb_ipc_semaphore_take | ( | const mtb_ipc_semaphore_t * | semaphore, |
| uint64_t | timeout_us | ||
| ) |
Takes/acquires a semaphore.
If the semaphore is available, it is acquired and this function returns. This function has a timeout argument (in microseconds). If the semaphore is not available, it blocks until it times out or succeeds in acquiring it.
| [in] | semaphore | The semaphore object. |
| [in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while MTB_IPC_NEVER_TIMEOUT can be used to make function block until semaphore is successfully taken. |
| cy_rslt_t mtb_ipc_semaphore_give | ( | const mtb_ipc_semaphore_t * | semaphore | ) |
Gives/releases a semaphore.
The semaphore is released allowing other tasks waiting on the semaphore to take it.
| [in] | semaphore | The semaphore object. |
| cy_rslt_t mtb_ipc_queue_init | ( | mtb_ipc_t * | obj, |
| mtb_ipc_queue_t * | queue, | ||
| mtb_ipc_queue_data_t * | queue_obj, | ||
| const mtb_ipc_queue_config_t * | config | ||
| ) |
Creates a new queue for a given IPC channel based on the given queue number and other parameters.
This function requires mtb_ipc_queue_data_t (queue_obj) pointer to shared memory. mtb_ipc_queue_data_t is used by other tasks/CPUs to refer to the queue. Note that this function must be called only by one of the tasks/CPUs for the same IPC channel. This CPU can call the function multiple times for the same IPC channel, but with a different queue number. The IPC channel index must be different from the channel index used for mtb_ipc_init because that channel is used internally by the semaphores.
| [out] | obj | Pointer to an IPC object. Must be initialized by mtb_ipc_init before initializing a queue. |
| [out] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| [in] | queue_obj | Queue data object stored in shared memory. |
| [in] | config | The user-provided configuration. Please refer to Snippet 2: Message queue example for initialization guidance. |
| void mtb_ipc_queue_free | ( | mtb_ipc_queue_t * | queue | ) |
Frees the queue.
This operation only removes the queue handle from the list of available queues. The queue pool and the queue handle allocated in the shared memory need to be freed (if dynamically allocated) by the application.
| [out] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| cy_rslt_t mtb_ipc_queue_get_handle | ( | mtb_ipc_t * | obj, |
| mtb_ipc_queue_t * | queue, | ||
| uint32_t | channel_num, | ||
| uint32_t | queue_num | ||
| ) |
Gets a handle pointer for a given IPC channel and queue number.
This function should be called by other tasks/CPUs that have not called the initialization function. Unpredicted behavior can happen if this function is called before mtb_ipc_queue_init. Please refer to implementation specific documentation for additional details.
| [out] | obj | The IPC object handle. |
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| [in] | channel_num | IPC channel to use for the queue messaging. |
| [in] | queue_num | Queue number. |
| void mtb_ipc_queue_register_callback | ( | mtb_ipc_queue_t * | queue, |
| mtb_ipc_queue_event_callback_t | callback, | ||
| void * | callback_arg | ||
| ) |
Registers a callback to be executed when certain events occur.
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| [in] | callback | The callback handler which will be invoked when an event triggers. |
| [in] | callback_arg | Generic argument that will be provided to the callback when called. |
| void mtb_ipc_queue_enable_event | ( | mtb_ipc_queue_t * | queue, |
| mtb_ipc_queue_event_t | event, | ||
| bool | enable | ||
| ) |
Enables which events trigger the callback execution.
It can trigger when a new item is written to the queue, read from the queue, when the queue becomes full, when the queue becomes empty or when there is a reset. Note that these events might execute callbacks associated to all queues that belong to an IPC channel.
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| [in] | event | The IPC event type |
| [in] | enable | True to turn on specified events, False to turn off |
Enables which events trigger the callback execution.
| cy_rslt_t mtb_ipc_queue_put | ( | mtb_ipc_queue_t * | queue, |
| void * | msg, | ||
| uint64_t | timeout_us | ||
| ) |
Adds one item to the queue.
This function can be called by any task/CPU. This function has a timeout argument (in microseconds). If the queue is full, it stays there until it times out or the queue is no longer full. This function can be blocking or non-blocking (timeout set to ZERO).
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| [in] | msg | Location of message queue item |
| [in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while MTB_IPC_NEVER_TIMEOUT can be used to make function block until element is successfully put into the queue. |
| cy_rslt_t mtb_ipc_queue_get | ( | mtb_ipc_queue_t * | queue, |
| void * | msg, | ||
| uint64_t | timeout_us | ||
| ) |
Removes one item from the queue.
This function can be called by any task/CPU. This function has a timeout argument (in microseconds). If the queue is empty, it stays there until it times out or the queue receives a new item. This function can be blocking or non-blocking (timeout set to ZERO).
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
| [out] | msg | Location to copy message queue item to |
| [in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while MTB_IPC_NEVER_TIMEOUT can be used to make function block until element is successfully taken from the queue. |
Removes one item from the queue.
| uint32_t mtb_ipc_queue_count | ( | const mtb_ipc_queue_t * | queue | ) |
Returns how many items are in the queue.
This function can be called by any task/CPU.
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
Returns how many items are in the queue.
| cy_rslt_t mtb_ipc_queue_reset | ( | const mtb_ipc_queue_t * | queue | ) |
Clears all the items in the queue.
This function can be called by the any task/CPU.
| [in] | queue | Queue handle used to reference queue_obj store in shared memory. The queue acts as the per-core handle for the shared data. |
Clears all the items in the queue.
| cy_rslt_t mtb_ipc_mbox_receiver_init | ( | mtb_ipc_t * | obj, |
| mtb_ipc_mbox_receiver_t * | receiver, | ||
| mtb_ipc_mbox_data_t * | mbox_obj, | ||
| const mtb_ipc_mbox_config_t * | config | ||
| ) |
Creates a single mailbox based on a given number.
The mailbox number range is 0- MTB_IPC_MAX_MBOXES.
| [in] | obj | Pointer to an IPC object. Must be initialized by mtb_ipc_init before initializing a mailbox. |
| [out] | receiver | Handle to the mailbox on the core intended to be the receiver. |
| [in] | mbox_obj | Mailbox data stored in shared memory. |
| [in] | config | The user-provided configuration. Please refer to Snippet 1: Binary semaphore example for initialization guidance |
| cy_rslt_t mtb_ipc_mbox_sender_get_handle | ( | mtb_ipc_t * | obj, |
| mtb_ipc_mbox_sender_t * | sender, | ||
| uint32_t | mbox_idx | ||
| ) |
Gets a handle pointer for a given mailbox index.
This function should be called by the core intended to be the mailbox sender. Unpredicted behavior can happen if this function is called before mtb_ipc_mbox_receiver_init. Do not call this in an interrupt service routine.
| [in] | obj | The IPC object handle. |
| [out] | sender | Handle to the mailbox on the core intended to be the sender |
| [in] | mbox_idx | Mailbox number in range 0 - MTB_IPC_MAX_MBOXES. |
THis function cannot be called in an ISR
| void mtb_ipc_mbox_receiver_free | ( | mtb_ipc_mbox_receiver_t * | receiver | ) |
Frees the mailbox and disconnects the receiver handle.
This should be called after freeing the sender on the other core.
This operation only removes the mailbox handle from the list of available mailboxes. The mailbox object allocated in the shared memory needs to be freed (if dynamically allocated) by the application.
| [out] | receiver | Mailbox handle used to reference mbox_object stored in shared memory. The receiver acts as the per-core handle for the shared data. |
| void mtb_ipc_mbox_sender_free | ( | mtb_ipc_mbox_sender_t * | sender | ) |
Disconnects the sender handle from the shared mailbox object.
This must be done before mtb_ipc_mbox_receiver_free.
This operation only removes the mailbox handle from the list of available mailboxes. The mailbox object allocated in the shared memory needs to be freed (if dynamically allocated) by the application.
| [out] | sender | Mailbox handle used to reference mbox_object stored in shared memory. The sender acts as the per-core handle for the shared data. |
| void mtb_ipc_mbox_receiver_register_callback | ( | mtb_ipc_mbox_receiver_t * | receiver, |
| mtb_ipc_mbox_event_callback_t | callback, | ||
| void * | callback_arg | ||
| ) |
Registers a callback to be executed on the receiver core when certain events occur.
| [in] | receiver | Mailbox handle used to reference mbox_obj store in shared memory. The receiver acts as the per-core handle for the shared data. |
| [in] | callback | The callback handler which will be invoked when an event triggers. |
| [in] | callback_arg | Generic argument that will be provided to the callback when called. |
| void mtb_ipc_mbox_sender_register_callback | ( | mtb_ipc_mbox_sender_t * | sender, |
| mtb_ipc_mbox_event_callback_t | callback, | ||
| void * | callback_arg | ||
| ) |
Registers a callback to be executed on the sender core when certain events occur.
| [in] | sender | Mailbox handle used to reference mbox_obj store in shared memory. The sender acts as the per-core handle for the shared data. |
| [in] | callback | The callback handler which will be invoked when an event triggers. |
| [in] | callback_arg | Generic argument that will be provided to the callback when called. |
| cy_rslt_t mtb_ipc_mbox_sender_put | ( | mtb_ipc_mbox_sender_t * | sender, |
| void * | payload, | ||
| uint64_t | timeout_us | ||
| ) |
Adds item to the mailbox.
This function can only be called by the sender for this mailbox. If the mailbox is full, it stays there until it times out or the mailbox is no longer full. This function can be blocking or non-blocking (timeout set to ZERO).
| [in] | sender | Mailbox handle used to reference mailbox object store in shared memory. The sender acts as the per-core handle for the shared data. |
| [in] | payload | Location of payload item |
| [in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while MTB_IPC_NEVER_TIMEOUT can be used to make function block until element is successfully put into the mailbox. |
| cy_rslt_t mtb_ipc_mbox_receiver_get | ( | mtb_ipc_mbox_receiver_t * | receiver, |
| void ** | payload, | ||
| uint64_t | timeout_us | ||
| ) |
Removes one item from the mailbox.
This function can be only called by a receiver handle. This function has a timeout argument (in microseconds). If the mailbox is empty, it stays there until it times out or the mailbox receives a new item. This function can be blocking or non-blocking (timeout set to ZERO).
| [in] | receiver | Mailbox handle used to reference mbox_obj store in shared memory. The receiver acts as the per-core handle for the shared data. |
| [out] | payload | Location to copy message mailbox item to |
| [in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while MTB_IPC_NEVER_TIMEOUT can be used to make function block until element is successfully taken from the mailbox. |
| void mtb_ipc_mbox_receiver_enable_event | ( | mtb_ipc_mbox_receiver_t * | receiver, |
| mtb_ipc_mbox_event_t | event, | ||
| bool | enable | ||
| ) |
Enables which events trigger the callback execution for the receiver.
It can trigger for these events mtb_ipc_mbox_event_t.
| [in] | receiver | Mailbox handle used to reference mbox_obj stored in shared memory. The receiver acts as the per-core handle for the shared data. |
| [in] | event | The IPC mailbox event type |
| [in] | enable | True to turn on specified events, False to turn off |
| void mtb_ipc_mbox_sender_enable_event | ( | mtb_ipc_mbox_sender_t * | sender, |
| mtb_ipc_mbox_event_t | event, | ||
| bool | enable | ||
| ) |
Enables which events trigger the callback execution for the sender.
It can trigger for these events mtb_ipc_mbox_event_t.
| [in] | sender | Mailbox handle used to reference mbox_obj stored in shared memory. The sender acts as the per-core handle for the shared data. |
| [in] | event | The IPC mailbox event type |
| [in] | enable | True to turn on specified events, False to turn off |