| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Modules | Macros | Functions
LPC43xx Inter Processor Communication(IPC) functions
LPC43xx dual core common code

## Detailed Description

The Inter Processor Communication(IPC) functions provide standalone and RTOS based support functions for sharing data between the M0 and M4 core.

Build procedure: LPCOpen 18xx/43xx build instructions

Submit bug reports for LPCOpen code here.

## Data Structures
struct | ipc_queue
| IPC Queue Structure used for sync between M0 and M4. More...

## Modules
| LPC43xx Inter Processor Communication(IPC) example

## Macros
#define | QUEUE_DATA_COUNT(q) ((uint32_t) ((q)->head - (q)->tail))
#define | QUEUE_IS_FULL(q) (QUEUE_DATA_COUNT(q) >= (q)->count)
#define | QUEUE_IS_EMPTY(q) ((q)->head == (q)->tail)
#define | QUEUE_IS_VALID(q) ((q)->valid == QUEUE_MAGIC_VALID)
#define | QUEUE_VALID 1
#define | QUEUE_INSERT 0
#define | QUEUE_FULL -1
#define | QUEUE_EMPTY -2
#define | QUEUE_ERROR -3
#define | QUEUE_TIMEOUT -4
#define | QUEUE_MAGIC_VALID 0xCAB51053

## Functions
int | IPC_pushMsgTout (const void *data, int tout)
| Function to push a message into queue with timeout.
int | IPC_popMsgTout (void *data, int tout)
| Function to read a message from queue with timeout.
static INLINE int | IPC_tryPushMsg (const void *data)
| Function to push the message into queue with no wait.
static INLINE int | IPC_tryPopMsg (void *data)
| Function to pop the message from queue with no wait.
static INLINE int | IPC_pushMsg (const void *data)
| Function to push the message into queue with wait.
static INLINE int | IPC_popMsg (void *data)
| Function to pop the message from queue with wait.
int | IPC_msgPending (int queue_write)
| Get number of pending items in queue.
void | IPC_msgNotify (void)
| Function to send notificaton interrupt.
void | IPC_initMsgQueue (void *data, int msgSize, int maxNoOfMsg)
| Function to initialize the IPC message queue.
const char * | IPC_strerror (int errnum)
| Function to convert IPC error number to string.

## Macro Definition Documentation

#define IPC_IRQ_Priority IRQ_PRIO_IPC

Definition at line 78 of file ipc_msg.c.

#define ipc_wait_event | ( |  | evt,
|  |  | sem
| ) |  | while ((evt))

Definition at line 224 of file ipc_msg.c.

#define ipc_wait_event_tout | ( |  | evt,
|  |  | tout,
|  |  | sem
| ) |  |

Value:
do { \
uint32_t cnt = Chip_RIT_GetCounter(LPC_RITIMER) + (tout * (SystemCoreClock / 1000)); \
if (cnt + 5000 < cnt) {cnt += 5000; } \
while ((evt) && Chip_RIT_GetCounter(LPC_RITIMER) < cnt) {} \
if (evt) {tout = 0; } \
} while (0)

Definition at line 226 of file ipc_msg.c.

#define QUEUE_DATA_COUNT | ( |  | q | ) | ((uint32_t) ((q)->head - (q)->tail))

This macro will get the number of items pending in q

Definition at line 56 of file ipc_msg.h.

#define QUEUE_EMPTY -2

Returned by dualcore IPC function when an attempt is made to fetch/pop an item from the Message Queue when the queue is empty.

Definition at line 117 of file ipc_msg.h.

#define QUEUE_ERROR -3

Returned by dualcore IPC function when an push/pop is made to a queue which was not initialized using IPC_initMsgQueue()

Definition at line 124 of file ipc_msg.h.

#define QUEUE_FULL -1

Returned by dualcore IPC function when an attempt is made to insert item into the Message Queue when the queue is full.

Definition at line 109 of file ipc_msg.h.

#define QUEUE_INSERT 0

Returned by dualcore IPC function when an item is successfully inserted into the Message Queue

Definition at line 101 of file ipc_msg.h.

#define QUEUE_IS_EMPTY | ( |  | q | ) | ((q)->head == (q)->tail)

This macro will evaluate to 1 if queue q is empty, 0 if it is not

Definition at line 66 of file ipc_msg.h.

#define QUEUE_IS_FULL | ( |  | q | ) | (QUEUE_DATA_COUNT(q) >= (q)->count)

This macro will evaluate to 1 if queue q is full, 0 if it is not

Definition at line 61 of file ipc_msg.h.

#define QUEUE_IS_VALID | ( |  | q | ) | ((q)->valid == QUEUE_MAGIC_VALID)

This macro will evaluate to 1 if queue q is initialized & valid, 0 if it is not

Definition at line 71 of file ipc_msg.h.

#define QUEUE_MAGIC_VALID 0xCAB51053

Macro used to identify if a queue is valid

Definition at line 137 of file ipc_msg.h.

#define QUEUE_TIMEOUT -4

Returned by dualcore IPC function when a push/pop operation did not complete within a given time.

Definition at line 131 of file ipc_msg.h.

#define QUEUE_VALID 1

Returned by dualcore IPC function when an item is successfully fetched from Message Queue

Definition at line 94 of file ipc_msg.h.

#define SHMEMM0 LOCATE_AT(SHARED_MEM_M0)

Definition at line 53 of file ipc_msg.c.

#define SHMEMM4 LOCATE_AT(SHARED_MEM_M4)

Definition at line 54 of file ipc_msg.c.

## Function Documentation

void EVENT_IPC_Receive | ( | void |  | ) |

Call-back function to handle IPC Message receive event.

