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

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

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ipc_example.c
Go to the documentation of this file.
1 /*
2 * @brief Example implementation of IPC using IPC library
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "lpc43xx_dualcore_config.h"
33 #include "ipc_msg.h"
34 #include "ipc_example.h"
35
36 #ifdef OS_FREE_RTOS
37 #include "FreeRTOS.h"
38 #include "task.h"
39
40 #elif defined(OS_UCOS_III)
41 #include "os.h"
42 #endif
43
48 /*****************************************************************************
49 * Private types/enumerations/variables
50 ****************************************************************************/
51
52 /* Array of IPC Event callback functions */
53 static void(*ipcex_callback_lookup[IPCEX_MAX_IDS]) (uint32_t);
54
55 /* Message QUEUE used by IPC library to exchange message between cores */
56 static ipcex_msg_t ipcex_queue[IPCEX_QUEUE_SZ];
57
58 /*****************************************************************************
59 * Public types/enumerations/variables
60 ****************************************************************************/
61
62 /*****************************************************************************
63 * Private functions
64 ****************************************************************************/
65
66 /* This task will receive the message from the other core
67 * and will invoke the appropriate callback with the message
68 */
69 static void ipcex_dispatch_task(void *loop)
70 {
71 int ret;
72 ipcex_msg_t msg;
73 do {
74 if (loop) {
75 ret = IPC_popMsg(&msg);
76 }
77 else {
78 ret = IPC_tryPopMsg(&msg);
79 }
80 if ((ret == QUEUE_VALID) && (msg.id < IPCEX_MAX_IDS)) {
81 if (ipcex_callback_lookup[msg.id]) {
82 ipcex_callback_lookup[msg.id](msg.data);
83 }
84 }
85 } while (loop);
86 }
87
88 /*****************************************************************************
89 * Public functions
90 ****************************************************************************/
91
92 /* IPC register callback function pointer */
93 int ipcex_register_callback(uint32_t id, void (*func)(uint32_t))
94 {
95 if (id >= IPCEX_MAX_IDS) {
96 return 0;
97 }
98
99 ipcex_callback_lookup[id] = func;
100 return 1;
101 }
102
103 /* IPC example implementation task */
104 void ipcex_tasks(void)
105 {
106 #ifdef OS_FREE_RTOS
107 /* Start Blinky event Task */
108 xTaskCreate(ipcex_dispatch_task, (signed char *) "IPC Ex",
109 configMINIMAL_STACK_SIZE, (void *) 1, TASK_PRIO_IPC_DISPATCH,
110 (xTaskHandle *) NULL);
111 #elif defined(OS_UCOS_III)
112 OS_ERR ret;
113 static OS_TCB mem_tcb;
114 static CPU_STK mem_stack[UCOS_MIN_STACK_SZ];
115
116 OSTaskCreate(
117 &mem_tcb,
118 "IPC Ex",
119 ipcex_dispatch_task,
120 (void *) 1,
121 TASK_PRIO_IPC_DISPATCH,
122 mem_stack,
123 32,
124 UCOS_MIN_STACK_SZ,
125 0,
126 0,
127 (void *) 0,
128 (OS_OPT) (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
129 (OS_ERR *) &ret);
130 if (ret != OS_ERR_NONE) {
131 DEBUGOUT("Unable to create IPC ex task : ret = %x\r\n", ret);
132 while (1) {}
133 }
134 #else
135 ipcex_dispatch_task(0);
136 #endif
137 }
138
139 /* Initialize the IPC queue */
140 void IPCEX_Init(void)
141 {
142 IPC_initMsgQueue(ipcex_queue, sizeof(ipcex_msg_t), IPCEX_QUEUE_SZ);
143 }
144
145 /* Push data on the queue */
146 int ipcex_msgPush(uint32_t id, uint32_t data)
147 {
148 ipcex_msg_t msg;
149 msg.id = id;
150 msg.data = data;
151 #if (defined(OS_FREE_RTOS) || defined(OS_UCOS_III))
152 return IPC_pushMsg(&msg);
153 #else
154 return IPC_tryPushMsg(&msg);
155 #endif
156 }
157