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