Returns
  None This is a weak function (hence can be overridden by the user's application with a function of same name. This call-back function will be called whenever there is a message received by the core that implements this function.

Definition at line 382 of file ipc_msg.c.

void IPC_initMsgQueue | ( | void * | data,
|  | int | msgSize,
|  | int | maxNoOfMsg
| ) |  |

Function to initialize the IPC message queue.

This function intializes the interprocessor communication message queue. IMPORTANT NOTE: MaxNoOfMsg must always be a power of 2.

Parameters

  data | : Pointer to the array of messages of size msgSize
  msgSize | : Size of the single data element in queue
  maxNoOfMsg | : Maximum number of items that can be stored in Queue

Returns
  None, will not return if there is error in given arguments

Definition at line 262 of file ipc_msg.c.

void IPC_IRQHandler | ( | void |  | ) |

Interrupt handler for IPC interrupts.

Returns
  None

Definition at line 392 of file ipc_msg.c.

static void ipc_misc_init | ( | void |  | ) |
| static

Definition at line 234 of file ipc_msg.c.

void IPC_msgNotify | ( | void |  | ) |

Function to send notificaton interrupt.

When called from the M0, it sends the notification interrupt to M4 and vice-versa.

Returns
  None

Definition at line 256 of file ipc_msg.c.

int IPC_msgPending | ( | int | queue_write | ) |

Get number of pending items in queue.

This function will get the number of pending items in the queue. If this function is called by M4 core with param queue_write set to non zero then this function will return the number of messages waiting in M4's Push Queue that is yet to be popped by the M0 core, or vice versa. If this function is called by M4 core with param queue_write set to zero then it returns the number of elements that can be popped without waiting (in other words number of messages pending in the M0's Push queue that is yet to be popped by M4 core), or vice versa.

Parameters

  queue_write | : 1 - read number of elements in write queue, 0 - read number of elements in read queue

Returns
  On success - Number of elements in queue (which will be >= 0),

Note
  On Error - QUEUE_ERROR (when queue is not initialized/valid)

Definition at line 362 of file ipc_msg.c.

static INLINE int IPC_popMsg | ( | void * | data | ) |
| static

Function to pop the message from queue with wait.

The function will pop the data from the IPC queue. If the queue is empty, it will wait (blocking) till the data is available.

Parameters

  data | : Pointer to store popped data

Returns
  status : Pop status

Definition at line 225 of file ipc_msg.h.

int IPC_popMsgTout | ( | void * | data,
|  | int | tout
| ) |  |

Function to read a message from queue with timeout.

This function will pop a message of size size, specified by IPC_initMsgQueue of the other core. If this function is called from M4 Core the message will be popped from M0 Queue and vice-versa.

Parameters

  data | : Pointer to store popped data
  tout | : non-zero value - timeout value in milliseconds, zero value - no blocking, negative value - blocking

Returns
  QUEUE_VALID on success,

Note
  QUEUE_EMPTY or QUEUE_ERROR on failure, QUEUE_TIMEOUT when there is a timeout

Definition at line 321 of file ipc_msg.c.

static INLINE int IPC_pushMsg | ( | const void * | data | ) |
| static

Function to push the message into queue with wait.

The function to push the data to the IPC queue. If the queue is full, it will wait till data is pushed (blocking).

Parameters

  data | : Pointer to data to be pushed

Returns
  QUEUE_INSERT on success, QUEUE_ERROR on failure

Definition at line 211 of file ipc_msg.h.

int IPC_pushMsgTout | ( | const void * | data,
|  | int | tout
| ) |  |

Function to push a message into queue with timeout.

This function will push an message of size size, specified by IPC_initMsgQueue. If this function is called from M4 Core the message will be pushed to M4 Queue and will be popped by M0, and vice-versa.

Parameters

  data | : Pointer to data to be pushed
  tout | : non-zero value - timeout value in milliseconds, zero value - no blocking, negative value - blocking

Returns
  QUEUE_INSERT on success,

Note
  QUEUE_FULL or QUEUE_ERROR on failure, QUEUE_TIMEOUT when there is a timeout

Definition at line 288 of file ipc_msg.c.

static void ipc_send_signal | ( | void |  | ) |
| static

Definition at line 245 of file ipc_msg.c.

const char* IPC_strerror | ( | int | errnum | ) |

Function to convert IPC error number to string.

This function returns the error string for the error value.

Parameters

  errnum | : IPC error value

Returns
  pointer to error string

Definition at line 405 of file ipc_msg.c.

static INLINE int IPC_tryPopMsg | ( | void * | data | ) |
| static

Function to pop the message from queue with no wait.

The function tries to pop the data from the IPC queue. If the queue is empty, it will return without blocking.

Parameters

  data | : Pointer to store popped data

Returns
  QUEUE_VALID on success, QUEUE_ERROR or QUEUE_EMPTY on failure

Definition at line 197 of file ipc_msg.h.

static INLINE int IPC_tryPushMsg | ( | const void * | data | ) |
| static

Function to push the message into queue with no wait.

The function tries to push the data to the IPC queue. If the queue is full, it will return without blocking. It is equivalent to calling IPC_pushMsgTout(data, 0).

Parameters

  data | : Pointer to data to be pushed

Returns
  QUEUE_INSERT on success, QUEUE_FULL or QUEUE_ERROR on failure

Definition at line 183 of file ipc_msg.h.

static void os_event_handler | ( | void |  | ) |
| static

Definition at line 218 of file ipc_msg.c.

## Variable Documentation

SHMEMM0 struct ipc_queue queue_m0 = {0}
| static

Definition at line 63 of file ipc_msg.c.

SHMEMM4 struct ipc_queue queue_m4 = {0}
| static

Definition at line 72 of file ipc_msg.c.