| 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
main.c
Go to the documentation of this file.
1 /*
2 * @brief Startup/Main file for Dual core demos
3 *
4 * Startup file (having reset and main routines)
5 * This file provides functions necessary to start all the example tasks
6 * based on the configuration.
7 *
8 * @note
9 * Copyright(C) NXP Semiconductors, 2012
10 * All rights reserved.
11 *
12 * @par
13 * Software that is described herein is for illustrative purposes only
14 * which provides customers with programming information regarding the
15 * LPC products. This software is supplied "AS IS" without any warranties of
16 * any kind, and NXP Semiconductors and its licensor disclaim any and
17 * all warranties, express or implied, including all implied warranties of
18 * merchantability, fitness for a particular purpose and non-infringement of
19 * intellectual property rights. NXP Semiconductors assumes no responsibility
20 * or liability for the use of the software, conveys no license or rights under any
21 * patent, copyright, mask work right, or any other intellectual property rights in
22 * or to any products. NXP Semiconductors reserves the right to make changes
23 * in the software without notification. NXP Semiconductors also makes no
24 * representation or warranty that such application will be suitable for the
25 * specified use without further testing or modification.
26 *
27 * @par
28 * Permission to use, copy, modify, and distribute this software and its
29 * documentation is hereby granted, under NXP Semiconductors' and its
30 * licensor's relevant copyrights in the software, without fee, provided that it
31 * is used in conjunction with NXP Semiconductors microcontrollers. This
32 * copyright, permission, and disclaimer notice must appear in all copies of
33 * this code.
34 */
35
36 /* General includes */
37 #include <stdio.h>
38 #include "lpc43xx_dualcore_config.h"
39 #include "ipc_msg.h"
40
41 #if defined(OS_FREE_RTOS)
42 #include "FreeRTOS.h"
43 #include "task.h"
44
45 #elif defined(OS_UCOS_III)
46 #include "os.h"
47 #endif
48
75 /*****************************************************************************
76 * Private types/enumerations/variables
77 ****************************************************************************/
78
79 /* Macro that calculates the start address of M0 image */
80 #define M0_IMAGE_ADDR (IMAGE_BASE_ADDR + M0_IMAGE_OFFSET)
81
82 /*****************************************************************************
83 * Public types/enumerations/variables
84 ****************************************************************************/
85
86 /*****************************************************************************
87 * Private functions
88 ****************************************************************************/
89
90 #ifdef OS_UCOS_III
91 /* UCOS-III Idle task hook */
92 static void APP_Task_Idle_Hook(void)
93 {
94 __WFI();
95 }
96 #endif
97
98 /* initialization routine for dual core examples */
99 static void prvSetupHardware(void)
100 {
101 #ifdef CORE_M4
102 /* Re-initialize CGU for proper operation */
103 Board_Init();
104
105 /* Time to Start M0 */
106 if (M0Image_Boot((uint32_t) M0_IMAGE_ADDR) < 0) {
107 while (1) {
108 __WFI();
109 }
110 }
111 MSleep(100);
112 #elif defined(CORE_M0)
113 extern void prvSetupTimerInterrupt(void);
114
115 /* Needs to be called coz durinig initializtion the
116 * global variable would have initialized to 0
117 */
118 SystemCoreClockUpdate();
119
120 #ifdef OS_FREE_RTOS
121 /* Disable global interrupts */
122 taskDISABLE_INTERRUPTS();
123 prvSetupTimerInterrupt();
124 #endif
125 #endif
126 #ifdef OS_UCOS_III
127 do {
128 extern void OS_CSP_TickInit(void);
129 OS_ERR ret;
130
131 CPU_IntDis();
132 CPU_Init();
133 OSInit(&ret);
134 if (ret != OS_ERR_NONE) {
135 DEBUGSTR("Unable init UCOS-III OS!\r\n");
136 while (1) {}
137 }
138 OS_CSP_TickInit();
139 OS_AppIdleTaskHookPtr = APP_Task_Idle_Hook;
140 } while(0);
141 #endif
142 /* Initialize the IPC Queue */
143 IPCEX_Init();
144
145 #ifdef EXAMPLE_USB_HOST
146 USBHOST_Init();
147 #endif
148 #ifdef EXAMPLE_USB_DEVICE
149 USBDEV_Init();
150 #endif
151 #ifdef EXAMPLE_LWIP
152 LWIP_Init();
153 #endif
154 #ifdef EXAMPLE_EMWIN
155 EMWIN_Init();
156 #endif
157 #ifdef EXAMPLE_BLINKY
158 BLINKY_Init();
159 #endif
160 }
161
162 /* Main tasks of LPC43xx Dual core examples */
163 static void main_tasks(void)
164 {
165 #if (defined(OS_FREE_RTOS) || defined(OS_UCOS_III))
166 const int loop = 0;
167 #else
168 const int loop = 1;
169 #endif
170
171 do {
172 ipcex_tasks();
173 #ifdef EXAMPLE_BLINKY
174 blinky_tasks();
175 #endif
176 #ifdef EXAMPLE_USB_HOST
177 usb_host_tasks();
178 #endif
179 #ifdef EXAMPLE_USB_DEVICE
180 usb_device_tasks();
181 #endif
182 #ifdef EXAMPLE_LWIP
183 lwip_tasks();
184 #endif
185 #ifdef EXAMPLE_EMWIN
186 emwin_tasks();
187 #endif
188 } while (loop);
189
190 #ifdef OS_FREE_RTOS
191 /* Start the scheduler */
192 vTaskStartScheduler();
193 #endif
194
195 #ifdef OS_UCOS_III
196 do {
197 OS_ERR ret;
198 OSStart(&ret);
199 if (ret != OS_ERR_NONE) {
200 DEBUGSTR("Unable start UCOS-III OS!\r\n");
201 while (1) {}
202 }
203 } while(0);
204 #endif
205
206 /* Control should never come here */
207 DEBUGSTR("Schedule Failure\r\n");
208 while (1) {}
209 }
210
211 /*****************************************************************************
212 * Public functions
213 ****************************************************************************/
214 /* Milli-second sleep function */
215 void MSleep(int32_t msecs)
216 {
217 int32_t curr = (int32_t) Chip_RIT_GetCounter(LPC_RITIMER);
218 int32_t final = curr + ((SystemCoreClock / 1000) * msecs);
219
220 /* If the value is zero let us not worry about it */
221 if (!msecs || (msecs < 0)) {
222 return;
223 }
224
225 if ((final < 0) && (curr > 0)) {
226 while (Chip_RIT_GetCounter(LPC_RITIMER) < (uint32_t) final) {}
227 }
228 else {
229 while ((int32_t) Chip_RIT_GetCounter(LPC_RITIMER) < final) {}
230 }
231 }
232
242 int main(void)
243 {
244 prvSetupHardware();
245 #ifdef CORE_M0
246 DEBUGSTR("Starting M0 Tasks...\r\n");
247 #else
248 DEBUGSTR("Starting M4 Tasks...\r\n");
249 #endif
250 main_tasks();
251 return 0;
252 }
253