| 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
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
73 // FIXME - needs standards formatting
74
75 static OS_TCB vLEDTask1TCB, vLEDTask2TCB, vUARTTaskTCB;
76 static CPU_STK vLEDTask1Stk[APP_CFG_TASK_START_STK_SIZE];
77 static CPU_STK vLEDTask2Stk[APP_CFG_TASK_START_STK_SIZE];
78 static CPU_STK vUARTTaskStk[APP_CFG_TASK_START_STK_SIZE];
79 extern void OS_CSP_TickInit(void);
80
81 /* Sets up system hardware */
82 static void prvSetupHardware(void)
83 {
84 Board_Init();
85
86 /* Initial LED0 state is off */
87 Board_LED_Set(0, false);
88 }
89
90 /* LED2 toggle thread */
91 static void vLEDTask2 (void *p_arg)
92 {
93 OS_ERR err;
94 bool LedState = true;
95
96 while (1) {
97 Board_LED_Set(1, LedState);
98 LedState = (bool) !LedState;
99
100 /* About a 7Hz on/off toggle rate */
101 OSTimeDlyHMSM(0u, 0u, 0u, 71u, OS_OPT_TIME_HMSM_STRICT, &err);
102 }
103 }
104
105 /* UART (or output) thread */
106 static void vUARTTask (void *p_arg)
107 {
108 OS_ERR err;
109 int tickCnt = 0;
110
111 while (1) {
112 DEBUGOUT("Tick: %d\r\n", tickCnt);
113 tickCnt++;
114
115 /* About a 1s delay here */
116 OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &err);
117 }
118 }
119
120 /* LED1 toggle thread */
121 static void vLEDTask1 (void *p_arg)
122 {
123 OS_ERR os_err;
124 bool LedState = true;
125
126 /* Start tick */
127 OS_CSP_TickInit();
128
129 /* Other tasks */
130 OSTaskCreate( (OS_TCB *)&vLEDTask2TCB,
131 (CPU_CHAR *)"vLEDTask2",
132 (OS_TASK_PTR )vLEDTask2,
133 (void *)0,
134 (OS_PRIO )APP_CFG_TASK_START_PRIO + 1,
135 (CPU_STK *)vLEDTask2Stk,
136 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE_LIMIT,
137 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
138 (OS_MSG_QTY )0u,
139 (OS_TICK )0u,
140 (void *)0,
141 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
142 (OS_ERR *)&os_err);
143 OSTaskCreate( (OS_TCB *)&vUARTTaskTCB,
144 (CPU_CHAR *)"vUARTTask",
145 (OS_TASK_PTR )vUARTTask,
146 (void *)0,
147 (OS_PRIO )APP_CFG_TASK_START_PRIO + 2,
148 (CPU_STK *)vUARTTaskStk,
149 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE_LIMIT,
150 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
151 (OS_MSG_QTY )0u,
152 (OS_TICK )0u,
153 (void *)0,
154 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
155 (OS_ERR *)&os_err);
156
157 while (1) {
158 Board_LED_Set(0, LedState);
159 LedState = (bool) !LedState;
160
161 /* About a 3Hz on/off toggle rate */
162 OSTimeDlyHMSM(0u, 0u, 0u, 156u, OS_OPT_TIME_HMSM_STRICT, &os_err);
163 }
164 }
165
170 int main(void)
171 {
172 OS_ERR os_err;
173
174 prvSetupHardware();
175
176 CPU_Init();
177
178 OSInit(&os_err);
179
180 OSTaskCreate( (OS_TCB *)&vLEDTask1TCB,
181 (CPU_CHAR *)"vLEDTask1",
182 (OS_TASK_PTR )vLEDTask1,
183 (void *)0,
184 (OS_PRIO )APP_CFG_TASK_START_PRIO,
185 (CPU_STK *)vLEDTask1Stk,
186 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE_LIMIT,
187 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
188 (OS_MSG_QTY )0u,
189 (OS_TICK )0u,
190 (void *)0,
191 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
192 (OS_ERR *)&os_err);
193
194 OSStart(&os_err);
195
196 (void) &os_err;
197
198 return 0;
199 }
200