LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ucos_iii_blinky.c
Go to the documentation of this file.
1 /*
2  * @brief Blinky example
3  *
4  * uC/OS-III 'blinky' example. Creates several LED blink threads and
5  * a UART output thread that ticks at about 1Hz.
6  *
7  * @note
8  * Copyright(C) NXP Semiconductors, 2012
9  * All rights reserved.
10  *
11  * @par
12  * Software that is described herein is for illustrative purposes only
13  * which provides customers with programming information regarding the
14  * LPC products. This software is supplied "AS IS" without any warranties of
15  * any kind, and NXP Semiconductors and its licensor disclaim any and
16  * all warranties, express or implied, including all implied warranties of
17  * merchantability, fitness for a particular purpose and non-infringement of
18  * intellectual property rights. NXP Semiconductors assumes no responsibility
19  * or liability for the use of the software, conveys no license or rights under any
20  * patent, copyright, mask work right, or any other intellectual property rights in
21  * or to any products. NXP Semiconductors reserves the right to make changes
22  * in the software without notification. NXP Semiconductors also makes no
23  * representation or warranty that such application will be suitable for the
24  * specified use without further testing or modification.
25  *
26  * @par
27  * Permission to use, copy, modify, and distribute this software and its
28  * documentation is hereby granted, under NXP Semiconductors' and its
29  * licensor's relevant copyrights in the software, without fee, provided that it
30  * is used in conjunction with NXP Semiconductors microcontrollers. This
31  * copyright, permission, and disclaimer notice must appear in all copies of
32  * this code.
33  */
34 
35 #include "board.h"
36 #include "os.h"
37 
74 /*****************************************************************************
75  * Private types/enumerations/variables
76  ****************************************************************************/
77 
82 
83 /*****************************************************************************
84  * Public types/enumerations/variables
85  ****************************************************************************/
86 
87 /*****************************************************************************
88  * Private functions
89  ****************************************************************************/
90 
91 extern void OS_CSP_TickInit(void);
92 
93 /* Sets up system hardware */
94 static void prvSetupHardware(void)
95 {
96  Board_Init();
97 
98  /* Initial LED0 state is off */
99  Board_LED_Set(0, false);
100 }
101 
102 /* LED2 toggle thread */
103 static void vLEDTask2(void *p_arg)
104 {
105  OS_ERR err;
106  bool LedState = true;
107 
108  while (1) {
109  Board_LED_Set(1, LedState);
110  LedState = (bool) !LedState;
111 
112  /* About a 7Hz on/off toggle rate */
113  OSTimeDlyHMSM(0u, 0u, 0u, 71u, OS_OPT_TIME_HMSM_STRICT, &err);
114  }
115 }
116 
117 /* UART (or output) thread */
118 static void vUARTTask(void *p_arg)
119 {
120  OS_ERR err;
121  int tickCnt = 0;
122 
123  while (1) {
124  DEBUGOUT("Tick: %d\r\n", tickCnt);
125  tickCnt++;
126 
127  /* About a 1s delay here */
128  OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &err);
129  }
130 }
131 
132 /* LED1 toggle thread */
133 static void vLEDTask1(void *p_arg)
134 {
135  OS_ERR os_err;
136  bool LedState = true;
137 
138  /* Start tick */
139  OS_CSP_TickInit();
140 
141  /* Other tasks */
142  OSTaskCreate( (OS_TCB *) &vLEDTask2TCB,
143  (CPU_CHAR *) "vLEDTask2",
145  (void *) 0,
147  (CPU_STK *) vLEDTask2Stk,
150  (OS_MSG_QTY) 0u,
151  (OS_TICK) 0u,
152  (void *) 0,
154  (OS_ERR *) &os_err);
155  OSTaskCreate( (OS_TCB *) &vUARTTaskTCB,
156  (CPU_CHAR *) "vUARTTask",
158  (void *) 0,
160  (CPU_STK *) vUARTTaskStk,
161  (CPU_STK_SIZE) APP_CFG_TASK_START_STK_SIZE_LIMIT,
162  (CPU_STK_SIZE) APP_CFG_TASK_START_STK_SIZE,
163  (OS_MSG_QTY) 0u,
164  (OS_TICK) 0u,
165  (void *) 0,
167  (OS_ERR *) &os_err);
168 
169  while (1) {
170  Board_LED_Set(0, LedState);
171  LedState = (bool) !LedState;
172 
173  /* About a 3Hz on/off toggle rate */
174  OSTimeDlyHMSM(0u, 0u, 0u, 156u, OS_OPT_TIME_HMSM_STRICT, &os_err);
175  }
176 }
177 
178 /*****************************************************************************
179  * Public functions
180  ****************************************************************************/
181 
186 int main(void)
187 {
188  OS_ERR os_err;
189 
191 
192  CPU_Init();
193 
194  OSInit(&os_err);
195 
196  OSTaskCreate( (OS_TCB *) &vLEDTask1TCB,
197  (CPU_CHAR *) "vLEDTask1",
199  (void *) 0,
201  (CPU_STK *) vLEDTask1Stk,
204  (OS_MSG_QTY) 0u,
205  (OS_TICK) 0u,
206  (void *) 0,
208  (OS_ERR *) &os_err);
209 
210  OSStart(&os_err);
211 
212  (void) &os_err;
213 
214  return 0;
215 }
216