LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
example_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  */
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 
93 /*****************************************************************************
94  * Private types/enumerations/variables
95  ****************************************************************************/
96 
97 /* Delay to be used for blinking the LEDs */
98 static const uint32_t xDelay = BLINKY_DEFAULT_DELAY;
99 
100 static void LED_Event_Task(void *loop);
101 
102 
103 /*****************************************************************************
104  * Public types/enumerations/variables
105  ****************************************************************************/
106 
107 /*****************************************************************************
108  * Private functions
109  ****************************************************************************/
110 
111 #ifdef OS_FREE_RTOS
112 /* Delay function used for blinking LED (FreeRTOS version)
113  * Calling this function will cause a delay of \a xDelay
114  * returns 0 when the time has lapsed else non zero
115  */
116 static int blink_delay(void)
117 {
118  vTaskDelay(xDelay);
119  return 0;
120 }
121 
122 #elif defined(OS_UCOS_III)
123 /* Delay function used for blinking LED (uCOS-III Version) */
124 static int blink_delay(void)
125 {
126  OS_ERR ret;
127  OSTimeDlyHMSM(0,0,xDelay/1000,xDelay%1000,OS_OPT_TIME_HMSM_STRICT,&ret);
128  return ret != OS_ERR_NONE;
129 }
130 
131 #else
132 
133 /* Delay function used for blinking LED (noOS version) */
134 static int blink_delay(void)
135 {
136  static int32_t final, init;
137  if (!init) {
138  int32_t curr = (int32_t) Chip_RIT_GetCounter();
139  final = curr + (SystemCoreClock / 1000) * xDelay;
140  init = 1 + (final < 0 && curr > 0);
141  }
142 
143  if ((init == 2 && Chip_RIT_GetCounter() >= (uint32_t) final) ||
144  (init == 1 && (int32_t) Chip_RIT_GetCounter() >= final)) {
145  init = 0;
146  }
147  return init != 0;
148 }
149 #endif
150 
151 /* Blink LED based on event from M0/M4
152  * This function when called from M0 will blink the LED
153  * based on message sent by M4 and vice-versa.
154  */
155 static void LED_blinkProc(uint32_t val)
156 {
157  Board_LED_Set((val >> 16) & 0xFFFF, val & 0xFFFF);
158 }
159 
160 /* Send blink event to M4/M0 from M0/M4
161  * This function if called from M4 will send the blink
162  * event to M0 and vice-versa.
163  */
164 static void LED_Event_Task(void *loop)
165 {
166  static int blink = 0;
167 
168 #if defined(OS_UCOS_III)
169  OS_CSP_TickInit();
170 #endif
171 
172  do {
173  if (!blink_delay()) {
174  if (ipcex_msgPush(IPCEX_ID_BLINKY, (BLINK_LED << 16) | blink) == QUEUE_INSERT)
175  blink = 1 - blink;
176  }
177  } while(loop);
178 }
179 
180 /*****************************************************************************
181  * Public functions
182  ****************************************************************************/
183 
184 #ifdef OS_FREE_RTOS
185 /* FreeRTOS blinky task */
186 void blinky_tasks(void)
187 {
188  /* Start Blinky event Task */
189  xTaskCreate( LED_Event_Task, ( signed char * ) "LED Event",
191  ( xTaskHandle * ) NULL );
192 }
193 
194 #elif defined(OS_UCOS_III)
195 
196 /* uCOS-III Blinky Task */
197 void blinky_tasks(void)
198 {
199  OS_ERR ret;
200  static OS_TCB mem_tcb;
201  static CPU_STK mem_stack[UCOS_MIN_STACK_SZ];
202 
203  OSTaskCreate (
204  &mem_tcb,
205  "Event Tsk",
207  (void *) 1,
209  mem_stack,
210  32,
212  0,
213  0,
214  (void *)0,
215  (OS_OPT)(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
216  (OS_ERR *)&ret);
217  if (ret != OS_ERR_NONE) {
218  printf("Unable to create event task!\r\n");
219  while (1);
220  }
221 }
222 
223 #else
224 /* Dual core blinky standalone task calling function */
225 void blinky_tasks(void)
226 {
227  LED_Event_Task((void *) 0);
228 }
229 #endif
230 
231 /* Initialization for Blinky dual core example */
232 void BLINKY_Init(void)
233 {
235 }
236