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
dualcore_blinky.c
Go to the documentation of this file.
1
/*
2
* @brief Blinky Example using Dual Core communication
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
/* The configuration file must use <filename> format
33
* since, this source file is shared across projects
34
*/
35
#include "lpc43xx_dualcore_config.h"
36
#include "
ipc_msg.h
"
37
#include "
ipc_example.h
"
38
39
#ifdef OS_FREE_RTOS
40
#include "FreeRTOS.h"
41
#include "task.h"
42
43
#elif defined(OS_UCOS_III)
44
#include "
os.h
"
45
46
#else
47
/* No OS configuration */
48
#endif
49
102
/*****************************************************************************
103
* Private types/enumerations/variables
104
****************************************************************************/
105
106
/* Delay to be used for blinking the LEDs */
107
static
const
uint32_t
xDelay
= BLINKY_DEFAULT_DELAY;
108
109
static
void
LED_Event_Task
(
void
*loop);
110
111
112
/*****************************************************************************
113
* Public types/enumerations/variables
114
****************************************************************************/
115
116
/*****************************************************************************
117
* Private functions
118
****************************************************************************/
119
120
#ifdef OS_FREE_RTOS
121
/* Delay function used for blinking LED (FreeRTOS version)
122
* Calling this function will cause a delay of \a xDelay
123
* returns 0 when the time has lapsed else non zero
124
*/
125
static
int
blink_delay
(
void
)
126
{
127
vTaskDelay(
xDelay
);
128
return
0;
129
}
130
131
#elif defined(OS_UCOS_III)
132
/* Delay function used for blinking LED (uCOS-III Version) */
133
static
int
blink_delay
(
void
)
134
{
135
OS_ERR
ret;
136
OSTimeDlyHMSM(0, 0,
xDelay
/ 1000,
xDelay
% 1000,
OS_OPT_TIME_HMSM_STRICT
, &ret);
137
return
ret !=
OS_ERR_NONE
;
138
}
139
140
#else
141
142
/* Delay function used for blinking LED (noOS version) */
143
static
int
blink_delay
(
void
)
144
{
145
static
int32_t
final
, init;
146
if
(!init) {
147
int32_t curr = (int32_t)
Chip_RIT_GetCounter
(
LPC_RITIMER
);
148
final
= curr + (
SystemCoreClock
/ 1000) *
xDelay
;
149
init = 1 + (final < 0 && curr > 0);
150
}
151
152
if
((init == 2 &&
Chip_RIT_GetCounter
(
LPC_RITIMER
) >= (
uint32_t
)
final
) ||
153
(init == 1 && (int32_t)
Chip_RIT_GetCounter
(
LPC_RITIMER
) >=
final
)) {
154
init = 0;
155
}
156
return
init != 0;
157
}
158
#endif
159
160
/* Blink LED based on event from M0/M4
161
* This function when called from M0 will blink the LED
162
* based on message sent by M4 and vice-versa.
163
*/
164
static
void
LED_blinkProc
(
uint32_t
val)
165
{
166
Board_LED_Set
((val >> 16) & 0xFFFF, val & 0xFFFF);
167
}
168
169
/* Send blink event to M4/M0 from M0/M4
170
* This function if called from M4 will send the blink
171
* event to M0 and vice-versa.
172
*/
173
static
void
LED_Event_Task
(
void
*loop)
174
{
175
static
int
blink = 0;
176
177
do
{
178
if
(!
blink_delay
()) {
179
if
(
ipcex_msgPush
(
IPCEX_ID_BLINKY
, (BLINK_LED << 16) | blink) ==
QUEUE_INSERT
)
180
blink = 1 - blink;
181
}
182
}
while
(loop);
183
}
184
185
/*****************************************************************************
186
* Public functions
187
****************************************************************************/
188
189
#ifdef OS_FREE_RTOS
190
/* FreeRTOS blinky task */
191
void
blinky_tasks
(
void
)
192
{
193
/* Start Blinky event Task */
194
xTaskCreate(
LED_Event_Task
, (
signed
char
* )
"LED Event"
,
195
configMINIMAL_STACK_SIZE
, (
void
*)1,
TASK_PRIO_BLINKY_EVENT
,
196
( xTaskHandle * )
NULL
);
197
}
198
199
#elif defined(OS_UCOS_III)
200
201
/* uCOS-III Blinky Task */
202
void
blinky_tasks
(
void
)
203
{
204
OS_ERR
ret;
205
static
OS_TCB
mem_tcb
;
206
static
CPU_STK
mem_stack
[
UCOS_MIN_STACK_SZ
];
207
208
OSTaskCreate
(
209
&mem_tcb,
210
"Event Tsk"
,
211
LED_Event_Task
,
212
(
void
*) 1,
213
TASK_PRIO_BLINKY_EVENT
,
214
mem_stack,
215
APP_CFG_TASK_START_STK_SIZE_LIMIT
,
216
UCOS_MIN_STACK_SZ
,
217
0,
218
0,
219
(
void
*)0,
220
(
OS_OPT
)(
OS_OPT_TASK_STK_CHK
|
OS_OPT_TASK_STK_CLR
),
221
(
OS_ERR
*)&ret);
222
if
(ret !=
OS_ERR_NONE
) {
223
printf(
"Unable to create event task!\r\n"
);
224
while
(1);
225
}
226
}
227
228
#else
229
/* Dual core blinky standalone task calling function */
230
void
blinky_tasks
(
void
)
231
{
232
LED_Event_Task
((
void
*) 0);
233
}
234
#endif
235
236
/* Initialization for Blinky dual core example */
237
void
BLINKY_Init
(
void
)
238
{
239
ipcex_register_callback
(
IPCEX_ID_BLINKY
,
LED_blinkProc
);
240
}
241
applications
lpc18xx_43xx
examples
dualcore_43xx
Blinky
dualcore_blinky.c
Generated on Fri May 10 2013 10:42:00 for LPCOpen Platform by
1.8.2