2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
31 * See http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html
\r
32 * for an introductory guide to using real time kernels, and FreeRTOS in
\r
37 * The DICE-KIT-16FX has two 7 segment displays and two buttons that can
\r
38 * generate interrupts. This example uses this IO as follows:
\r
41 * - Left 7 segment display -
\r
43 * 7 'flash' tasks are created, each of which toggles a single segment of the
\r
44 * left display. Each task executes at a fixed frequency, with a different
\r
45 * frequency being used by each task.
\r
47 * When button SW2 is pressed an interrupt is generated that wakes up a 'dice'
\r
48 * task. The dice task suspends the 7 tasks that are accessing the left display
\r
49 * before simulating a dice being thrown by generating a random number between
\r
50 * 1 and 6. After the number has been generated the task sleeps for 5 seconds,
\r
51 * if SW2 is pressed again within the 5 seconds another random number is
\r
52 * generated, if SW2 is not pressed within the 5 seconds then the 7 tasks are
\r
53 * un-suspended and will once again toggle the segments of the left hand display.
\r
56 * - Right 7 segment display -
\r
58 * Control of the right side 7 segment display is very similar to that of the
\r
59 * left, except co-routines are used to toggle the segments instead of tasks,
\r
60 * and button SW3 is used instead of SW2.
\r
65 * Only one dice task is actually defined. Two instances of this single
\r
66 * definition are created, the first to simulate a dice being thrown on the left
\r
67 * display, and the other to simulate a dice being thrown on the right display.
\r
68 * The task parameter is used to let the dice tasks know which display to
\r
71 * Both dice tasks and the flash tasks operate completely independently under
\r
72 * the control of FreeRTOS. 11 tasks and 7 co-routines are created in total,
\r
73 * including the idle task.
\r
75 * The co-routines all execute within a single low priority task.
\r
79 * When this demo is executing as expected:
\r
81 * + Every segment of both displays will toggle at a fixed frequency - with each
\r
82 * segment using a different frequency.
\r
83 * + When a button is pushed the segment toggling will temporarily stop and the
\r
84 * dice 'throw' will start whereby the display will show a fast changing random
\r
85 * number for a few seconds before the dice value is chosen and displayed.
\r
86 * + If the button is not pushed again within five seconds of the dice value being
\r
87 * displayed the segment toggling will commence again.
\r
91 /* Kernel includes. */
\r
92 #include "FreeRTOS.h"
\r
95 /* Demo includes. */
\r
96 #include "DiceTask.h"
\r
97 #include "ParTest.h"
\r
100 /* The priority at which the dice task execute. */
\r
101 #define mainDICE_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
104 * Sets up the MCU IO for the 7 segment displays and the button inputs.
\r
106 static void prvSetupHardware( void );
\r
109 * The function that creates the flash tasks and co-routines (the tasks and
\r
110 * co-routines that toggle the 7 segment display segments.
\r
112 extern vCreateFlashTasksAndCoRoutines( void );
\r
114 /*-----------------------------------------------------------*/
\r
118 /* Setup the MCU IO. */
\r
119 prvSetupHardware();
\r
121 /* Create the tasks and co-routines that toggle the display segments. */
\r
122 vCreateFlashTasksAndCoRoutines();
\r
124 /* Create a 'dice' task to control the left hand display. */
\r
125 xTaskCreate( vDiceTask, "Dice1", configMINIMAL_STACK_SIZE, ( void * ) configLEFT_DISPLAY, mainDICE_PRIORITY, NULL );
\r
127 /* Create a 'dice' task to control the right hand display. */
\r
128 xTaskCreate( vDiceTask, "Dice2", configMINIMAL_STACK_SIZE, ( void * ) configRIGHT_DISPLAY, mainDICE_PRIORITY, NULL );
\r
130 /* Start the scheduler running. */
\r
131 vTaskStartScheduler();
\r
133 /* If this loop is executed then there was insufficient heap memory for the
\r
134 idle task to be created - causing vTaskStartScheduler() to return. */
\r
137 /*-----------------------------------------------------------*/
\r
139 static void prvSetupHardware( void )
\r
141 /* Setup interrupt hardware - interrupts are kept disabled for now to
\r
142 prevent any interrupts attempting to cause a context switch before the
\r
143 scheduler has been started. */
\r
145 portDISABLE_INTERRUPTS();
\r
148 /* Set Port3 as output (7Segment Display). */
\r
151 /* Use Port 5 as I/O-Port. */
\r
155 /* Set Port5 as output (7Segment Display). */
\r
158 /* Disable inputs on the following ports. */
\r
170 /* Enable P00_0/INT8 and P00_1/INT9 as input. */
\r
173 /* Enable external interrupt 8. */
\r
176 /* LB0, LA0 = 11 -> falling edge. */
\r
180 /* Reset and enable the interrupt request. */
\r
184 /* Enable external interrupt 9. */
\r
187 /* LB1, LA1 = 11 -> falling edge. */
\r
191 /* Reset and enable the interrupt request. */
\r