1 /* --------------------------------------------------------------------------
2 * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 * Purpose: Example program
21 *---------------------------------------------------------------------------*/
25 #include "RTE_Components.h" // Component selection
26 #include CMSIS_device_header
28 #include "FreeRTOS.h" // Keil::RTOS:FreeRTOS:Core
29 #include "task.h" // Keil::RTOS:FreeRTOS:Core
31 TaskHandle_t tid_phaseA; /* Thread id of thread: phase_a */
32 TaskHandle_t tid_phaseB; /* Thread id of thread: phase_b */
33 TaskHandle_t tid_phaseC; /* Thread id of thread: phase_c */
34 TaskHandle_t tid_phaseD; /* Thread id of thread: phase_d */
35 TaskHandle_t tid_clock; /* Thread id of thread: clock */
45 /*----------------------------------------------------------------------------
46 * Function 'signal_func' called from multiple threads
47 *---------------------------------------------------------------------------*/
48 void signal_func (TaskHandle_t tid) {
49 xTaskNotify (tid_clock, 0x0100, eSetBits);/* set signal to clock thread */
50 vTaskDelay (500); /* delay 500ms */
51 xTaskNotify (tid_clock, 0x0100, eSetBits);/* set signal to clock thread */
52 vTaskDelay (500); /* delay 500ms */
53 xTaskNotify (tid, 0x0001, eSetBits); /* set signal to thread 'thread' */
54 vTaskDelay (500); /* delay 500ms */
57 /*----------------------------------------------------------------------------
58 * Thread 1 'phaseA': Phase A output
59 *---------------------------------------------------------------------------*/
60 void phaseA (void *argument) {
62 xTaskNotifyWait (0, 0x0001, NULL, portMAX_DELAY); /* wait for an thread flag */
64 signal_func(tid_phaseB); /* call signal function */
69 /*----------------------------------------------------------------------------
70 * Thread 2 'phaseB': Phase B output
71 *---------------------------------------------------------------------------*/
72 void phaseB (void *argument) {
74 xTaskNotifyWait (0, 0x0001, NULL, portMAX_DELAY); /* wait for an thread flag */
76 signal_func(tid_phaseC); /* call signal function */
81 /*----------------------------------------------------------------------------
82 * Thread 3 'phaseC': Phase C output
83 *---------------------------------------------------------------------------*/
84 void phaseC (void *argument) {
86 xTaskNotifyWait (0, 0x0001, NULL, portMAX_DELAY); /* wait for an thread flag */
88 signal_func(tid_phaseD); /* call signal function */
93 /*----------------------------------------------------------------------------
94 * Thread 4 'phaseD': Phase D output
95 *---------------------------------------------------------------------------*/
96 void phaseD (void *argument) {
98 xTaskNotifyWait (0, 0x0001, NULL, portMAX_DELAY); /* wait for an thread flag */
100 signal_func(tid_phaseA); /* call signal function */
105 /*----------------------------------------------------------------------------
106 * Thread 5 'clock': Signal Clock
107 *---------------------------------------------------------------------------*/
108 void clock (void *argument) {
110 xTaskNotifyWait (0, 0x0100, NULL, portMAX_DELAY); /* wait for an thread flag */
111 vTaskDelay(80); /* delay 80ms */
115 /*----------------------------------------------------------------------------
116 * Initialize and start threads
117 *---------------------------------------------------------------------------*/
118 void app_main (void *argument) {
120 xTaskCreate (phaseA, "PhaseA", 64, NULL, tskIDLE_PRIORITY+1, &tid_phaseA);
121 xTaskCreate (phaseB, "PhaseB", 64, NULL, tskIDLE_PRIORITY+1, &tid_phaseB);
122 xTaskCreate (phaseC, "PhaseC", 64, NULL, tskIDLE_PRIORITY+1, &tid_phaseC);
123 xTaskCreate (phaseD, "PhaseD", 64, NULL, tskIDLE_PRIORITY+1, &tid_phaseD);
124 xTaskCreate (clock, "Clock", 64, NULL, tskIDLE_PRIORITY+1, &tid_clock);
126 xTaskNotify (tid_phaseA, 0x0001, eSetBits); /* set signal to phaseA thread */
128 vTaskDelay (portMAX_DELAY);
133 SystemCoreClockUpdate();
135 xTaskCreate (app_main, "app_main", 64, NULL, tskIDLE_PRIORITY+1, NULL);
137 vTaskStartScheduler();