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.
For binary semaphores, initialize the semaphore for the task/CPU. Then take/give the semaphore. For queues, only one task/CPU may initialize a queue. Other tasks/CPUs then get the handle of the created queue. Use the get/put functions to take out or put in items to the queue.
API Reference | |
IPC HAL Results | |
IPC specific return codes. | |
Data Structures | |
struct | cyhal_ipc_queue_t |
IPC queue structure element. More... | |
Typedefs | |
typedef void(* | cyhal_ipc_event_callback_t) (void *callback_arg, cyhal_ipc_event_t event) |
Event handler for IPC interrupts. | |
Enumerations | |
enum | cyhal_ipc_event_t { CYHAL_IPC_NO_INTR = 0 , CYHAL_IPC_QUEUE_WRITE = 1 << 0 , CYHAL_IPC_QUEUE_READ = 1 << 1 , CYHAL_IPC_QUEUE_FULL = 1 << 2 , CYHAL_IPC_QUEUE_EMPTY = 1 << 3 , CYHAL_IPC_QUEUE_RESET = 1 << 4 } |
Flags enum of IPC events. More... | |
Functions | |
cy_rslt_t | cyhal_ipc_semaphore_init (cyhal_ipc_t *obj, uint32_t semaphore_num, bool preemptable) |
Creates a single semaphore based on a given number. More... | |
void | cyhal_ipc_semaphore_free (cyhal_ipc_t *obj) |
Frees the IPC semaphore. More... | |
cy_rslt_t | cyhal_ipc_semaphore_take (cyhal_ipc_t *obj, uint32_t timeout_us) |
Takes/acquires a semaphore. More... | |
cy_rslt_t | cyhal_ipc_semaphore_give (cyhal_ipc_t *obj) |
Gives/releases a semaphore. More... | |
cy_rslt_t | cyhal_ipc_queue_init (cyhal_ipc_t *obj, cyhal_ipc_queue_t *queue_handle) |
Creates a new queue for a given IPC channel based on the given queue number and other parameters. More... | |
void | cyhal_ipc_queue_free (cyhal_ipc_t *obj) |
Frees the queue. More... | |
cy_rslt_t | cyhal_ipc_queue_get_handle (cyhal_ipc_t *obj, uint32_t channel_num, uint32_t queue_num) |
Gets a handle pointer for a given IPC channel and queue number. More... | |
void | cyhal_ipc_queue_register_callback (cyhal_ipc_t *obj, cyhal_ipc_event_callback_t callback, void *callback_arg) |
Registers a callback to be executed when certain events occur. More... | |
void | cyhal_ipc_queue_enable_event (cyhal_ipc_t *obj, cyhal_ipc_event_t event, uint8_t intr_priority, bool enable) |
Enables which events trigger the callback execution. More... | |
cy_rslt_t | cyhal_ipc_queue_put (cyhal_ipc_t *obj, void *msg, uint32_t timeout_us) |
Adds one item to the queue. More... | |
cy_rslt_t | cyhal_ipc_queue_get (cyhal_ipc_t *obj, void *msg, uint32_t timeout_us) |
Removes one item from the queue. More... | |
uint32_t | cyhal_ipc_queue_count (cyhal_ipc_t *obj) |
Returns how many items are in the queue. More... | |
cy_rslt_t | cyhal_ipc_queue_reset (cyhal_ipc_t *obj) |
Clear all the items in the queue. More... | |
struct cyhal_ipc_queue_t |
enum cyhal_ipc_event_t |
Flags enum of IPC events.
Multiple events can be enabled via cyhal_ipc_queue_enable_event and the callback from cyhal_ipc_queue_register_callback will be run to notify.
cy_rslt_t cyhal_ipc_semaphore_init | ( | cyhal_ipc_t * | obj, |
uint32_t | semaphore_num, | ||
bool | preemptable | ||
) |
Creates a single semaphore based on a given number.
This function must be called by all tasks/CPUs accessing the semaphore.
[out] | obj | Pointer to an IPC object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | semaphore_num | The semaphore number to initialize. |
[in] | preemptable | Allows whether the semaphore can be preempted by another task. |
void cyhal_ipc_semaphore_free | ( | cyhal_ipc_t * | obj | ) |
Frees the IPC semaphore.
This function frees the resources associated with the semaphore.
[in,out] | obj | The IPC object. |
cy_rslt_t cyhal_ipc_semaphore_take | ( | cyhal_ipc_t * | obj, |
uint32_t | timeout_us | ||
) |
Takes/acquires a semaphore.
If the semaphore is available, it is acquired and this function and 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] | obj | The IPC object. |
[in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while CYHAL_IPC_NEVER_TIMEOUT can be used to make function block until semaphore is successfully taken. |
cy_rslt_t cyhal_ipc_semaphore_give | ( | cyhal_ipc_t * | obj | ) |
Gives/releases a semaphore.
The semaphore is released allowing other tasks waiting on the semaphore to take it.
[in] | obj | The IPC object. |
cy_rslt_t cyhal_ipc_queue_init | ( | cyhal_ipc_t * | obj, |
cyhal_ipc_queue_t * | queue_handle | ||
) |
Creates a new queue for a given IPC channel based on the given queue number and other parameters.
This function requires cyhal_ipc_queue_t (queue handle) pointer to shared memory. Some elements of cyhal_ipc_queue_t structure are expected to be filled by user. One key element of the structure to be filled by user is a pointer to the queue pool allocated in the shared memory. Queue handle 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.
[out] | obj | Pointer to an IPC object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | queue_handle | Queue handle. Fields channel_num, queue_num, queue_pool, num_items and item_size are expected to be filled by user before initialization. Please refer to Snippet 2: Message queue example for initialization guidance. |
void cyhal_ipc_queue_free | ( | cyhal_ipc_t * | obj | ) |
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 needs to be freed (if dynamically allocated) by the application.
[in,out] | obj | The IPC object |
cy_rslt_t cyhal_ipc_queue_get_handle | ( | cyhal_ipc_t * | obj, |
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.
[out] | obj | The IPC object handle. |
[in] | channel_num | IPC channel to use for the queue messaging. |
[in] | queue_num | Queue number. |
void cyhal_ipc_queue_register_callback | ( | cyhal_ipc_t * | obj, |
cyhal_ipc_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
Registers a callback to be executed when certain events occur.
[in] | obj | The IPC object. |
[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 cyhal_ipc_queue_enable_event | ( | cyhal_ipc_t * | obj, |
cyhal_ipc_event_t | event, | ||
uint8_t | intr_priority, | ||
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. When defining the ISR priority, the last call to this function overwrites the priority for all queue callbacks registered to the same IPC channel.
[in] | obj | The IPC object |
[in] | event | The IPC event type |
[in] | intr_priority | The priority for NVIC interrupt events |
[in] | enable | True to turn on specified events, False to turn off |
cy_rslt_t cyhal_ipc_queue_put | ( | cyhal_ipc_t * | obj, |
void * | msg, | ||
uint32_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] | obj | The IPC object |
[in] | msg | Location of message queue item |
[in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while CYHAL_IPC_NEVER_TIMEOUT can be used to make function block until element is successfully put into the queue. |
cy_rslt_t cyhal_ipc_queue_get | ( | cyhal_ipc_t * | obj, |
void * | msg, | ||
uint32_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] | obj | The IPC object |
[out] | msg | Location of message queue item |
[in] | timeout_us | Timeout in microseconds. Value 0 can be used if no timeout needed while CYHAL_IPC_NEVER_TIMEOUT can be used to make function block until element is successfully taken from the queue. |
uint32_t cyhal_ipc_queue_count | ( | cyhal_ipc_t * | obj | ) |
Returns how many items are in the queue.
This function can be called by any task/CPU.
[in] | obj | The IPC object |
cy_rslt_t cyhal_ipc_queue_reset | ( | cyhal_ipc_t * | obj | ) |
Clear all the items in the queue.
This function can be called by the any task/CPU.
[in] | obj | The IPC object |