LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Related Pages
Modules
Data Structures
Files
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
60
/*****************************************************************************
61
* Private types/enumerations/variables
62
****************************************************************************/
63
64
/* Macro that calculates the start address of M0 image */
65
#define M0_IMAGE_ADDR (IMAGE_BASE_ADDR + M0_IMAGE_OFFSET)
66
67
/*****************************************************************************
68
* Public types/enumerations/variables
69
****************************************************************************/
70
71
/*****************************************************************************
72
* Private functions
73
****************************************************************************/
74
75
/* initialization routine for dual core examples */
76
static
void
prvSetupHardware
(
void
)
77
{
78
#ifdef CORE_M4
79
/* Re-initialize CGU for proper operation */
80
Board_Init
();
81
Board_LED_Init
();
82
83
/* Time to Start M0 */
84
if
(
M0Image_Boot
((
uint32_t
)
M0_IMAGE_ADDR
) < 0) {
85
while
(1) {
86
__WFI();
87
}
88
}
89
MSleep
(100);
90
#elif defined(CORE_M0)
91
extern
void
prvSetupTimerInterrupt(
void
);
92
93
/* Needs to be called coz durinig initializtion the
94
* global variable would have initialized to 0
95
*/
96
SystemCoreClockUpdate
();
97
98
#ifdef OS_FREE_RTOS
99
/* Disable global interrupts */
100
taskDISABLE_INTERRUPTS();
101
prvSetupTimerInterrupt();
102
#endif
103
#endif
104
105
/* Initialize the IPC Queue */
106
IPCEX_Init
();
107
108
#ifdef EXAMPLE_USB_HOST
109
USBHOST_Init
();
110
#endif
111
#ifdef EXAMPLE_USB_DEVICE
112
USBDEV_Init
();
113
#endif
114
#ifdef EXAMPLE_LWIP
115
LWIP_Init
();
116
#endif
117
#ifdef EXAMPLE_EMWIN
118
EMWIN_Init
();
119
#endif
120
#ifdef EXAMPLE_BLINKY
121
BLINKY_Init
();
122
#endif
123
}
124
125
/* Main tasks of LPC43xx Dual core examples */
126
static
void
main_tasks
(
void
)
127
{
128
#if (defined(OS_FREE_RTOS) || defined(OS_UCOS_III))
129
const
int
loop = 0;
130
#else
131
const
int
loop = 1;
132
#endif
133
134
#ifdef OS_UCOS_III
135
// extern void OS_CSP_TickInit(void);
136
OS_ERR ret;
137
OSInit(&ret);
138
if
(ret != OS_ERR_NONE) {
139
DEBUGSTR
(
"Unable init UCOS-III OS!\r\n"
);
140
while
(1) {}
141
}
142
#endif
143
144
do
{
145
ipcex_tasks
();
146
#ifdef EXAMPLE_BLINKY
147
blinky_tasks
();
148
#endif
149
#ifdef EXAMPLE_USB_HOST
150
usb_host_tasks
();
151
#endif
152
#ifdef EXAMPLE_USB_DEVICE
153
usb_device_tasks
();
154
#endif
155
#ifdef EXAMPLE_LWIP
156
lwip_tasks
();
157
#endif
158
#ifdef EXAMPLE_EMWIN
159
emwin_tasks
();
160
#endif
161
}
while
(loop);
162
163
#ifdef OS_FREE_RTOS
164
/* Start the scheduler */
165
vTaskStartScheduler();
166
#endif
167
168
#ifdef OS_UCOS_III
169
// OS_CSP_TickInit();
170
OSStart(&ret);
171
if
(ret != OS_ERR_NONE) {
172
DEBUGSTR
(
"Unable start UCOS-III OS!\r\n"
);
173
while
(1) {}
174
}
175
#endif
176
177
/* Control should never come here */
178
DEBUGSTR
(
"Schedule Failure\r\n"
);
179
while
(1) {}
180
}
181
182
/*****************************************************************************
183
* Public functions
184
****************************************************************************/
185
/* Milli-second sleep function */
186
void
MSleep
(int32_t msecs)
187
{
188
int32_t curr = (int32_t)
Chip_RIT_GetCounter
();
189
int32_t
final
= curr + ((
SystemCoreClock
/ 1000) * msecs);
190
191
/* If the value is zero let us not worry about it */
192
if
(!msecs || (msecs < 0)) {
193
return
;
194
}
195
196
if
((
final
< 0) && (curr > 0)) {
197
while
(
Chip_RIT_GetCounter
() < (
uint32_t
)
final
) {}
198
}
199
else
{
200
while
((int32_t)
Chip_RIT_GetCounter
() <
final
) {}
201
}
202
}
203
213
int
main
(
void
)
214
{
215
prvSetupHardware
();
216
#ifdef CORE_M0
217
DEBUGSTR
(
"Starting M0 Tasks...\r\n"
);
218
#else
219
DEBUGSTR
(
"Starting M4 Tasks...\r\n"
);
220
#endif
221
main_tasks
();
222
return
0;
223
}
224
applications
lpc18xx_43xx
examples
43xx_dualcore
common
main.c
Generated on Fri Nov 16 2012 13:36:32 for LPCOpen Platform by
1.8.2